Ticket #44: otr.diff

File otr.diff, 30.6 KB (added by noel@…, at 2008-12-03T16:22:15Z)

bitlbee-otr ported to 1.2.3 main line

Line 
1diff -rc bitlbee-1.2.3-orig/Makefile bitlbee-otr/Makefile
2*** bitlbee-1.2.3-orig/Makefile Sat Sep  6 05:33:14 2008
3--- bitlbee-otr/Makefile        Tue Dec  2 00:11:21 2008
4***************
5*** 10,16 ****
6 
7  # Program variables
8  objects = account.o bitlbee.o crypting.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) user.o
9! headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/nogaim.h
10  subdirs = lib protocols
11 
12  ifeq ($(TARGET),i586-mingw32msvc)
13--- 10,16 ----
14 
15  # Program variables
16  objects = account.o bitlbee.o crypting.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) user.o
17! headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ipc.h irc.h log.h nick.h otr.h query.h set.h sock.h storage.h user.h lib/events.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/nogaim.h
18  subdirs = lib protocols
19 
20  ifeq ($(TARGET),i586-mingw32msvc)
21***************
22*** 19,25 ****
23  EFLAGS+=-lsecur32
24  OUTFILE=bitlbee.exe
25  else
26! objects += unix.o conf.o log.o
27  OUTFILE=bitlbee
28  endif
29 
30--- 19,25 ----
31  EFLAGS+=-lsecur32
32  OUTFILE=bitlbee.exe
33  else
34! objects += unix.o conf.o log.o otr.o
35  OUTFILE=bitlbee
36  endif
37 
38diff -rc bitlbee-1.2.3-orig/bitlbee.h bitlbee-otr/bitlbee.h
39*** bitlbee-1.2.3-orig/bitlbee.h        Sun Sep  7 05:07:07 2008
40--- bitlbee-otr/bitlbee.h       Mon Dec  1 21:38:40 2008
41***************
42*** 136,141 ****
43--- 136,142 ----
44  #include "sock.h"
45  #include "misc.h"
46  #include "proxy.h"
47+ #include "otr.h"
48 
49  typedef struct global {
50        /* In forked mode, child processes store the fd of the IPC socket here. */
51***************
52*** 147,152 ****
53--- 148,154 ----
54        GList *storage; /* The first backend in the list will be used for saving */
55        char *helpfile;
56        int restart;
57+       OtrlMessageAppOps otr_ops;   /* collects interface functions required by OTR */
58  } global_t;
59 
60  int bitlbee_daemon_init( void );
61diff -rc bitlbee-1.2.3-orig/configure bitlbee-otr/configure
62*** bitlbee-1.2.3-orig/configure        Sat Sep  6 05:33:13 2008
63--- bitlbee-otr/configure       Thu Aug  7 17:58:00 2008
64***************
65*** 30,35 ****
66--- 30,36 ----
67  strip=1
68  gcov=0
69  plugins=1
70+ otr=auto
71 
72  events=glib
73  ldap=0
74***************
75*** 70,75 ****
76--- 71,77 ----
77  --strip=0/1   Disable/enable binary stripping         $strip
78  --gcov=0/1    Disable/enable test coverage reporting  $gcov
79  --plugins=0/1 Disable/enable plugins support          $plugins
80+ --otr=0/1/auto        Disable/enable OTR encryption support   $otr
81 
82  --events=...  Event handler (glib, libevent)          $events
83  --ssl=...     SSL library to use (gnutls, nss, openssl, bogus, auto)
84***************
85*** 410,415 ****
86--- 412,439 ----
87        echo '#define WITH_PLUGINS' >> config.h
88  fi
89 
90+ otrprefix=""
91+ for i in / /usr /usr/local /home/noel/bitlbee; do
92+       if [ -f ${i}/lib/libotr.a ]; then
93+               otrprefix=${i}
94+               break
95+       fi
96+ done
97+ if [ "$otr" = "auto" ]; then
98+       if [ -n "$otrprefix" ]; then
99+               otr=1
100+       else
101+               otr=0
102+       fi
103+ fi
104+ if [ "$otr" = 1 ]; then
105+       echo '#define WITH_OTR' >> config.h
106+       echo "EFLAGS+=-L${otrprefix}/lib -lotr" >> Makefile.settings
107+       echo "CFLAGS+=-I${otrprefix}/include" >> Makefile.settings
108+ else
109+       echo '#undef WITH_OTR' >> config.h
110+ fi
111+
112  echo
113  if [ -z "$BITLBEE_VERSION" -a -d .bzr ] && type bzr > /dev/null 2> /dev/null; then
114        nick=`bzr nick`
115***************
116*** 535,540 ****
117--- 559,570 ----
118        echo '  Binary stripping disabled.'
119  fi
120 
121+ if [ "$otr" = "1" ]; then
122+       echo '  Off-the-Record (OTR) Messaging enabled.'
123+ else
124+       echo '  Off-the-Record (OTR) Messaging disabled.'
125+ fi
126+
127  echo '  Using event handler: '$events
128  echo '  Using SSL library: '$ssl
129  echo '  Building with these storage backends: '$STORAGES
130diff -rc bitlbee-1.2.3-orig/doc/README bitlbee-otr/doc/README
131*** bitlbee-1.2.3-orig/doc/README       Sat Sep  6 05:33:13 2008
132--- bitlbee-otr/doc/README      Mon Dec  1 22:06:54 2008
133***************
134*** 67,72 ****
135--- 67,76 ----
136  BitlBee's only real dependency is GLib. This is available on virtually every
137  platform. Any recent version of GLib (2.4 or higher) will work.
138 
139+ Off-the-Record encryption support will be included by default if the
140+ configure script finds libotr in one of the usual places. You can pass
141+ --otr=1 or --otr=0 to force it on or off, respectively.
142+
143  These days, MSN Messenger clients have to connect to the MS Passport servers
144  through HTTPS. BitlBee can use several SSL libraries for this: GnuTLS, NSS
145  (which comes with Mozilla) and OpenSSL. OpenSSL is not GPL-compatible in some
146diff -rc bitlbee-1.2.3-orig/irc.c bitlbee-otr/irc.c
147*** bitlbee-1.2.3-orig/irc.c    Sat Sep  6 08:17:52 2008
148--- bitlbee-otr/irc.c   Mon Dec  1 23:52:03 2008
149***************
150*** 149,160 ****
151--- 149,163 ----
152        s = set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
153        s = set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
154        s = set_add( &irc->set, "charset", "utf-8", set_eval_charset, irc );
155+       s = set_add( &irc->set, "color_encrypted", "true", set_eval_bool, irc );
156        s = set_add( &irc->set, "debug", "false", set_eval_bool, irc );
157        s = set_add( &irc->set, "default_target", "root", NULL, irc );
158        s = set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc );
159        s = set_add( &irc->set, "handle_unknown", "root", NULL, irc );
160        s = set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc );
161        s = set_add( &irc->set, "ops", "both", set_eval_ops, irc );
162+       s = set_add( &irc->set, "otr_ops", "true", set_eval_bool, irc );
163+       s = set_add( &irc->set, "otr_policy", "opportunistic", set_eval_otr_policy, irc );
164        s = set_add( &irc->set, "password", NULL, set_eval_password, irc );
165        s->flags |= SET_NULL_OK;
166        s = set_add( &irc->set, "private", "true", set_eval_bool, irc );
167***************
168*** 167,172 ****
169--- 170,177 ----
170        s = set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc );
171       
172        conf_loaddefaults( irc );
173+
174+       irc->otr = otr_new();
175       
176        /* Evaluator sets the iconv/oconv structures. */
177        set_eval_charset( set_find( &irc->set, "charset" ), set_getstr( &irc->set, "charset" ) );
178***************
179*** 320,325 ****
180--- 325,332 ----
181       
182        g_free( irc->last_target );
183       
184+       otr_free(irc->otr);
185+       
186        g_free( irc );
187       
188        if( global.conf->runmode == RUNMODE_INETD ||
189***************
190*** 715,723 ****
191                        if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) )
192                                strcat( namelist, "+" );
193                        else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
194!                                ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) )
195!                               strcat( namelist, "@" );
196!                       
197                        strcat( namelist, u->nick );
198                        strcat( namelist, " " );
199                }
200--- 722,732 ----
201                        if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) )
202                                strcat( namelist, "+" );
203                        else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
204!                                ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
205!                                ( u->encrypted > 1 && set_getbool( &irc->set, "otr_ops" ) ) )
206!                         strcat( namelist, "@" );
207!                       else if ( u->encrypted > 1 && set_getbool( &irc->set, "otr_ops" ) )
208!                         strcat ( namelist, "%" );
209                        strcat( namelist, u->nick );
210                        strcat( namelist, " " );
211                }
212***************
213*** 739,744 ****
214--- 748,757 ----
215                                *namelist = 0;
216                        }
217                       
218+                       if( u->encrypted > 1 && set_getbool( &irc->set, "otr_ops" ) )
219+                         strcat( namelist, "@" );
220+                       else if ( u->encrypted > 1 && set_getbool( &irc->set, "otr_ops" ) )
221+                         strcat ( namelist, "%" );
222                        strcat( namelist, u->nick );
223                        strcat( namelist, " " );
224                }
225***************
226*** 780,786 ****
227        irc_reply( irc,   2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->myhost );
228        irc_reply( irc,   3, ":%s", IRCD_INFO );
229        irc_reply( irc,   4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES );
230!       irc_reply( irc,   5, "PREFIX=(ov)@+ CHANTYPES=#& CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", CMODES, MAX_NICK_LENGTH - 1 );
231        irc_motd( irc );
232        irc->umode[0] = '\0';
233        irc_umode_set( irc, "+" UMODE, 1 );
234--- 793,799 ----
235        irc_reply( irc,   2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->myhost );
236        irc_reply( irc,   3, ":%s", IRCD_INFO );
237        irc_reply( irc,   4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES );
238!       irc_reply( irc,   5, "PREFIX=(ohv)@%%+ CHANTYPES=#& CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", CMODES, MAX_NICK_LENGTH - 1 );
239        irc_motd( irc );
240        irc->umode[0] = '\0';
241        irc_umode_set( irc, "+" UMODE, 1 );
242diff -rc bitlbee-1.2.3-orig/irc.h bitlbee-otr/irc.h
243*** bitlbee-1.2.3-orig/irc.h    Sat Sep  6 05:33:14 2008
244--- bitlbee-otr/irc.h   Thu Aug  7 17:11:13 2008
245***************
246*** 26,33 ****
247  #ifndef _IRC_H
248  #define _IRC_H
249 
250  #define IRC_MAX_LINE 512
251! #define IRC_MAX_ARGS 8
252 
253  #define IRC_LOGIN_TIMEOUT 60
254  #define IRC_PING_STRING "PinglBee"
255--- 26,35 ----
256  #ifndef _IRC_H
257  #define _IRC_H
258 
259+ #include "otr.h"
260+
261  #define IRC_MAX_LINE 512
262! #define IRC_MAX_ARGS 16
263 
264  #define IRC_LOGIN_TIMEOUT 60
265  #define IRC_PING_STRING "PinglBee"
266***************
267*** 96,101 ****
268--- 98,105 ----
269        gint r_watch_source_id;
270        gint w_watch_source_id;
271        gint ping_source_id;
272+       
273+       otr_t *otr;            /* OTR state and book keeping */
274  } irc_t;
275 
276  #include "user.h"
277diff -rc bitlbee-1.2.3-orig/lib/misc.c bitlbee-otr/lib/misc.c
278*** bitlbee-1.2.3-orig/lib/misc.c       Sat Sep  6 05:33:13 2008
279--- bitlbee-otr/lib/misc.c      Thu Aug  7 17:11:13 2008
280***************
281*** 87,92 ****
282--- 87,93 ----
283        { "lt",     "<" },
284        { "gt",     ">" },
285        { "amp",    "&" },
286+       { "apos",   "'" },
287        { "quot",   "\"" },
288        { "aacute", "á" },
289        { "eacute", "é" },
290***************
291*** 118,123 ****
292--- 119,125 ----
293        char *out = g_malloc( strlen( in ) + 1 );
294        char *s = out, *cs;
295        int i, matched;
296+       int taglen;
297       
298        memset( out, 0, strlen( in ) + 1 );
299       
300***************
301*** 134,142 ****
302                        while( *in && *in != '>' )
303                                in ++;
304                       
305                        if( *in )
306                        {
307!                               if( g_strncasecmp( cs+1, "br", 2) == 0 )
308                                        *(s++) = '\n';
309                                in ++;
310                        }
311--- 136,153 ----
312                        while( *in && *in != '>' )
313                                in ++;
314                       
315+                       taglen = in-cs-1;   /* not <0 because the above loop runs at least once */
316                        if( *in )
317                        {
318!                               if( g_strncasecmp( cs+1, "b", taglen) == 0 )
319!                                       *(s++) = '\x02';
320!                               else if( g_strncasecmp( cs+1, "/b", taglen) == 0 )
321!                                       *(s++) = '\x02';
322!                               else if( g_strncasecmp( cs+1, "i", taglen) == 0 )
323!                                       *(s++) = '\x1f';
324!                               else if( g_strncasecmp( cs+1, "/i", taglen) == 0 )
325!                                       *(s++) = '\x1f';
326!                               else if( g_strncasecmp( cs+1, "br", 2) == 0 )
327                                        *(s++) = '\n';
328                                in ++;
329                        }
330diff -rc bitlbee-1.2.3-orig/lib/ssl_bogus.c bitlbee-otr/lib/ssl_bogus.c
331*** bitlbee-1.2.3-orig/lib/ssl_bogus.c  Sat Sep  6 05:33:13 2008
332--- bitlbee-otr/lib/ssl_bogus.c Thu Aug  7 17:11:13 2008
333***************
334*** 27,32 ****
335--- 27,36 ----
336 
337  int ssl_errno;
338 
339+ void ssl_init( void )
340+ {
341+ }
342+
343  void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
344  {
345        return( NULL );
346diff -rc bitlbee-1.2.3-orig/lib/ssl_client.h bitlbee-otr/lib/ssl_client.h
347*** bitlbee-1.2.3-orig/lib/ssl_client.h Sat Sep  6 05:33:13 2008
348--- bitlbee-otr/lib/ssl_client.h        Thu Aug  7 17:11:13 2008
349***************
350*** 46,51 ****
351--- 46,54 ----
352  typedef gboolean (*ssl_input_function)(gpointer, void*, b_input_condition);
353 
354 
355+ /* Perform any global initialization the SSL library might need. */
356+ G_MODULE_EXPORT void ssl_init( void );
357+
358  /* Connect to host:port, call the given function when the connection is
359     ready to be used for SSL traffic. This is all done asynchronously, no
360     blocking I/O! (Except for the DNS lookups, for now...) */
361diff -rc bitlbee-1.2.3-orig/lib/ssl_gnutls.c bitlbee-otr/lib/ssl_gnutls.c
362*** bitlbee-1.2.3-orig/lib/ssl_gnutls.c Sat Sep  6 05:33:13 2008
363--- bitlbee-otr/lib/ssl_gnutls.c        Thu Aug  7 17:11:13 2008
364***************
365*** 60,65 ****
366--- 60,72 ----
367  static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
368 
369 
370+ void ssl_init( void )
371+ {
372+       gnutls_global_init();
373+       initialized = TRUE;
374+       atexit( gnutls_global_deinit );
375+ }
376+
377  void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
378  {
379        struct scd *conn = g_new0( struct scd, 1 );
380***************
381*** 121,129 ****
382       
383        if( !initialized )
384        {
385!               gnutls_global_init();
386!               initialized = TRUE;
387!               atexit( gnutls_global_deinit );
388        }
389       
390        gnutls_certificate_allocate_credentials( &conn->xcred );
391--- 128,134 ----
392       
393        if( !initialized )
394        {
395!               ssl_init();
396        }
397       
398        gnutls_certificate_allocate_credentials( &conn->xcred );
399diff -rc bitlbee-1.2.3-orig/lib/ssl_nss.c bitlbee-otr/lib/ssl_nss.c
400*** bitlbee-1.2.3-orig/lib/ssl_nss.c    Sat Sep  6 05:33:13 2008
401--- bitlbee-otr/lib/ssl_nss.c   Thu Aug  7 17:11:13 2008
402***************
403*** 90,95 ****
404--- 90,103 ----
405  }
406 
407 
408+ void ssl_init( void )
409+ {
410+       PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
411+       NSS_NoDB_Init(NULL);
412+       NSS_SetDomesticPolicy();
413+       initialized = TRUE;
414+ }
415+
416  void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
417  {
418        struct scd *conn = g_new0( struct scd, 1 );
419***************
420*** 106,114 ****
421       
422        if( !initialized )
423        {
424!               PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
425!               NSS_NoDB_Init(NULL);
426!               NSS_SetDomesticPolicy();
427        }
428 
429       
430--- 114,120 ----
431       
432        if( !initialized )
433        {
434!               ssl_init();
435        }
436 
437       
438diff -rc bitlbee-1.2.3-orig/lib/ssl_openssl.c bitlbee-otr/lib/ssl_openssl.c
439*** bitlbee-1.2.3-orig/lib/ssl_openssl.c        Sat Sep  6 05:33:13 2008
440--- bitlbee-otr/lib/ssl_openssl.c       Thu Aug  7 17:11:13 2008
441***************
442*** 56,61 ****
443--- 56,67 ----
444  static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
445 
446 
447+ void ssl_init( void )
448+ {
449+       initialized = TRUE;
450+       SSLeay_add_ssl_algorithms();
451+ }
452+
453  void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
454  {
455        struct scd *conn = g_new0( struct scd, 1 );
456***************
457*** 114,121 ****
458       
459        if( !initialized )
460        {
461!               initialized = TRUE;
462!               SSLeay_add_ssl_algorithms();
463        }
464       
465        meth = TLSv1_client_method();
466--- 120,126 ----
467       
468        if( !initialized )
469        {
470!               ssl_init();
471        }
472       
473        meth = TLSv1_client_method();
474diff -rc bitlbee-1.2.3-orig/log.c bitlbee-otr/log.c
475*** bitlbee-1.2.3-orig/log.c    Sat Sep  6 05:33:13 2008
476--- bitlbee-otr/log.c   Thu Aug  7 17:11:13 2008
477***************
478*** 29,38 ****
479 
480  static log_t logoutput;
481 
482! static void log_null(int level, char *logmessage);
483! static void log_irc(int level, char *logmessage);
484! static void log_syslog(int level, char *logmessage);
485! static void log_console(int level, char *logmessage);
486 
487  void log_init(void) {
488        openlog("bitlbee", LOG_PID, LOG_DAEMON);       
489--- 29,38 ----
490 
491  static log_t logoutput;
492 
493! static void log_null(int level, const char *logmessage);
494! static void log_irc(int level, const char *logmessage);
495! static void log_syslog(int level, const char *logmessage);
496! static void log_console(int level, const char *logmessage);
497 
498  void log_init(void) {
499        openlog("bitlbee", LOG_PID, LOG_DAEMON);       
500***************
501*** 96,102 ****
502 
503  }
504 
505! void log_message(int level, char *message, ... ) {
506 
507        va_list ap;
508        char *msgstring;
509--- 96,102 ----
510 
511  }
512 
513! void log_message(int level, const char *message, ... ) {
514 
515        va_list ap;
516        char *msgstring;
517***************
518*** 121,137 ****
519        return;
520  }
521 
522! void log_error(char *functionname) {
523        log_message(LOGLVL_ERROR, "%s: %s", functionname, strerror(errno));
524       
525        return;
526  }
527 
528! static void log_null(int level, char *message) {
529        return;
530  }
531 
532! static void log_irc(int level, char *message) {
533        if(level == LOGLVL_ERROR)
534                irc_write_all(1, "ERROR :Error: %s", message);
535        if(level == LOGLVL_WARNING)
536--- 121,137 ----
537        return;
538  }
539 
540! void log_error(const char *functionname) {
541        log_message(LOGLVL_ERROR, "%s: %s", functionname, strerror(errno));
542       
543        return;
544  }
545 
546! static void log_null(int level, const char *message) {
547        return;
548  }
549 
550! static void log_irc(int level, const char *message) {
551        if(level == LOGLVL_ERROR)
552                irc_write_all(1, "ERROR :Error: %s", message);
553        if(level == LOGLVL_WARNING)
554***************
555*** 146,152 ****
556        return;
557  }
558 
559! static void log_syslog(int level, char *message) {
560        if(level == LOGLVL_ERROR)
561                syslog(LOG_ERR, "%s", message);
562        if(level == LOGLVL_WARNING)
563--- 146,152 ----
564        return;
565  }
566 
567! static void log_syslog(int level, const char *message) {
568        if(level == LOGLVL_ERROR)
569                syslog(LOG_ERR, "%s", message);
570        if(level == LOGLVL_WARNING)
571***************
572*** 160,166 ****
573        return;
574  }
575 
576! static void log_console(int level, char *message) {
577        if(level == LOGLVL_ERROR)
578                fprintf(stderr, "Error: %s\n", message);
579        if(level == LOGLVL_WARNING)
580--- 160,166 ----
581        return;
582  }
583 
584! static void log_console(int level, const char *message) {
585        if(level == LOGLVL_ERROR)
586                fprintf(stderr, "Error: %s\n", message);
587        if(level == LOGLVL_WARNING)
588diff -rc bitlbee-1.2.3-orig/log.h bitlbee-otr/log.h
589*** bitlbee-1.2.3-orig/log.h    Sat Sep  6 05:33:13 2008
590--- bitlbee-otr/log.h   Thu Aug  7 17:11:13 2008
591***************
592*** 43,59 ****
593  } logoutput_t;
594 
595  typedef struct log_t {
596!       void (*error)(int level, char *logmessage);
597!       void (*warning)(int level, char *logmessage);
598!       void (*informational)(int level, char *logmessage);
599  #ifdef DEBUG
600!       void (*debug)(int level, char *logmessage);
601  #endif
602  } log_t;
603 
604  void log_init(void);
605  void log_link(int level, int output);
606! void log_message(int level, char *message, ...) G_GNUC_PRINTF( 2, 3 );
607! void log_error(char *functionname);
608 
609  #endif
610--- 43,59 ----
611  } logoutput_t;
612 
613  typedef struct log_t {
614!       void (*error)(int level, const char *logmessage);
615!       void (*warning)(int level, const char *logmessage);
616!       void (*informational)(int level, const char *logmessage);
617  #ifdef DEBUG
618!       void (*debug)(int level, const char *logmessage);
619  #endif
620  } log_t;
621 
622  void log_init(void);
623  void log_link(int level, int output);
624! void log_message(int level, const char *message, ...) G_GNUC_PRINTF( 2, 3 );
625! void log_error(const char *functionname);
626 
627  #endif
628diff -rc bitlbee-1.2.3-orig/protocols/jabber/jabber.c bitlbee-otr/protocols/jabber/jabber.c
629*** bitlbee-1.2.3-orig/protocols/jabber/jabber.c        Sat Sep  6 05:33:13 2008
630--- bitlbee-otr/protocols/jabber/jabber.c       Mon Dec  1 21:57:59 2008
631***************
632*** 527,532 ****
633--- 527,533 ----
634        struct prpl *ret = g_new0( struct prpl, 1 );
635       
636        ret->name = "jabber";
637+     ret->mms = 0;                        /* no limit */
638        ret->login = jabber_login;
639        ret->init = jabber_init;
640        ret->logout = jabber_logout;
641diff -rc bitlbee-1.2.3-orig/protocols/msn/msn.c bitlbee-otr/protocols/msn/msn.c
642*** bitlbee-1.2.3-orig/protocols/msn/msn.c      Sat Sep  6 05:33:13 2008
643--- bitlbee-otr/protocols/msn/msn.c     Mon Dec  1 22:00:04 2008
644***************
645*** 316,321 ****
646--- 316,322 ----
647        struct prpl *ret = g_new0(struct prpl, 1);
648       
649        ret->name = "msn";
650+     ret->mms = 1409;         /* this guess taken from libotr UPGRADING file */
651        ret->login = msn_login;
652        ret->init = msn_init;
653        ret->logout = msn_logout;
654diff -rc bitlbee-1.2.3-orig/protocols/nogaim.c bitlbee-otr/protocols/nogaim.c
655*** bitlbee-1.2.3-orig/protocols/nogaim.c       Sat Sep  6 05:33:14 2008
656--- bitlbee-otr/protocols/nogaim.c      Tue Dec  2 00:04:17 2008
657***************
658*** 627,632 ****
659--- 627,641 ----
660                }
661                irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
662                                                          u->away?'-':'+', u->nick );
663+               if( set_getbool( &ic->irc->set, "otr_ops" ) )
664+               {
665+                       if( u->encrypted > 1 )
666+                               irc_write( ic->irc, ":%s MODE %s %co %s", from, ic->irc->channel,
667+                                                                         u->away?'-':'+', u->nick );
668+                       else if( u->encrypted )
669+                               irc_write( ic->irc, ":%s MODE %s %ch %s", from, ic->irc->channel,
670+                                                                         u->away?'-':'+', u->nick );
671+               }
672                g_free( from );
673        }
674  }
675***************
676*** 636,644 ****
677        irc_t *irc = ic->irc;
678        char *wrapped;
679        user_t *u;
680!       
681        u = user_findhandle( ic, handle );
682-       
683        if( !u )
684        {
685                char *h = set_getstr( &irc->set, "handle_unknown" );
686--- 645,659 ----
687        irc_t *irc = ic->irc;
688        char *wrapped;
689        user_t *u;
690!
691!       /* pass the message through OTR */
692!       msg = otr_handle_message(ic, handle, msg);
693!       if(!msg) {
694!               /* this was an internal OTR protocol message */
695!               return;
696!       }
697!
698        u = user_findhandle( ic, handle );
699        if( !u )
700        {
701                char *h = set_getstr( &irc->set, "handle_unknown" );
702***************
703*** 648,653 ****
704--- 663,669 ----
705                        if( set_getbool( &irc->set, "debug" ) )
706                                imcb_log( ic, "Ignoring message from unknown handle %s", handle );
707                       
708+                       g_free(msg);
709                        return;
710                }
711                else if( g_strncasecmp( h, "add", 3 ) == 0 )
712***************
713*** 680,685 ****
714--- 696,702 ----
715        wrapped = word_wrap( msg, 425 );
716        irc_msgfrom( irc, u->nick, wrapped );
717        g_free( wrapped );
718+       g_free( msg );
719  }
720 
721  void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags )
722***************
723*** 972,977 ****
724--- 989,995 ----
725                for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0;
726                irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost,
727                                                            irc->channel, pm, v, list );
728+               /* FIXME: do the same thing for op and halfop */
729        }
730       
731        return value;
732***************
733*** 993,1002 ****
734                buf = escape_html( msg );
735                msg = buf;
736        }
737       
738!       st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags );
739!       g_free( buf );
740!       
741        return st;
742  }
743 
744--- 1011,1021 ----
745                buf = escape_html( msg );
746                msg = buf;
747        }
748+
749+       /* if compiled without otr support, this just calls the prpl buddy_msg */
750+       st = otr_send_message(ic, handle, msg, flags);
751       
752!       g_free(buf);
753        return st;
754  }
755 
756diff -rc bitlbee-1.2.3-orig/protocols/nogaim.h bitlbee-otr/protocols/nogaim.h
757*** bitlbee-1.2.3-orig/protocols/nogaim.h       Sat Sep  6 05:33:13 2008
758--- bitlbee-otr/protocols/nogaim.h      Tue Dec  2 00:04:40 2008
759***************
760*** 131,136 ****
761--- 131,140 ----
762        /* You should set this to the name of your protocol.
763         * - The user sees this name ie. when imcb_log() is used. */
764        const char *name;
765+     /* Maximum Message Size of this protocol.
766+      * - Introduced for OTR, in order to fragment large protocol messages.
767+      * - 0 means "unlimited". */
768+     unsigned int mms;
769 
770        /* Added this one to be able to add per-account settings, don't think
771         * it should be used for anything else. You are supposed to use the
772diff -rc bitlbee-1.2.3-orig/protocols/oscar/oscar.c bitlbee-otr/protocols/oscar/oscar.c
773*** bitlbee-1.2.3-orig/protocols/oscar/oscar.c  Sat Sep  6 05:33:13 2008
774--- bitlbee-otr/protocols/oscar/oscar.c Thu Aug  7 17:11:13 2008
775***************
776*** 2642,2647 ****
777--- 2642,2648 ----
778  {
779        struct prpl *ret = g_new0(struct prpl, 1);
780        ret->name = "oscar";
781+     ret->mms = 2343;       /* this guess taken from libotr UPGRADING file */
782        ret->away_states = oscar_away_states;
783        ret->init = oscar_init;
784        ret->login = oscar_login;
785diff -rc bitlbee-1.2.3-orig/protocols/yahoo/yahoo.c bitlbee-otr/protocols/yahoo/yahoo.c
786*** bitlbee-1.2.3-orig/protocols/yahoo/yahoo.c  Sat Sep  6 05:33:13 2008
787--- bitlbee-otr/protocols/yahoo/yahoo.c Thu Aug  7 17:11:13 2008
788***************
789*** 350,355 ****
790--- 350,356 ----
791  {
792        struct prpl *ret = g_new0(struct prpl, 1);
793        ret->name = "yahoo";
794+     ret->mms = 832;           /* this guess taken from libotr UPGRADING file */
795        ret->init = byahoo_init;
796       
797        ret->login = byahoo_login;
798***************
799*** 664,669 ****
800--- 665,673 ----
801        struct im_connection *ic = byahoo_get_ic_by_id( id );
802       
803        imcb_error( ic, "%s", err );
804+       
805+       if( fatal )
806+               imc_logout( ic, TRUE );
807  }
808 
809  /* TODO: Clear up the mess of inp and d structures */
810diff -rc bitlbee-1.2.3-orig/query.c bitlbee-otr/query.c
811*** bitlbee-1.2.3-orig/query.c  Sat Sep  6 05:33:13 2008
812--- bitlbee-otr/query.c Thu Aug  7 17:11:13 2008
813***************
814*** 102,107 ****
815--- 102,110 ----
816        query_t *q, *n, *def;
817        int count = 0;
818       
819+       if(!ic)
820+               return;
821+       
822        q = irc->queries;
823        def = query_default( irc );
824       
825***************
826*** 144,150 ****
827                        imcb_log( q->ic, "Accepted: %s", q->question );
828                else
829                        irc_usermsg( irc, "Accepted: %s", q->question );
830!               q->yes( q->data );
831        }
832        else
833        {
834--- 147,154 ----
835                        imcb_log( q->ic, "Accepted: %s", q->question );
836                else
837                        irc_usermsg( irc, "Accepted: %s", q->question );
838!               if( q->yes )
839!                       q->yes( q->data );
840        }
841        else
842        {
843***************
844*** 152,158 ****
845                        imcb_log( q->ic, "Rejected: %s", q->question );
846                else
847                        irc_usermsg( irc, "Rejected: %s", q->question );
848!               q->no( q->data );
849        }
850        q->data = NULL;
851       
852--- 156,163 ----
853                        imcb_log( q->ic, "Rejected: %s", q->question );
854                else
855                        irc_usermsg( irc, "Rejected: %s", q->question );
856!               if( q->no )
857!                       q->no( q->data );
858        }
859        q->data = NULL;
860       
861diff -rc bitlbee-1.2.3-orig/root_commands.c bitlbee-otr/root_commands.c
862*** bitlbee-1.2.3-orig/root_commands.c  Sat Sep  6 06:10:19 2008
863--- bitlbee-otr/root_commands.c Mon Dec  1 21:53:05 2008
864***************
865*** 28,33 ****
866--- 28,34 ----
867  #include "crypting.h"
868  #include "bitlbee.h"
869  #include "help.h"
870+ #include "otr.h"
871 
872  #include <string.h>
873 
874***************
875*** 1096,1100 ****
876--- 1097,1102 ----
877        { "nick",           1, cmd_nick,           0 },
878        { "qlist",          0, cmd_qlist,          0 },
879        { "join_chat",      2, cmd_join_chat,      0 },
880+       { "otr",            1, cmd_otr,            0 },
881        { NULL }
882  };
883diff -rc bitlbee-1.2.3-orig/set.c bitlbee-otr/set.c
884*** bitlbee-1.2.3-orig/set.c    Sat Sep  6 05:33:13 2008
885--- bitlbee-otr/set.c   Mon Dec  1 23:51:44 2008
886***************
887*** 245,247 ****
888--- 245,261 ----
889       
890        return value;
891  }
892+
893+ /* possible values: never, opportunistic, manual, always */
894+ char *set_eval_otr_policy( set_t *set, char *value )
895+ {
896+       if ( !strcmp(value, "never") )
897+               return value;
898+       if ( !strcmp(value, "opportunistic") )
899+               return value;
900+       if ( !strcmp(value, "manual") )
901+               return value;
902+       if ( !strcmp(value, "always") )
903+               return value;
904+       return SET_INVALID;
905+ }
906diff -rc bitlbee-1.2.3-orig/set.h bitlbee-otr/set.h
907*** bitlbee-1.2.3-orig/set.h    Sat Sep  6 05:33:13 2008
908--- bitlbee-otr/set.h   Mon Dec  1 23:52:49 2008
909***************
910*** 100,104 ****
911--- 100,105 ----
912  /* Some not very generic evaluators that really shouldn't be here... */
913  char *set_eval_to_char( set_t *set, char *value );
914  char *set_eval_ops( set_t *set, char *value );
915+ char *set_eval_otr_policy( set_t *set, char *value );
916 
917  #endif /* __SET_H__ */
918diff -rc bitlbee-1.2.3-orig/storage.c bitlbee-otr/storage.c
919*** bitlbee-1.2.3-orig/storage.c        Sat Sep  6 15:35:56 2008
920--- bitlbee-otr/storage.c       Mon Dec  1 21:47:36 2008
921***************
922*** 28,33 ****
923--- 28,34 ----
924  #define BITLBEE_CORE
925  #include "bitlbee.h"
926  #include "crypting.h"
927+ #include "otr.h"
928 
929  extern storage_t storage_text;
930  extern storage_t storage_xml;
931***************
932*** 139,144 ****
933--- 140,147 ----
934                return STORAGE_NO_SUCH_USER;
935        }
936       
937+       otr_save(irc);
938+       
939        st = ((storage_t *)global.storage->data)->save(irc, overwrite);
940       
941        if (password != NULL) {
942***************
943*** 181,188 ****
944        /* First, try to rename in the current write backend, assuming onick
945         * is stored there */
946        status = primary_storage->rename(onick, nnick, password);
947!       if (status != STORAGE_NO_SUCH_USER)
948                return status;
949 
950        /* Try to load from a migration backend and save to the current backend.
951         * Explicitly remove the account from the migration backend as otherwise
952--- 184,193 ----
953        /* First, try to rename in the current write backend, assuming onick
954         * is stored there */
955        status = primary_storage->rename(onick, nnick, password);
956!       if (status != STORAGE_NO_SUCH_USER) {
957!               otr_rename(onick, nnick);
958                return status;
959+       }
960 
961        /* Try to load from a migration backend and save to the current backend.
962         * Explicitly remove the account from the migration backend as otherwise
963***************
964*** 206,211 ****
965--- 211,217 ----
966        irc_free(irc);
967 
968        storage_remove(onick, password);
969+       otr_rename(onick, nnick);
970 
971        return STORAGE_OK;
972  }
973diff -rc bitlbee-1.2.3-orig/unix.c bitlbee-otr/unix.c
974*** bitlbee-1.2.3-orig/unix.c   Sat Sep  6 05:33:13 2008
975--- bitlbee-otr/unix.c  Thu Aug  7 17:11:13 2008
976***************
977*** 26,34 ****
978--- 26,36 ----
979  #include "bitlbee.h"
980  #include "commands.h"
981  #include "crypting.h"
982+ #include "otr.h"
983  #include "protocols/nogaim.h"
984  #include "help.h"
985  #include "ipc.h"
986+ #include "lib/ssl_client.h"
987  #include <signal.h>
988  #include <unistd.h>
989  #include <sys/time.h>
990***************
991*** 53,58 ****
992--- 55,67 ----
993       
994        b_main_init();
995        nogaim_init();
996+       /* Ugly Note: libotr and gnutls both use libgcrypt. libgcrypt
997+          has a process-global config state whose initialization happpens
998+          twice if libotr and gnutls are used together. libotr installs custom
999+          memory management functions for libgcrypt while our gnutls module
1000+          uses the defaults. Therefore we initialize OTR after SSL. *sigh* */
1001+       ssl_init();
1002+       otr_init();
1003       
1004        srand( time( NULL ) ^ getpid() );
1005        global.helpfile = g_strdup( HELP_FILE );
1006diff -rc bitlbee-1.2.3-orig/user.c bitlbee-otr/user.c
1007*** bitlbee-1.2.3-orig/user.c   Sat Sep  6 05:33:13 2008
1008--- bitlbee-otr/user.c  Mon Dec  1 22:15:04 2008
1009***************
1010*** 140,146 ****
1011                return( NULL );
1012  }
1013 
1014! user_t *user_findhandle( struct im_connection *ic, char *handle )
1015  {
1016        user_t *u;
1017        char *nick;
1018--- 140,146 ----
1019                return( NULL );
1020  }
1021 
1022! user_t *user_findhandle( struct im_connection *ic, const char *handle )
1023  {
1024        user_t *u;
1025        char *nick;
1026diff -rc bitlbee-1.2.3-orig/user.h bitlbee-otr/user.h
1027*** bitlbee-1.2.3-orig/user.h   Sat Sep  6 05:33:13 2008
1028--- bitlbee-otr/user.h  Mon Dec  1 22:15:11 2008
1029***************
1030*** 36,41 ****
1031--- 36,42 ----
1032       
1033        char is_private;
1034        char online;
1035+       char encrypted;
1036       
1037        char *handle;
1038        char *group;
1039***************
1040*** 55,61 ****
1041  user_t *user_add( struct irc *irc, char *nick );
1042  int user_del( irc_t *irc, char *nick );
1043  G_MODULE_EXPORT user_t *user_find( irc_t *irc, char *nick );
1044! G_MODULE_EXPORT user_t *user_findhandle( struct im_connection *ic, char *handle );
1045  void user_rename( irc_t *irc, char *oldnick, char *newnick );
1046 
1047  #endif /* __USER_H__ */
1048--- 56,62 ----
1049  user_t *user_add( struct irc *irc, char *nick );
1050  int user_del( irc_t *irc, char *nick );
1051  G_MODULE_EXPORT user_t *user_find( irc_t *irc, char *nick );
1052! G_MODULE_EXPORT user_t *user_findhandle( struct im_connection *ic, const char *handle );
1053  void user_rename( irc_t *irc, char *oldnick, char *newnick );
1054 
1055  #endif /* __USER_H__ */