Changes in irc.c [50e1776:5e2615a]
Legend:
- Unmodified
- Added
- Removed
-
irc.c
r50e1776 r5e2615a 45 45 { 46 46 irc_t *irc; 47 struct sockaddr_storage sock; 48 socklen_t socklen = sizeof( sock ); 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]; 49 55 50 56 irc = g_new0( irc_t, 1 ); … … 65 71 irc->channel = g_strdup( ROOT_CHAN ); 66 72 73 i = sizeof( *sock ); 74 #ifdef IPV6 75 i6 = sizeof( *sock6 ); 76 #endif 77 67 78 if( global.conf->hostname ) 68 {69 79 irc->myhost = g_strdup( global.conf->hostname ); 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 { 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 ) 78 86 irc->myhost = g_strdup( ipv6_unwrap( buf ) ); 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 { 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 ) 94 105 irc->host = g_strdup( ipv6_unwrap( buf ) ); 95 } 96 else 97 { 98 /* Rare, but possible. */ 99 strncpy( irc->host, "localhost.localdomain", NI_MAXHOST ); 100 } 101 } 102 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 103 121 if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 ) 104 122 irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc ); … … 641 659 } 642 660 } 643 else if( ( c = irc_chat_by_channel( irc,channel ) ) )661 else if( ( c = chat_by_channel( channel ) ) ) 644 662 { 645 663 GList *l; … … 788 806 void irc_topic( irc_t *irc, char *channel ) 789 807 { 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 ) 808 if( g_strcasecmp( channel, irc->channel ) == 0 ) 809 { 795 810 irc_reply( irc, 332, "%s :%s", channel, CONTROL_TOPIC ); 811 } 796 812 else 797 irc_reply( irc, 331, "%s :No topic for this channel", channel ); 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 } 798 821 } 799 822 … … 927 950 if( *nick == '#' || *nick == '&' ) 928 951 { 929 if( !( c = irc_chat_by_channel( irc,nick ) ) )952 if( !( c = chat_by_channel( nick ) ) ) 930 953 { 931 954 irc_reply( irc, 403, "%s :Channel does not exist", nick ); … … 1193 1216 return TRUE; 1194 1217 } 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.