source: protocols/jabber/jabber.c @ dd788bb

Last change on this file since dd788bb was dd788bb, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-09-21T07:32:39Z

Added enough to not make it crash on login, and it can properly receive
messages now. Just try to figure out why it doesn't get typing
notifications...

  • Property mode set to 100644
File size: 5.6 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       
[70f6aab8]103        xt_free( jd->xt );
104       
[21167d2]105        g_free( jd->username );
106        g_free( jd );
[f06894d]107}
108
109static int jabber_send_im( struct gaim_connection *gc, char *who, char *message, int len, int away )
110{
[21167d2]111        return 0;
[f06894d]112}
113
[dd788bb]114static GList *jabber_away_states( struct gaim_connection *gc )
115{
116        GList *l = NULL;
117       
118        l = g_list_append( l, (void*) "Online" );
119        l = g_list_append( l, (void*) "Away" );
120        l = g_list_append( l, (void*) "Extended Away" );
121        l = g_list_append( l, (void*) "Do Not Disturb" );
122       
123        return( l );
124}
125
126static void jabber_set_away( struct gaim_connection *gc, char *state, char *message )
127{
128}
129
[f06894d]130void jabber_init()
131{
132        struct prpl *ret = g_new0(struct prpl, 1);
133       
134        ret->name = "jabber";
135        ret->login = jabber_login;
136        ret->acc_init = jabber_acc_init;
137        ret->close = jabber_close;
138        ret->send_im = jabber_send_im;
[dd788bb]139        ret->away_states = jabber_away_states;
[f06894d]140//      ret->get_status_string = jabber_get_status_string;
[dd788bb]141        ret->set_away = jabber_set_away;
[f06894d]142//      ret->set_info = jabber_set_info;
143//      ret->get_info = jabber_get_info;
144//      ret->add_buddy = jabber_add_buddy;
145//      ret->remove_buddy = jabber_remove_buddy;
146//      ret->chat_send = jabber_chat_send;
147//      ret->chat_invite = jabber_chat_invite;
148//      ret->chat_leave = jabber_chat_leave;
149//      ret->chat_open = jabber_chat_open;
150//      ret->keepalive = jabber_keepalive;
151//      ret->add_permit = jabber_add_permit;
152//      ret->rem_permit = jabber_rem_permit;
153//      ret->add_deny = jabber_add_deny;
154//      ret->rem_deny = jabber_rem_deny;
155//      ret->send_typing = jabber_send_typing;
156        ret->handle_cmp = g_strcasecmp;
157
158        register_protocol(ret);
159}
160
161#if 0
162int main( int argc, char *argv[] )
163{
164        struct xt_parser *xt = xt_new( NULL );
165        struct xt_node *msg;
166        int i;
167        char buf[512];
168       
169        msg = xt_new_node( "message", NULL, xt_new_node( "body", "blaataap-test", NULL ) );
170        xt_add_child( msg, xt_new_node( "html", NULL, xt_new_node( "body", "<b>blaataap in html</b>", NULL ) ) );
171        xt_add_attr( msg, "xmlns", "jabber:client" );
172        xt_add_attr( xt_find_node( msg->children, "html" ), "xmlns", "html rotte zooi" );
173        printf( "%s\n", xt_to_string( msg ) );
174       
175        while( ( i = read( 0, buf, 512 ) ) > 0 )
176        {
177                if( xt_feed( xt, buf, i ) < 1 )
178                        break;
179        }
180        xt->handlers = jabber_handlers;
181        xt_handle( xt, NULL );
182       
183        xt_cleanup( xt, NULL );
184        printf( "%d\n", xt->root );
185       
186        xt_free( xt );
187}
[21167d2]188#endif
Note: See TracBrowser for help on using the repository browser.