From 30264e86c5eb890babf00445f5b306c5e1d48551 Mon Sep 17 00:00:00 2001 From: Anibal Avelar Date: Mon, 24 Nov 2008 02:11:16 -0600 Subject: [PATCH] Added UUID-Mac-Address support, and other details for presence --- configure.ac | 4 ++-- src/sipe.c | 19 ++++++----------- src/tests.c | 13 +++++++++++- src/uuid.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 2eacb4b7..7300a790 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ # version of this package -m4_define(pidgin_sipe_version, 1.2.0) +m4_define(pidgin_sipe_version, 1.3.0) # lower and upper-bound versions of Pidgin m4_define(pidgin_version_max, 2.0.0) -AC_INIT([pidgin-sipe], [1.2.0]) +AC_INIT([pidgin-sipe], [1.3.0]) AC_PREREQ([2.50]) AM_INIT_AUTOMAKE([1.9 dist-bzip2 tar-ustar]) diff --git a/src/sipe.c b/src/sipe.c index 709db12b..8ee30c18 100644 --- a/src/sipe.c +++ b/src/sipe.c @@ -70,7 +70,8 @@ static char *gentag() static char *getuuid() { - return g_strdup_printf("01010101"); //TODO Should be taken from the MAC ADDRESS + //return g_strdup_printf("01010101"); //TODO Should be taken from the MAC ADDRESS + return get_macaddr(); } static char *genbranch() @@ -131,11 +132,6 @@ static void do_notifies(struct sipe_account_data *sip) { GSList *tmp = sip->watcher; purple_debug_info("sipe", "do_notifies()\n"); - //if ((sip->republish != -1) || sip->republish < time(NULL)) { - // if (purple_account_get_bool(sip->account, "doservice", TRUE)) { - // send_service(sip); - // } - //} while (tmp) { purple_debug_info("sipe", "notifying %s\n", ((struct sipe_watcher*)tmp->data)->name); @@ -828,7 +824,7 @@ static void sign_outgoing_message (struct sipmsg * msg, struct sipe_account_data //sipmsg_add_header_pos(msg, "Authorization", buf, 5); } g_free(buf); - } else if (!strcmp(method,"SUBSCRIBE") || !strcmp(method,"SERVICE") || !strcmp(method,"MESSAGE") || !strcmp(method,"INVITE") || !strcmp(method,"NOTIFY") || !strcmp(method, "ACK") || !strcmp(method, "BYE") || !strcmp(method, "INFO")) { + } else if (!strcmp(method,"SUBSCRIBE") || !strcmp(method,"SERVICE") || !strcmp(method,"MESSAGE") || !strcmp(method,"INVITE") || !strcmp(method, "ACK") || !strcmp(method, "NOTIFY") || !strcmp(method, "BYE") || !strcmp(method, "INFO")) { sip->registrar.nc=3; sip->registrar.type=2; @@ -1804,19 +1800,18 @@ static void send_publish(struct sipe_account_data *sip) { gchar *uri = g_strdup_printf("sip:%s", sip->username); gchar *doc = g_strdup_printf( - "%s%s35003500", - uri, uri, + "%s%s35003500", + uri, generateUUIDfromEPID(getuuid()), uri, "00:00:00-05:00", // TODO timezone "PC" // TODO machine name ); gchar *tmp = get_contact(sip); - gchar *hdr = g_strdup_printf("Contact: %s; +sip.instance=\"\"\r\nContent-Type: application/msrtc-category-publish+xml\r\n", tmp,generateUUIDfromEPID(getuuid())); + gchar *hdr = g_strdup_printf("Contact: %s; +sip.instance=\"\"\r\nAccept: application/ms-location-profile-definition+xml\r\nContent-Type: application/msrtc-category-publish+xml\r\n", tmp,generateUUIDfromEPID(getuuid())); g_free(tmp); send_sip_request(sip->gc, "SERVICE", uri, uri, hdr, doc, NULL, process_service_response); //sip->republish = time(NULL) + 500; - g_free(hdr); g_free(uri); g_free(doc); @@ -1925,7 +1920,7 @@ static void process_input_message(struct sipe_account_data *sip, struct sipmsg * process_incoming_message(sip, msg); found = TRUE; } else if (!strcmp(msg->method, "NOTIFY")) { - purple_debug_info("sipe","send->process_incoming_notify\n"); + purple_debug_info("sipe","send->process_incoming_notify\n"); process_incoming_notify(sip, msg); found = TRUE; } else if (!strcmp(msg->method, "SUBSCRIBE")) { diff --git a/src/tests.c b/src/tests.c index c8331d5e..10d264a4 100644 --- a/src/tests.c +++ b/src/tests.c @@ -161,9 +161,20 @@ int main() char *calcUUID = generateUUIDfromEPID(testEpid); printf("\n\nTesting MS-SIPRE uuid derivation\n"); - + assert_equal(expectedUUID, calcUUID, strlen(expectedUUID), FALSE); g_free(calcUUID); + + guchar addr[6]; + long mac = mac_addr_sys(addr); + gchar nmac[6]; + + int i,j; + for (i = 0,j=0; i < 6; i++,j+=2) { + g_sprintf(&nmac[j], "%02X", addr[i]); + } + + printf("Mac: %s\n", g_strdup(nmac)); /* end tests from MS-SIPRE */ diff --git a/src/uuid.c b/src/uuid.c index c72e9908..e6da0715 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -19,6 +19,15 @@ #include #include +#include +#include + +#include +#include +#include +#include +#include + #include #include #include "uuid.h" @@ -83,3 +92,63 @@ char *generateUUIDfromEPID(const char *epid) printUUID(&result, buf); return g_strdup(buf); } + +long mac_addr_sys (const char *addr) +{ +/* implementation for Linux */ + struct ifreq ifr; + struct ifreq *IFR; + struct ifconf ifc; + char buf[1024]; + int s, i; + int ok = 0; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s==-1) { + return -1; + } + + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = buf; + ioctl(s, SIOCGIFCONF, &ifc); + + IFR = ifc.ifc_req; + for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) { + + strcpy(ifr.ifr_name, IFR->ifr_name); + if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) { + if (! (ifr.ifr_flags & IFF_LOOPBACK)) { + if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { + ok = 1; + break; + } + } + } + } + + close(s); + if (ok) { + bcopy( ifr.ifr_hwaddr.sa_data, addr, 6); + } + else { + return -1; + } + return 0; +} + +gchar *get_macaddr() +{ + + guchar addr[6]; + long mac_add = mac_addr_sys(addr); + gchar nmac[6]; + + if (mac_add == 0){ + int i,j; + for (i = 0,j=0; i < 6; i++,j+=2) { + g_sprintf(&nmac[j], "%02X", addr[i]); + } + return g_strdup(nmac); + } + return g_strdup_printf("01010101"); //Default +} -- 2.11.4.GIT