Changeset 0c85c08
- Timestamp:
- 2010-08-31T23:18:21Z (14 years ago)
- Branches:
- master
- Children:
- 934db064
- Parents:
- f5c0d8e
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
bitlbee.h
rf5c0d8e r0c85c08 142 142 #include "misc.h" 143 143 #include "proxy.h" 144 #include "otr.h"145 144 146 145 typedef struct global { … … 154 153 char *helpfile; 155 154 int restart; 156 OtrlMessageAppOps otr_ops; /* collects interface functions required by OTR */157 155 } global_t; 158 156 -
irc.c
rf5c0d8e r0c85c08 29 29 30 30 GSList *irc_connection_list; 31 GSList *irc_plugins; 31 32 32 33 static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond ); … … 42 43 char *host = NULL, *myhost = NULL; 43 44 irc_user_t *iu; 45 GSList *l; 44 46 set_t *s; 45 47 bee_t *b; … … 164 166 nogaim_init(); 165 167 168 for( l = irc_plugins; l; l = l->next ) 169 { 170 irc_plugin_t *p = l->data; 171 if( p->irc_new ) 172 p->irc_new( irc ); 173 } 174 166 175 return irc; 167 176 } … … 207 216 void irc_free( irc_t * irc ) 208 217 { 218 GSList *l; 219 209 220 irc->status |= USTATUS_SHUTDOWN; 210 221 211 222 log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd ); 223 224 for( l = irc_plugins; l; l = l->next ) 225 { 226 irc_plugin_t *p = l->data; 227 if( p->irc_free ) 228 p->irc_free( irc ); 229 } 212 230 213 231 if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->b->set, "save_on_quit" ) ) … … 932 950 return SET_INVALID; 933 951 } 952 953 void register_irc_plugin( const struct irc_plugin *p ) 954 { 955 irc_plugins = g_slist_prepend( irc_plugins, (gpointer) p ); 956 } -
irc.h
rf5c0d8e r0c85c08 26 26 #ifndef _IRC_H 27 27 #define _IRC_H 28 29 #include "otr.h"30 28 31 29 #define IRC_MAX_LINE 512 … … 88 86 gint login_source_id; /* To slightly delay some events at login time. */ 89 87 90 otr_t *otr; /* OTR state and book keeping */ 88 struct otr *otr; /* OTR state and book keeping, used by the OTR plugin. 89 TODO: Some mechanism for plugindata. */ 91 90 92 91 struct bee *b; … … 221 220 } irc_channel_del_user_type_t; 222 221 222 /* These are a glued a little bit to the core/bee layer and a little bit to 223 IRC. The first user is OTR, and I guess at some point we'll get to shape 224 this a little bit more as other uses come up. */ 225 typedef struct irc_plugin 226 { 227 /* Called at the end of irc_new(). Can be used to add settings, etc. */ 228 gboolean (*irc_new)( irc_t *irc ); 229 /* At the end of irc_free(). */ 230 void (*irc_free)( irc_t *irc ); 231 232 /* Called by bee_irc_user_privmsg_cb(). Return NULL if you want to 233 abort sending the msg. */ 234 char* (*filter_msg_out)( irc_user_t *iu, const char *msg, int flags ); 235 /* Called by bee_irc_user_msg(). Return NULL if you swallowed the 236 message and don't want anything to go to the user. */ 237 char* (*filter_msg_in)( irc_user_t *iu, const char *msg, int flags ); 238 } irc_plugin_t; 239 240 extern GSList *irc_plugins; /* struct irc_plugin */ 241 223 242 /* irc.c */ 224 243 extern GSList *irc_connection_list; … … 245 264 246 265 void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv ); 266 267 void register_irc_plugin( const struct irc_plugin *p ); 247 268 248 269 /* irc_channel.c */ -
otr.c
rf5c0d8e r0c85c08 109 109 } pair_t; 110 110 111 static OtrlMessageAppOps otr_ops; /* collects interface functions required by OTR */ 112 111 113 112 114 /** misc. helpers/subroutines: **/ … … 174 176 OtrlPrivKey *match_privkey(irc_t *irc, const char **args); 175 177 178 /* functions to be called for certain events */ 179 static const struct irc_plugin otr_plugin; 180 176 181 177 182 /*** routines declared in otr.h: ***/ … … 182 187 183 188 /* fill global OtrlMessageAppOps */ 184 global.otr_ops.policy = &op_policy;185 global.otr_ops.create_privkey = &op_create_privkey;186 global.otr_ops.is_logged_in = &op_is_logged_in;187 global.otr_ops.inject_message = &op_inject_message;188 global.otr_ops.notify = NULL;189 global.otr_ops.display_otr_message = &op_display_otr_message;190 global.otr_ops.update_context_list = NULL;191 global.otr_ops.protocol_name = NULL;192 global.otr_ops.protocol_name_free = NULL;193 global.otr_ops.new_fingerprint = &op_new_fingerprint;194 global.otr_ops.write_fingerprints = &op_write_fingerprints;195 global.otr_ops.gone_secure = &op_gone_secure;196 global.otr_ops.gone_insecure = &op_gone_insecure;197 global.otr_ops.still_secure = &op_still_secure;198 global.otr_ops.log_message = &op_log_message;199 global.otr_ops.max_message_size = &op_max_message_size;200 global.otr_ops.account_name = &op_account_name;201 global.otr_ops.account_name_free = NULL;189 otr_ops.policy = &op_policy; 190 otr_ops.create_privkey = &op_create_privkey; 191 otr_ops.is_logged_in = &op_is_logged_in; 192 otr_ops.inject_message = &op_inject_message; 193 otr_ops.notify = NULL; 194 otr_ops.display_otr_message = &op_display_otr_message; 195 otr_ops.update_context_list = NULL; 196 otr_ops.protocol_name = NULL; 197 otr_ops.protocol_name_free = NULL; 198 otr_ops.new_fingerprint = &op_new_fingerprint; 199 otr_ops.write_fingerprints = &op_write_fingerprints; 200 otr_ops.gone_secure = &op_gone_secure; 201 otr_ops.gone_insecure = &op_gone_insecure; 202 otr_ops.still_secure = &op_still_secure; 203 otr_ops.log_message = &op_log_message; 204 otr_ops.max_message_size = &op_max_message_size; 205 otr_ops.account_name = &op_account_name; 206 otr_ops.account_name_free = NULL; 202 207 203 208 root_command_add( "otr", 1, cmd_otr, 0 ); 204 } 205 206 otr_t *otr_new(void) 207 { 208 otr_t *otr = g_new0(otr_t, 1); 209 210 otr->us = otrl_userstate_create(); 211 212 return otr; 213 } 214 215 void otr_free(otr_t *otr) 216 { 209 register_irc_plugin( &otr_plugin ); 210 } 211 212 gboolean otr_irc_new(irc_t *irc) 213 { 214 set_t *s; 215 GSList *l; 216 217 irc->otr = g_new0(otr_t, 1); 218 irc->otr->us = otrl_userstate_create(); 219 220 s = set_add( &irc->b->set, "otr_color_encrypted", "true", set_eval_bool, irc ); 221 222 s = set_add( &irc->b->set, "otr_policy", "oppurtunistic", set_eval_list, irc ); 223 l = g_slist_prepend( NULL, "never" ); 224 l = g_slist_prepend( l, "opportunistic" ); 225 l = g_slist_prepend( l, "manual" ); 226 l = g_slist_prepend( l, "always" ); 227 s->eval_data = l; 228 229 return TRUE; 230 } 231 232 void otr_irc_free(irc_t *irc) 233 { 234 otr_t *otr = irc->otr; 217 235 otrl_userstate_free(otr->us); 218 236 if(otr->keygen) { … … 339 357 } 340 358 341 ignore_msg = otrl_message_receiving(irc->otr->us, & global.otr_ops, ic,359 ignore_msg = otrl_message_receiving(irc->otr->us, &otr_ops, ic, 342 360 ic->acc->user, ic->acc->prpl->name, handle, msg, &newmsg, 343 361 &tlvs, NULL, NULL); … … 393 411 } 394 412 395 st = otrl_message_sending(irc->otr->us, & global.otr_ops, ic,413 st = otrl_message_sending(irc->otr->us, &otr_ops, ic, 396 414 ic->acc->user, ic->acc->prpl->name, handle, 397 415 msg, NULL, &otrmsg, NULL, NULL); … … 409 427 return 1; 410 428 } 411 st = otrl_message_fragment_and_send(& global.otr_ops, ic, ctx,429 st = otrl_message_fragment_and_send(&otr_ops, ic, ctx, 412 430 otrmsg, OTRL_FRAGMENT_SEND_ALL, NULL); 413 431 otrl_message_free(otrmsg); … … 420 438 return st; 421 439 } 440 441 static const struct irc_plugin otr_plugin = 442 { 443 otr_irc_new, 444 otr_irc_free, 445 }; 422 446 423 447 static void cmd_otr(irc_t *irc, char **args) … … 663 687 } 664 688 665 otrl_message_disconnect(irc->otr->us, & global.otr_ops,689 otrl_message_disconnect(irc->otr->us, &otr_ops, 666 690 u->bu->ic, u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, u->bu->handle); 667 691 … … 721 745 "SMP already in phase %d, sending abort before reinitiating", 722 746 ctx->smstate->nextExpected+1); 723 otrl_message_abort_smp(irc->otr->us, & global.otr_ops, u->bu->ic, ctx);747 otrl_message_abort_smp(irc->otr->us, &otr_ops, u->bu->ic, ctx); 724 748 otrl_sm_state_free(ctx->smstate); 725 749 } … … 729 753 if(ctx->smstate->secret == NULL) { 730 754 irc_usermsg(irc, "smp: initiating with %s...", u->nick); 731 otrl_message_initiate_smp(irc->otr->us, & global.otr_ops,755 otrl_message_initiate_smp(irc->otr->us, &otr_ops, 732 756 u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2])); 733 757 /* smp is now in EXPECT2 */ … … 736 760 received the SMP1, so let's issue a response */ 737 761 irc_usermsg(irc, "smp: responding to %s...", u->nick); 738 otrl_message_respond_smp(irc->otr->us, & global.otr_ops,762 otrl_message_respond_smp(irc->otr->us, &otr_ops, 739 763 u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2])); 740 764 /* smp is now in EXPECT3 */ … … 1050 1074 irc_t *irc = ic->bee->ui_data; 1051 1075 OtrlUserState us = irc->otr->us; 1052 OtrlMessageAppOps *ops = & global.otr_ops;1076 OtrlMessageAppOps *ops = &otr_ops; 1053 1077 OtrlTLV *tlv = NULL; 1054 1078 ConnContext *context; -
otr.h
rf5c0d8e r0c85c08 72 72 void otr_init(void); 73 73 74 /* called from irc_new()/irc_free() */75 otr_t *otr_new();76 void otr_free(otr_t *otr);77 78 74 /* called by storage_* functions */ 79 75 void otr_load(struct irc *irc); … … 98 94 typedef void *OtrlMessageAppOps; 99 95 100 #define otr_init() {}101 #define otr_new() (NULL)102 96 #define otr_free(otr) {} 103 97 #define otr_load(irc) {} -
storage.c
rf5c0d8e r0c85c08 28 28 #define BITLBEE_CORE 29 29 #include "bitlbee.h" 30 #include "otr.h"31 30 32 31 extern storage_t storage_text; … … 115 114 116 115 status = st->load(irc, password); 117 if (status == STORAGE_OK) { 118 otr_load(irc); 116 if (status == STORAGE_OK) 119 117 return status; 120 }118 121 119 if (status != STORAGE_NO_SUCH_USER) 122 120 return status; … … 139 137 return STORAGE_NO_SUCH_USER; 140 138 } 141 142 otr_save(irc); 139 143 140 st = ((storage_t *)global.storage->data)->save(irc, overwrite); 144 141 … … 166 163 ret = status; 167 164 } 168 if (ret == STORAGE_OK) {169 otr_remove(nick);170 }171 165 172 166 return ret; … … 182 176 storage_t *primary_storage = gl->data; 183 177 irc_t *irc; 184 178 185 179 /* First, try to rename in the current write backend, assuming onick 186 180 * is stored there */ 187 181 status = primary_storage->rename(onick, nnick, password); 188 if (status != STORAGE_NO_SUCH_USER) { 189 otr_rename(onick, nnick); 182 if (status != STORAGE_NO_SUCH_USER) 190 183 return status; 191 }192 184 193 185 /* Try to load from a migration backend and save to the current backend. … … 213 205 214 206 storage_remove(onick, password); 215 otr_rename(onick, nnick);216 207 217 208 return STORAGE_OK;
Note: See TracChangeset
for help on using the changeset viewer.