Changeset 5a71d9c
- Timestamp:
- 2008-02-09T17:58:13Z (17 years ago)
- Branches:
- master
- Children:
- f55cfe9
- Parents:
- a13855a
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
irc.c
ra13855a r5a71d9c 102 102 103 103 irc_connection_list = g_slist_append( irc_connection_list, irc ); 104 105 set_add( &irc->set, "away_devoice", "true", set_eval_away_devoice, irc ); 104 106 105 set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc ); 107 106 set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc ); … … 115 114 set_add( &irc->set, "handle_unknown", "root", NULL, irc ); 116 115 set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc ); 117 set_add( &irc->set, "ops", "both", set_eval_ops, irc ); 116 set_add( &irc->set, "op_buddies", "false", set_eval_op_buddies, irc ); 117 set_add( &irc->set, "op_root", "true", set_eval_op_root, irc ); 118 set_add( &irc->set, "op_user", "true", set_eval_op_user, irc ); 118 119 set_add( &irc->set, "password", NULL, passchange, irc ); 119 120 set_add( &irc->set, "private", "true", set_eval_bool, irc ); … … 124 125 set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc ); 125 126 set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc ); 127 set_add( &irc->set, "voice_buddies", "notaway", set_eval_voice_buddies, irc ); 126 128 127 129 conf_loaddefaults( irc ); … … 643 645 char namelist[385] = ""; 644 646 struct groupchat *c = NULL; 645 char *ops = set_getstr( &irc->set, "ops" ); 647 char *oo = set_getstr(&irc->set, "op_buddies"); 648 char *vo = set_getstr(&irc->set, "voice_buddies"); 646 649 647 650 /* RFCs say there is no error reply allowed on NAMES, so when the … … 658 661 } 659 662 660 if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice") )663 if( u->ic && !u->away && !strcmp(vo, "notaway") ) 661 664 strcat( namelist, "+" ); 662 else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) || 663 ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ) 665 else if( ( strcmp( u->nick, irc->mynick ) == 0 && set_getbool(&irc->set, "op_root") ) || 666 ( strcmp( u->nick, irc->nick ) == 0 && set_getbool(&irc->set, "op_user") ) || 667 ( !u->away && !strcmp(oo, "notaway") ) || 668 ( u->encrypted>1 && !strcmp(oo, "trusted") ) || 669 ( u->encrypted && !strcmp(oo, "encrypted") ) ) 664 670 strcat( namelist, "@" ); 665 671 … … 674 680 /* root and the user aren't in the channel userlist but should 675 681 show up in /NAMES, so list them first: */ 676 sprintf( namelist, "%s%s %s%s ", strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->mynick, 677 strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->nick ); 678 682 sprintf( namelist, "%s%s %s%s ", set_getbool(&irc->set, "op_root") ? "@" : "", irc->mynick, 683 set_getbool(&irc->set, "op_user") ? "@" : "", irc->nick ); 684 685 /* TODO: Honor op/voice_buddies in chats?! */ 679 686 for( l = c->in_room; l; l = l->next ) if( ( u = user_findhandle( c->ic, l->data ) ) ) 680 687 { -
irc.h
ra13855a r5a71d9c 30 30 31 31 #define IRC_MAX_LINE 512 32 #define IRC_MAX_ARGS 832 #define IRC_MAX_ARGS 16 33 33 34 34 #define IRC_LOGIN_TIMEOUT 60 -
lib/misc.c
ra13855a r5a71d9c 143 143 char *s = out, *cs; 144 144 int i, matched; 145 int taglen; 145 146 146 147 memset( out, 0, strlen( in ) + 1 ); … … 159 160 in ++; 160 161 162 taglen = in-cs-1; /* not <0 because the above loop runs at least once */ 161 163 if( *in ) 162 164 { 163 if( g_strncasecmp( cs+1, "br", 2) == 0 ) 165 if( g_strncasecmp( cs+1, "b", taglen) == 0 ) 166 *(s++) = '\x02'; 167 else if( g_strncasecmp( cs+1, "/b", taglen) == 0 ) 168 *(s++) = '\x02'; 169 else if( g_strncasecmp( cs+1, "i", taglen) == 0 ) 170 *(s++) = '\x1f'; 171 else if( g_strncasecmp( cs+1, "/i", taglen) == 0 ) 172 *(s++) = '\x1f'; 173 else if( g_strncasecmp( cs+1, "br", 2) == 0 ) 164 174 *(s++) = '\n'; 165 175 in ++; -
otr.c
ra13855a r5a71d9c 35 35 void op_gone_secure(void *opdata, ConnContext *context); 36 36 37 void op_gone_secure(void *opdata, ConnContext *context);38 39 37 void op_gone_insecure(void *opdata, ConnContext *context); 40 38 … … 53 51 void cmd_otr_abort(irc_t *irc, char **args); /* TODO: does this cmd even make sense? */ 54 52 void cmd_otr_request(irc_t *irc, char **args); /* TODO: do we even need this? */ 55 void cmd_otr_auth(irc_t *irc, char **args); 53 void cmd_otr_smp(irc_t *irc, char **args); 54 void cmd_otr_trust(irc_t *irc, char **args); 56 55 /* TODO: void cmd_otr_affirm(irc_t *irc, char **args); */ 57 56 void cmd_otr_fprints(irc_t *irc, char **args); … … 62 61 { "abort", 1, &cmd_otr_abort, 0 }, 63 62 { "request", 1, &cmd_otr_request, 0 }, 64 { "auth", 2, &cmd_otr_auth, 0 }, 63 { "smp", 2, &cmd_otr_smp, 0 }, 64 { "trust", 6, &cmd_otr_trust, 0 }, 65 65 { "fprints", 0, &cmd_otr_fprints, 0 }, 66 66 { "info", 1, &cmd_otr_info, 0 }, … … 97 97 const char *protocol); 98 98 99 /* determine the nick for a given handle/protocol pair */ 99 /* determine the nick for a given handle/protocol pair 100 returns "handle/protocol" if not found */ 100 101 const char *peernick(irc_t *irc, const char *handle, const char *protocol); 102 103 /* determine the user_t for a given handle/protocol pair 104 returns NULL if not found */ 105 user_t *peeruser(irc_t *irc, const char *handle, const char *protocol); 101 106 102 107 /* handle SMP TLVs from a received message */ 103 108 void otr_handle_smp(struct im_connection *ic, const char *handle, OtrlTLV *tlvs); 109 110 /* update op/voice flag of given user according to encryption state and settings 111 returns 0 if neither op_buddies nor voice_buddies is set to "encrypted", 112 i.e. msgstate should be announced seperately */ 113 int otr_update_modeflags(irc_t *irc, user_t *u); 104 114 105 115 /* show the list of fingerprints associated with a given context */ … … 239 249 240 250 if(!g_mutex_trylock(ic->irc->otr_mutex)) { 241 /* TODO: queue msgs received during keygen for later */ 242 irc_usermsg(ic->irc, "msg from %s during keygen - dropped", 251 user_t *u = user_findhandle(ic, handle); 252 253 /* fallback for non-otr clients */ 254 if(u && !u->encrypted) { 255 return g_strdup(msg); 256 } 257 258 /* TODO: queue msgs received during keygen for later? */ 259 irc_usermsg(ic->irc, "otr msg from %s during keygen - dropped", 243 260 peernick(ic->irc, handle, ic->acc->prpl->name)); 244 261 return NULL; … … 283 300 int otr_send_message(struct im_connection *ic, const char *handle, const char *msg, int flags) 284 301 { 285 286 287 288 302 int st; 303 char *otrmsg = NULL; 304 ConnContext *ctx = NULL; 305 289 306 if(!g_mutex_trylock(ic->irc->otr_mutex)) { 290 irc_usermsg(ic->irc, "msg to %s during keygen - not sent", 291 peernick(ic->irc, handle, ic->acc->prpl->name)); 292 return 1; 307 user_t *u = user_findhandle(ic, handle); 308 309 /* Fallback for non-otr clients. 310 Yes, we must be very sure this doesn't send stuff in the clear where it 311 shouldn't... */ 312 if(u && !u->encrypted) { 313 return ic->acc->prpl->buddy_msg(ic, (char *)handle, (char *)msg, flags); 314 } 315 316 /* otherwise refuse to send */ 317 irc_usermsg(ic->irc, "otr msg to %s not sent during keygen", 318 peernick(ic->irc, handle, ic->acc->prpl->name)); 319 return 1; 293 320 } 294 321 … … 414 441 415 442 int op_display_otr_message(void *opdata, const char *accountname, 416 const char *protocol, const char *username, const char *m sg)443 const char *protocol, const char *username, const char *message) 417 444 { 418 445 struct im_connection *ic = check_imc(opdata, accountname, protocol); 419 420 log_message(LOGLVL_DEBUG, "op_display_otr_message '%s' '%s' '%s' '%s'", accountname, protocol, username, msg); 421 422 irc_usermsg(ic->irc, "%s", msg); 423 446 char *msg = g_strdup(message); 447 448 log_message(LOGLVL_DEBUG, "op_display_otr_message '%s' '%s' '%s' '%s'", accountname, protocol, username, message); 449 450 strip_html(msg); 451 irc_usermsg(ic->irc, "otr: %s", msg); 452 453 g_free(msg); 424 454 return 0; 425 455 } … … 452 482 struct im_connection *ic = 453 483 check_imc(opdata, context->accountname, context->protocol); 484 user_t *u; 454 485 455 486 log_message(LOGLVL_DEBUG, "op_gone_secure '%s' '%s' '%s'", context->accountname, context->protocol, context->username); 456 487 457 irc_usermsg(ic->irc, "conversation with %s is now off the record", 458 peernick(ic->irc, context->username, context->protocol)); 488 u = peeruser(ic->irc, context->username, context->protocol); 489 if(!u) { 490 log_message(LOGLVL_ERROR, 491 "BUG: otr.c: op_gone_secure: user_t for %s/%s not found!", 492 context->username, context->protocol); 493 return; 494 } 495 if(context->active_fingerprint->trust[0]) 496 u->encrypted = 2; 497 else 498 u->encrypted = 1; 499 if(!otr_update_modeflags(ic->irc, u)) 500 irc_usermsg(ic->irc, "conversation with %s is now off the record", u->nick); 459 501 } 460 502 … … 463 505 struct im_connection *ic = 464 506 check_imc(opdata, context->accountname, context->protocol); 507 user_t *u; 465 508 466 509 log_message(LOGLVL_DEBUG, "op_gone_insecure '%s' '%s' '%s'", context->accountname, context->protocol, context->username); 467 510 468 irc_usermsg(ic->irc, "conversation with %s is now in the clear", 469 peernick(ic->irc, context->username, context->protocol)); 511 u = peeruser(ic->irc, context->username, context->protocol); 512 if(!u) { 513 log_message(LOGLVL_ERROR, 514 "BUG: otr.c: op_gone_insecure: user_t for %s/%s not found!", 515 context->username, context->protocol); 516 return; 517 } 518 u->encrypted = 0; 519 if(!otr_update_modeflags(ic->irc, u)) 520 irc_usermsg(ic->irc, "conversation with %s is now in the clear", u->nick); 470 521 } 471 522 … … 474 525 struct im_connection *ic = 475 526 check_imc(opdata, context->accountname, context->protocol); 527 user_t *u; 476 528 477 529 log_message(LOGLVL_DEBUG, "op_still_secure '%s' '%s' '%s' is_reply=%d", 478 530 context->accountname, context->protocol, context->username, is_reply); 479 531 480 irc_usermsg(ic->irc, "otr connection with %s has been refreshed", 481 peernick(ic->irc, context->username, context->protocol)); 532 u = peeruser(ic->irc, context->username, context->protocol); 533 if(!u) { 534 log_message(LOGLVL_ERROR, 535 "BUG: otr.c: op_still_secure: user_t for %s/%s not found!", 536 context->username, context->protocol); 537 return; 538 } 539 if(context->active_fingerprint->trust[0]) 540 u->encrypted = 2; 541 else 542 u->encrypted = 1; 543 if(!otr_update_modeflags(ic->irc, u)) 544 irc_usermsg(ic->irc, "otr connection with %s has been refreshed", u->nick); 482 545 } 483 546 484 547 void op_log_message(void *opdata, const char *message) 485 548 { 486 log_message(LOGLVL_INFO, "%s", message); 549 char *msg = g_strdup(message); 550 551 strip_html(msg); 552 log_message(LOGLVL_INFO, "otr: %s", msg); 553 g_free(msg); 487 554 } 488 555 489 556 int op_max_message_size(void *opdata, ConnContext *context) 490 557 { 491 /* TODO: make max_message_size a property of the prpl. 492 the values here are taken from the libotr UPGRADING file */ 493 if(!strcmp(context->protocol, "msn")) 494 return 1409; 495 if(!strcmp(context->protocol, "yahoo")) 496 return 832; 497 if(!strcmp(context->protocol, "oscar")) 498 return 2343; 558 struct im_connection *ic = 559 check_imc(opdata, context->accountname, context->protocol); 560 561 return ic->acc->prpl->mms; 499 562 } 500 563 … … 542 605 } 543 606 544 void cmd_otr_ auth(irc_t *irc, char **args)607 void cmd_otr_smp(irc_t *irc, char **args) 545 608 { 546 609 user_t *u; … … 589 652 } 590 653 654 int hexval(char a) 655 { 656 int x=tolower(a); 657 658 if(x>='a' && x<='f') 659 x = x - 'a' + 10; 660 else if(x>='0' && x<='9') 661 x = x - '0'; 662 else 663 return -1; 664 665 return x; 666 } 667 668 void cmd_otr_trust(irc_t *irc, char **args) 669 { 670 user_t *u; 671 ConnContext *ctx; 672 unsigned char raw[20]; 673 Fingerprint *fp; 674 int i,j; 675 676 u = user_find(irc, args[1]); 677 if(!u || !u->ic) { 678 irc_usermsg(irc, "%s: unknown user", args[1]); 679 return; 680 } 681 682 ctx = otrl_context_find(irc->otr_us, u->handle, 683 u->ic->acc->user, u->ic->acc->prpl->name, 0, NULL, NULL, NULL); 684 if(!ctx) { 685 irc_usermsg(irc, "%s: no otr context with user", args[1]); 686 return; 687 } 688 689 /* convert given fingerprint to raw representation */ 690 for(i=0; i<5; i++) { 691 for(j=0; j<4; j++) { 692 char *p = args[2+i]+(2*j); 693 char *q = p+1; 694 int x, y; 695 696 if(!*p || !*q) { 697 irc_usermsg(irc, "failed: truncated fingerprint block %d", i+1); 698 return; 699 } 700 701 x = hexval(*p); 702 y = hexval(*q); 703 if(x<0) { 704 irc_usermsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+1, i+1); 705 return; 706 } 707 if(y<0) { 708 irc_usermsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+2, i+1); 709 return; 710 } 711 712 raw[i*4+j] = x*16 + y; 713 } 714 } 715 fp = otrl_context_find_fingerprint(ctx, raw, 0, NULL); 716 if(!fp) { 717 irc_usermsg(irc, "failed: no such fingerprint for %s", args[1]); 718 } else { 719 char *trust = args[7] ? args[7] : "affirmed"; 720 otrl_context_set_trust(fp, trust); 721 irc_usermsg(irc, "fingerprint match, trust set to \"%s\"", trust); 722 if(u->encrypted) 723 u->encrypted = 2; 724 otr_update_modeflags(irc, u); 725 } 726 } 727 591 728 void cmd_otr_fprints(irc_t *irc, char **args) 592 729 { … … 649 786 u->ic->acc->user, u->ic->acc->prpl->name, 0, NULL, NULL, NULL); 650 787 if(!ctx) { 651 irc_usermsg(irc, "no otr info on%s", args[1]);788 irc_usermsg(irc, "no otr context with %s", args[1]); 652 789 return; 653 790 } … … 672 809 irc_usermsg(irc, " otr offer status: %s", offer_status); 673 810 irc_usermsg(irc, " connection state: %s", message_state); 674 irc_usermsg(irc, " protocol version: %d", ctx->protocol_version); 675 fp = ctx->active_fingerprint; 676 if(!fp) { 677 irc_usermsg(irc, " active f'print: none"); 678 } else { 679 otrl_privkey_hash_to_human(human, fp->fingerprint); 680 if(!fp->trust || fp->trust[0] == '\0') { 681 trust="untrusted"; 811 812 if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 813 irc_usermsg(irc, " protocol version: %d", ctx->protocol_version); 814 fp = ctx->active_fingerprint; 815 if(!fp) { 816 irc_usermsg(irc, " active f'print: none?"); 682 817 } else { 683 trust=fp->trust; 684 } 685 irc_usermsg(irc, " active f'print: %s (%s)", human, trust); 818 otrl_privkey_hash_to_human(human, fp->fingerprint); 819 if(!fp->trust || fp->trust[0] == '\0') { 820 trust="untrusted"; 821 } else { 822 trust=fp->trust; 823 } 824 irc_usermsg(irc, " active f'print: %s (%s)", human, trust); 825 } 686 826 } 687 827 } … … 809 949 } 810 950 811 const char *peernick(irc_t *irc, const char *handle, const char *protocol)951 user_t *peeruser(irc_t *irc, const char *handle, const char *protocol) 812 952 { 813 953 user_t *u; 814 static char fallback[512]; 815 816 g_snprintf(fallback, 511, "%s/%s", handle, protocol); 954 817 955 for(u=irc->users; u; u=u->next) { 818 956 struct prpl *prpl; … … 822 960 if(strcmp(prpl->name, protocol) == 0 823 961 && prpl->handle_cmp(u->handle, handle) == 0) { 824 return u->nick; 825 } 826 } 827 828 return fallback; 962 return u; 963 } 964 } 965 966 return NULL; 967 } 968 969 const char *peernick(irc_t *irc, const char *handle, const char *protocol) 970 { 971 static char fallback[512]; 972 973 user_t *u = peeruser(irc, handle, protocol); 974 if(u) { 975 return u->nick; 976 } else { 977 g_snprintf(fallback, 511, "%s/%s", handle, protocol); 978 return fallback; 979 } 980 } 981 982 int otr_update_modeflags(irc_t *irc, user_t *u) 983 { 984 char *vo = set_getstr(&irc->set, "voice_buddies"); 985 char *oo = set_getstr(&irc->set, "op_buddies"); 986 char eflag=0, tflag=0; 987 int e = u->encrypted; 988 int t = (u->encrypted > 1); 989 990 if(!strcmp(vo, "encrypted")) 991 eflag='v'; 992 else if(!strcmp(oo, "encrypted")) 993 eflag='o'; 994 if(!strcmp(vo, "trusted")) 995 tflag='v'; 996 else if(!strcmp(oo, "trusted")) 997 tflag='o'; 998 999 if(!eflag) 1000 return 0; 1001 1002 if(tflag) { 1003 irc_write( irc, ":%s!%s@%s MODE %s %c%c%c%c %s %s", irc->mynick, irc->mynick, irc->myhost, 1004 irc->channel, e?'+':'-', eflag, t?'+':'-', tflag, u->nick, u->nick ); 1005 } else { 1006 irc_write( irc, ":%s!%s@%s MODE %s %c%c %s", irc->mynick, irc->mynick, irc->myhost, 1007 irc->channel, e?'+':'-', eflag, u->nick ); 1008 } 1009 1010 return 1; 829 1011 } 830 1012 … … 966 1148 account_t *acc = (account_t *)data; 967 1149 968 /* TODO: remember that we didn't want a key? */969 1150 irc_usermsg(acc->irc, "proceeding without key, otr inoperable on %s/%s", 970 1151 acc->user, acc->prpl->name); 1152 /* TODO: 1153 irc_usermsg(acc->irc, "setting otr policy for %s/%s to \"never\"", 1154 acc->user, acc->prpl->name); 1155 set_setstr(acc->set, "otr_policy", "never"); 1156 */ 971 1157 } 972 1158 -
protocols/jabber/jabber.c
ra13855a r5a71d9c 511 511 512 512 ret->name = "jabber"; 513 ret->mms = 0; /* no limit */ 513 514 ret->login = jabber_login; 514 515 ret->init = jabber_init; -
protocols/msn/msn.c
ra13855a r5a71d9c 372 372 373 373 ret->name = "msn"; 374 ret->mms = 1409; /* this guess taken from libotr UPGRADING file */ 374 375 ret->login = msn_login; 375 376 ret->init = msn_init; -
protocols/nogaim.c
ra13855a r5a71d9c 603 603 604 604 /* LISPy... */ 605 if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ 606 ( u->online ) && /* Don't touch offline people */ 607 ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ 608 ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ 605 if( ( u->online ) && /* Don't touch offline people */ 606 ( ( ( u->online != oo ) && !u->away ) || /* Do joining people */ 607 ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* Do people changing state */ 609 608 { 610 609 char *from; … … 619 618 ic->irc->myhost ); 620 619 } 621 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, 622 u->away?'-':'+', u->nick ); 620 if(!strcmp(set_getstr(&ic->irc->set, "voice_buddies"), "notaway")) { 621 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, 622 u->away?'-':'+', u->nick ); 623 } 624 if(!strcmp(set_getstr(&ic->irc->set, "op_buddies"), "notaway")) { 625 irc_write( ic->irc, ":%s MODE %s %co %s", from, ic->irc->channel, 626 u->away?'-':'+', u->nick ); 627 } 623 628 g_free( from ); 624 629 } -
protocols/nogaim.h
ra13855a r5a71d9c 136 136 * - The user sees this name ie. when imcb_log() is used. */ 137 137 const char *name; 138 /* Maximum Message Size of this protocol. 139 * - Introduced for OTR, in order to fragment large protocol messages. 140 * - 0 means "unlimited". */ 141 unsigned int mms; 138 142 139 143 /* Added this one to be able to add per-account settings, don't think -
protocols/oscar/oscar.c
ra13855a r5a71d9c 2603 2603 struct prpl *ret = g_new0(struct prpl, 1); 2604 2604 ret->name = "oscar"; 2605 ret->mms = 2343; /* this guess taken from libotr UPGRADING file */ 2605 2606 ret->away_states = oscar_away_states; 2606 2607 ret->init = oscar_init; -
protocols/yahoo/yahoo.c
ra13855a r5a71d9c 354 354 struct prpl *ret = g_new0(struct prpl, 1); 355 355 ret->name = "yahoo"; 356 ret->mms = 832; /* this guess taken from libotr UPGRADING file */ 356 357 ret->init = byahoo_init; 357 358 -
set.c
ra13855a r5a71d9c 209 209 } 210 210 211 char *set_eval_op s( set_t *set, char *value )211 char *set_eval_op_root( set_t *set, char *value ) 212 212 { 213 213 irc_t *irc = set->data; 214 215 if( g_strcasecmp( value, "user" ) == 0 ) 216 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost, 217 irc->channel, "+o-o", irc->nick, irc->mynick ); 218 else if( g_strcasecmp( value, "root" ) == 0 ) 219 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost, 220 irc->channel, "-o+o", irc->nick, irc->mynick ); 221 else if( g_strcasecmp( value, "both" ) == 0 ) 222 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost, 223 irc->channel, "+oo", irc->nick, irc->mynick ); 224 else if( g_strcasecmp( value, "none" ) == 0 ) 225 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost, 226 irc->channel, "-oo", irc->nick, irc->mynick ); 214 char *ret = set_eval_bool(set, value); 215 int b = bool2int(ret); 216 217 irc_write( irc, ":%s!%s@%s MODE %s %s %s", irc->mynick, irc->mynick, irc->myhost, 218 irc->channel, b?"+o":"-o", irc->mynick ); 219 return ret; 220 } 221 222 char *set_eval_op_user( set_t *set, char *value ) 223 { 224 irc_t *irc = set->data; 225 char *ret = set_eval_bool(set, value); 226 int b = bool2int(ret); 227 228 irc_write( irc, ":%s!%s@%s MODE %s %s %s", irc->mynick, irc->mynick, irc->myhost, 229 irc->channel, b?"+o":"-o", irc->nick ); 230 return ret; 231 } 232 233 /* generalized version of set_eval_op/voice_buddies */ 234 char *set_eval_mode_buddies( set_t *set, char *value, char modeflag ) 235 { 236 irc_t *irc = set->data; 237 char op[64], deop[64]; 238 int nop=0, ndeop=0; 239 user_t *u; 240 int mode; 241 242 if(!strcmp(value, "false")) 243 mode=0; 244 else if(!strcmp(value, "encrypted")) 245 mode=1; 246 else if(!strcmp(value, "trusted")) 247 mode=2; 248 else if(!strcmp(value, "notaway")) 249 mode=3; 227 250 else 228 251 return NULL; 229 252 253 /* sorry for calling them op/deop - too lazy for search+replace :P */ 254 op[0]='\0'; 255 deop[0]='\0'; 256 for(u=irc->users; u; u=u->next) { 257 /* we're only concerned with online buddies */ 258 if(!u->ic || !u->online) 259 continue; 260 261 /* just in case... */ 262 if(strlen(u->nick) >= 64) 263 continue; 264 265 /* dump out ops/deops when the corresponding name list fills up */ 266 if(strlen(op)+strlen(u->nick)+2 > 64) { 267 char *flags = g_strnfill(nop, modeflag); 268 irc_write( irc, ":%s!%s@%s MODE %s +%s%s", irc->mynick, irc->mynick, irc->myhost, 269 irc->channel, flags, op ); 270 op[0]='\0'; 271 g_free(flags); 272 } 273 if(strlen(deop)+strlen(u->nick)+2 > 64) { 274 char *flags = g_strnfill(ndeop, modeflag); 275 irc_write( irc, ":%s!%s@%s MODE %s -%s%s", irc->mynick, irc->mynick, irc->myhost, 276 irc->channel, flags, deop ); 277 deop[0]='\0'; 278 g_free(flags); 279 } 280 281 switch(mode) { 282 /* "false" */ 283 case 0: 284 g_strlcat(deop, " ", 64); 285 g_strlcat(deop, u->nick, 64); 286 ndeop++; 287 break; 288 /* "encrypted" */ 289 case 1: 290 if(u->encrypted) { 291 g_strlcat(op, " ", 64); 292 g_strlcat(op, u->nick, 64); 293 nop++; 294 } else { 295 g_strlcat(deop, " ", 64); 296 g_strlcat(deop, u->nick, 64); 297 ndeop++; 298 } 299 break; 300 /* "trusted" */ 301 case 2: 302 if(u->encrypted > 1) { 303 g_strlcat(op, " ", 64); 304 g_strlcat(op, u->nick, 64); 305 nop++; 306 } else { 307 g_strlcat(deop, " ", 64); 308 g_strlcat(deop, u->nick, 64); 309 ndeop++; 310 } 311 break; 312 /* "notaway" */ 313 case 3: 314 if(u->away) { 315 g_strlcat(deop, " ", 64); 316 g_strlcat(deop, u->nick, 64); 317 ndeop++; 318 } else { 319 g_strlcat(op, " ", 64); 320 g_strlcat(op, u->nick, 64); 321 nop++; 322 } 323 } 324 } 325 /* dump anything left in op/deop lists */ 326 if(*op) { 327 char *flags = g_strnfill(nop, modeflag); 328 irc_write( irc, ":%s!%s@%s MODE %s +%s%s", irc->mynick, irc->mynick, irc->myhost, 329 irc->channel, flags, op ); 330 g_free(flags); 331 } 332 if(*deop) { 333 char *flags = g_strnfill(ndeop, modeflag); 334 irc_write( irc, ":%s!%s@%s MODE %s -%s%s", irc->mynick, irc->mynick, irc->myhost, 335 irc->channel, flags, deop ); 336 g_free(flags); 337 } 338 230 339 return value; 340 } 341 342 char *set_eval_op_buddies( set_t *set, char *value ) 343 { 344 return set_eval_mode_buddies(set, value, 'o'); 345 } 346 347 char *set_eval_voice_buddies( set_t *set, char *value ) 348 { 349 return set_eval_mode_buddies(set, value, 'v'); 231 350 } 232 351 -
set.h
ra13855a r5a71d9c 96 96 /* Some not very generic evaluators that really shouldn't be here... */ 97 97 char *set_eval_to_char( set_t *set, char *value ); 98 char *set_eval_ops( set_t *set, char *value ); 98 char *set_eval_op_root( set_t *set, char *value ); 99 char *set_eval_op_user( set_t *set, char *value ); 100 char *set_eval_op_buddies( set_t *set, char *value ); 101 char *set_eval_voice_buddies( set_t *set, char *value ); 99 102 char *set_eval_charset( set_t *set, char *value ); 100 103 -
user.h
ra13855a r5a71d9c 37 37 char is_private; 38 38 char online; 39 char encrypted; 39 40 40 41 char *handle;
Note: See TracChangeset
for help on using the changeset viewer.