[pisa-src] r1806 - in trunk: Makefile.am pairing/create_accept_headers.c pairing/create_accept_headers.h pairing/packet_handler_accept.c pairing/packet_handler_accept.h

  • From: Diego Biurrun <diego@xxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Thu, 26 Nov 2009 14:57:00 +0100

Author: biurrun
Date: Thu Nov 26 14:56:59 2009
New Revision: 1806

Log:
Merge contents of create_accept_headers.c into packet_handler_accept.c.
The functions are used nowhere else and the file does not grow too big.

Deleted:
   trunk/pairing/create_accept_headers.c
   trunk/pairing/create_accept_headers.h
Modified:
   trunk/Makefile.am
   trunk/pairing/packet_handler_accept.c
   trunk/pairing/packet_handler_accept.h

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am   Thu Nov 26 14:50:58 2009        (r1805)
+++ trunk/Makefile.am   Thu Nov 26 14:56:59 2009        (r1806)
@@ -83,7 +83,6 @@
 
 pairing_accept_SOURCES     = $(pairing_ACCEPT_SEND_SRCS)     \
                              pairing/accept.c                \
-                             pairing/create_accept_headers.c \
                              pairing/packet_handler_accept.c
 
 pairing_send_SOURCES       = $(pairing_ACCEPT_SEND_SRCS)   \

Modified: trunk/pairing/packet_handler_accept.c
==============================================================================
--- trunk/pairing/packet_handler_accept.c       Thu Nov 26 14:50:58 2009        
(r1805)
+++ trunk/pairing/packet_handler_accept.c       Thu Nov 26 14:56:59 2009        
(r1806)
@@ -17,6 +17,99 @@
 #include "packet_handler_accept.h"
 
 
+/** Creates a header_general structure which holds a header_ack_1 structure 
and fills both.
+ *
+ *  @return A pointer to the header_general structure. Returns NULL on error.
+ */
+header_general* create_ack_1_struct(void)
+{
+        config_t cfg;
+        const char *nickname, *ipv4_addr, *ipv6_addr;
+       int success;
+
+        header_general *gen_hdr = malloc(sizeof(header_general));
+        gen_hdr->msg_type = MSG_ACK_1;
+
+        // Read config file
+        config_init(&cfg);
+        if (!config_read_file(&cfg, FILE_SERVER_CONFIG))
+        {
+                DEBUG("Error reading %s on line %d: %s\n", FILE_SERVER_CONFIG, 
cfg.error_line, cfg.error_text);
+                return NULL;
+        }
+
+        DEBUG_HIGH(LINE_BREAK);
+        DEBUG_HIGH("General header created.");
+        DEBUG_HIGH("\tMessage type: %d", gen_hdr->msg_type);
+        DEBUG_HIGH("ack_1 structure created:");
+
+
+        // Look up nickname
+        success = config_lookup_string(&cfg, "server_settings.nickname", 
&nickname);
+        if (success != CONFIG_TRUE || !nickname)
+        {       // If the setting doesn't exist, set the string to be empty
+                *((gen_hdr->msg.header_ack_1).nickname) = 0;
+                DEBUG_HIGH("\nNickname not found.");
+        }
+        else    // ... write the contents into the structure
+                strncpy((char*)&((gen_hdr->msg.header_ack_1).nickname), 
nickname, LENGTH_NICKNAME);
+        DEBUG_HIGH("\tNickname: \'%s\'", 
((gen_hdr->msg.header_ack_1).nickname));
+
+
+        // Look up the IPv4 address
+        success = config_lookup_string(&cfg, "server_settings.ipv4_addr", 
&ipv4_addr);
+        if (success != CONFIG_TRUE || !ipv4_addr)
+        {       // If the setting doesn't exist, set the string to be empty
+                *((gen_hdr->msg.header_ack_1).ipv4_addr) = 0;
+                DEBUG_HIGH("\tIPv4 address not found!");
+        }
+        else    // ... write the contents into the structure
+                strncpy((char*)&((gen_hdr->msg.header_ack_1).ipv4_addr), 
ipv4_addr, INET_ADDRSTRLEN+1);
+        DEBUG_HIGH("\tIPv4 address: \'%s\'", 
(gen_hdr->msg.header_ack_1).ipv4_addr);
+
+
+        // Look up the IPv6 address
+        success = config_lookup_string(&cfg, "server_settings.ipv6_addr", 
&ipv6_addr);
+        if (success != CONFIG_TRUE || !ipv6_addr)
+        {       // If the setting doesn't exist, set the string to be empty
+                *((gen_hdr->msg.header_ack_1).ipv6_addr) = 0;
+                DEBUG_HIGH("\tIPv6 address not found!");
+        }
+        else    // ... write the contents into the structure
+                strncpy((char*)&((gen_hdr->msg.header_ack_1).ipv6_addr), 
ipv6_addr, INET6_ADDRSTRLEN+1);
+        DEBUG_HIGH("\tIPv6 address: \'%s\'", 
(gen_hdr->msg.header_ack_1).ipv6_addr);
+
+        config_destroy(&cfg);
+
+        DEBUG_HIGH(LINE_BREAK);
+
+        return gen_hdr;
+}
+
+
+/** Creates a header_general structure which holds a header_ack_2 structure 
and fills both.
+ *
+ *  @return A pointer to the header_general structure. Returns NULL on error.
+ */
+header_general* create_ack_2_struct(char *password)
+{
+        assert(password != NULL);
+
+        header_general *gen_hdr = malloc(sizeof(header_general));
+        gen_hdr->msg_type = MSG_ACK_2;
+
+        strncpy((char*)&((gen_hdr->msg.header_ack_2).password), password, 
LENGTH_PASSWORD);
+
+        DEBUG_HIGH(LINE_BREAK);
+        DEBUG_HIGH("General header created.");
+        DEBUG_HIGH("\tMessage type: %d", gen_hdr->msg_type);
+        DEBUG_HIGH("Password structure created:");
+        DEBUG_HIGH("\tPassword: \'%s\'", (gen_hdr->msg.header_ack_2).password);
+        DEBUG_HIGH(LINE_BREAK);
+
+        return gen_hdr;
+}
+
 /** This function handles a password packet sent from the user to the relay.
  *
  *  @param socket_addr Pointer to sockaddr_in6 structure connected to peer.

Modified: trunk/pairing/packet_handler_accept.h
==============================================================================
--- trunk/pairing/packet_handler_accept.h       Thu Nov 26 14:50:58 2009        
(r1805)
+++ trunk/pairing/packet_handler_accept.h       Thu Nov 26 14:56:59 2009        
(r1806)
@@ -18,7 +18,6 @@
 #include "common_headers.h"
 #include "hash.h"
 #include "libconfig_wrapper.h"
-#include "create_accept_headers.h"
 
 /** Default password file is set statically. **/
 #define FILE_PWD "sha.txt"

Other related posts:

  • » [pisa-src] r1806 - in trunk: Makefile.am pairing/create_accept_headers.c pairing/create_accept_headers.h pairing/packet_handler_accept.c pairing/packet_handler_accept.h - Diego Biurrun