Changeset 764c7d1


Ignore:
Timestamp:
2008-02-03T21:30:03Z (16 years ago)
Author:
Sven Moritz Hallberg <sm@…>
Branches:
master
Children:
3c80a9d
Parents:
b5c8a34
Message:

OTR support, first checkin

Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    rb5c8a34 r764c7d1  
    1010
    1111# Program variables
    12 objects = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o
    13 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
     12objects = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o otr.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o
     13headers = 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
    1414subdirs = lib protocols
    1515
  • bitlbee.c

    rb5c8a34 r764c7d1  
    139139        log_link( LOGLVL_ERROR, LOGOUTPUT_IRC );
    140140        log_link( LOGLVL_WARNING, LOGOUTPUT_IRC );
     141    /* TODO: Remove debugging log_link's */
     142        log_link( LOGLVL_INFO, LOGOUTPUT_IRC );
     143        log_link( LOGLVL_DEBUG, LOGOUTPUT_IRC );
    141144       
    142145        return( 0 );
  • bitlbee.h

    rb5c8a34 r764c7d1  
    133133#include "misc.h"
    134134#include "proxy.h"
     135#include "otr.h"
    135136
    136137typedef struct global {
     
    143144        char *helpfile;
    144145        int restart;
     146        OtrlMessageAppOps otr_ops;   /* collects interface functions required by OTR */
    145147} global_t;
    146148
  • configure

    rb5c8a34 r764c7d1  
    3030gcov=0
    3131plugins=1
     32otr=auto
    3233
    3334events=glib
     
    7071--gcov=0/1      Disable/enable test coverage reporting  $gcov
    7172--plugins=0/1   Disable/enable plugins support          $plugins
     73--otr=0/1/auto  Disable/enable OTR encryption support   $otr
    7274
    7375--events=...    Event handler (glib, libevent)          $events
     
    174176        if $PKG_CONFIG glib-2.0 --atleast-version=$GLIB_MIN_VERSION; then
    175177                cat<<EOF>>Makefile.settings
    176 EFLAGS+=`$PKG_CONFIG --libs glib-2.0 gmodule-2.0`
    177 CFLAGS+=`$PKG_CONFIG --cflags glib-2.0 gmodule-2.0`
     178EFLAGS+=`$PKG_CONFIG --libs glib-2.0 gmodule-2.0 gthread-2.0`
     179CFLAGS+=`$PKG_CONFIG --cflags glib-2.0 gmodule-2.0 gthread-2.0`
    178180EOF
    179181        else
     
    385387fi
    386388
     389if [ "$otr" = "auto" ]; then
     390        for i in /lib /usr/lib /usr/local/lib; do
     391                if [ -f $i/libotr.a ]; then
     392                        otr=1
     393                        break
     394                fi
     395        done
     396fi
     397if [ "$otr" = 0 ]; then
     398        echo '#undef WITH_OTR' >> config.h
     399else
     400        echo '#define WITH_OTR' >> config.h
     401        echo "EFLAGS+=-lotr" >> Makefile.settings
     402fi
     403
    387404echo
    388405if [ -z "$BITLBEE_VERSION" -a -d .bzr ] && type bzr > /dev/null 2> /dev/null; then
     
    504521fi
    505522
     523if [ "$otr" = "1" ]; then
     524        echo '  Off-the-Record (OTR) Messaging enabled.'
     525else
     526        echo '  Off-the-Record (OTR) Messaging disabled.'
     527fi
     528
    506529echo '  Using event handler: '$events
    507530echo '  Using SSL library: '$ssl
  • irc.c

    rb5c8a34 r764c7d1  
    126126       
    127127        conf_loaddefaults( irc );
     128
     129        irc->otr_us = otrl_userstate_create();
     130        irc->otr_mutex = g_mutex_new();
    128131       
    129132        return( irc );
     
    276279                }
    277280        }
     281       
     282        otrl_userstate_free(irc->otr_us);
     283        g_mutex_free(irc->otr_mutex);
     284       
    278285        g_free(irc);
    279286       
  • irc.h

    rb5c8a34 r764c7d1  
    2626#ifndef _IRC_H
    2727#define _IRC_H
     28
     29#include "otr.h"
    2830
    2931#define IRC_MAX_LINE 512
     
    9597        gint w_watch_source_id;
    9698        gint ping_source_id;
     99       
     100        OtrlUserState otr_us;
     101        GMutex *otr_mutex;      /* for locking otr during keygen */
    97102} irc_t;
    98103
  • log.c

    rb5c8a34 r764c7d1  
    3030static log_t logoutput;
    3131
    32 static void log_null(int level, char *logmessage);
    33 static void log_irc(int level, char *logmessage);
    34 static void log_syslog(int level, char *logmessage);
    35 static void log_console(int level, char *logmessage);
     32static void log_null(int level, const char *logmessage);
     33static void log_irc(int level, const char *logmessage);
     34static void log_syslog(int level, const char *logmessage);
     35static void log_console(int level, const char *logmessage);
    3636
    3737void log_init(void) {
     
    9797}
    9898
    99 void log_message(int level, char *message, ... ) {
     99void log_message(int level, const char *message, ... ) {
    100100
    101101        va_list ap;
     
    122122}
    123123
    124 void log_error(char *functionname) {
     124void log_error(const char *functionname) {
    125125        log_message(LOGLVL_ERROR, "%s: %s", functionname, strerror(errno));
    126126       
     
    128128}
    129129
    130 static void log_null(int level, char *message) {
     130static void log_null(int level, const char *message) {
    131131        return;
    132132}
    133133
    134 static void log_irc(int level, char *message) {
     134static void log_irc(int level, const char *message) {
    135135        if(level == LOGLVL_ERROR)
    136136                irc_write_all(1, "ERROR :Error: %s", message);
     
    147147}
    148148
    149 static void log_syslog(int level, char *message) {
     149static void log_syslog(int level, const char *message) {
    150150        if(level == LOGLVL_ERROR)
    151151                syslog(LOG_ERR, "%s", message);
     
    161161}
    162162
    163 static void log_console(int level, char *message) {
     163static void log_console(int level, const char *message) {
    164164        if(level == LOGLVL_ERROR)
    165165                fprintf(stderr, "Error: %s\n", message);
  • log.h

    rb5c8a34 r764c7d1  
    4444
    4545typedef struct log_t {
    46         void (*error)(int level, char *logmessage);
    47         void (*warning)(int level, char *logmessage);
    48         void (*informational)(int level, char *logmessage);
     46        void (*error)(int level, const char *logmessage);
     47        void (*warning)(int level, const char *logmessage);
     48        void (*informational)(int level, const char *logmessage);
    4949#ifdef DEBUG
    50         void (*debug)(int level, char *logmessage);
     50        void (*debug)(int level, const char *logmessage);
    5151#endif
    5252} log_t;
     
    5454void log_init(void);
    5555void log_link(int level, int output);
    56 void log_message(int level, char *message, ...) G_GNUC_PRINTF( 2, 3 );
    57 void log_error(char *functionname);
     56void log_message(int level, const char *message, ...) G_GNUC_PRINTF( 2, 3 );
     57void log_error(const char *functionname);
    5858
    5959#endif
  • protocols/nogaim.c

    rb5c8a34 r764c7d1  
    630630        char *wrapped;
    631631        user_t *u;
    632        
     632
     633        /* pass the message through OTR */
     634        msg = otr_handle_message(ic, handle, msg);
     635        if(!msg) {
     636                /* this was an internal OTR protocol message */
     637                return;
     638        }
     639
    633640        u = user_findhandle( ic, handle );
    634        
    635641        if( !u )
    636642        {
     
    642648                                imcb_log( ic, "Ignoring message from unknown handle %s", handle );
    643649                       
     650                        g_free(msg);
    644651                        return;
    645652                }
     
    674681        irc_msgfrom( irc, u->nick, wrapped );
    675682        g_free( wrapped );
     683        g_free( msg );
    676684}
    677685
     
    991999                msg = buf;
    9921000        }
    993        
    994         st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags );
    995         g_free( buf );
    996        
     1001
     1002        /* if compiled without otr support, this just calls the prpl buddy_msg */
     1003        st = otr_send_message(ic, handle, msg, flags);
     1004       
     1005        g_free(buf);
    9971006        return st;
    9981007}
  • root_commands.c

    rb5c8a34 r764c7d1  
    2929#include "bitlbee.h"
    3030#include "help.h"
     31#include "otr.h"
    3132
    3233#include <string.h>
     
    8586                return;
    8687       
     88        if(!g_mutex_trylock(irc->otr_mutex)) {
     89                irc_usermsg(irc, "keygen in progress, bitlbee comatose - please wait");
     90                return;
     91        }
     92       
    8793        for( i = 0; commands[i].command; i++ )
    8894                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
     
    9197                        {
    9298                                irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
     99                                g_mutex_unlock(irc->otr_mutex);
    93100                                return;
    94101                        }
    95102                        commands[i].execute( irc, cmd );
     103                        g_mutex_unlock(irc->otr_mutex);
    96104                        return;
    97105                }
    98106       
    99107        irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] );
     108        g_mutex_unlock(irc->otr_mutex);
    100109}
    101110
     
    241250               
    242251                irc_usermsg( irc, "Account successfully added" );
     252               
     253                otr_check_for_key(a);
    243254        }
    244255        else if( g_strcasecmp( cmd[1], "del" ) == 0 )
     
    9911002        { "qlist",          0, cmd_qlist,          0 },
    9921003        { "join_chat",      2, cmd_join_chat,      0 },
     1004        { "otr",            1, cmd_otr,            0 },
    9931005        { NULL }
    9941006};
  • storage.c

    rb5c8a34 r764c7d1  
    2929#include "bitlbee.h"
    3030#include "crypting.h"
     31#include "otr.h"
    3132
    3233extern storage_t storage_text;
     
    115116                if (status == STORAGE_OK) {
    116117                        irc_setpass(irc, password);
     118                        otr_load(irc);          /* load our OTR userstate */
    117119                        return status;
    118120                }
    119121               
    120                 if (status != STORAGE_NO_SUCH_USER)
     122                if (status != STORAGE_NO_SUCH_USER) {
    121123                        return status;
     124                }
    122125        }
    123126       
     
    127130storage_status_t storage_save (irc_t *irc, int overwrite)
    128131{
    129         return ((storage_t *)global.storage->data)->save(irc, overwrite);
     132        storage_status_t st;
     133       
     134        otr_save(irc);
     135        st = ((storage_t *)global.storage->data)->save(irc, overwrite);
     136        return st;
    130137}
    131138
     
    147154                        ret = status;
    148155        }
     156        if (ret == STORAGE_OK) {
     157                otr_remove(nick);
     158        }
    149159       
    150160        return ret;
     
    157167        storage_t *primary_storage = gl->data;
    158168        irc_t *irc;
    159 
     169       
    160170        /* First, try to rename in the current write backend, assuming onick
    161171         * is stored there */
    162172        status = primary_storage->rename(onick, nnick, password);
    163         if (status != STORAGE_NO_SUCH_USER)
     173        if (status != STORAGE_NO_SUCH_USER) {
     174                otr_rename(onick, nnick);
    164175                return status;
     176        }
    165177
    166178        /* Try to load from a migration backend and save to the current backend.
     
    186198
    187199        storage_remove(onick, password);
     200        otr_rename(onick, nnick);
    188201
    189202        return STORAGE_OK;
  • unix.c

    rb5c8a34 r764c7d1  
    2727#include "commands.h"
    2828#include "crypting.h"
     29#include "otr.h"
    2930#include "protocols/nogaim.h"
    3031#include "help.h"
     
    5455        b_main_init();
    5556        nogaim_init();
     57        otr_init();
    5658       
    5759        srand( time( NULL ) ^ getpid() );
  • user.c

    rb5c8a34 r764c7d1  
    141141}
    142142
    143 user_t *user_findhandle( struct im_connection *ic, char *handle )
     143user_t *user_findhandle( struct im_connection *ic, const char *handle )
    144144{
    145145        user_t *u;
  • user.h

    rb5c8a34 r764c7d1  
    5656int user_del( irc_t *irc, char *nick );
    5757G_MODULE_EXPORT user_t *user_find( irc_t *irc, char *nick );
    58 G_MODULE_EXPORT user_t *user_findhandle( struct im_connection *ic, char *handle );
     58G_MODULE_EXPORT user_t *user_findhandle( struct im_connection *ic, const char *handle );
    5959void user_rename( irc_t *irc, char *oldnick, char *newnick );
    6060
Note: See TracChangeset for help on using the changeset viewer.