source: protocols/jabber/jabber.c @ 21167d2

Last change on this file since 21167d2 was 21167d2, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-09-20T19:42:27Z

It can send a valid (pre-XMPP) login packet. Lots of work to do, still...

  • Property mode set to 100644
File size: 5.3 KB
RevLine 
[f06894d]1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Jabber module - Main file                                                *
5*                                                                           *
6*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
7*                                                                           *
8*  This program is free software; you can redistribute it and/or modify     *
9*  it under the terms of the GNU General Public License as published by     *
10*  the Free Software Foundation; either version 2 of the License, or        *
11*  (at your option) any later version.                                      *
12*                                                                           *
13*  This program is distributed in the hope that it will be useful,          *
14*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
15*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
16*  GNU General Public License for more details.                             *
17*                                                                           *
18*  You should have received a copy of the GNU General Public License along  *
19*  with this program; if not, write to the Free Software Foundation, Inc.,  *
20*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
21*                                                                           *
22\***************************************************************************/
23
24#include <glib.h>
25#include <string.h>
26#include <unistd.h>
27#include <ctype.h>
28#include <stdio.h>
29
[21167d2]30#include "ssl_client.h"
[f06894d]31#include "xmltree.h"
32#include "bitlbee.h"
33#include "jabber.h"
34
35static void jabber_acc_init( account_t *acc )
36{
37        set_t *s;
38       
39        s = set_add( &acc->set, "port", "5222", set_eval_int, acc );
40        s->flags |= ACC_SET_OFFLINE_ONLY;
41       
42        s = set_add( &acc->set, "priority", "0", set_eval_resprio, acc );
43       
44        s = set_add( &acc->set, "resource", "BitlBee", set_eval_resprio, acc );
45       
46        s = set_add( &acc->set, "server", NULL, set_eval_account, acc );
47        s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
48       
49        s = set_add( &acc->set, "ssl", "false", set_eval_bool, acc );
50        s->flags |= ACC_SET_OFFLINE_ONLY;
51       
52        s = set_add( &acc->set, "tls", "try", set_eval_tls, acc );
53        s->flags |= ACC_SET_OFFLINE_ONLY;
54}
55
56static void jabber_login( account_t *acc )
57{
[21167d2]58        struct gaim_connection *gc = new_gaim_conn( acc );
59        struct jabber_data *jd = g_new0( struct jabber_data, 1 );
60       
61        jd->gc = gc;
62        gc->proto_data = jd;
63       
64        jd->username = g_strdup( acc->user );
65        jd->server = strchr( jd->username, '@' );
66       
67        if( jd->server == NULL )
68        {
69                hide_login_progress( gc, "Incomplete account name (format it like <username@jabberserver.name>)" );
70                signoff( gc );
71                return;
72        }
73       
74        /* So don't think of free()ing jd->server.. :-) */
75        *jd->server = 0;
76        jd->server ++;
77       
78        if( set_getbool( &acc->set, "ssl" ) )
79        {
80                signoff( gc );
81                /* TODO! */
82        }
83        else
84        {
85                jd->fd = proxy_connect( jd->server, set_getint( &acc->set, "port" ), jabber_connected_plain, gc );
86        }
[f06894d]87}
88
89static void jabber_close( struct gaim_connection *gc )
90{
[21167d2]91        struct jabber_data *jd = gc->proto_data;
92       
93        if( jd->r_inpa >= 0 )
94                b_event_remove( jd->r_inpa );
95        if( jd->w_inpa >= 0 )
96                b_event_remove( jd->w_inpa );
97       
98        if( jd->ssl )
99                ssl_disconnect( jd->ssl );
100        if( jd->fd >= 0 )
101                closesocket( jd->fd );
102       
103        g_free( jd->username );
104        g_free( jd );
[f06894d]105}
106
107static int jabber_send_im( struct gaim_connection *gc, char *who, char *message, int len, int away )
108{
[21167d2]109        return 0;
[f06894d]110}
111
112void jabber_init()
113{
114        struct prpl *ret = g_new0(struct prpl, 1);
115       
116        ret->name = "jabber";
117        ret->login = jabber_login;
118        ret->acc_init = jabber_acc_init;
119        ret->close = jabber_close;
120        ret->send_im = jabber_send_im;
121//      ret->away_states = jabber_away_states;
122//      ret->get_status_string = jabber_get_status_string;
123//      ret->set_away = jabber_set_away;
124//      ret->set_info = jabber_set_info;
125//      ret->get_info = jabber_get_info;
126//      ret->add_buddy = jabber_add_buddy;
127//      ret->remove_buddy = jabber_remove_buddy;
128//      ret->chat_send = jabber_chat_send;
129//      ret->chat_invite = jabber_chat_invite;
130//      ret->chat_leave = jabber_chat_leave;
131//      ret->chat_open = jabber_chat_open;
132//      ret->keepalive = jabber_keepalive;
133//      ret->add_permit = jabber_add_permit;
134//      ret->rem_permit = jabber_rem_permit;
135//      ret->add_deny = jabber_add_deny;
136//      ret->rem_deny = jabber_rem_deny;
137//      ret->send_typing = jabber_send_typing;
138        ret->handle_cmp = g_strcasecmp;
139
140        register_protocol(ret);
141}
142
143#if 0
144int main( int argc, char *argv[] )
145{
146        struct xt_parser *xt = xt_new( NULL );
147        struct xt_node *msg;
148        int i;
149        char buf[512];
150       
151        msg = xt_new_node( "message", NULL, xt_new_node( "body", "blaataap-test", NULL ) );
152        xt_add_child( msg, xt_new_node( "html", NULL, xt_new_node( "body", "<b>blaataap in html</b>", NULL ) ) );
153        xt_add_attr( msg, "xmlns", "jabber:client" );
154        xt_add_attr( xt_find_node( msg->children, "html" ), "xmlns", "html rotte zooi" );
155        printf( "%s\n", xt_to_string( msg ) );
156       
157        while( ( i = read( 0, buf, 512 ) ) > 0 )
158        {
159                if( xt_feed( xt, buf, i ) < 1 )
160                        break;
161        }
162        xt->handlers = jabber_handlers;
163        xt_handle( xt, NULL );
164       
165        xt_cleanup( xt, NULL );
166        printf( "%d\n", xt->root );
167       
168        xt_free( xt );
169}
[21167d2]170#endif
Note: See TracBrowser for help on using the repository browser.