示例#1
0
xmlnode * response_error( int         code    ,
                          const char *id      ,
                          const char *name    ,
                          const char *message )
{
    GString *status = g_string_new    ( "" );
    xmlnode *error  = xnode_new       ( "function-response" );
    xmlnode *meth   = xnode_new_child ( error, name         );
    xmlnode *value  = xnode_new_child ( error, "alist"      );
    xmlnode *stat   = xnode_new_child ( value, "int"        );
    xmlnode *mesg   = xnode_new_child ( value, "string"     );

    // set the id attribute on the method and the 
    // status and message alist key name attributes:
    xnode_set_attrib      ( meth  , "id"  , id );
    xnode_set_attrib      ( stat  , "name", "status"  );
    xnode_set_attrib      ( mesg  , "name", "message" );

    // insert the data for the status and message:
    g_string_append_printf( status, "%d"       , code );
    xnode_insert_data     ( stat  , status->str, -1   );
    xnode_insert_data     ( mesg  , message    , -1   );
    g_string_free         ( status, TRUE );

    return error;
}
示例#2
0
xmlnode * func_call ( const char *name, const char *id, xmlnode *args )
{
    xmlnode *mcall = xnode_new      ( "function-call" );
    xmlnode *meth  = xnode_new_child( mcall , name    );
    xnode_set_attrib( meth, "id", id );
    if( args )
        xnode_insert_child( mcall, args );
    return mcall;
}
示例#3
0
static void _elim_roomlist_add ( PurpleRoomlist     *list ,
                                 PurpleRoomlistRoom *room )
{
    g_return_if_fail( list && room );

    xmlnode *alist  = xnode_new( "alist" );
    char    *ID     = new_elim_id();

    __roomlist_insert_account( list->account, alist );
    AL_PTR ( alist , "roomlist-id" , list          );
    AL_STR ( alist , "room-name"   , room->name    );
    AL_ENUM( alist , "room-type"   , room->type    , ":roomlist-room-type" );
    AL_PTR ( alist , "room-parent" , room->parent  );
    AL_BOOL( alist , "room-expanded-once", room->expanded_once );

    xmlnode *fields = xnode_new_child( alist, "alist" );
    xnode_set_attrib( fields, "name", "fields" );

    GList *listf = g_list_first( list->fields );
    GList *roomf = g_list_first( room->fields );

#define NNEXTT( a, b ) a = g_list_next( a ), b = g_list_next( b )
#define PTR_TO_BOOL(_p) (_p != NULL)

    for( ; listf && roomf ; NNEXTT( listf, roomf ) )
    {
        PurpleRoomlistField *f = (PurpleRoomlistField*) listf->data;
        switch( f->type )
        {
          case PURPLE_ROOMLIST_FIELD_BOOL:
            AL_BOOL( fields, f->name, PTR_TO_BOOL( roomf->data ) );
            break;

          case PURPLE_ROOMLIST_FIELD_INT:
            AL_INT ( fields, f->name, roomf->data );
            break;

          case PURPLE_ROOMLIST_FIELD_STRING:
            AL_STR ( fields, f->name, roomf->data );
            break;

          default:
            fprintf( stderr, "unsupported room list field type.\n" );
            break;
        }
    }

    xmlnode *mcall = func_call( "elim-roomlist-add", ID, alist );
    g_free( ID );
    add_outbound_sexp( mcall );
}
示例#4
0
xmlnode * response_value( int         code  ,
                          const char *id    ,
                          const char *name  ,
                          xmlnode    *val   )
{
    GString *status = g_string_new    ( "" );
    xmlnode *mresp  = xnode_new       ( "function-response" );
    xmlnode *meth   = xnode_new_child ( mresp, name         );
    xmlnode *value  = xnode_new_child ( mresp, "alist"      );
    xmlnode *stat   = xnode_new_child ( value, "int"        );

    xnode_set_attrib      ( meth  , "id"  , id );
    xnode_set_attrib      ( stat  , "name", "status" );
    xnode_set_attrib      ( val   , "name", "value"  );

    g_string_append_printf( status, "%d"       , code );
    xnode_insert_data     ( stat  , status->str, -1   );
    g_string_free         ( status, TRUE  );

    xnode_insert_child    ( value , val   );

    return mresp;
}
示例#5
0
static void _elim_roomlist_create ( PurpleRoomlist *list )
{
    g_return_if_fail( list );

    xmlnode    *alist = xnode_new( "alist" );
    char       *ID    = new_elim_id();    
    
    __roomlist_insert_account( list->account, alist );
    AL_PTR ( alist, "roomlist-id", list );

    xmlnode *flist = xnode_new_child( alist, "alist" );
    xnode_set_attrib( flist, "name", "fields" );
    g_list_foreach( list->fields, __roomlist_add_list_field, flist );

    xmlnode *mcall = func_call( "elim-roomlist-create", ID, alist );
    g_free( ID );
    add_outbound_sexp( mcall );
}
示例#6
0
static void _elim_chat_remove_users    ( PurpleConversation *conv  , 
                                         GList              *users )
{
    char    *ID    = new_elim_id();
    xmlnode *args  = xnode_new( "alist" );
    xmlnode *mcall = func_call( "elim-chat-remove-users", ID, args );
    xmlnode *list  = xnode_new( "list" );
    g_free( ID );
    fprintf( stderr, "(_elim_chat_remove_users)\n" );

    _elim_conv_args( args, conv );
    for( ; users; users = users->next )
    {
        xmlnode *user = xnode_new_child( list, "string" );
        xnode_insert_data( user, users->data ? users->data : "", -1 );
    }

    AL_NODE( args, "participants", list );

    fprintf( stderr, "(_elim_chat_remove_users:DONE)\n" );
    add_outbound_sexp( mcall );
}