[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 | |
---|
| 35 | static 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 | |
---|
| 56 | static 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 | |
---|
| 89 | static void jabber_close( struct gaim_connection *gc ) |
---|
| 90 | { |
---|
[21167d2] | 91 | struct jabber_data *jd = gc->proto_data; |
---|
| 92 | |
---|
[4a0614e] | 93 | jabber_end_stream( gc ); |
---|
| 94 | |
---|
[21167d2] | 95 | if( jd->r_inpa >= 0 ) |
---|
| 96 | b_event_remove( jd->r_inpa ); |
---|
| 97 | if( jd->w_inpa >= 0 ) |
---|
| 98 | b_event_remove( jd->w_inpa ); |
---|
| 99 | |
---|
| 100 | if( jd->ssl ) |
---|
| 101 | ssl_disconnect( jd->ssl ); |
---|
| 102 | if( jd->fd >= 0 ) |
---|
| 103 | closesocket( jd->fd ); |
---|
| 104 | |
---|
[70f6aab8] | 105 | xt_free( jd->xt ); |
---|
| 106 | |
---|
[21167d2] | 107 | g_free( jd->username ); |
---|
| 108 | g_free( jd ); |
---|
[f06894d] | 109 | } |
---|
| 110 | |
---|
| 111 | static int jabber_send_im( struct gaim_connection *gc, char *who, char *message, int len, int away ) |
---|
| 112 | { |
---|
[4a0614e] | 113 | struct xt_node *node; |
---|
| 114 | int st; |
---|
| 115 | |
---|
| 116 | node = xt_new_node( "body", message, NULL ); |
---|
| 117 | node = jabber_make_packet( "message", "chat", who, node ); |
---|
| 118 | st = jabber_write_packet( gc, node ); |
---|
| 119 | xt_free_node( node ); |
---|
| 120 | |
---|
| 121 | return st; |
---|
[f06894d] | 122 | } |
---|
| 123 | |
---|
[dd788bb] | 124 | static GList *jabber_away_states( struct gaim_connection *gc ) |
---|
| 125 | { |
---|
| 126 | GList *l = NULL; |
---|
| 127 | |
---|
| 128 | l = g_list_append( l, (void*) "Online" ); |
---|
| 129 | l = g_list_append( l, (void*) "Away" ); |
---|
| 130 | l = g_list_append( l, (void*) "Extended Away" ); |
---|
| 131 | l = g_list_append( l, (void*) "Do Not Disturb" ); |
---|
| 132 | |
---|
| 133 | return( l ); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | static void jabber_set_away( struct gaim_connection *gc, char *state, char *message ) |
---|
| 137 | { |
---|
| 138 | } |
---|
| 139 | |
---|
[f06894d] | 140 | void jabber_init() |
---|
| 141 | { |
---|
| 142 | struct prpl *ret = g_new0(struct prpl, 1); |
---|
| 143 | |
---|
| 144 | ret->name = "jabber"; |
---|
| 145 | ret->login = jabber_login; |
---|
| 146 | ret->acc_init = jabber_acc_init; |
---|
| 147 | ret->close = jabber_close; |
---|
| 148 | ret->send_im = jabber_send_im; |
---|
[dd788bb] | 149 | ret->away_states = jabber_away_states; |
---|
[f06894d] | 150 | // ret->get_status_string = jabber_get_status_string; |
---|
[dd788bb] | 151 | ret->set_away = jabber_set_away; |
---|
[f06894d] | 152 | // ret->set_info = jabber_set_info; |
---|
| 153 | // ret->get_info = jabber_get_info; |
---|
| 154 | // ret->add_buddy = jabber_add_buddy; |
---|
| 155 | // ret->remove_buddy = jabber_remove_buddy; |
---|
| 156 | // ret->chat_send = jabber_chat_send; |
---|
| 157 | // ret->chat_invite = jabber_chat_invite; |
---|
| 158 | // ret->chat_leave = jabber_chat_leave; |
---|
| 159 | // ret->chat_open = jabber_chat_open; |
---|
| 160 | // ret->keepalive = jabber_keepalive; |
---|
| 161 | // ret->add_permit = jabber_add_permit; |
---|
| 162 | // ret->rem_permit = jabber_rem_permit; |
---|
| 163 | // ret->add_deny = jabber_add_deny; |
---|
| 164 | // ret->rem_deny = jabber_rem_deny; |
---|
| 165 | // ret->send_typing = jabber_send_typing; |
---|
| 166 | ret->handle_cmp = g_strcasecmp; |
---|
| 167 | |
---|
| 168 | register_protocol(ret); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | #if 0 |
---|
| 172 | int main( int argc, char *argv[] ) |
---|
| 173 | { |
---|
| 174 | struct xt_parser *xt = xt_new( NULL ); |
---|
| 175 | struct xt_node *msg; |
---|
| 176 | int i; |
---|
| 177 | char buf[512]; |
---|
| 178 | |
---|
| 179 | msg = xt_new_node( "message", NULL, xt_new_node( "body", "blaataap-test", NULL ) ); |
---|
| 180 | xt_add_child( msg, xt_new_node( "html", NULL, xt_new_node( "body", "<b>blaataap in html</b>", NULL ) ) ); |
---|
| 181 | xt_add_attr( msg, "xmlns", "jabber:client" ); |
---|
| 182 | xt_add_attr( xt_find_node( msg->children, "html" ), "xmlns", "html rotte zooi" ); |
---|
| 183 | printf( "%s\n", xt_to_string( msg ) ); |
---|
| 184 | |
---|
| 185 | while( ( i = read( 0, buf, 512 ) ) > 0 ) |
---|
| 186 | { |
---|
| 187 | if( xt_feed( xt, buf, i ) < 1 ) |
---|
| 188 | break; |
---|
| 189 | } |
---|
| 190 | xt->handlers = jabber_handlers; |
---|
| 191 | xt_handle( xt, NULL ); |
---|
| 192 | |
---|
| 193 | xt_cleanup( xt, NULL ); |
---|
| 194 | printf( "%d\n", xt->root ); |
---|
| 195 | |
---|
| 196 | xt_free( xt ); |
---|
| 197 | } |
---|
[21167d2] | 198 | #endif |
---|