[hipl-commit] [trunk] Rev 3588: uncrustified lib/dht

  • From: Rene Hummen <rene.hummen@xxxxxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Thu, 11 Feb 2010 01:13:22 +0200

Committer: Rene Hummen <rene.hummen@xxxxxxxxxxxxxxxxx>
Date: Thu Feb 11 00:13:03 2010 +0100
Revision: 3588
Revision-id: rene.hummen@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  uncrustified lib/dht

Modified:
  M  lib/dht/libhipdht.c
  M  lib/dht/libhipdht.h
  M  lib/dht/libhipdhtxml.c
  M  lib/dht/libhipdhtxml.h

=== modified file 'lib/dht/libhipdht.c'
--- lib/dht/libhipdht.c 2010-01-19 13:10:46 +0000
+++ lib/dht/libhipdht.c 2010-02-10 23:13:03 +0000
@@ -2,11 +2,11 @@
  * @file libdht/libhipopendht.c
  *
  * <LICENSE TEMLPATE LINE - LEAVE THIS LINE INTACT>
- * 
- * Functions to use OpenDHT/Bamboo-DHT/OpenLookup-v1/OpenLookup-v2. Supports 
+ *
+ * Functions to use OpenDHT/Bamboo-DHT/OpenLookup-v1/OpenLookup-v2. Supports
  * put, get, put-rm and rm messages.
  *
- * @brief All the necessary functionality for DHT (OpenDHT/OpenLookup) usage. 
+ * @brief All the necessary functionality for DHT (OpenDHT/OpenLookup) usage.
  *
  * @author: Samu Varjonen <samu.varjonen@xxxxxxx>
  **/
@@ -32,15 +32,14 @@
 #include "libhipdhtxml.h"
 
 /**
- *  For interrupting the connect in gethosts_hit 
+ *  For interrupting the connect in gethosts_hit
  *  @param signo signal number
  *
  *  @return void
  */
-static void 
-connect_alarm(int signo)
+static void connect_alarm(int signo)
 {
-       return; 
+    return;
 }
 
 /**
@@ -51,173 +50,180 @@
  *
  * @return Returns positive if socket creation was ok negative on error.
  */
-int 
-init_dht_gateway_socket_gw(int sockfd, struct addrinfo *gateway) 
+int init_dht_gateway_socket_gw(int sockfd, struct addrinfo *gateway)
 {
-       /* default address family */
-       int af = AF_INET;
-
-       if(gateway)
-               af = gateway->ai_family;
-       
-       if ((sockfd = socket(af, SOCK_STREAM, IPPROTO_TCP)) < 0)
-               HIP_PERROR("OpenDHT socket\n");
-    
-       return(sockfd);      
+    /* default address family */
+    int af = AF_INET;
+
+    if (gateway) {
+        af = gateway->ai_family;
+    }
+
+    if ((sockfd = socket(af, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+        HIP_PERROR("OpenDHT socket\n");
+    }
+
+    return sockfd;
 }
 
-/** 
+/**
  * resolve_dht_gateway_info - Resolves the gateway address
  *
  * @param gateway_name FQDN of the gateway
  * @param gateway      Addrinfo struct where the result will be stored
  * @param gateway_port  Port number of the used gateway
  * @param af           address family
- * 
+ *
  * @return Returns 0 on success otherwise -1
  */
-int 
-resolve_dht_gateway_info(char *gateway_name, 
-                            struct addrinfo ** gateway,
-                            in_port_t gateway_port,
-                            int af) 
+int resolve_dht_gateway_info(char *gateway_name,
+                             struct addrinfo **gateway,
+                             in_port_t gateway_port,
+                             int af)
 {
-       struct addrinfo hints;
-       struct sockaddr_in  *sa_v4 = NULL;
-       struct sockaddr_in6 *sa_v6 = NULL;
-       int error;
-       char opendht_serving_gateway_port_str[7];
-       
-       if ((af != AF_INET) && (af != AF_INET6)) {
-               error = -1;
-               HIP_DEBUG("Wrong address family!\n");
-               return error;
-       }
-       
-       memset(&hints, 0, sizeof(hints));
-       hints.ai_family = af;
-       hints.ai_socktype = SOCK_STREAM;
-       /* For some reason this does not work anymore -samu */
-       /* hints.ai_flags = AI_NODHT; */
-       error = 0;
-       
-       sprintf(opendht_serving_gateway_port_str, "%d", gateway_port);
-       error = getaddrinfo(gateway_name, opendht_serving_gateway_port_str, 
&hints, gateway);
-       if (error != 0) {
-               HIP_DEBUG("OpenDHT gateway resolving failed %s\n", 
gateway_name);
-               HIP_DEBUG("%s\n",gai_strerror(error));
-       } else {
-               if (af == AF_INET) {
-                       sa_v4 = (struct sockaddr_in *) (*gateway)->ai_addr;
-                       HIP_DEBUG_INADDR("OpenDHT gateway IPv4", 
&(sa_v4->sin_addr));
-               } else if (af == AF_INET6) {
-                       sa_v6 = (struct sockaddr_in6 *) (*gateway)->ai_addr;
-                       HIP_DEBUG_IN6ADDR("OpenDHT gateway IPv6", 
&(sa_v6->sin6_addr));
-               }
-       }
-       
-       return error;
+    struct addrinfo hints;
+    struct sockaddr_in *sa_v4  = NULL;
+    struct sockaddr_in6 *sa_v6 = NULL;
+    int error;
+    char opendht_serving_gateway_port_str[7];
+
+    if ((af != AF_INET) && (af != AF_INET6)) {
+        error = -1;
+        HIP_DEBUG("Wrong address family!\n");
+        return error;
+    }
+
+    memset(&hints, 0, sizeof(hints));
+    hints.ai_family   = af;
+    hints.ai_socktype = SOCK_STREAM;
+    /* For some reason this does not work anymore -samu */
+    /* hints.ai_flags = AI_NODHT; */
+    error = 0;
+
+    sprintf(opendht_serving_gateway_port_str, "%d", gateway_port);
+    error = getaddrinfo(gateway_name, opendht_serving_gateway_port_str,
+                        &hints, gateway);
+    if (error != 0) {
+        HIP_DEBUG("OpenDHT gateway resolving failed %s\n", gateway_name);
+        HIP_DEBUG("%s\n", gai_strerror(error));
+    } else {
+        if (af == AF_INET) {
+            sa_v4 = (struct sockaddr_in *) (*gateway)->ai_addr;
+            HIP_DEBUG_INADDR("OpenDHT gateway IPv4", &(sa_v4->sin_addr));
+        } else if (af == AF_INET6) {
+            sa_v6 = (struct sockaddr_in6 *) (*gateway)->ai_addr;
+            HIP_DEBUG_IN6ADDR("OpenDHT gateway IPv6", &(sa_v6->sin6_addr));
+        }
+    }
+
+    return error;
 }
 
 /**
  *  connect_dht_gateway - Connects to given v4 or v6 gateway
  *
  *  @param sockfd Socket that will be the one connecting
- *  @param addrinfo Address to connect to 
+ *  @param addrinfo Address to connect to
  *  @param blocking 1 for blocking connect 0 for nonblocking
  *
  *  @return Returns 0 on success -1 otherwise, if nonblocking can return 
EINPRGORESS
  */
-int 
-connect_dht_gateway(int sockfd,
-                          struct addrinfo * gateway,
-                          int blocking)
+int connect_dht_gateway(int sockfd,
+                        struct addrinfo *gateway,
+                        int blocking)
 {
-       int flags = 0, error = 0;
-       struct sockaddr_in *sa_v4;
-       struct sockaddr_in6 *sa_v6;
-       
-       struct sigaction act, oact;
-       act.sa_handler = connect_alarm;
-       sigemptyset(&act.sa_mask);
-       act.sa_flags = 0;
-       
-       if(gateway == NULL){
-               HIP_ERROR("No OpenDHT Serving Gateway Address.\n");
-               return(-1);
-       }
-       
-       if(blocking == 0)
-               goto unblock;
-       
-       /* blocking connect */
-       if(sigaction(SIGALRM, &act, &oact) < 0){
-               HIP_DEBUG("Signal error before OpenDHT connect, "
-                         "connecting without alarm\n");
-               error = connect(sockfd, gateway->ai_addr, gateway->ai_addrlen);
-       }else {
-               HIP_DEBUG("Connecting to OpenDHT with alarm\n");
-               if (alarm(DHT_CONNECT_TIMEOUT) != 0)
-                       HIP_DEBUG("Alarm was already set, connecting 
without\n");
-               error = connect(sockfd, gateway->ai_addr, gateway->ai_addrlen);
-               alarm(0);
-               if (sigaction(SIGALRM, &oact, &act) <0 ) 
-                       HIP_DEBUG("Signal error after OpenDHT connect\n");
-       }
-       
-       if(error < 0){
-               HIP_PERROR("OpenDHT connect:");
-               if (errno == EINTR)
-                       HIP_DEBUG("Connect to OpenDHT timedout\n");
-               return(-1);
-       }else{
-               if(gateway->ai_family == AF_INET){
-                       sa_v4 = (struct sockaddr_in *)gateway->ai_addr;
-                       HIP_DEBUG_INADDR("Connected to OpenDHT v4 gateway", 
&(sa_v4->sin_addr));
-               }
-               else if(gateway->ai_family == AF_INET6){
-                       sa_v6 = (struct sockaddr_in6 *)gateway->ai_addr;
-                       HIP_DEBUG_IN6ADDR("Connected to OpenDHT v6 gateway", 
&(sa_v6->sin6_addr));
-               }
-               else{
-                       HIP_DEBUG("Wrong address family for OPENDHT gateway 
%d\n", gateway->ai_family);
-               }
-               return(0);
-       }       
+    int flags = 0, error = 0;
+    struct sockaddr_in *sa_v4;
+    struct sockaddr_in6 *sa_v6;
+
+    struct sigaction act, oact;
+    act.sa_handler = connect_alarm;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags   = 0;
+
+    if (gateway == NULL) {
+        HIP_ERROR("No OpenDHT Serving Gateway Address.\n");
+        return -1;
+    }
+
+    if (blocking == 0) {
+        goto unblock;
+    }
+
+    /* blocking connect */
+    if (sigaction(SIGALRM, &act, &oact) < 0) {
+        HIP_DEBUG("Signal error before OpenDHT connect, "
+                  "connecting without alarm\n");
+        error = connect(sockfd, gateway->ai_addr, gateway->ai_addrlen);
+    } else {
+        HIP_DEBUG("Connecting to OpenDHT with alarm\n");
+        if (alarm(DHT_CONNECT_TIMEOUT) != 0) {
+            HIP_DEBUG("Alarm was already set, connecting without\n");
+        }
+        error = connect(sockfd, gateway->ai_addr, gateway->ai_addrlen);
+        alarm(0);
+        if (sigaction(SIGALRM, &oact, &act) < 0) {
+            HIP_DEBUG("Signal error after OpenDHT connect\n");
+        }
+    }
+
+    if (error < 0) {
+        HIP_PERROR("OpenDHT connect:");
+        if (errno == EINTR) {
+            HIP_DEBUG("Connect to OpenDHT timedout\n");
+        }
+        return -1;
+    } else {
+        if (gateway->ai_family == AF_INET) {
+            sa_v4 = (struct sockaddr_in *) gateway->ai_addr;
+            HIP_DEBUG_INADDR("Connected to OpenDHT v4 gateway",
+                             &(sa_v4->sin_addr));
+        } else if (gateway->ai_family == AF_INET6)    {
+            sa_v6 = (struct sockaddr_in6 *) gateway->ai_addr;
+            HIP_DEBUG_IN6ADDR("Connected to OpenDHT v6 gateway",
+                              &(sa_v6->sin6_addr));
+        } else {
+            HIP_DEBUG("Wrong address family for OPENDHT gateway %d\n",
+                      gateway->ai_family);
+        }
+        return 0;
+    }
 unblock:
-       /* unblocking connect */
-       flags = fcntl(sockfd, F_GETFL, 0);
-       fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); 
-       
-       if(gateway->ai_family == AF_INET){
-               sa_v4 = (struct sockaddr_in *)gateway->ai_addr;
-               HIP_DEBUG_INADDR("Connecting to OpenDHT v4 gateway", 
&(sa_v4->sin_addr));
-       }
-       else if(gateway->ai_family == AF_INET6){
-               sa_v6 = (struct sockaddr_in6 *)gateway->ai_addr;
-               HIP_DEBUG_IN6ADDR("Connecting to OpenDHT v6 gateway", 
&(sa_v6->sin6_addr));
-       }
-       else{
-               HIP_DEBUG("Wrong address family for OPENDHT gateway %d\n", 
gateway->ai_family);
-       }
-       
-       if(connect(sockfd, gateway->ai_addr, gateway->ai_addrlen) < 0){
-               if (errno == EINPROGRESS)
-                       return(EINPROGRESS);
-               else{
-                       HIP_PERROR("OpenDHT connect:");
-                       return(-1);
-               }
-       }else{
-               /* connect ok */
-               return(0);
-       }
+    /* unblocking connect */
+    flags = fcntl(sockfd, F_GETFL, 0);
+    fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
+
+    if (gateway->ai_family == AF_INET) {
+        sa_v4 = (struct sockaddr_in *) gateway->ai_addr;
+        HIP_DEBUG_INADDR("Connecting to OpenDHT v4 gateway",
+                         &(sa_v4->sin_addr));
+    } else if (gateway->ai_family == AF_INET6)    {
+        sa_v6 = (struct sockaddr_in6 *) gateway->ai_addr;
+        HIP_DEBUG_IN6ADDR("Connecting to OpenDHT v6 gateway",
+                          &(sa_v6->sin6_addr));
+    } else {
+        HIP_DEBUG("Wrong address family for OPENDHT gateway %d\n",
+                  gateway->ai_family);
+    }
+
+    if (connect(sockfd, gateway->ai_addr, gateway->ai_addrlen) < 0) {
+        if (errno == EINPROGRESS) {
+            return EINPROGRESS;
+        } else {
+            HIP_PERROR("OpenDHT connect:");
+            return -1;
+        }
+    } else {
+        /* connect ok */
+        return 0;
+    }
 }
 
-/** 
- * opendht_put_rm - Builds XML RPC packet and sends it through given socket 
and reads the response
+/**
+ * opendht_put_rm - Builds XML RPC packet and sends it through given socket and
+ * reads the response
  *
- * @param sockfd Socket to be used with the send 
+ * @param sockfd Socket to be used with the send
  * @param key Key for the openDHT
  * @param value Value to be stored to the openDHT
  * @param secret Value to be used as a secret in remove
@@ -227,44 +233,43 @@
  *
  * @return Returns integer -1 on error, on success 0
  */
-int 
-opendht_put_rm(int sockfd, 
-              unsigned char * key,
-              unsigned char * value, 
-              unsigned char * secret,
-              unsigned char * host,
-              int opendht_port,
-              int opendht_ttl)
+int opendht_put_rm(int sockfd,
+                   unsigned char *key,
+                   unsigned char *value,
+                   unsigned char *secret,
+                   unsigned char *host,
+                   int opendht_port,
+                   int opendht_ttl)
 {
-       int key_len = 0;
-       char put_packet[HIP_MAX_PACKET];
-       char tmp_key[21];
-       
-       key_len = opendht_handle_key(key, tmp_key);
-       
-       /* Put operation FQDN->HIT */
-       memset(put_packet, '\0', sizeof(put_packet));
-       if (build_packet_put_rm((unsigned char *)tmp_key,
-                               key_len,
-                               (unsigned char *)value,
-                               strlen((char *)value),
-                               (unsigned char *)secret,
-                               strlen((char *)secret),
-                               opendht_port,
-                               (unsigned char *)host,
-                               put_packet, opendht_ttl) != 0)
-        {
-               HIP_DEBUG("Put(rm) packet creation failed.\n");
-               return(-1);
-        }
-       _HIP_DEBUG("Host address in OpenDHT put(rm) : %s\n", host); 
-       HIP_DEBUG("Actual OpenDHT send starts here\n");
-       send(sockfd, put_packet, strlen(put_packet), 0);
-       return(0);
+    int key_len = 0;
+    char put_packet[HIP_MAX_PACKET];
+    char tmp_key[21];
+
+    key_len = opendht_handle_key(key, tmp_key);
+
+    /* Put operation FQDN->HIT */
+    memset(put_packet, '\0', sizeof(put_packet));
+    if (build_packet_put_rm((unsigned char *) tmp_key,
+                            key_len,
+                            (unsigned char *) value,
+                            strlen((char *) value),
+                            (unsigned char *) secret,
+                            strlen((char *) secret),
+                            opendht_port,
+                            (unsigned char *) host,
+                            put_packet, opendht_ttl) != 0) {
+        HIP_DEBUG("Put(rm) packet creation failed.\n");
+        return -1;
+    }
+    _HIP_DEBUG("Host address in OpenDHT put(rm) : %s\n", host);
+    HIP_DEBUG("Actual OpenDHT send starts here\n");
+    send(sockfd, put_packet, strlen(put_packet), 0);
+    return 0;
 }
 
-/** 
- * opendht_put - Builds XML RPC packet and sends it through given socket and 
reads the response
+/**
+ * opendht_put - Builds XML RPC packet and sends it through given socket and
+ * reads the response
  *
  * @param key Key for the openDHT
  * @param value Value to be stored to the openDHT
@@ -275,53 +280,50 @@
  *
  * @return Returns integer -1 on error, on success 0
  */
-int 
-opendht_put(unsigned char * key,
-           unsigned char * value, 
-           unsigned char * host,
-           int opendht_port,
-           int opendht_ttl, 
-           void *put_packet)
+int opendht_put(unsigned char *key,
+                unsigned char *value,
+                unsigned char *host,
+                int opendht_port,
+                int opendht_ttl,
+                void *put_packet)
 {
-       int key_len = 0;
-       int value_len = 0;
-       char tmp_key[21];   
-       char tmp_value[21];
-        
-       key_len = opendht_handle_key(key, tmp_key);   
-       value_len = opendht_handle_value(value, tmp_value);
-       
-       /* Put operation FQDN->HIT */
-       if (key_len > 0) {
-               if (build_packet_put((unsigned char *)tmp_key,
-                                    key_len,
-                                    (unsigned char *)tmp_value,
-                                    value_len,
-                                    opendht_port,
-                                    (unsigned char *)host,
-                                    (char*)put_packet, opendht_ttl) != 0)
-               {
-                       HIP_DEBUG("Put packet creation failed.\n");
-                       return(-1);
-               }
-       }  else {
-               if (build_packet_put((unsigned char *)tmp_key,
-                                    key_len,
-                                    (unsigned char *)value,
-                                    strlen((char *)value),
-                                    opendht_port,
-                                    (unsigned char *)host,
-                                    (char*)put_packet, opendht_ttl) != 0)
-               {
-                       HIP_DEBUG("Put packet creation failed.\n");
-                       return(-1);
-               }
-       }
-       _HIP_DEBUG("HTTP packet for put is ready to be sent to queue\n"); 
-       return(0);
+    int key_len   = 0;
+    int value_len = 0;
+    char tmp_key[21];
+    char tmp_value[21];
+
+    key_len   = opendht_handle_key(key, tmp_key);
+    value_len = opendht_handle_value(value, tmp_value);
+
+    /* Put operation FQDN->HIT */
+    if (key_len > 0) {
+        if (build_packet_put((unsigned char *) tmp_key,
+                             key_len,
+                             (unsigned char *) tmp_value,
+                             value_len,
+                             opendht_port,
+                             (unsigned char *) host,
+                             (char *) put_packet, opendht_ttl) != 0) {
+            HIP_DEBUG("Put packet creation failed.\n");
+            return -1;
+        }
+    }  else {
+        if (build_packet_put((unsigned char *) tmp_key,
+                             key_len,
+                             (unsigned char *) value,
+                             strlen((char *) value),
+                             opendht_port,
+                             (unsigned char *) host,
+                             (char *) put_packet, opendht_ttl) != 0) {
+            HIP_DEBUG("Put packet creation failed.\n");
+            return -1;
+        }
+    }
+    _HIP_DEBUG("HTTP packet for put is ready to be sent to queue\n");
+    return 0;
 }
 
-/** 
+/**
  * opendht_send - Sends the given packet to the given socket
  *
  * @param sockfd Socket to be used with the send
@@ -329,25 +331,27 @@
  *
  * @return Returns integer -1 on error, on success 0
  */
-int 
-opendht_send(int sockfd, void *packet)
+int opendht_send(int sockfd, void *packet)
 {
-       int err = 0, len = strlen((char *)packet); 
-  
-       _HIP_DEBUG("Packet: %s\n",put_packet);
-       _HIP_DEBUG("OpenDHT send: packet length: %d\n", len);
-       
-       if (len > 0)
-               err = send(sockfd, (char *) packet, len, 0);
-
-       if (err < 1)
-               HIP_PERROR("Error opendht_send: ");
+    int err = 0, len = strlen((char *) packet);
+
+    _HIP_DEBUG("Packet: %s\n", put_packet);
+    _HIP_DEBUG("OpenDHT send: packet length: %d\n", len);
+
+    if (len > 0) {
+        err = send(sockfd, (char *) packet, len, 0);
+    }
+
+    if (err < 1) {
+        HIP_PERROR("Error opendht_send: ");
+    }
 
     return 0;
 }
 
-/** 
- * opendht_rm - Builds XML RPC packet and sends it through given socket and 
reads the response
+/**
+ * opendht_rm - Builds XML RPC packet and sends it through given socket and
+ * reads the response
  *
  * @param sockfd Socket to be used with the send
  * @param key Key for the openDHT
@@ -359,44 +363,43 @@
  *
  * @return Returns integer -1 on error, on success 0
  */
-int 
-opendht_rm(int sockfd, 
-          unsigned char * key,
-          unsigned char * value, 
-          unsigned char * secret,
-          unsigned char * host,
-          int opendht_port,
-          int opendht_ttl)
+int opendht_rm(int sockfd,
+               unsigned char *key,
+               unsigned char *value,
+               unsigned char *secret,
+               unsigned char *host,
+               int opendht_port,
+               int opendht_ttl)
 {
-       int key_len = 0;
-       char put_packet[HIP_MAX_PACKET];
-       char tmp_key[21];
-       
-       key_len = opendht_handle_key(key, tmp_key);
-       
-       /* Rm operation */
-       memset(put_packet, '\0', sizeof(put_packet));
-       if (build_packet_rm((unsigned char *)tmp_key,
-                           key_len,
-                           (unsigned char *)value,
-                           strlen((char *)value),
-                           (unsigned char *)secret,
-                           strlen((char *)secret),
-                           opendht_port,
-                           (unsigned char *)host,
-                           put_packet, opendht_ttl) != 0)
-        {
-               HIP_DEBUG("Rm packet creation failed.\n");
-               return(-1);
-        }
-       _HIP_DEBUG("Host address in OpenDHT rm : %s\n", host); 
-       HIP_DEBUG("Actual OpenDHT send starts here\n");
-       send(sockfd, put_packet, strlen(put_packet), 0);
-       return(0);
+    int key_len = 0;
+    char put_packet[HIP_MAX_PACKET];
+    char tmp_key[21];
+
+    key_len = opendht_handle_key(key, tmp_key);
+
+    /* Rm operation */
+    memset(put_packet, '\0', sizeof(put_packet));
+    if (build_packet_rm((unsigned char *) tmp_key,
+                        key_len,
+                        (unsigned char *) value,
+                        strlen((char *) value),
+                        (unsigned char *) secret,
+                        strlen((char *) secret),
+                        opendht_port,
+                        (unsigned char *) host,
+                        put_packet, opendht_ttl) != 0) {
+        HIP_DEBUG("Rm packet creation failed.\n");
+        return -1;
+    }
+    _HIP_DEBUG("Host address in OpenDHT rm : %s\n", host);
+    HIP_DEBUG("Actual OpenDHT send starts here\n");
+    send(sockfd, put_packet, strlen(put_packet), 0);
+    return 0;
 }
 
-/** 
- * opendht_get - Builds XML RPC packet and sends it through given socket and 
reads the response
+/**
+ * opendht_get - Builds XML RPC packet and sends it through given socket and
+ * reads the response
  *
  * @param sockfd Socket to be used with the send
  * @param key Key for the openDHT
@@ -405,32 +408,30 @@
  *
  * @return Returns integer -1 on error, on success 0
  */
-int 
-opendht_get(int sockfd, 
-           unsigned char * key, 
-           unsigned char * host,
-           int port)
+int opendht_get(int sockfd,
+                unsigned char *key,
+                unsigned char *host,
+                int port)
 {
-       int key_len = 0;
-       char get_packet[HIP_MAX_PACKET];
-       char tmp_key[21];
-       
-       key_len = opendht_handle_key(key, tmp_key);
-    
-       /* Get operation */
-       memset(get_packet, '\0', sizeof(get_packet));
-       if (build_packet_get((unsigned char *)tmp_key,
-                            key_len,
-                            port,
-                            (unsigned char *)host,
-                            get_packet) !=0)
-        {
-               HIP_DEBUG("Get packet creation failed.\n");  
-               return(-1);
-        }
-       
-       send(sockfd, get_packet, strlen(get_packet), 0);
-       return(0);
+    int key_len = 0;
+    char get_packet[HIP_MAX_PACKET];
+    char tmp_key[21];
+
+    key_len = opendht_handle_key(key, tmp_key);
+
+    /* Get operation */
+    memset(get_packet, '\0', sizeof(get_packet));
+    if (build_packet_get((unsigned char *) tmp_key,
+                         key_len,
+                         port,
+                         (unsigned char *) host,
+                         get_packet) != 0) {
+        HIP_DEBUG("Get packet creation failed.\n");
+        return -1;
+    }
+
+    send(sockfd, get_packet, strlen(get_packet), 0);
+    return 0;
 }
 
 /**
@@ -441,34 +442,30 @@
  *
  * @return larger than 0 if value was in IPv6 format (len of out_value)
  */
-int 
-opendht_handle_value(unsigned char * value, char * out_value) 
+int opendht_handle_value(unsigned char *value, char *out_value)
 {
-       int err = 0, value_len = 0;
-       char tmp_value[21];
-       struct in6_addr addrvalue;
-       
-       memset(tmp_value, '\0', sizeof(tmp_value));
-       
-       if (inet_pton(AF_INET6, (char *)value, &addrvalue.s6_addr) == 0)
-        {
-               /* inet_pton failed because of invalid IPv6 address */
-               /* copy data to value as it is*/
-               /* restricting length to 21, data after it will be lost*/
-               memcpy(out_value, value, sizeof(tmp_value)); 
-               value_len = sizeof(tmp_value);
-               err = value_len;
-        } 
-       else 
-        {
-               /* value was in IPv6 format so propably is a HIT */
-               memcpy(tmp_value, addrvalue.s6_addr, sizeof(addrvalue.s6_addr));
-               value_len = sizeof(addrvalue.s6_addr);
-               err = value_len;
-               memcpy(out_value, tmp_value, sizeof(tmp_value));
-        }
-       
-       return(err);
+    int err = 0, value_len = 0;
+    char tmp_value[21];
+    struct in6_addr addrvalue;
+
+    memset(tmp_value, '\0', sizeof(tmp_value));
+
+    if (inet_pton(AF_INET6, (char *) value, &addrvalue.s6_addr) == 0) {
+        /* inet_pton failed because of invalid IPv6 address */
+        /* copy data to value as it is*/
+        /* restricting length to 21, data after it will be lost*/
+        memcpy(out_value, value, sizeof(tmp_value));
+        value_len = sizeof(tmp_value);
+        err       = value_len;
+    } else {
+        /* value was in IPv6 format so propably is a HIT */
+        memcpy(tmp_value, addrvalue.s6_addr, sizeof(addrvalue.s6_addr));
+        value_len = sizeof(addrvalue.s6_addr);
+        err       = value_len;
+        memcpy(out_value, tmp_value, sizeof(tmp_value));
+    }
+
+    return err;
 }
 
 /**
@@ -479,78 +476,74 @@
  *
  * @return -1 if false otherwise it will be len of out_key
  */
-int 
-opendht_handle_key(unsigned char * key, char * out_key) 
+int opendht_handle_key(unsigned char *key, char *out_key)
 {
-       int err = 0, key_len = 0, i = 0 ;
-       unsigned char tmp_key[21];
-       struct in6_addr addrkey;
-       unsigned char *sha_retval;
-       int key_len_specified_in_bytes = 20;
-       unsigned char *paddedkey = NULL;
-       /* Below three variables are used for key padding logic */
-       int k = 0;
-       unsigned char tempChar1 =' ';
-       unsigned char tempChar2 =' ';
-       
-       /* check for too long keys and convert HITs to numeric form */
-       memset(tmp_key, '\0', sizeof(tmp_key));
-       
-       if (inet_pton(AF_INET6, (char *)key, &addrkey.s6_addr) == 0)
-       {
-               /* inet_pton failed because of invalid IPv6 address */
-               memset(tmp_key,'\0',sizeof(tmp_key));
-               /* strlen works now but maybe not later */
-               for (i = 0; i < strlen((char *)key); i++ )
-                       key[i] = (unsigned char)tolower(key[i]);
-               if (key[strlen((char *)key)] == '.')
-                       key[strlen((char *)key)] = '\0';
-               sha_retval = SHA1(key, strlen((char *)key), tmp_key); 
-               key_len = 20;
-               err = key_len;
-               _HIP_HEXDUMP("KEY FOR OPENDHT", tmp_key, key_len);
-               if (!sha_retval)
-               {
-                       HIP_DEBUG("SHA1 error when creating key for 
OpenDHT.\n");
-                       return(-1);
-               }                
-       }
-       else 
-       {
-               /* We require only last 100 bits of the HIT. That is to say
-                  to ignore first 28 bits we need to shift 28 bits left the 
HIT.
-                  Follwoing logic does it and zero padding is already done in 
memset
-                  above for tmp_key to make it 160 bit long key */
-               paddedkey = malloc(key_len_specified_in_bytes +4);
-               memset(paddedkey, '\0', key_len_specified_in_bytes +4);
-               memcpy(paddedkey, addrkey.s6_addr, sizeof(addrkey.s6_addr));    
        
-               paddedkey = paddedkey + 3;
-               while (k <13)
-               {       /*We get the MSB hex byte from tempchar1 and LSB 
temchar2 */
-                       tempChar1 = *(paddedkey+k);
-                       tempChar2 = *(paddedkey+k+1);
-                       tempChar1 = tempChar1 << 4 ;
-                       tempChar2 = tempChar2 >> 4 ;
-                       *(paddedkey+k) = tempChar1 | tempChar2 ;
-                       k++;
-               }
-               _HIP_DEBUG("New key value:  %d.\n", k);
-               memcpy(tmp_key, paddedkey, k+1);
-               key_len = key_len_specified_in_bytes ;
-               err = key_len;
-       }
-       memcpy(out_key, tmp_key, sizeof(tmp_key));
-
-       if(paddedkey)
-       {
-               paddedkey = paddedkey -3 ;
-               free(paddedkey);
-       }
-       return(err);
+    int err                        = 0, key_len = 0, i = 0;
+    unsigned char tmp_key[21];
+    struct in6_addr addrkey;
+    unsigned char *sha_retval;
+    int key_len_specified_in_bytes = 20;
+    unsigned char *paddedkey       = NULL;
+    /* Below three variables are used for key padding logic */
+    int k                          = 0;
+    unsigned char tempChar1        = ' ';
+    unsigned char tempChar2        = ' ';
+
+    /* check for too long keys and convert HITs to numeric form */
+    memset(tmp_key, '\0', sizeof(tmp_key));
+
+    if (inet_pton(AF_INET6, (char *) key, &addrkey.s6_addr) == 0) {
+        /* inet_pton failed because of invalid IPv6 address */
+        memset(tmp_key, '\0', sizeof(tmp_key));
+        /* strlen works now but maybe not later */
+        for (i = 0; i < strlen((char *) key); i++) {
+            key[i] = (unsigned char) tolower(key[i]);
+        }
+        if (key[strlen((char *) key)] == '.') {
+            key[strlen((char *) key)] = '\0';
+        }
+        sha_retval = SHA1(key, strlen((char *) key), tmp_key);
+        key_len    = 20;
+        err        = key_len;
+        _HIP_HEXDUMP("KEY FOR OPENDHT", tmp_key, key_len);
+        if (!sha_retval) {
+            HIP_DEBUG("SHA1 error when creating key for OpenDHT.\n");
+            return -1;
+        }
+    } else {
+        /* We require only last 100 bits of the HIT. That is to say
+         * to ignore first 28 bits we need to shift 28 bits left the HIT.
+         * Follwoing logic does it and zero padding is already done in memset
+         * above for tmp_key to make it 160 bit long key */
+        paddedkey = malloc(key_len_specified_in_bytes + 4);
+        memset(paddedkey, '\0', key_len_specified_in_bytes + 4);
+        memcpy(paddedkey, addrkey.s6_addr, sizeof(addrkey.s6_addr));
+        paddedkey = paddedkey + 3;
+        while (k < 13) { /*We get the MSB hex byte from tempchar1 and LSB 
temchar2 */
+            tempChar1        = *(paddedkey + k);
+            tempChar2        = *(paddedkey + k + 1);
+            tempChar1        = tempChar1 << 4;
+            tempChar2        = tempChar2 >> 4;
+            *(paddedkey + k) = tempChar1 | tempChar2;
+            k++;
+        }
+        _HIP_DEBUG("New key value:  %d.\n", k);
+        memcpy(tmp_key, paddedkey, k + 1);
+        key_len = key_len_specified_in_bytes;
+        err     = key_len;
+    }
+    memcpy(out_key, tmp_key, sizeof(tmp_key));
+
+    if (paddedkey) {
+        paddedkey = paddedkey - 3;
+        free(paddedkey);
+    }
+    return err;
 }
 
-/** 
- * opendht_read_response - Reads from the given socket and parses the XML RPC 
response
+/**
+ * opendht_read_response - Reads from the given socket and parses the XML RPC
+ * response
  *
  * @param sockfd Socket to be used with the send
  * @param[out] answer Buffer where the response value will be saved
@@ -558,129 +551,126 @@
  * @return Returns integer, same as in read_packet_content
  * TODO: see read_packet_content
  */
-int 
-opendht_read_response(int sockfd, unsigned char * answer)
+int opendht_read_response(int sockfd, unsigned char *answer)
 {
-       int ret = 0, pton_ret = 0;
-       int bytes_read = 0, total = 0;
-       char read_buffer[HIP_MAX_PACKET];
-       /* char tmp_buffer[HIP_MAX_PACKET]; */
-       struct in_addr ipv4;
-       struct in6_addr ipv6;
-       
-       memset(&ipv6, 0, sizeof(struct in6_addr));
-       
-       if (sockfd <= 0 || answer == NULL) {
-               HIP_ERROR("sockfd=%p, answer=%p\n", sockfd, answer);
-               return -1;
-       }
-       
-       memset(read_buffer, '\0', sizeof(read_buffer));
-       do
-        {
-               bytes_read = recv(sockfd, &read_buffer[total],
-                                 sizeof(read_buffer), 0);
-               total += bytes_read;
-        }
-       while (bytes_read > 0 && total < sizeof(read_buffer) - 1);
-       
-       /* Parse answer */
-       memset(answer, '\0', 1);
-       ret = 0;
-       ret = read_packet_content(read_buffer, (char *)answer);
-       
-       /* If answer was IPv4 address mapped to IPv6 revert to IPv4 format*/
-       pton_ret = inet_pton(AF_INET6, (char *)answer, &ipv6);
-       
-       if (pton_ret && IN6_IS_ADDR_V4MAPPED(&ipv6)) {
-               IPV6_TO_IPV4_MAP(&ipv6, &ipv4);
-               sprintf((char *)answer, "%s", inet_ntoa(ipv4));
-       }
-       
-       return ret;
+    int ret        = 0, pton_ret = 0;
+    int bytes_read = 0, total = 0;
+    char read_buffer[HIP_MAX_PACKET];
+    /* char tmp_buffer[HIP_MAX_PACKET]; */
+    struct in_addr ipv4;
+    struct in6_addr ipv6;
+
+    memset(&ipv6, 0, sizeof(struct in6_addr));
+
+    if (sockfd <= 0 || answer == NULL) {
+        HIP_ERROR("sockfd=%p, answer=%p\n", sockfd, answer);
+        return -1;
+    }
+
+    memset(read_buffer, '\0', sizeof(read_buffer));
+    do {
+        bytes_read = recv(sockfd, &read_buffer[total],
+                          sizeof(read_buffer), 0);
+        total     += bytes_read;
+    } while (bytes_read > 0 && total < sizeof(read_buffer) - 1);
+
+    /* Parse answer */
+    memset(answer, '\0', 1);
+    ret      = 0;
+    ret      = read_packet_content(read_buffer, (char *) answer);
+
+    /* If answer was IPv4 address mapped to IPv6 revert to IPv4 format*/
+    pton_ret = inet_pton(AF_INET6, (char *) answer, &ipv6);
+
+    if (pton_ret && IN6_IS_ADDR_V4MAPPED(&ipv6)) {
+        IPV6_TO_IPV4_MAP(&ipv6, &ipv4);
+        sprintf((char *) answer, "%s", inet_ntoa(ipv4));
+    }
+
+    return ret;
 }
-    
+
 /**
- * hip_opendht_get_key - creates socket, connects to OpenDHT and gets the 
value under given key
+ * hip_opendht_get_key - creates socket, connects to OpenDHT and gets the value
+ * under given key
  *
  * @param *value_handler(), a pointer function which treats different values 
from openDHT based
  * on the function assigned to it by the caller
  * @param gateway A addrinfo struct containing the gateway address
  * @param key Pointer to key to be fetched
  * @param[out] opaque_answer Pointer to memory area where the corresponding 
value will be saved
- *       opaque_answer is set by poiner function sent as param
- * @param dont_verify_hdrr if passed 0 HDRR sig and hostid verification is 
done, otherwise skipped 
+ *        opaque_answer is set by poiner function sent as param
+ * @param dont_verify_hdrr if passed 0 HDRR sig and hostid verification is 
done, otherwise skipped
  *
  * @return integer -1 on error, on success 0
  */
-int 
-hip_opendht_get_key(int (*value_handler)(unsigned char * packet, void * 
answer),
-                   struct addrinfo * gateway, 
-                   const char * key, void * opaque_answer, 
-                   int dont_verify_hdrr)
+int hip_opendht_get_key(int (*value_handler)(unsigned char *packet, void 
*answer),
+                        struct addrinfo *gateway,
+                        const char *key, void *opaque_answer,
+                        int dont_verify_hdrr)
 {
-       int err = 0, sfd = -1;
-       char hostname[256];
-       char *host_addr = NULL;
-       struct hostent *hoste = NULL;
-        /* To convert DHT key (HIT) to in6_addr structure */
-       struct in6_addr hit_key; 
-        
-       memset(hostname,'\0',sizeof(hostname));
-       HIP_IFEL((gethostname(hostname, sizeof(hostname))),-1,"Error getting 
hostname\n");
-       HIP_IFEL(!(hoste = gethostbyname(hostname)),-1,
-               "Encountered an error when getting host address\n");
-       if (hoste->h_addrtype == AF_INET)
-               host_addr = inet_ntoa(*(struct in_addr *)*hoste->h_addr_list);
-       else if (hoste->h_addrtype == AF_INET6) {
-               HIP_IFEL(inet_ntop(AF_INET6, &hoste->h_addr_list, 
-                       host_addr, sizeof(INET6_ADDRSTRLEN)),
-                       -1,"Error converting host IPv6 address\n");
-       }
-       else {
-               HIP_DEBUG("Unknown host address family\n");
-               goto out_err;
-       }
-
-       host_addr = OPENDHT_GATEWAY;
-       _HIP_DEBUG("Host addresss %s\n", host_addr);
-       sfd = init_dht_gateway_socket_gw(sfd, gateway);
-       HIP_IFEL((err = connect_dht_gateway(sfd, gateway, 1))
-                       ,-1,"OpenDHT connect error\n");
-       HIP_IFEL((err = opendht_get(sfd, (unsigned char *)key, 
-                                   (unsigned char *)host_addr, OPENDHT_PORT)),
-               -1, "Opendht_get error");
-       HIP_IFEL(opendht_read_response(sfd, opaque_answer), 
-                -1, "Opendht_read_response error\n"); 
-       _HIP_DUMP_MSG((struct hip_common *)opaque_answer);
-
-       /* Check if we found the key from lookup service or not */
-       /* why this was comparison to null and not 0 */
-       HIP_IFEL((((struct hip_common *)opaque_answer)->payload_len == 0),
-                -1, "NULL response\n");
-
-       /* Call the hdrr verification function, in case of hdrr
-          if key for lookup is hit, it has to be hdrr */
-       
-       if ((inet_pton(AF_INET6, key, &hit_key.s6_addr) == 0) || 
dont_verify_hdrr) { 
-               _HIP_DEBUG("lookup is not for HDRR or " 
-                          "HDRR verification flag not set so skipping 
verification \n");
-       } else {
-               err = verify_hddr_lib ((struct hip_common 
*)opaque_answer,&hit_key);
-               if (err != 0) {
-                       /*HDRR verification failed*/
-                       opaque_answer = NULL ;
-                       HIP_DEBUG("HDRR verification failed \n");
-                       err = -1 ;
-               } else HIP_DEBUG("HDRR verification was successful\n");
-                                       
-       }
+    int err               = 0, sfd = -1;
+    char hostname[256];
+    char *host_addr       = NULL;
+    struct hostent *hoste = NULL;
+    /* To convert DHT key (HIT) to in6_addr structure */
+    struct in6_addr hit_key;
+
+    memset(hostname, '\0', sizeof(hostname));
+    HIP_IFEL((gethostname(hostname, sizeof(hostname))), -1, "Error getting 
hostname\n");
+    HIP_IFEL(!(hoste = gethostbyname(hostname)), -1,
+             "Encountered an error when getting host address\n");
+    if (hoste->h_addrtype == AF_INET) {
+        host_addr = inet_ntoa(*(struct in_addr *) *hoste->h_addr_list);
+    } else if (hoste->h_addrtype == AF_INET6) {
+        HIP_IFEL(inet_ntop(AF_INET6, &hoste->h_addr_list,
+                           host_addr, sizeof(INET6_ADDRSTRLEN)),
+                 -1, "Error converting host IPv6 address\n");
+    } else {
+        HIP_DEBUG("Unknown host address family\n");
+        goto out_err;
+    }
+
+    host_addr = OPENDHT_GATEWAY;
+    _HIP_DEBUG("Host addresss %s\n", host_addr);
+    sfd       = init_dht_gateway_socket_gw(sfd, gateway);
+    HIP_IFEL((err = connect_dht_gateway(sfd, gateway, 1))
+             , -1, "OpenDHT connect error\n");
+    HIP_IFEL((err = opendht_get(sfd, (unsigned char *) key,
+                                (unsigned char *) host_addr, OPENDHT_PORT)),
+             -1, "Opendht_get error");
+    HIP_IFEL(opendht_read_response(sfd, opaque_answer),
+             -1, "Opendht_read_response error\n");
+    _HIP_DUMP_MSG((struct hip_common *) opaque_answer);
+
+    /* Check if we found the key from lookup service or not */
+    /* why this was comparison to null and not 0 */
+    HIP_IFEL((((struct hip_common *) opaque_answer)->payload_len == 0),
+             -1, "NULL response\n");
+
+    /* Call the hdrr verification function, in case of hdrr
+     * if key for lookup is hit, it has to be hdrr */
+
+    if ((inet_pton(AF_INET6, key, &hit_key.s6_addr) == 0) || dont_verify_hdrr) 
{
+        _HIP_DEBUG("lookup is not for HDRR or "
+                   "HDRR verification flag not set so skipping verification 
\n");
+    } else {
+        err = verify_hddr_lib((struct hip_common *) opaque_answer, &hit_key);
+        if (err != 0) {
+            /*HDRR verification failed*/
+            opaque_answer = NULL;
+            HIP_DEBUG("HDRR verification failed \n");
+            err           = -1;
+        } else {HIP_DEBUG("HDRR verification was successful\n");
+        }
+    }
 
 out_err:
-       if (sfd)
-               close(sfd); 
+    if (sfd) {
+        close(sfd);
+    }
 
-       return(err);
+    return err;
 }
 
 /**
@@ -691,19 +681,17 @@
  *
  * @return status of the operation 0 on success, -1 on failure
  */
-int 
-handle_hdrr_value (unsigned char *packet, void *hdrr)
-{       
-       struct hip_locator *locator;
-       
-       locator = hip_get_param((struct hip_common *)packet, HIP_PARAM_LOCATOR);
-       if (locator)
-       { 
-               memcpy(hdrr, packet, HIP_MAX_PACKET);
-               return 0 ;
-       }
-       else            
-               return -1 ;             
+int handle_hdrr_value(unsigned char *packet, void *hdrr)
+{
+    struct hip_locator *locator;
+
+    locator = hip_get_param((struct hip_common *) packet, HIP_PARAM_LOCATOR);
+    if (locator) {
+        memcpy(hdrr, packet, HIP_MAX_PACKET);
+        return 0;
+    } else {
+        return -1;
+    }
 }
 
 /**
@@ -714,57 +702,55 @@
  *
  * @return status of the operation 0 on success, -1 on failure
  */
-int 
-handle_locator_all_values (unsigned char *packet, void *locator_complete)
+int handle_locator_all_values(unsigned char *packet, void *locator_complete)
 {
-       struct hip_locator *locator;
-       locator = hip_get_param((struct hip_common *)packet, HIP_PARAM_LOCATOR);
-       if (locator)
-    { 
-               memcpy(locator_complete, locator, HIP_MAX_PACKET);
-               return 0 ;
-       }
-       else
-               return -1 ;             
+    struct hip_locator *locator;
+    locator = hip_get_param((struct hip_common *) packet, HIP_PARAM_LOCATOR);
+    if (locator) {
+        memcpy(locator_complete, locator, HIP_MAX_PACKET);
+        return 0;
+    } else {
+        return -1;
+    }
 }
 
 /**
  * handle_locator_value - This function copies the 2nd address (ipv4) from
  * the locator from packet returned from lookup
- * 
+ *
  * @param *packet response returned from the lookup service
  * @param *locator_ipv4 opaque pointer passed to point to the ipv4 address
  *
  * @return status of the operation 0 on success, -1 on failure
  */
-int 
-handle_locator_value (unsigned char *packet, void *locator_ipv4)
+int handle_locator_value(unsigned char *packet, void *locator_ipv4)
 {
-       struct hip_locator *locator;
-       struct hip_locator_info_addr_item *locator_address_item = NULL;
-       int locator_item_count = 0;
-       struct in6_addr addr6;
-       struct in_addr addr4;
-   
-       locator = hip_get_param((struct hip_common *)packet, HIP_PARAM_LOCATOR);
-
-       if (locator) {
-               locator_item_count = hip_get_locator_addr_item_count(locator);
-               locator_item_count--;
-               locator_address_item = hip_get_locator_first_addr_item(locator);
-               memcpy(&addr6, 
-                       (struct 
in6_addr*)&locator_address_item[locator_item_count].address, 
-                               sizeof(struct in6_addr));
-               if (IN6_IS_ADDR_V4MAPPED(&addr6)) {
-                       IPV6_TO_IPV4_MAP(&addr6, &addr4);
-                       sprintf((char*)locator_ipv4, "%s", inet_ntoa(addr4));
-               } else {
-                       hip_in6_ntop(&addr6, (char*)locator_ipv4);
-                       _HIP_DEBUG("Value: %s\n", (char*)locator_ipv4);
-               }
-               return 0 ;
-       } else
-               return -1;      
+    struct hip_locator *locator;
+    struct hip_locator_info_addr_item *locator_address_item = NULL;
+    int locator_item_count                                  = 0;
+    struct in6_addr addr6;
+    struct in_addr addr4;
+
+    locator = hip_get_param((struct hip_common *) packet, HIP_PARAM_LOCATOR);
+
+    if (locator) {
+        locator_item_count   = hip_get_locator_addr_item_count(locator);
+        locator_item_count--;
+        locator_address_item = hip_get_locator_first_addr_item(locator);
+        memcpy(&addr6,
+               (struct in6_addr *) 
&locator_address_item[locator_item_count].address,
+               sizeof(struct in6_addr));
+        if (IN6_IS_ADDR_V4MAPPED(&addr6)) {
+            IPV6_TO_IPV4_MAP(&addr6, &addr4);
+            sprintf((char *) locator_ipv4, "%s", inet_ntoa(addr4));
+        } else {
+            hip_in6_ntop(&addr6, (char *) locator_ipv4);
+            _HIP_DEBUG("Value: %s\n", (char *) locator_ipv4);
+        }
+        return 0;
+    } else {
+        return -1;
+    }
 }
 
 /**
@@ -775,14 +761,14 @@
  *
  * @return status of the operation 0 on success, -1 on failure
  */
-int 
-handle_hit_value (unsigned char *packet, void *hit)
+int handle_hit_value(unsigned char *packet, void *hit)
 {
-       if (ipv6_addr_is_hit((struct in6_addr*)packet)) {
-               hip_in6_ntop((struct in6_addr *)packet, (char*)hit);
-               return 0 ;
-       } else 
-               return -1 ;
+    if (ipv6_addr_is_hit((struct in6_addr *) packet)) {
+        hip_in6_ntop((struct in6_addr *) packet, (char *) hit);
+        return 0;
+    } else {
+        return -1;
+    }
 }
 
 /**
@@ -793,86 +779,86 @@
  *
  * @return status of the operation 0 on success, -1 on failure
  */
-int 
-handle_ip_value (unsigned char *packet, void *ip)
+int handle_ip_value(unsigned char *packet, void *ip)
 {
-       hip_in6_ntop((struct in6_addr *)packet, (char*)ip);
-       if ((char*)ip)
-               return 0 ;
-       else 
-               return -1 ;
+    hip_in6_ntop((struct in6_addr *) packet, (char *) ip);
+    if ((char *) ip) {
+        return 0;
+    } else {
+        return -1;
+    }
 }
 
 /**
- * verify_hddr_lib - It sends the dht response to hipdaemon first appending 
one more 
- *                   user param for holding a structure hdrr_info hdrr_info is 
used by 
+ * verify_hddr_lib - It sends the dht response to hipdaemon first appending 
one more
+ *                   user param for holding a structure hdrr_info hdrr_info is 
used by
  *                   daemon to mark signature and host id verification results 
to flags
  *                   then adding user header for recognizing the message at 
daemon side
- * 
+ *
  * @param *hipcommonmsg Packet returned from the lookup service
  * @param *addrkey Key that was used for the lookup
  *
  * @return OR of the signature and host id verification, 0 in case of success
  */
-int 
-verify_hddr_lib (struct hip_common * hipcommonmsg, struct in6_addr * addrkey)
+int verify_hddr_lib(struct hip_common *hipcommonmsg, struct in6_addr *addrkey)
 {
-       struct hip_hdrr_info hdrr_info; 
-       struct hip_hdrr_info *hdrr_info_response; 
-       int err = 0 ;
-       
-       memcpy(&hdrr_info.dht_key, addrkey, sizeof(struct in6_addr));
-       hdrr_info.sig_verified = -1;
-       hdrr_info.hit_verified = -1;
-       HIP_IFEL(hip_build_user_hdr(hipcommonmsg, 
SO_HIP_VERIFY_DHT_HDRR_RESP,0),-1,
-                       "Building daemon header failed\n");
-       hip_build_param_hip_hdrr_info(hipcommonmsg, &hdrr_info);
-       _HIP_DUMP_MSG (hipcommonmsg);
-
-       HIP_INFO("Asking signature verification info from daemon...\n");
-       HIP_IFEL(hip_send_recv_daemon_info(hipcommonmsg, 0, 0), 
-                -1, "Send recv daemon info failed\n");
-      
-       hdrr_info_response = hip_get_param (hipcommonmsg, HIP_PARAM_HDRR_INFO);
-       _HIP_DUMP_MSG (hipcommonmsg);
-       HIP_DEBUG ("Sig verified (0=true): %d\nHit Verified (0=true): %d \n"
-               ,hdrr_info_response->sig_verified, 
hdrr_info_response->hit_verified);
-       return (hdrr_info_response->sig_verified | 
hdrr_info_response->hit_verified);
+    struct hip_hdrr_info hdrr_info;
+    struct hip_hdrr_info *hdrr_info_response;
+    int err = 0;
+
+    memcpy(&hdrr_info.dht_key, addrkey, sizeof(struct in6_addr));
+    hdrr_info.sig_verified = -1;
+    hdrr_info.hit_verified = -1;
+    HIP_IFEL(hip_build_user_hdr(hipcommonmsg, SO_HIP_VERIFY_DHT_HDRR_RESP, 0), 
-1,
+             "Building daemon header failed\n");
+    hip_build_param_hip_hdrr_info(hipcommonmsg, &hdrr_info);
+    _HIP_DUMP_MSG(hipcommonmsg);
+
+    HIP_INFO("Asking signature verification info from daemon...\n");
+    HIP_IFEL(hip_send_recv_daemon_info(hipcommonmsg, 0, 0),
+             -1, "Send recv daemon info failed\n");
+
+    hdrr_info_response = hip_get_param(hipcommonmsg, HIP_PARAM_HDRR_INFO);
+    _HIP_DUMP_MSG(hipcommonmsg);
+    HIP_DEBUG("Sig verified (0=true): %d\nHit Verified (0=true): %d \n"
+              , hdrr_info_response->sig_verified, 
hdrr_info_response->hit_verified);
+    return hdrr_info_response->sig_verified | hdrr_info_response->hit_verified;
 
 out_err:
-       return err;
+    return err;
 }
 
 /**
  * handle_cert_key - This prepares the key for publishing certificates
- 
+ *
  * @param *lhit Local HIT used
  * @param *rhit HIT of the remote host
  * @param[out] *final_key Resulting key value after processing
  *
  * @return length of the key or -1 in case of error
  */
-int
-handle_cert_key(struct in6_addr *lhit, struct in6_addr *rhit, void *final_key)
+int handle_cert_key(struct in6_addr *lhit,
+                    struct in6_addr *rhit,
+                    void *final_key)
 {
-       void *result = NULL ;
-       unsigned char *sha_retval;
-       int key_len = sizeof(rhit->s6_addr)*2;
-       
-       result = malloc (key_len);
-               /*concatenate both*/    
-       memcpy(result,&rhit->s6_addr,sizeof(rhit->s6_addr));
-       memcpy(result+sizeof(rhit->s6_addr),
-                               &lhit->s6_addr,sizeof(lhit->s6_addr));
-       sha_retval = SHA1(result, key_len, final_key); 
-       key_len = 20;
-       _HIP_HEXDUMP("KEY FOR OPENDHT", final_key, key_len);
-       if (!sha_retval)
-       {
-       HIP_DEBUG("SHA1 error when creating key for OpenDHT.\n");
-               key_len = -1;
-       }
-       if(result)
-               free (result);
-       return key_len ;
+    void *result              = NULL;
+    unsigned char *sha_retval = NULL;
+    int key_len               = sizeof(rhit->s6_addr) * 2;
+
+    result = malloc(key_len);
+    /*concatenate both*/
+    memcpy(result, &rhit->s6_addr, sizeof(rhit->s6_addr));
+    memcpy(result + sizeof(rhit->s6_addr),
+           &lhit->s6_addr, sizeof(lhit->s6_addr));
+    sha_retval = SHA1(result, key_len, final_key);
+    key_len    = 20;
+    _HIP_HEXDUMP("KEY FOR OPENDHT", final_key, key_len);
+    if (!sha_retval) {
+        HIP_DEBUG("SHA1 error when creating key for OpenDHT.\n");
+        key_len = -1;
+    }
+    if (result) {
+        free(result);
+    }
+    return key_len;
 }

=== modified file 'lib/dht/libhipdht.h'
--- lib/dht/libhipdht.h 2010-01-19 13:10:46 +0000
+++ lib/dht/libhipdht.h 2010-02-10 23:13:03 +0000
@@ -19,7 +19,7 @@
 #define STATE_OPENDHT_WAITING_CONNECT 2
 #define STATE_OPENDHT_START_SEND 3
 #define DHT_CONNECT_TIMEOUT 2
-#define OPENDHT_SERVERS_FILE HIPL_SYSCONFDIR"/dhtservers"
+#define OPENDHT_SERVERS_FILE HIPL_SYSCONFDIR "/dhtservers"
 #define OPENDHT_ERROR_COUNT_MAX 3
 
 int init_dht_gateway_socket_gw(int, struct addrinfo *);
@@ -28,11 +28,11 @@
 
 int connect_dht_gateway(int, struct addrinfo *, int);
 
-int opendht_put_rm(int, unsigned char *, unsigned char *, 
+int opendht_put_rm(int, unsigned char *, unsigned char *,
                    unsigned char *, unsigned char *, int, int);
 
-int opendht_put(unsigned char * key, unsigned char * value,
-                unsigned char * host, int opendht_port,
+int opendht_put(unsigned char *key, unsigned char *value,
+                unsigned char *host, int opendht_port,
                 int opendht_ttl, void *put_packet);
 
 int opendht_rm(int, unsigned char *, unsigned char *,
@@ -42,10 +42,11 @@
 
 int opendht_send(int sockfd, void *packet);
 
-int hip_opendht_get_key(int (*value_handler)(unsigned char * packet,
-               void * answer),struct addrinfo * gateway, 
-               const char * key, void * opaque_answer, 
-               int dont_verify_hdrr);
+int hip_opendht_get_key(int (*value_handler)(unsigned char *packet,
+                                             void *answer),
+                                             struct addrinfo *gateway,
+                        const char *key, void *opaque_answer,
+                        int dont_verify_hdrr);
 int opendht_handle_key(unsigned char *, char *);
 
 int opendht_handle_value(unsigned char *, char *);
@@ -53,13 +54,15 @@
 
 int opendht_read_response(int, unsigned char *);
 
-int (*value_handler)(unsigned char * packet, void * answer);  
+int (*value_handler)(unsigned char *packet, void *answer);
 
-int handle_hdrr_value (unsigned char *packet, void *hdrr);
-int handle_locator_value (unsigned char *packet, void *locator_ipv4);
-int handle_hit_value (unsigned char *packet, void *hit); 
-int handle_locator_all_values (unsigned char *packet, void *locator_complete);
-int handle_ip_value (unsigned char *packet, void *ip);
-int handle_cert_key(struct in6_addr *lhit, struct in6_addr *rhit, void 
*final_key);
-int verify_hddr_lib (struct hip_common *hipcommonmsg,struct in6_addr *addrkey);
+int handle_hdrr_value(unsigned char *packet, void *hdrr);
+int handle_locator_value(unsigned char *packet, void *locator_ipv4);
+int handle_hit_value(unsigned char *packet, void *hit);
+int handle_locator_all_values(unsigned char *packet, void *locator_complete);
+int handle_ip_value(unsigned char *packet, void *ip);
+int handle_cert_key(struct in6_addr *lhit,
+                    struct in6_addr *rhit,
+                    void *final_key);
+int verify_hddr_lib(struct hip_common *hipcommonmsg, struct in6_addr *addrkey);
 #endif /* lib_opendht */

=== modified file 'lib/dht/libhipdhtxml.c'
--- lib/dht/libhipdhtxml.c      2010-01-19 13:10:46 +0000
+++ lib/dht/libhipdhtxml.c      2010-02-10 23:13:03 +0000
@@ -8,13 +8,13 @@
 #include "hipd/netdev.h"
 
 xmlNodePtr xml_new_param(xmlNodePtr node_parent, char *type, char *value);
- 
-/** 
+
+/**
  * build_packet_put_rm - Builds HTTP XML packet for removable put
- * 
+ *
  * @param key Key that is used in to the openDHT
  * @param key_len Length of the key in bytes
- * @param value Value to be stored in to the openDHT 
+ * @param value Value to be stored in to the openDHT
  * @param value_len Lenght of value in bytes
  * @param secret Secret used in remove
  * @param secret_len Length of the secret used in remove
@@ -24,109 +24,119 @@
  * @param ttl Time-to-live for the key-value pair
  *
  * @return integer 0
- * 
+ *
  * @note Seems to return zero even on error -Samu
  *
  * @note host_ip for openlookup google apps version must be openlookup.net
  */
-int build_packet_put_rm(unsigned char * key, 
-                     int key_len,
-                    unsigned char * value,
-                     int value_len, 
-                     unsigned char *secret,
-                     int secret_len,
-                     int port,
-                     unsigned char * host_ip,
-                    char * out_buffer,
-                     int ttl) 
+int build_packet_put_rm(unsigned char *key,
+                        int key_len,
+                        unsigned char *value,
+                        int value_len,
+                        unsigned char *secret,
+                        int secret_len,
+                        int port,
+                        unsigned char *host_ip,
+                        char *out_buffer,
+                        int ttl)
 {
-    int err = 0;
-    char *key64 = NULL;
-    char *value64 = NULL;
+    int err        = 0;
+    char *key64    = NULL;
+    char *value64  = NULL;
     char *secret64 = NULL;
 
     unsigned char *sha_retval;
     char secret_hash[21];
 
     /* Create a XML document */
-    xmlDocPtr xml_doc = NULL;
-    xmlNodePtr xml_root = NULL;
-    xmlNodePtr xml_node;
-    xmlNodePtr xml_node_skip;
+    xmlDocPtr xml_doc         = NULL;
+    xmlNodePtr xml_root       = NULL;
+    xmlNodePtr xml_node       = NULL;
+    xmlNodePtr xml_node_skip  = NULL;
     unsigned char *xml_buffer = NULL;
-    int xml_len = 0;
+    int xml_len               = 0;
 
     char ttl_str[10];
-    
-    HIP_IFEL(!(key64 = (char *)base64_encode((unsigned char *)key, 
-                                            (unsigned int)key_len)),
-            -1, "Failed to encode key64\n");
-    HIP_IFEL(!(value64 = (char *)base64_encode((unsigned char *)value, 
-                                              (unsigned int)value_len)),
-            -1, "Failed to encode value64\n");
+
+    HIP_IFEL(!(key64 = (char *) base64_encode((unsigned char *) key,
+                                              (unsigned int) key_len)),
+             -1, "Failed to encode key64\n");
+    HIP_IFEL(!(value64 = (char *) base64_encode((unsigned char *) value,
+                                                (unsigned int) value_len)),
+             -1, "Failed to encode value64\n");
 
     memset(secret_hash, '\0', sizeof(secret_hash));
 
-    sha_retval = SHA1(secret, secret_len, (unsigned char *)secret_hash);
-    if (!sha_retval)
-        {
-            HIP_DEBUG("SHA1 error when creating hash of the secret for the 
removable put\n");
-            return(-1);
-        }
-    HIP_IFEL(!(secret64 = (char *)base64_encode((unsigned char *)secret_hash, 
(unsigned int)20)),
-            -1, "Failed to encode secret64\n");
+    sha_retval = SHA1(secret, secret_len, (unsigned char *) secret_hash);
+    if (!sha_retval) {
+        HIP_DEBUG("SHA1 error when creating hash of the secret for the 
removable put\n");
+        return -1;
+    }
+    HIP_IFEL(!(secret64 = (char *) base64_encode((unsigned char *) secret_hash,
+                                                 (unsigned int) 20)),
+             -1, "Failed to encode secret64\n");
 
     memset(ttl_str, '\0', sizeof(char[10]));
-    sprintf((char *)&ttl_str, "%d", ttl);
-    _HIP_DEBUG("TTL STR %s INT %d\n",ttl_str, ttl);
+    sprintf((char *) &ttl_str, "%d", ttl);
+    _HIP_DEBUG("TTL STR %s INT %d\n", ttl_str, ttl);
 
-    xml_doc = xmlNewDoc(BAD_CAST "1.0");
+    xml_doc  = xmlNewDoc(BAD_CAST "1.0");
     xml_root = xmlNewNode(NULL, BAD_CAST "methodCall");
     xmlDocSetRootElement(xml_doc, xml_root);
-    if (secret_len > 0)
+    if (secret_len > 0) {
         xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "methodName", BAD_CAST 
"put_removable");
-    else
+    } else {
         xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "methodName", BAD_CAST 
"put");
+    }
     xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "params", NULL);
-    xml_new_param(xml_node, "base64", (char *)key64);
-    xml_new_param(xml_node, "base64", (char *)value64);
+    xml_new_param(xml_node, "base64", (char *) key64);
+    xml_new_param(xml_node, "base64", (char *) value64);
 
     xml_node_skip = xml_node;
-    if (secret_len > 0)
-        {
-            xml_new_param(xml_node, "string", "SHA");
-            xml_new_param(xml_node, "base64", (char *)secret64);
-        }
+    if (secret_len > 0) {
+        xml_new_param(xml_node, "string", "SHA");
+        xml_new_param(xml_node, "base64", (char *) secret64);
+    }
 
-    xml_new_param(xml_node_skip, "int", (char *)&ttl_str);  
-    xml_new_param(xml_node_skip, "string", (char *)BAD_CAST "HIPL");
+    xml_new_param(xml_node_skip, "int", (char *) &ttl_str);
+    xml_new_param(xml_node_skip, "string", (char *) BAD_CAST "HIPL");
     xmlDocDumpFormatMemory(xml_doc, &xml_buffer, &xml_len, 0);
 
     memset(out_buffer, '\0', sizeof(out_buffer));
-    sprintf(out_buffer, 
+    sprintf(out_buffer,
             "POST / HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: "
             "hipl\r\nContent-Type: "
-            "text/xml\r\nContent-length: %d\r\n\r\n", 
+            "text/xml\r\nContent-length: %d\r\n\r\n",
             host_ip, port, xml_len);
     memcpy(&out_buffer[strlen(out_buffer)], xml_buffer, xml_len);
-  
+
     _HIP_DEBUG("\n\n%s\n\n", out_buffer);
 
-out_err:    
+out_err:
 
-    if (xml_buffer) xmlFree(xml_buffer);
-    if (xml_doc) xmlFreeDoc(xml_doc);
-    if (key64) free(key64);
-    if (secret64) free(secret64);
-    if (value64) free(value64); 
-    return(0);
+    if (xml_buffer) {
+        xmlFree(xml_buffer);
+    }
+    if (xml_doc) {
+        xmlFreeDoc(xml_doc);
+    }
+    if (key64) {
+        free(key64);
+    }
+    if (secret64) {
+        free(secret64);
+    }
+    if (value64) {
+        free(value64);
+    }
+    return 0;
 }
 
-/** 
+/**
  * build_packet_put - Builds HTTP XML packet for put
  * @param key Key that is used in to the openDHT
  * @param key_len Length of the key in bytes
- * @param value Value to be stored in to the openDHT 
+ * @param value Value to be stored in to the openDHT
  * @param value_len Lenght of value in bytes
  * @param port Port for the openDHT (5851)
  * @param host_ip Host IP
@@ -140,30 +150,30 @@
  *
  * @note host_ip for openlookup google apps version must be openlookup.net
  */
-int build_packet_put(unsigned char * key, 
+int build_packet_put(unsigned char *key,
                      int key_len,
-                    unsigned char * value,
-                     int value_len, 
+                     unsigned char *value,
+                     int value_len,
                      int port,
-                     unsigned char * host_ip,
-                    char * out_buffer,
-                     int ttl) 
+                     unsigned char *host_ip,
+                     char *out_buffer,
+                     int ttl)
 {
     int ret = 0;
     ret = build_packet_put_rm(key,
                               key_len,
                               value,
                               value_len,
-                              (unsigned char *)"",
+                              (unsigned char *) "",
                               0,
                               port,
                               host_ip,
                               out_buffer,
                               ttl);
-    return(ret);
+    return ret;
 }
 
-/** 
+/**
  * build_packet_get - Builds HTTP XML packet for get
  * @param key Key that is used in to the openDHT
  * @param key_len Length of the key in bytes
@@ -177,59 +187,58 @@
  *
  * @note host_ip for openlookup google apps version must be openlookup.net
  */
-int build_packet_get(unsigned char * key,
+int build_packet_get(unsigned char *key,
                      int key_len,
                      int port,
-                     unsigned char * host_ip,
-                    char * out_buffer) 
+                     unsigned char *host_ip,
+                     char *out_buffer)
 {
-       int err = 0;
-       char *key64 = NULL; 
-       
-       /* Create a XML document */
-       xmlDocPtr xml_doc = NULL;
-       xmlNodePtr xml_root = NULL;
-       xmlNodePtr xml_node;
-       unsigned char *xml_buffer = NULL;
-       int xml_len = 0;
-       
-       HIP_IFEL(!(key64 = (char *)base64_encode((unsigned char *)key, 
(unsigned int)key_len)),
-                -1, "Failed to encode key64\n");
-       
-       xml_doc = xmlNewDoc(BAD_CAST "1.0");
-       xml_root = xmlNewNode(NULL, BAD_CAST "methodCall");
-       xmlDocSetRootElement(xml_doc, xml_root);
-       xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "methodName", BAD_CAST 
"get");
-       xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "params", NULL);
-       xml_new_param(xml_node, "base64", (char *)key64);
-       xml_new_param(xml_node, "int", "10");   /* maxvals */
-       xml_new_param(xml_node, "base64", "");  /* placemark */ 
-       xml_new_param(xml_node, "string", (char *)BAD_CAST "HIPL");
-       xmlDocDumpFormatMemory(xml_doc, &xml_buffer, &xml_len, 0);
-       
-       memset(out_buffer, '\0', sizeof(out_buffer));
-       sprintf(out_buffer, 
-               "POST / HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: "
-               "hipl\r\nContent-Type: "
-               "text/xml\r\nContent-length: %d\r\n\r\n", 
-               host_ip, port, xml_len);
-       memcpy(&out_buffer[strlen(out_buffer)], xml_buffer, xml_len);
-       
-       _HIP_DEBUG("\n\n%s\n\n", out_buffer);
-       
+    int err                   = 0;
+    char *key64               = NULL;
+    /* Create a XML document */
+    xmlDocPtr xml_doc         = NULL;
+    xmlNodePtr xml_root       = NULL;
+    xmlNodePtr xml_node       = NULL;
+    unsigned char *xml_buffer = NULL;
+    int xml_len               = 0;
+
+    HIP_IFEL(!(key64 = (char *) base64_encode((unsigned char *) key, (unsigned 
int) key_len)),
+             -1, "Failed to encode key64\n");
+
+    xml_doc  = xmlNewDoc(BAD_CAST "1.0");
+    xml_root = xmlNewNode(NULL, BAD_CAST "methodCall");
+    xmlDocSetRootElement(xml_doc, xml_root);
+    xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "methodName", BAD_CAST 
"get");
+    xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "params", NULL);
+    xml_new_param(xml_node, "base64", (char *) key64);
+    xml_new_param(xml_node, "int", "10");       /* maxvals */
+    xml_new_param(xml_node, "base64", "");      /* placemark */
+    xml_new_param(xml_node, "string", (char *) BAD_CAST "HIPL");
+    xmlDocDumpFormatMemory(xml_doc, &xml_buffer, &xml_len, 0);
+
+    memset(out_buffer, '\0', sizeof(out_buffer));
+    sprintf(out_buffer,
+            "POST / HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: "
+            "hipl\r\nContent-Type: "
+            "text/xml\r\nContent-length: %d\r\n\r\n",
+            host_ip, port, xml_len);
+    memcpy(&out_buffer[strlen(out_buffer)], xml_buffer, xml_len);
+
+    _HIP_DEBUG("\n\n%s\n\n", out_buffer);
+
 out_err:
-       
-       xmlFree(xml_buffer);
-       xmlFreeDoc(xml_doc);  
-       free(key64);
-       return(0);
+
+    xmlFree(xml_buffer);
+    xmlFreeDoc(xml_doc);
+    free(key64);
+    return 0;
 }
 
-/** 
+/**
  * build_packet_rm - Builds HTTP XML packet for rm
  * @param key Key that is used in to the openDHT
  * @param key_len Length of the key in bytes
- * @param value Value to be removed in to the openDHT 
+ * @param value Value to be removed in to the openDHT
  * @param value_len Lenght of value in bytes
  * @param secret Plain text secret (has of which sent earlier)
  * @param secret_len Length of the secret
@@ -239,104 +248,100 @@
  * @param ttl Time-to-live for the key-value pair
  *
  * @return integer 0
- * 
+ *
  * @note returns zero even on error -Samu
  *
  * @note host_ip for openlookup google apps version must be openlookup.net
  */
-int build_packet_rm(unsigned char * key, 
+int build_packet_rm(unsigned char *key,
                     int key_len,
-                    unsigned char * value,
-                    int value_len, 
-                    unsigned char * secret,
+                    unsigned char *value,
+                    int value_len,
+                    unsigned char *secret,
                     int secret_len,
                     int port,
-                    unsigned char * host_ip,
-                    char * out_buffer,
-                    int ttl) 
+                    unsigned char *host_ip,
+                    char *out_buffer,
+                    int ttl)
 {
-    int err = 0;
-    char *key64 = NULL;
-    char *value64 = NULL;
+    int err        = 0;
+    char *key64    = NULL;
+    char *value64  = NULL;
     char *secret64 = NULL;
-
     unsigned char *sha_retval;
     char value_hash[21];
-
     char ttl_str[10];
-
     /* Create a XML document */
-    xmlDocPtr xml_doc = NULL;
-    xmlNodePtr xml_root = NULL;
-    xmlNodePtr xml_node;
+    xmlDocPtr xml_doc         = NULL;
+    xmlNodePtr xml_root       = NULL;
+    xmlNodePtr xml_node       = NULL;
     unsigned char *xml_buffer = NULL;
-    int xml_len = 0;
+    int xml_len               = 0;
 
-    HIP_IFEL(!(key64 = (char *)base64_encode((unsigned char *)key, (unsigned 
int)key_len)),
-            -1, "Failed to encode key64\n");
-    HIP_IFEL(!(secret64 = (char *)base64_encode((unsigned char *)secret, 
(unsigned int)secret_len)),
-            -1, "Failed to encode secret64\n");
+    HIP_IFEL(!(key64 = (char *) base64_encode((unsigned char *) key, (unsigned 
int) key_len)),
+             -1, "Failed to encode key64\n");
+    HIP_IFEL(!(secret64 = (char *) base64_encode((unsigned char *) secret, 
(unsigned int) secret_len)),
+             -1, "Failed to encode secret64\n");
 
     memset(value_hash, '\0', sizeof(value_hash));
-    sha_retval = SHA1(value, value_len, (unsigned char *)value_hash);
-    if (!sha_retval)
-        {
-            HIP_DEBUG("SHA1 error when creating hash of the value for rm 
msg\n");
-            return(-1);
-        }
-    HIP_IFEL(!(value64 = (char *)base64_encode((unsigned char *)value_hash, 
20)),
-            -1, "Failed to encode value64\n");
+    sha_retval = SHA1(value, value_len, (unsigned char *) value_hash);
+    if (!sha_retval) {
+        HIP_DEBUG("SHA1 error when creating hash of the value for rm msg\n");
+        return -1;
+    }
+    HIP_IFEL(!(value64 = (char *) base64_encode((unsigned char *) value_hash, 
20)),
+             -1, "Failed to encode value64\n");
 
     memset(ttl_str, '\0', sizeof(char[10]));
-    sprintf((char *)&ttl_str, "%d", ttl);
+    sprintf((char *) &ttl_str, "%d", ttl);
 
-    xml_doc = xmlNewDoc(BAD_CAST "1.0");
+    xml_doc  = xmlNewDoc(BAD_CAST "1.0");
     xml_root = xmlNewNode(NULL, BAD_CAST "methodCall");
     xmlDocSetRootElement(xml_doc, xml_root);
     xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "methodName", BAD_CAST 
"rm");
     xml_node = xmlNewChild(xml_root, NULL, BAD_CAST "params", NULL);
-    xml_new_param(xml_node, "base64", (char *)key64);
-    xml_new_param(xml_node, "base64", (char *)value64);
-    xml_new_param(xml_node, "string", (char *)BAD_CAST "SHA");
-    xml_new_param(xml_node, "base64", (char *)secret64);
-    xml_new_param(xml_node, "int", (char *)&ttl_str);  
-    xml_new_param(xml_node, "string", (char *)BAD_CAST "HIPL");
+    xml_new_param(xml_node, "base64", (char *) key64);
+    xml_new_param(xml_node, "base64", (char *) value64);
+    xml_new_param(xml_node, "string", (char *) BAD_CAST "SHA");
+    xml_new_param(xml_node, "base64", (char *) secret64);
+    xml_new_param(xml_node, "int", (char *) &ttl_str);
+    xml_new_param(xml_node, "string", (char *) BAD_CAST "HIPL");
     xmlDocDumpFormatMemory(xml_doc, &xml_buffer, &xml_len, 0);
 
     memset(out_buffer, '\0', sizeof(out_buffer));
-    sprintf(out_buffer, 
+    sprintf(out_buffer,
             "POST / HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: "
             "hipl\r\nContent-Type: "
-            "text/xml\r\nContent-length: %d\r\n\r\n", 
+            "text/xml\r\nContent-length: %d\r\n\r\n",
             host_ip, port, xml_len);
     memcpy(&out_buffer[strlen(out_buffer)], xml_buffer, xml_len);
-    
+
     _HIP_DEBUG("\n\n%s\n\n", out_buffer);
-    
+
 out_err:
 
     xmlFree(xml_buffer);
     xmlFreeDoc(xml_doc);
     free(key64);
     free(secret64);
-    free(value64); 
-    return(0);
+    free(value64);
+    return 0;
 }
 
-/** 
+/**
  * read_packet_content - Builds HTTP XML packet for put
  * @param in_buffer Should contain packet to be parsed including the HTTP 
header
  * @param out_value Value received is stored here
  *
  * @return Integer -1 if error, on success 0, len if LOCATOR or other binary
  */
-int read_packet_content(char * in_buffer, char * out_value)
+int read_packet_content(char *in_buffer, char *out_value)
 {
-    int ret = 0, i = 0, ii = 0;
-    int evpret = 0;
-    char * place = NULL;
+    int ret           = 0, i = 0, ii = 0;
+    int evpret        = 0;
+    char *place       = NULL;
     char tmp_tmp_buffer[HIP_MAX_PACKET];
-    char tmp_buffer[HIP_MAX_PACKET]; 
+    char tmp_buffer[HIP_MAX_PACKET];
     xmlDocPtr xml_doc = NULL;
     xmlNodePtr xml_node;
     xmlNodePtr xml_node_value;
@@ -347,9 +352,9 @@
     memset(out_value, '\0', sizeof(out_value));
     answers.count = 0;
     answers.addrs[0] = '\0';
-      
-    _HIP_DEBUG("\n\nXML Parser got this input\n\n%s\n\n",in_buffer);
-    
+
+    _HIP_DEBUG("\n\nXML Parser got this input\n\n%s\n\n", in_buffer);
+
     /* To be on the safe side, let's remove 0x0a's from in_buffer */
     while (in_buffer[i] != '\0') {
         if (in_buffer[i] != '\n') {
@@ -359,20 +364,18 @@
         i++;
     }
     tmp_tmp_buffer[ii] = '\0';
-    
-    _HIP_DEBUG("\n\nAfter clean up\n\n%s\n\n",tmp_tmp_buffer);
-       
+
+    _HIP_DEBUG("\n\nAfter clean up\n\n%s\n\n", tmp_tmp_buffer);
+
     /*!!!! is there a http header !!!!*/
-    if (strncmp(tmp_tmp_buffer, "HTTP", 4) !=0) 
-    { 
+    if (strncmp(tmp_tmp_buffer, "HTTP", 4) != 0) {
         HIP_DEBUG("Parser error: no HTTP header in the packet.\n");
         ret = -1;
         goto out_err;
     }
-    
+
     /* is there a xml document */
-    if ((place = strstr(tmp_tmp_buffer, "<?xml")) == NULL)
-    {
+    if ((place = strstr(tmp_tmp_buffer, "<?xml")) == NULL) {
         HIP_DEBUG("Parser error: no XML content in the packet.\n");
         ret = -1;
         goto out_err;
@@ -381,154 +384,147 @@
     /* copy the xml part to tmp_buffer */
     sprintf(tmp_buffer, "%s\n", place);
 
-    if ((xml_doc = xmlParseMemory(tmp_buffer, strlen(tmp_buffer))) == NULL)    
-    { 
+    if ((xml_doc = xmlParseMemory(tmp_buffer, strlen(tmp_buffer))) == NULL) {
         HIP_DEBUG("Libxml2 encountered error while parsing content.\n");
         ret = -1;
         goto out_err;
     }
 
     xml_node = xmlDocGetRootElement(xml_doc);
-    if (xml_node->children) /* params or fault */
-    {
+    if (xml_node->children) { /* params or fault */
         xml_node = xml_node->children;
-        /* check if error from DHT 
-           <fault><value><struct><member><name>faultString</name><value>java...
-        */
-        if (!strcmp((char *)xml_node->name, "fault"))
-        {
-             if (xml_node->children)
-                  xml_node = xml_node->children; /* value */
-             if (xml_node->children) 
-                  xml_node = xml_node->children; /* struct */
-             if (xml_node->children)
-                  xml_node = xml_node->children; /* member */
-             if (xml_node->children)
-                  xml_node = xml_node->children; /* name */
-             if (xml_node->next)
-             {
-                  xml_node_value = xml_node->next; /* value */
-                  xml_data = xmlNodeGetContent(xml_node_value);
-                  /* strcpy((char *)out_value, (char *)xml_data); */
-                  xmlFree(xml_data);
-                  HIP_DEBUG("Error from the openDHT: %s\n", xml_data);
-                  ret = -1;
-                  goto out_err;
-             }
+        /* check if error from DHT
+         * <fault><value><struct><member><name>faultString</name><value>java...
+         */
+        if (!strcmp((char *) xml_node->name, "fault")) {
+            if (xml_node->children) {
+                xml_node = xml_node->children;   /* value */
+            }
+            if (xml_node->children) {
+                xml_node = xml_node->children;   /* struct */
+            }
+            if (xml_node->children) {
+                xml_node = xml_node->children;   /* member */
+            }
+            if (xml_node->children) {
+                xml_node = xml_node->children;   /* name */
+            }
+            if (xml_node->next) {
+                xml_node_value = xml_node->next;   /* value */
+                xml_data       = xmlNodeGetContent(xml_node_value);
+                /* strcpy((char *)out_value, (char *)xml_data); */
+                xmlFree(xml_data);
+                HIP_DEBUG("Error from the openDHT: %s\n", xml_data);
+                ret            = -1;
+                goto out_err;
+            }
         }
     }
 
-    if (xml_node->children) /* param */
+    if (xml_node->children) { /* param */
         xml_node = xml_node->children;
-    if (!xml_node)
-    {
+    }
+    if (!xml_node) {
         HIP_DEBUG("Parser error: unknown XML format.\n");
         ret = -1;
         goto out_err;
     }
     xml_node_value = NULL;
-    if (!strcmp((char *)xml_node->name, "param") &&
+    if (!strcmp((char *) xml_node->name, "param") &&
         xml_node->children &&
-        !strcmp((char *)xml_node->children->name, "value"))
+        !strcmp((char *) xml_node->children->name, "value")) {
         xml_node_value = xml_node->children->children;
-    if(!xml_node_value)
-    {
+    }
+    if (!xml_node_value) {
         HIP_DEBUG("Parser error: element has no content.\n");
         ret = -1;
         goto out_err;
-    }    
+    }
 
-    /* If there is a string "<int>" in the response, 
-       then there is only status code */
+    /* If there is a string "<int>" in the response,
+     * then there is only status code */
     place = NULL;
-    if ((place = strstr(tmp_buffer, "<int>")) != NULL)
-    {
+    if ((place = strstr(tmp_buffer, "<int>")) != NULL) {
         /* retrieve status code only */
         xml_data = xmlNodeGetContent(xml_node_value);
-        if (strcmp((char *)xml_node_value->name, "int")==0)
-        {
-            sscanf((const char *)xml_data, "%d", &ret);
+        if (strcmp((char *) xml_node_value->name, "int") == 0) {
+            sscanf((const char *) xml_data, "%d", &ret);
             xmlFree(xml_data);
-            if (ret == 0) /* put success */
+            if (ret == 0) { /* put success */
                 goto out_err;
-            if (ret == 1)
-            {
+            }
+            if (ret == 1) {
                 HIP_DEBUG("OpenDHT error: over capacity.\n");
                 ret = -1;
                 goto out_err;
             }
-            if (ret == 2)
-            {
+            if (ret == 2) {
                 HIP_DEBUG("OpenDHT error: try again.\n");
                 ret = -1;
                 goto out_err;
             }
-        }
-        else
-        {
+        } else {
             HIP_DEBUG("Parser error: did not find status code.\n");
             ret = -1;
             goto out_err;
         }
-    }
-    else
-    {
-         /* retrieve the first value in array */
-         if (!strcmp((char *)xml_node_value->name, "array") &&
+    } else {
+        /* retrieve the first value in array */
+        if (!strcmp((char *) xml_node_value->name, "array") &&
             xml_node_value->children &&
-            !strcmp((char *)xml_node_value->children->name, "data"))
+            !strcmp((char *) xml_node_value->children->name, "data")) {
             xml_node = xml_node_value->children->children;
+        }
 
-         if (!strcmp((char *)xml_node->name, "value") &&
+        if (!strcmp((char *) xml_node->name, "value") &&
             xml_node->children &&
-            !strcmp((char *)xml_node->children->name, "array"))
+            !strcmp((char *) xml_node->children->name, "array")) {
             xml_node = xml_node->children->children; /* inner data element */
-
-         /* check if there was no corresponging data for the key (<data> has 
no children) */
-         if (!xml_node->children && !strcmp((char *)xml_node->name, "data")) 
-         {
+        }
+        /* check if there was no corresponging data for the key (<data> has no 
children) */
+        if (!xml_node->children && !strcmp((char *) xml_node->name, "data")) {
             HIP_DEBUG("Key was not found from the DHT\n");
             out_value[0] = '\0';
-            ret = 0;
+            ret          = 0;
             goto out_err;
-         }   
-
-         for (xml_node = xml_node->children; xml_node; xml_node = 
xml_node->next) {
-           if (!strcmp((char *)xml_node->children->name, "base64"))
-             {         
-               xml_node_value = xml_node->children->children;
-
-               xml_data = xmlNodeGetContent(xml_node_value);
-
-               _HIP_DEBUG("XML_DATA %s len = %d\n", (char *)xml_data, 
strlen((char *)xml_data));
-
-               evpret = EVP_DecodeBlock((unsigned char *)out_value, xml_data, 
-                                        strlen((char *)xml_data));
-               _HIP_HEXDUMP("LOC from DHT", out_value, evpret);
-               out_value[evpret] = '\0';
-               memcpy(answers.addrs, out_value, strlen(out_value));
-               _HIP_DEBUG("Values under the key in DHT: %s\n",out_value);
-               answers.count = 1;
-
-               if (evpret > 1) 
-                   hip_print_locator_addresses((struct hip_common *)out_value);
-               ret = 0;
-             } 
-           else 
-             {
-               HIP_DEBUG("Parser error: couldn't parse response value.\n");
-               ret = -1;
-               goto out_err;
-             }
-         }
+        }
+
+        for (xml_node = xml_node->children; xml_node; xml_node = 
xml_node->next) {
+            if (!strcmp((char *) xml_node->children->name, "base64")) {
+                xml_node_value = xml_node->children->children;
+
+                xml_data = xmlNodeGetContent(xml_node_value);
+
+                _HIP_DEBUG("XML_DATA %s len = %d\n", (char *) xml_data, 
strlen((char *) xml_data));
+
+                evpret = EVP_DecodeBlock((unsigned char *) out_value, xml_data,
+                                                    strlen((char *) xml_data));
+                _HIP_HEXDUMP("LOC from DHT", out_value, evpret);
+                out_value[evpret] = '\0';
+                memcpy(answers.addrs, out_value, strlen(out_value));
+                _HIP_DEBUG("Values under the key in DHT: %s\n", out_value);
+                answers.count = 1;
+
+                if (evpret > 1) {
+                    hip_print_locator_addresses((struct hip_common *) 
out_value);
+                }
+                ret = 0;
+            } else {
+                HIP_DEBUG("Parser error: couldn't parse response value.\n");
+                ret = -1;
+                goto out_err;
+            }
+        }
     }
 
- out_err:
-    if (xml_doc != NULL) 
+out_err:
+    if (xml_doc != NULL) {
         xmlFreeDoc(xml_doc);
-    if (answers.count > 0)
-      xmlFree(xml_data);
-    return(ret);
+    }
+    if (answers.count > 0) {
+        xmlFree(xml_data);
+    }
+    return ret;
 }
 
 /* build_packet_get and build_packet_put helper function, used only in this 
file */
@@ -538,7 +534,5 @@
     xmlNodePtr xml_node_value;
     xml_node_param = xmlNewChild(node_parent, NULL, BAD_CAST "param", NULL);
     xml_node_value = xmlNewChild(xml_node_param, NULL, BAD_CAST "value", NULL);
-    return(xmlNewChild(xml_node_value, NULL, BAD_CAST type, BAD_CAST value)); 
+    return xmlNewChild(xml_node_value, NULL, BAD_CAST type, BAD_CAST value);
 }
-
-

=== modified file 'lib/dht/libhipdhtxml.h'
--- lib/dht/libhipdhtxml.h      2010-01-19 13:10:46 +0000
+++ lib/dht/libhipdhtxml.h      2010-02-10 23:13:03 +0000
@@ -15,23 +15,24 @@
 
 /* All XML RPC packet creation and reading functions */
 
-int build_packet_put_rm(unsigned char *, int, unsigned char *, 
-                     int, unsigned char *, int, int, unsigned char*, char *, 
int);
-
-int build_packet_put(unsigned char *, int, unsigned char *, 
-                     int, int, unsigned char*, char *, int);
-
-int build_packet_get(unsigned char *, int, int, unsigned char*, char *);
+int build_packet_put_rm(unsigned char *, int, unsigned char *,
+                        int, unsigned char *, int, int, unsigned char *,
+                        char *, int);
+
+int build_packet_put(unsigned char *, int, unsigned char *,
+                     int, int, unsigned char *, char *, int);
+
+int build_packet_get(unsigned char *, int, int, unsigned char *, char *);
 
 int build_packet_rm(unsigned char *, int, unsigned char *,
-                    int, unsigned char *, int, int, unsigned char *, char *, 
int); 
+                    int, unsigned char *, int, int, unsigned char *,
+                    char *, int);
 
 int read_packet_content(char *, char *);
 
 struct opendht_answers {
-  int count;
-  char addrs[440];
+    int  count;
+    char addrs[440];
 };
 
 #endif /* HIP_LIBHIPOPENDHTXML_H */
-

Other related posts:

  • » [hipl-commit] [trunk] Rev 3588: uncrustified lib/dht - Rene Hummen