Mercurial > pidgin
changeset 8838:518455386538
[gaim-migrate @ 9604]
-Fix the compile error in perl that was my fault
-Rename a network.c function and change it's signature (is that work
applicable in c?)
-Make rendezvous crash when trying to sign on
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 28 Apr 2004 03:16:40 +0000 |
parents | 25206a0fb4e4 |
children | ebbc39e0050d |
files | plugins/perl/common/Account.xs src/network.c src/network.h src/protocols/irc/dcc_send.c src/protocols/jabber/si.c src/protocols/novell/novell.c src/protocols/oscar/im.c src/protocols/oscar/oscar.c src/protocols/rendezvous/mdns.c src/protocols/rendezvous/mdns.h src/protocols/rendezvous/rendezvous.c |
diffstat | 11 files changed, 58 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/perl/common/Account.xs Wed Apr 28 03:10:31 2004 +0000 +++ b/plugins/perl/common/Account.xs Wed Apr 28 03:16:40 2004 +0000 @@ -60,11 +60,6 @@ const char *ui gboolean value -void -gaim_account_set_public_ip(account, ip) - Gaim::Account account - const char *ip - gboolean gaim_account_is_connected(account) Gaim::Account account @@ -110,10 +105,6 @@ Gaim::Account account const char *ui -const char * -gaim_account_get_public_ip(account) - Gaim::Account account - MODULE = Gaim::Account PACKAGE = Gaim::Accounts PREFIX = gaim_accounts_
--- a/src/network.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/network.c Wed Apr 28 03:16:40 2004 +0000 @@ -30,11 +30,35 @@ #include "network.h" #include "prefs.h" +const unsigned char * +gaim_network_ip_atoi(const char *ip) +{ + static unsigned char ret[4]; + gchar delimiter = '.'; + gchar **split; + int i; + + g_return_val_if_fail(ip != NULL, NULL); + + split = g_strsplit(ip, &delimiter, 4); + for (i = 0; split[i] != NULL; i++) + ret[i] = atoi(split[i]); + g_strfreev(split); + + /* i should always be 4 */ + if (i != 4) + return NULL; + + return ret; +} + void gaim_network_set_public_ip(const char *ip) { g_return_if_fail(ip != NULL); + /* XXX - Ensure the IP address is valid */ + gaim_prefs_set_string("/core/network/public_ip", ip); } @@ -69,6 +93,7 @@ tmp = inet_ntoa(addr.sin_addr); strncpy(ip, tmp, sizeof(ip)); + return ip; } @@ -106,7 +131,7 @@ } const char * -gaim_network_get_ip_for_account(const GaimAccount *account, int fd) +gaim_network_get_my_ip(int fd) { const char *ip = NULL;
--- a/src/network.h Wed Apr 28 03:10:31 2004 +0000 +++ b/src/network.h Wed Apr 28 03:16:40 2004 +0000 @@ -35,6 +35,20 @@ /*@{*/ /** + * Converts a dot-decimal IP address to an array of unsigned + * chars. For example, converts 192.168.0.1 to a 4 byte + * array containing 192, 168, 0 and 1. + * + * @param ip An IP address in dot-decimal notiation. + * @return An array of 4 bytes containing an IP addresses + * equivalent to the given parameter, or NULL if + * the given IP address is invalid. This value + * is statically allocated and should not be + * freed. + */ +const unsigned char *gaim_network_ip_atoi(const char *ip); + +/** * Sets the IP address of the local system in preferences. This * is the IP address that should be used for incoming connections * (file transfer, direct IM, etc.) and should therefore be @@ -48,7 +62,7 @@ * Returns the IP address of the local system set in preferences. * * This returns the value set via gaim_network_set_public_ip(). - * You probably want to use gaim_network_get_ip_for_account() instead. + * You probably want to use gaim_network_get_my_ip() instead. * * @return The local IP address set in preferences. */ @@ -57,7 +71,7 @@ /** * Returns the IP address of the local system. * - * You probably want to use gaim_network_get_ip_for_account() instead. + * You probably want to use gaim_network_get_my_ip() instead. * * @note The returned string is a pointer to a static buffer. If this * function is called twice, it may be important to make a copy @@ -87,7 +101,7 @@ * @param fd The fd to use to help figure out the IP, or -1. * @return The local IP address to be used. */ -const char *gaim_network_get_ip_for_account(const GaimAccount *account, int fd); +const char *gaim_network_get_my_ip(int fd); /** * Attempts to open a listening port ONLY on the specified port number.
--- a/src/protocols/irc/dcc_send.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/irc/dcc_send.c Wed Apr 28 03:16:40 2004 +0000 @@ -285,7 +285,7 @@ /* Send the intended recipient the DCC request */ arg[0] = xfer->who; - inet_aton(gaim_network_get_ip_for_account(gaim_xfer_get_account(xfer), irc->fd), &addr); + inet_aton(gaim_network_get_my_ip(irc->fd), &addr); arg[1] = tmp = g_strdup_printf("\001DCC SEND \"%s\" %u %hu %u\001", xfer->filename, ntohl(addr.s_addr), port, xfer->size);
--- a/src/protocols/jabber/si.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/jabber/si.c Wed Apr 28 03:16:40 2004 +0000 @@ -281,7 +281,7 @@ return; } - host = gaim_network_get_ip_for_account(jsx->js->gc->account, jsx->js->fd); + host = gaim_network_get_my_ip(jsx->js->fd); buffer[0] = 0x05; buffer[1] = 0x00; @@ -429,7 +429,7 @@ return; } - xmlnode_set_attrib(streamhost, "host", gaim_network_get_ip_for_account(jsx->js->gc->account, jsx->js->fd)); + xmlnode_set_attrib(streamhost, "host", gaim_network_get_my_ip(jsx->js->fd)); xfer->local_port = gaim_network_get_port_from_fd(fd); port = g_strdup_printf("%hu", xfer->local_port); xmlnode_set_attrib(streamhost, "port", port);
--- a/src/protocols/novell/novell.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/novell/novell.c Wed Apr 28 03:16:40 2004 +0000 @@ -1148,7 +1148,7 @@ gaim_connection_update_progress(gc, _("Authenticating..."), 2, NOVELL_CONNECT_STEPS); - my_addr = gaim_network_get_ip_for_account(user->client_data, gsc->fd); + my_addr = gaim_network_get_my_ip(gsc->fd); pwd = gaim_account_get_password(user->client_data); ua = _user_agent_string();
--- a/src/protocols/oscar/im.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/oscar/im.c Wed Apr 28 03:16:40 2004 +0000 @@ -779,6 +779,7 @@ /* aim_tlvlist_add_raw(&subtl, 0x000e, 2, "en"); aim_tlvlist_add_raw(&subtl, 0x000d, 8, "us-ascii"); aim_tlvlist_add_raw(&subtl, 0x000c, 24, "Please accept this file."); */ + /* XXX - Change oft_info->clientip to an array of 4 bytes */ if (oft_info->clientip) { fu8_t ip[4]; char *nexttoken;
--- a/src/protocols/oscar/oscar.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/oscar/oscar.c Wed Apr 28 03:16:40 2004 +0000 @@ -1277,7 +1277,6 @@ static void oscar_ask_sendfile(GaimConnection *gc, const char *destsn) { OscarData *od = (OscarData *)gc->proto_data; - GaimAccount *account = gaim_connection_get_account(gc); GaimXfer *xfer; struct aim_oft_info *oft_info; const char *ip; @@ -1288,7 +1287,7 @@ xfer = gaim_xfer_new(gaim_connection_get_account(gc), GAIM_XFER_SEND, destsn); /* Create the oscar-specific data */ - ip = gaim_network_get_ip_for_account(account, od->conn ? od->conn->fd : -1); + ip = gaim_network_get_my_ip(od->conn ? od->conn->fd : -1); oft_info = aim_oft_createinfo(od->sess, NULL, destsn, ip, 0, 0, 0, NULL); xfer->data = oft_info;
--- a/src/protocols/rendezvous/mdns.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/rendezvous/mdns.c Wed Apr 28 03:16:40 2004 +0000 @@ -772,16 +772,16 @@ } int -mdns_advertise_a(int fd, const char *name, unsigned char *ip) +mdns_advertise_a(int fd, const char *name, const unsigned char *ip) { int ret; ResourceRecord *rr; ResourceRecordRDataA *rdata; int i; - if ((name == NULL) || (strlen(name) > 255)) { - return -EINVAL; - } + g_return_val_if_fail(name != NULL, -EINVAL); + g_return_val_if_fail(strlen(name) <= 255, -EINVAL); + g_return_val_if_fail(ip != NULL, -EINVAL); rdata = g_malloc(4); for (i = 0; i < 4; i++) @@ -878,7 +878,7 @@ } int -mdns_advertise_aaaa(int fd, const char *name, unsigned char *ip) +mdns_advertise_aaaa(int fd, const char *name, const unsigned char *ip) { int ret; ResourceRecord *rr;
--- a/src/protocols/rendezvous/mdns.h Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/rendezvous/mdns.h Wed Apr 28 03:16:40 2004 +0000 @@ -166,11 +166,11 @@ int mdns_query(int fd, const char *domain, unsigned short type); int mdns_send_rr(int fd, ResourceRecord *rr); -int mdns_advertise_a(int fd, const char *name, unsigned char *ip); +int mdns_advertise_a(int fd, const char *name, const unsigned char *ip); int mdns_advertise_null(int fd, const char *name, const char *data, unsigned short rdlength); int mdns_advertise_ptr(int fd, const char *name, const char *domain); int mdns_advertise_txt(int fd, const char *name, const GSList *txt); -int mdns_advertise_aaaa(int fd, const char *name, unsigned char *ip); +int mdns_advertise_aaaa(int fd, const char *name, const unsigned char *ip); int mdns_advertise_srv(int fd, const char *name, unsigned short port, const char *target); /**
--- a/src/protocols/rendezvous/rendezvous.c Wed Apr 28 03:10:31 2004 +0000 +++ b/src/protocols/rendezvous/rendezvous.c Wed Apr 28 03:16:40 2004 +0000 @@ -481,34 +481,18 @@ g_free(rdata); } -static int *rendezvous_get_ip_as_int_array(int fd) -{ - static int ret[4]; - const char *ip, *nexttoken; - int i = 0; - - ip = gaim_network_get_local_system_ip(fd); - nexttoken = strtok((char *)ip, "."); - while (nexttoken && i < 4) { - ret[i] = atoi(nexttoken); - nexttoken = strtok(NULL, "."); - } - - return ret; -} - static void rendezvous_send_online(GaimConnection *gc) { RendezvousData *rd = gc->proto_data; GaimAccount *account = gaim_connection_get_account(gc); const gchar *me; gchar *myname, *mycomp; - unsigned char *myip; + const unsigned char *myip; me = gaim_account_get_username(account); myname = g_strdup_printf("%s._presence._tcp.local", me); mycomp = g_strdup_printf("%s.local", strchr(me, '@') + 1); - myip = rendezvous_get_ip_as_int_array(rd->fd); + myip = gaim_network_ip_atoi(gaim_network_get_local_system_ip(rd->fd)); mdns_advertise_a(rd->fd, mycomp, myip); mdns_advertise_ptr(rd->fd, "_presence._tcp.local", myname);