Changes in irc.c [5b52a48:b0a33a5]
Legend:
- Unmodified
- Added
- Removed
-
irc.c
r5b52a48 rb0a33a5 33 33 GSList *irc_connection_list = NULL; 34 34 35 static char *passchange( irc_t *irc, void *set, char *value ) 36 { 37 irc_setpass( irc, value ); 38 irc_usermsg( irc, "Password successfully changed" ); 39 return NULL; 35 static char *passchange (irc_t *irc, void *set, char *value) 36 { 37 irc_setpass (irc, value); 38 return (NULL); 40 39 } 41 40 … … 47 46 char buf[128]; 48 47 #ifdef IPV6 49 struct sockaddr_in6 sock[1]; 50 #else 48 struct sockaddr_in6 sock6[1]; 49 unsigned int i6; 50 #endif 51 51 struct sockaddr_in sock[1]; 52 #endif53 52 54 53 irc = g_new0( irc_t, 1 ); … … 70 69 71 70 i = sizeof( *sock ); 71 #ifdef IPV6 72 i6 = sizeof( *sock6 ); 73 #endif 72 74 73 75 if( global.conf->hostname ) 74 76 irc->myhost = g_strdup( global.conf->hostname ); 75 77 #ifdef IPV6 76 else if( getsockname( irc->fd, (struct sockaddr*) sock , &i ) == 0 && sock->sin6_family == AF_INETx)77 { 78 if( ( peer = gethostbyaddr( (char*) &sock ->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx) ) )78 else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 79 { 80 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 79 81 irc->myhost = g_strdup( peer->h_name ); 80 else if( inet_ntop( AF_INET x, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )82 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 81 83 irc->myhost = g_strdup( ipv6_unwrap( buf ) ); 82 84 } 83 #e lse84 else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET x)85 { 86 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET x) ) )85 #endif 86 else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 87 { 88 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 87 89 irc->myhost = g_strdup( peer->h_name ); 88 else if( inet_ntop( AF_INET x, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )90 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 89 91 irc->myhost = g_strdup( buf ); 90 92 } 91 #endif92 93 93 94 i = sizeof( *sock ); 94 95 #ifdef IPV6 95 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx ) 96 { 97 if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) ) 96 i6 = sizeof( *sock6 ); 97 if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 98 { 99 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 98 100 irc->host = g_strdup( peer->h_name ); 99 else if( inet_ntop( AF_INET x, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )101 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 100 102 irc->host = g_strdup( ipv6_unwrap( buf ) ); 101 103 } 102 #else 103 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx ) 104 { 105 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) ) 104 else 105 #endif 106 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 107 { 108 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 106 109 irc->host = g_strdup( peer->h_name ); 107 else if( inet_ntop( AF_INET x, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )110 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 108 111 irc->host = g_strdup( buf ); 109 112 } 110 #endif111 113 112 114 /* Rare, but possible. */ … … 121 123 irc_connection_list = g_slist_append( irc_connection_list, irc ); 122 124 123 set_add( &irc->set, "away_devoice", "true", set_eval_away_devoice, irc);124 set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc);125 set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc);126 set_add( &irc->set, "auto_reconnect_delay", "300", set_eval_int, irc);127 set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc);128 set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc);129 set_add( &irc->set, "charset", "iso8859-1", set_eval_charset, irc);130 set_add( &irc->set, "debug", "false", set_eval_bool, irc);131 set_add( &irc->set, "default_target", "root", NULL, irc);132 set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc);133 set_add( &irc->set, "handle_unknown", "root", NULL, irc);134 set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc);135 set_add( &irc->set, "ops", "both", set_eval_ops, irc);136 set_add( &irc->set, "password", NULL, passchange, irc);137 set_add( &irc->set, "private", "true", set_eval_bool, irc);138 set_add( &irc->set, "query_order", "lifo", NULL, irc);139 set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc);140 set_add( &irc->set, "strip_html", "true", NULL, irc);141 set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc);142 set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc);125 set_add( irc, "away_devoice", "true", set_eval_away_devoice ); 126 set_add( irc, "auto_connect", "true", set_eval_bool ); 127 set_add( irc, "auto_reconnect", "false", set_eval_bool ); 128 set_add( irc, "auto_reconnect_delay", "300", set_eval_int ); 129 set_add( irc, "buddy_sendbuffer", "false", set_eval_bool ); 130 set_add( irc, "buddy_sendbuffer_delay", "200", set_eval_int ); 131 set_add( irc, "charset", "iso8859-1", set_eval_charset ); 132 set_add( irc, "debug", "false", set_eval_bool ); 133 set_add( irc, "default_target", "root", NULL ); 134 set_add( irc, "display_namechanges", "false", set_eval_bool ); 135 set_add( irc, "handle_unknown", "root", NULL ); 136 set_add( irc, "lcnicks", "true", set_eval_bool ); 137 set_add( irc, "ops", "both", set_eval_ops ); 138 set_add( irc, "private", "true", set_eval_bool ); 139 set_add( irc, "query_order", "lifo", NULL ); 140 set_add( irc, "save_on_quit", "true", set_eval_bool ); 141 set_add( irc, "strip_html", "true", NULL ); 142 set_add( irc, "to_char", ": ", set_eval_to_char ); 143 set_add( irc, "typing_notice", "false", set_eval_bool ); 144 set_add( irc, "password", NULL, passchange); 143 145 144 146 conf_loaddefaults( irc ); … … 204 206 void irc_free(irc_t * irc) 205 207 { 206 account_t *account ;208 account_t *account, *accounttmp; 207 209 user_t *user, *usertmp; 210 nick_t *nick, *nicktmp; 208 211 help_t *helpnode, *helpnodetmp; 212 set_t *setnode, *setnodetmp; 209 213 210 214 log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd ); 211 215 212 if( irc->status & USTATUS_IDENTIFIED && set_getint( &irc->set, "save_on_quit" ) )216 if( irc->status & USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) 213 217 if( storage_save( irc, TRUE ) != STORAGE_OK ) 214 218 irc_usermsg( irc, "Error while saving settings!" ); … … 250 254 query_del(irc, irc->queries); 251 255 252 while (irc->accounts) 253 account_del(irc, irc->accounts); 254 255 while (irc->set) 256 set_del(&irc->set, irc->set->key); 256 if (irc->accounts != NULL) { 257 account = irc->accounts; 258 while (account != NULL) { 259 g_free(account->user); 260 g_free(account->pass); 261 g_free(account->server); 262 accounttmp = account; 263 account = account->next; 264 g_free(accounttmp); 265 } 266 } 257 267 258 268 if (irc->users != NULL) { … … 279 289 g_hash_table_destroy(irc->watches); 280 290 291 if (irc->nicks != NULL) { 292 nick = irc->nicks; 293 while (nick != NULL) { 294 g_free(nick->nick); 295 g_free(nick->handle); 296 297 nicktmp = nick; 298 nick = nick->next; 299 g_free(nicktmp); 300 } 301 } 281 302 if (irc->help != NULL) { 282 303 helpnode = irc->help; … … 289 310 } 290 311 } 312 if (irc->set != NULL) { 313 setnode = irc->set; 314 while (setnode != NULL) { 315 g_free(setnode->key); 316 g_free(setnode->def); 317 g_free(setnode->value); 318 319 setnodetmp = setnode; 320 setnode = setnode->next; 321 g_free(setnodetmp); 322 } 323 } 291 324 g_free(irc); 292 325 … … 299 332 void irc_setpass (irc_t *irc, const char *pass) 300 333 { 301 g_free (irc->password);334 if (irc->password) g_free (irc->password); 302 335 303 336 if (pass) { 304 337 irc->password = g_strdup (pass); 338 irc_usermsg (irc, "Password successfully changed"); 305 339 } else { 306 340 irc->password = NULL; … … 333 367 } 334 368 335 if( ( cs = set_getstr( &irc->set, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )369 if( ( cs = set_getstr( irc, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) ) 336 370 { 337 371 conv[IRC_MAX_LINE] = 0; … … 553 587 554 588 strip_newlines( line ); 555 if( ( cs = set_getstr( &irc->set, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )589 if( ( cs = set_getstr( irc, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) ) 556 590 { 557 591 char conv[IRC_MAX_LINE+1]; … … 621 655 char namelist[385] = ""; 622 656 struct conversation *c = NULL; 657 char *ops = set_getstr( irc, "ops" ); 623 658 624 659 /* RFCs say there is no error reply allowed on NAMES, so when the … … 635 670 } 636 671 637 if( u->gc && !u->away && set_get bool( &irc->set, "away_devoice" ) )672 if( u->gc && !u->away && set_getint( irc, "away_devoice" ) ) 638 673 strcat( namelist, "+" ); 674 else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) || 675 ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ) 676 strcat( namelist, "@" ); 639 677 640 678 strcat( namelist, u->nick ); … … 645 683 { 646 684 GList *l; 647 char *ops = set_getstr( &irc->set, "ops" );648 685 649 686 /* root and the user aren't in the channel userlist but should … … 893 930 { 894 931 char *nick, *s; 895 char reason[ 128];932 char reason[64]; 896 933 897 934 if( u->gc && u->gc->flags & OPT_LOGGING_OUT ) 898 935 { 899 if( u->gc-> acc->server)936 if( u->gc->user->proto_opt[0][0] ) 900 937 g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost, 901 u->gc-> acc->server);938 u->gc->user->proto_opt[0] ); 902 939 else if( ( s = strchr( u->gc->username, '@' ) ) ) 903 940 g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost, … … 905 942 else 906 943 g_snprintf( reason, sizeof( reason ), "%s %s.%s", irc->myhost, 907 u->gc-> acc->prpl->name, irc->myhost );944 u->gc->prpl->name, irc->myhost ); 908 945 909 946 /* proto_opt might contain garbage after the : */ … … 981 1018 else if( g_strncasecmp( s + 1, "TYPING", 6 ) == 0 ) 982 1019 { 983 if( u && u->gc && u->gc-> acc->prpl->send_typing && strlen( s ) >= 10 )1020 if( u && u->gc && u->gc->prpl->send_typing && strlen( s ) >= 10 ) 984 1021 { 985 1022 time_t current_typing_notice = time( NULL ); … … 987 1024 if( current_typing_notice - u->last_typing_notice >= 5 ) 988 1025 { 989 u->gc-> acc->prpl->send_typing( u->gc, u->handle, s[8] == '1' );1026 u->gc->prpl->send_typing( u->gc, u->handle, s[8] == '1' ); 990 1027 u->last_typing_notice = current_typing_notice; 991 1028 } … … 1020 1057 } 1021 1058 } 1022 else if( c && c->gc && c->gc-> acc && c->gc->acc->prpl )1059 else if( c && c->gc && c->gc->prpl ) 1023 1060 { 1024 1061 return( bim_chat_msg( c->gc, c->id, s ) ); … … 1052 1089 if( !u || !u->gc ) return; 1053 1090 1054 if( set_getint( &irc->set, "buddy_sendbuffer" ) && set_getint( &irc->set, "buddy_sendbuffer_delay" ) > 0 )1091 if( set_getint( irc, "buddy_sendbuffer" ) && set_getint( irc, "buddy_sendbuffer_delay" ) > 0 ) 1055 1092 { 1056 1093 int delay; … … 1079 1116 strcat( u->sendbuf, "\n" ); 1080 1117 1081 delay = set_getint( &irc->set, "buddy_sendbuffer_delay" );1118 delay = set_getint( irc, "buddy_sendbuffer_delay" ); 1082 1119 if( delay <= 5 ) 1083 1120 delay *= 1000; … … 1144 1181 int len = strlen( irc->nick) + 3; 1145 1182 prefix = g_new (char, len ); 1146 g_snprintf( prefix, len, "%s%s", irc->nick, set_getstr( &irc->set, "to_char" ) );1183 g_snprintf( prefix, len, "%s%s", irc->nick, set_getstr( irc, "to_char" ) ); 1147 1184 prefix[len-1] = 0; 1148 1185 }
Note: See TracChangeset
for help on using the changeset viewer.