Changes in irc.c [5e2615a:50e1776]
Legend:
- Unmodified
- Added
- Removed
-
irc.c
r5e2615a r50e1776 45 45 { 46 46 irc_t *irc; 47 struct hostent *peer; 48 unsigned int i; 49 char buf[128]; 50 #ifdef IPV6 51 struct sockaddr_in6 sock6[1]; 52 unsigned int i6; 53 #endif 54 struct sockaddr_in sock[1]; 47 struct sockaddr_storage sock; 48 socklen_t socklen = sizeof( sock ); 55 49 56 50 irc = g_new0( irc_t, 1 ); … … 71 65 irc->channel = g_strdup( ROOT_CHAN ); 72 66 73 i = sizeof( *sock );74 #ifdef IPV675 i6 = sizeof( *sock6 );76 #endif77 78 67 if( global.conf->hostname ) 68 { 79 69 irc->myhost = g_strdup( global.conf->hostname ); 80 #ifdef IPV6 81 else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 82 { 83 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 84 irc->myhost = g_strdup( peer->h_name ); 85 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 70 } 71 else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) 72 { 73 char buf[NI_MAXHOST+1]; 74 75 if( getnameinfo( (struct sockaddr *) &sock, socklen, buf, 76 NI_MAXHOST, NULL, -1, 0 ) == 0 ) 77 { 86 78 irc->myhost = g_strdup( ipv6_unwrap( buf ) ); 87 } 88 #endif 89 else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 90 { 91 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 92 irc->myhost = g_strdup( peer->h_name ); 93 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 94 irc->myhost = g_strdup( buf ); 95 } 96 97 i = sizeof( *sock ); 98 #ifdef IPV6 99 i6 = sizeof( *sock6 ); 100 if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 101 { 102 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 103 irc->host = g_strdup( peer->h_name ); 104 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 79 } 80 else 81 { 82 /* Rare, but possible. */ 83 strncpy( irc->myhost, "localhost.localdomain", NI_MAXHOST ); 84 } 85 } 86 87 if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) 88 { 89 char buf[NI_MAXHOST+1]; 90 91 if( getnameinfo( (struct sockaddr *)&sock, socklen, buf, 92 NI_MAXHOST, NULL, -1, 0 ) == 0 ) 93 { 105 94 irc->host = g_strdup( ipv6_unwrap( buf ) ); 106 } 107 else 108 #endif 109 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 110 { 111 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 112 irc->host = g_strdup( peer->h_name ); 113 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 114 irc->host = g_strdup( buf ); 115 } 116 117 /* Rare, but possible. */ 118 if( !irc->host ) irc->host = g_strdup( "localhost." ); 119 if( !irc->myhost ) irc->myhost = g_strdup( "localhost." ); 120 95 } 96 else 97 { 98 /* Rare, but possible. */ 99 strncpy( irc->host, "localhost.localdomain", NI_MAXHOST ); 100 } 101 } 102 121 103 if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 ) 122 104 irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc ); … … 659 641 } 660 642 } 661 else if( ( c = chat_by_channel(channel ) ) )643 else if( ( c = irc_chat_by_channel( irc, channel ) ) ) 662 644 { 663 645 GList *l; … … 806 788 void irc_topic( irc_t *irc, char *channel ) 807 789 { 808 if( g_strcasecmp( channel, irc->channel ) == 0 ) 809 { 790 struct groupchat *c = irc_chat_by_channel( irc, channel ); 791 792 if( c && c->topic ) 793 irc_reply( irc, 332, "%s :%s", channel, c->topic ); 794 else if( g_strcasecmp( channel, irc->channel ) == 0 ) 810 795 irc_reply( irc, 332, "%s :%s", channel, CONTROL_TOPIC ); 811 }812 796 else 813 { 814 struct groupchat *c = chat_by_channel( channel ); 815 816 if( c ) 817 irc_reply( irc, 332, "%s :BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", channel, c->title ); 818 else 819 irc_reply( irc, 331, "%s :No topic for this channel", channel ); 820 } 797 irc_reply( irc, 331, "%s :No topic for this channel", channel ); 821 798 } 822 799 … … 950 927 if( *nick == '#' || *nick == '&' ) 951 928 { 952 if( !( c = chat_by_channel(nick ) ) )929 if( !( c = irc_chat_by_channel( irc, nick ) ) ) 953 930 { 954 931 irc_reply( irc, 403, "%s :Channel does not exist", nick ); … … 1216 1193 return TRUE; 1217 1194 } 1195 1196 struct groupchat *irc_chat_by_channel( irc_t *irc, char *channel ) 1197 { 1198 struct groupchat *c; 1199 account_t *a; 1200 1201 /* This finds the connection which has a conversation which belongs to this channel */ 1202 for( a = irc->accounts; a; a = a->next ) 1203 { 1204 if( a->ic == NULL ) 1205 continue; 1206 1207 c = a->ic->groupchats; 1208 while( c ) 1209 { 1210 if( c->channel && g_strcasecmp( c->channel, channel ) == 0 ) 1211 return c; 1212 1213 c = c->next; 1214 } 1215 } 1216 1217 return NULL; 1218 }
Note: See TracChangeset
for help on using the changeset viewer.