Changeset 934db064
- Timestamp:
- 2010-09-01T22:09:27Z (14 years ago)
- Branches:
- master
- Children:
- 2dcaf9a
- Parents:
- 0c85c08
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
irc.h
r0c85c08 r934db064 230 230 void (*irc_free)( irc_t *irc ); 231 231 232 /* Problem with the following two functions is ordering if multiple 233 plugins are handling them. Let's keep fixing that problem for 234 whenever it becomes important. */ 235 232 236 /* Called by bee_irc_user_privmsg_cb(). Return NULL if you want to 233 237 abort sending the msg. */ 234 char* (*filter_msg_out)( irc_user_t *iu, c onst char *msg, int flags );238 char* (*filter_msg_out)( irc_user_t *iu, char *msg, int flags ); 235 239 /* Called by bee_irc_user_msg(). Return NULL if you swallowed the 236 240 message and don't want anything to go to the user. */ 237 char* (*filter_msg_in)( irc_user_t *iu, c onst char *msg, int flags );241 char* (*filter_msg_in)( irc_user_t *iu, char *msg, int flags ); 238 242 } irc_plugin_t; 239 243 -
irc_im.c
r0c85c08 r934db064 192 192 } 193 193 194 static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg , time_t sent_at )194 static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg_, time_t sent_at ) 195 195 { 196 196 irc_t *irc = bee->ui_data; … … 199 199 char *wrapped, *ts = NULL; 200 200 irc_channel_t *ic = NULL; 201 char *msg = g_strdup( msg_ ); 202 GSList *l; 201 203 202 204 if( sent_at > 0 && set_getbool( &irc->b->set, "display_timestamps" ) ) … … 224 226 } 225 227 228 for( l = irc_plugins; l; l = l->next ) 229 { 230 irc_plugin_t *p = l->data; 231 if( p->filter_msg_in ) 232 { 233 char *s = p->filter_msg_in( iu, msg, 0 ); 234 if( s ) 235 { 236 if( s != msg ) 237 g_free( msg ); 238 msg = s; 239 } 240 else 241 { 242 /* Modules can swallow messages. */ 243 return TRUE; 244 } 245 } 246 } 247 248 if( ( g_strcasecmp( set_getstr( &bee->set, "strip_html" ), "always" ) == 0 ) || 249 ( ( bu->ic->flags & OPT_DOES_HTML ) && set_getbool( &bee->set, "strip_html" ) ) ) 250 { 251 char *s = g_strdup( msg ); 252 strip_html( s ); 253 g_free( msg ); 254 msg = s; 255 } 256 226 257 wrapped = word_wrap( msg, 425 ); 227 258 irc_send_msg( iu, "PRIVMSG", dst, wrapped, prefix ); … … 229 260 g_free( wrapped ); 230 261 g_free( prefix ); 262 g_free( msg ); 231 263 g_free( ts ); 232 264 … … 349 381 } 350 382 383 if( iu->pastebuf == NULL ) 384 iu->pastebuf = g_string_new( msg ); 385 else 386 { 387 b_event_remove( iu->pastebuf_timer ); 388 g_string_append_printf( iu->pastebuf, "\n%s", msg ); 389 } 390 351 391 if( set_getbool( &iu->irc->b->set, "paste_buffer" ) ) 352 392 { 353 393 int delay; 354 355 if( iu->pastebuf == NULL )356 iu->pastebuf = g_string_new( msg );357 else358 {359 b_event_remove( iu->pastebuf_timer );360 g_string_append_printf( iu->pastebuf, "\n%s", msg );361 }362 394 363 395 if( ( delay = set_getint( &iu->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) … … 369 401 } 370 402 else 371 return bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); 403 { 404 bee_irc_user_privmsg_cb( iu, 0, 0 ); 405 406 return TRUE; 407 } 372 408 } 373 409 … … 375 411 { 376 412 irc_user_t *iu = data; 377 378 bee_user_msg( iu->irc->b, iu->bu, iu->pastebuf->str, 0 ); 379 380 g_string_free( iu->pastebuf, TRUE ); 381 iu->pastebuf = 0; 413 char *msg = g_string_free( iu->pastebuf, FALSE ); 414 GSList *l; 415 416 for( l = irc_plugins; l; l = l->next ) 417 { 418 irc_plugin_t *p = l->data; 419 if( p->filter_msg_out ) 420 { 421 char *s = p->filter_msg_out( iu, msg, 0 ); 422 if( s ) 423 { 424 if( s != msg ) 425 g_free( msg ); 426 msg = s; 427 } 428 else 429 { 430 /* Modules can swallow messages. */ 431 iu->pastebuf = NULL; 432 g_free( msg ); 433 return FALSE; 434 } 435 } 436 } 437 438 bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); 439 440 g_free( msg ); 441 iu->pastebuf = NULL; 382 442 iu->pastebuf_timer = 0; 383 443 -
otr.c
r0c85c08 r934db064 344 344 } 345 345 346 char *otr_ handle_message(struct im_connection *ic, const char *handle, const char *msg)346 char *otr_filter_msg_in(irc_user_t *iu, char *msg, int flags) 347 347 { 348 348 int ignore_msg; … … 350 350 OtrlTLV *tlvs = NULL; 351 351 char *colormsg; 352 irc_t *irc = ic->bee->ui_data; 352 irc_t *irc = iu->irc; 353 struct im_connection *ic = iu->bu->ic; 353 354 354 355 /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ 355 356 if(ic->acc->prpl->options & OPT_NOOTR) { 356 return (g_strdup(msg));357 return msg; 357 358 } 358 359 359 360 ignore_msg = otrl_message_receiving(irc->otr->us, &otr_ops, ic, 360 ic->acc->user, ic->acc->prpl->name, handle, msg, &newmsg,361 ic->acc->user, ic->acc->prpl->name, iu->bu->handle, msg, &newmsg, 361 362 &tlvs, NULL, NULL); 362 363 363 otr_handle_smp(ic, handle, tlvs);364 otr_handle_smp(ic, iu->bu->handle, tlvs); 364 365 365 366 if(ignore_msg) { … … 371 372 } else { 372 373 /* OTR has processed this message */ 373 ConnContext *context = otrl_context_find(irc->otr->us, handle,374 ConnContext *context = otrl_context_find(irc->otr->us, iu->bu->handle, 374 375 ic->acc->user, ic->acc->prpl->name, 0, NULL, NULL, NULL); 375 376 if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED && 376 set_getbool(&ic->bee->set, " color_encrypted")) {377 set_getbool(&ic->bee->set, "otr_color_encrypted")) { 377 378 /* color according to f'print trust */ 378 379 int color; … … 398 399 } 399 400 400 int otr_send_message(struct im_connection *ic, const char *handle, constchar *msg, int flags)401 char *otr_filter_msg_out(irc_user_t *iu, char *msg, int flags) 401 402 { 402 403 int st; 403 404 char *otrmsg = NULL; 404 405 ConnContext *ctx = NULL; 405 irc_t *irc = ic->bee->ui_data; 406 irc_t *irc = iu->irc; 407 struct im_connection *ic = iu->bu->ic; 406 408 407 409 /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ 408 410 if(ic->acc->prpl->options & OPT_NOOTR) { 409 /* TODO(wilmer): const */ 410 return (ic->acc->prpl->buddy_msg(ic, (char*) handle, (char*) msg, flags)); 411 return msg; 411 412 } 412 413 413 414 st = otrl_message_sending(irc->otr->us, &otr_ops, ic, 414 ic->acc->user, ic->acc->prpl->name, handle,415 ic->acc->user, ic->acc->prpl->name, iu->bu->handle, 415 416 msg, NULL, &otrmsg, NULL, NULL); 416 417 if(st) { 417 return st;418 return NULL; 418 419 } 419 420 420 421 ctx = otrl_context_find(irc->otr->us, 421 handle, ic->acc->user, ic->acc->prpl->name,422 iu->bu->handle, ic->acc->user, ic->acc->prpl->name, 422 423 1, NULL, NULL, NULL); 423 424 … … 425 426 if(!ctx) { 426 427 otrl_message_free(otrmsg); 427 return 1;428 return NULL; 428 429 } 429 430 st = otrl_message_fragment_and_send(&otr_ops, ic, ctx, … … 433 434 /* note: otrl_message_sending handles policy, so that if REQUIRE_ENCRYPTION is set, 434 435 this case does not occur */ 435 st = ic->acc->prpl->buddy_msg( ic, (char *)handle, (char *)msg, flags ); 436 } 437 438 return st; 436 return msg; 437 } 438 439 /* TODO: Error reporting should be done here now (if st!=0), probably. */ 440 441 return NULL; 439 442 } 440 443 … … 443 446 otr_irc_new, 444 447 otr_irc_free, 448 otr_filter_msg_out, 449 otr_filter_msg_in, 445 450 }; 446 451 … … 716 721 } 717 722 718 /* TODO(wilmer): imc_buddy_msg(u->bu->ic, u->bu->handle, "?OTR?", 0); */723 bee_user_msg(irc->b, u->bu, "?OTR?", 0); 719 724 } 720 725 -
otr.h
r0c85c08 r934db064 41 41 42 42 43 #ifdef WITH_OTR44 43 #include <libotr/proto.h> 45 44 #include <libotr/message.h> … … 81 80 int otr_check_for_key(struct account *a); 82 81 83 /* called from imcb_buddy_msg() */84 char *otr_handle_message(struct im_connection *ic, const char *handle,85 const char *msg);86 87 /* called from imc_buddy_msg() */88 int otr_send_message(struct im_connection *ic, const char *handle, const char *msg,89 int flags);90 91 #else92 93 typedef void otr_t;94 typedef void *OtrlMessageAppOps;95 96 #define otr_free(otr) {}97 #define otr_load(irc) {}98 #define otr_save(irc) {}99 #define otr_remove(nick) {}100 #define otr_rename(onick,nnick) {}101 #define otr_check_for_key(acc) (0)102 #define otr_handle_message(ic,handle,msg) (g_strdup(msg))103 #define otr_send_message(ic,h,m,f) (ic->acc->prpl->buddy_msg(ic,h,m,f))104 105 void cmd_otr_nosupport(void *, char **);106 107 82 #endif 108 #endif -
protocols/bee_user.c
r0c85c08 r934db064 238 238 } 239 239 240 if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||241 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )242 strip_html( msg );243 244 240 if( bee->ui->user_msg && bu ) 245 241 bee->ui->user_msg( bee, bu, msg, sent_at );
Note: See TracChangeset
for help on using the changeset viewer.