add buddy to the buddy list

Kamanashis Roy Shuva kamanashisroy at gmail.com
Thu Aug 2 10:33:32 EDT 2007


May be I should change the subject.

*My main problem is that I cannot find a way to send invitation request to
the chat servers to add a buddy to the buddy list.  *

Is there any abstract / protocol independent way to send this request ? Or
am I thinking wrong to need that ?


On 7/31/07, Kamanashis Roy Shuva <kamanashisroy at gmail.com> wrote:
> Hi,
>
>   I have wrote a purple based server that connects to the im servers
> and sends ims. At first I send the im to the buddies. But the messages
> did not reach in the remote end. Then I added the "purple based server
> accounts" at the remote buddy list. And then I was able to get the
> messages sent from this program.
>
>   To send im to new buddy , I have first added the buddy to the buddy
> list. And then sent the message. But the remote end got a request to
> add buddy only for msn account. So I failed to register buddy in the
> server. For more information I also initiated the buddylist system.
>
>    So is there any way to send request for adding buddy? Or is there
> any way that I can use buddy from database ?
>
>    Here are some important parts of my code,
>
>
> static void add_newone(PurpleAccount *account, const char *username,
> const char *group, const char *alias) {
>         PurpleGroup *grp;
>         PurpleBuddy *buddy;
>
>         /* see if the buddy is already there */
>         if(purple_find_buddy( account, username)) {
>                 return;
>         }
>
>         grp = purple_find_group(group);
>         if (!grp) {
>                 /* creating a new group */
>                 grp = purple_group_new(group);
>                 purple_blist_add_group(grp, NULL);
>         }
>         buddy = purple_buddy_new(account, username, alias);
>         purple_blist_add_buddy(buddy, NULL, grp, NULL);
>         purple_account_add_buddy(account, buddy);
>         ECHOC("added buddy %s in account
> %s\n",username,purple_account_get_username(account));
> }
>
> static void nullclient_permit_anyone(PurpleAccount *account, const
> char *username, const char *group, const char *alias) {
>         ECHOC("request accepted for buddy %s in account
> %s\n",username,purple_account_get_username(account));
>         add_newone(account, username, group, alias);
> }
>
> static PurpleBlistUiOps blist_ui_ops =
> {
>   ._purple_reserved1 = NULL,
>   ._purple_reserved2 = NULL,
>   ._purple_reserved3 = NULL,
>   ._purple_reserved4 = NULL,
>   .destroy = NULL,
>   .new_list = NULL,
>   .new_node = NULL,
>   .remove = NULL,
>   .request_add_buddy = nullclient_permit_anyone,
>   .request_add_chat = NULL,
>   .request_add_group = NULL,
>   .set_visible = NULL,
>   .show = NULL,
>   .update = NULL,
> };
>
>
> void nullclient_init()
> {
>         /* initiate libpurple */
>         init_libpurple();
>         /* TODO: create a hashtable */
>         // message_list = g_hash_table_new(a,b);
>         /* set ui options */
>         purple_blist_set_ui_ops(&blist_ui_ops);
>         /* initiate buddy list */
>         purple_blist_init();
>         /* initiate conversation system */
>         purple_conversations_init();
>         /* initiate accounts subsystem */
>         purple_accounts_init();
>         /* activate all accounts */
>         nullclient_activate_all_accounts();
>         /* enable debug */
>         //purple_debug_set_ui_ops(&debug_opt);
>         purple_debug_set_enabled(FALSE);
>         prepare_signals();
>         /* connect to the accounts */
> }
>
> void nullclient_send_im(const char*to,const char*proto_name,const
char*msg) {
>         PurpleAccount *acc;
>         GList*iter;
>         const char*proto;
>         const char*username;
>         PurpleConnection*conn;
>         PurplePluginProtocolInfo *prpl_info;
>
>         /* argument checkup */
>         if(!to || !proto_name || !msg) {
>                 ERROR("bad argument\n");
>                 return;
>         }
>
>         ECHO3("sending message to [%s]@[%s] : [%s]\n",to,proto_name,msg);
>
>         /* traverse the accounts to find the appropriate protocol */
>         iter = purple_accounts_get_all_active();
>         for (; iter; iter = iter->next) {
>                 acc = iter->data;
>                 proto = purple_account_get_protocol_name(acc);
>                 username = purple_account_get_username(acc);
>                 ECHO3("traversing : [%s] : [%s]\n",username,proto);
>                 if(!strcasestr(proto,proto_name)) {
>                         continue;
>                 }
>                 ECHO4("got you\n");
>                 conn = purple_account_get_connection(acc);
>                 if(conn == NULL) {
>                         ECHO4("no connection found\n");
>                         continue;
>                 }
>
>                 /* if the buddy is not present in the buddy list */
>                 if(purple_find_buddy( acc, to)) {
>                         /* TODO: see if there is the buddy added in the
hash table */
>                         // g_hash_table_find();
>                         /* TODO: enque the message to a global list of
enqued messages */
>                         /* add the buddy */
>                         add_newone(acc, to, "random_users", to);
>                 }
>
>                 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(conn->prpl);
>                 if (prpl_info && prpl_info->send_im) {
>                         prpl_info->send_im(conn, to, msg,
PURPLE_MESSAGE_NO_LOG |
> PURPLE_MESSAGE_SEND);
>                         ECHO4("successful\n");
>                 } else {
>                         ECHO4("failed\n");
>                 }
>
> #if 0
>                 /* send message */
>                 if(serv_send_im(conn, to, msg
>                         , PURPLE_MESSAGE_NO_LOG
>                                 | PURPLE_MESSAGE_SEND
>                                 )
>                         ) {
>                         ECHO4("successful\n");
>                 } else {
>                         ECHO4("failed\n");
>                 }
> #endif
>                 goto message_sent;
>         }
>         ECHO3("no active account found to send data\n");
>         message_sent:
>         g_list_free(iter);
> }
>
>
>
>
>
>
> --
> -- Thanks
>
> Kamanashis Roy
>


-- 
-- Thanks

Kamanashis Roy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pidgin.im/pipermail/devel/attachments/20070802/7b0cbc26/attachment.html>


More information about the Devel mailing list