Author: biurrun Date: Fri Nov 27 10:51:45 2009 New Revision: 1843 Log: Merge common_headers.h into common.h. common_headers.h depends on common.h anyway and the contents are not logically different enough to warrant separating them into two headers. Deleted: trunk/pairing/common_headers.h Modified: trunk/pairing/accept.c trunk/pairing/common.c trunk/pairing/common.h trunk/pairing/management.c trunk/pairing/packet_handler.h trunk/pairing/send.c Modified: trunk/pairing/accept.c ============================================================================== --- trunk/pairing/accept.c Fri Nov 27 10:32:18 2009 (r1842) +++ trunk/pairing/accept.c Fri Nov 27 10:51:45 2009 (r1843) @@ -23,7 +23,6 @@ #include "libpisa/global.h" #include "libpisa/hitlist.h" #include "common.h" -#include "common_headers.h" #define TIMER_INTERVAL 60 Modified: trunk/pairing/common.c ============================================================================== --- trunk/pairing/common.c Fri Nov 27 10:32:18 2009 (r1842) +++ trunk/pairing/common.c Fri Nov 27 10:51:45 2009 (r1843) @@ -21,7 +21,6 @@ #include "common.h" #include "libpisa/cfg.h" #include "libconfig_wrapper.h" -#include "common_headers.h" /** Checks to see if addr has only the characters allowed in an IPv6 address (or HIT). Modified: trunk/pairing/common.h ============================================================================== --- trunk/pairing/common.h Fri Nov 27 10:32:18 2009 (r1842) +++ trunk/pairing/common.h Fri Nov 27 10:51:45 2009 (r1843) @@ -14,8 +14,10 @@ #ifndef PISA_COMMON_H #define PISA_COMMON_H +#include <stdint.h> #include <stdio.h> #include <assert.h> +#include <netinet/in.h> #include <sys/types.h> #include <sys/socket.h> #include <time.h> @@ -50,6 +52,7 @@ extern struct global_send_variables global_send; // Constants +#define LENGTH_ERROR_STRING 128 #define LENGTH_PASSWORD 50 #define LENGTH_NICKNAME 100 #define LENGTH_TIMEOUT 80 @@ -59,11 +62,19 @@ #define PORT 7000 #define FILE_KNOWN_RELAYS "known_relays.cfg" +#define FILE_SERVER_CONFIG "relay_config.cfg" +#define FILE_USER_CONFIG "user_config.cfg" // Debug message macros #define CHECK_FOR_NULL_HDR(hdr) \ if (hdr == NULL) { DEBUG("Header could not be created. Exiting."); return 0; } +// If you add a new message type, update print_msg_info() in common.c +#define MSG_PASSWORD 0 +#define MSG_ACK_1 1 +#define MSG_PWD_REQUEST 2 +#define MSG_ERROR 3 +#define MSG_ACK_2 4 // Debug levels #define DEBUG_LEVEL_OFF 0 @@ -111,4 +122,52 @@ #define DEBUG_LOW(fmt, args...) DEBUG_EMPTY #endif + +/* Structure to hold a password */ +typedef struct header_password { + uint8_t password[LENGTH_PASSWORD]; +} __attribute__ ((packed)) header_password; + +/* Structure to hold an acknowledgement sent from the relay back to the user. + * Contains IPv4 and IPv6 addresses for storage on the user's computer. */ +typedef struct header_ack_1 { + uint8_t nickname[LENGTH_NICKNAME]; + uint8_t ipv4_addr[INET_ADDRSTRLEN+1]; + uint8_t ipv6_addr[INET6_ADDRSTRLEN+1]; +} __attribute__ ((packed)) header_ack_1; + +/* Structure used to send an error message. */ +typedef struct header_error { + uint8_t error_type; + uint8_t error_string[LENGTH_ERROR_STRING]; +} __attribute__ ((packed)) header_error; + +/* Used when the user wishes to request a password for a friend. */ +// Password fields: nickname (required), password, passphrase, expiration (with defaults read from config file) +typedef struct header_pwd_request { + uint8_t nickname[LENGTH_NICKNAME]; + long int expiration1; + long int expiration2; +} __attribute__ ((packed)) header_pwd_request; + +/* Structure to hold an acknowledgement sent from the relay back to the user. + * Contains the password generated for the user's friend. */ +typedef struct header_ack_2 { + uint8_t password[LENGTH_PASSWORD]; +} __attribute__ ((packed)) header_ack_2; + +/* General message header */ +typedef struct header_general { + uint8_t msg_type; + + union msg { + struct header_password header_password; + struct header_ack_1 header_ack_1; + struct header_error header_error; + struct header_pwd_request header_pwd_request; + struct header_ack_2 header_ack_2; + } msg; + +} __attribute__ ((packed)) header_general; + #endif /* PISA_COMMON_H */ Modified: trunk/pairing/management.c ============================================================================== --- trunk/pairing/management.c Fri Nov 27 10:32:18 2009 (r1842) +++ trunk/pairing/management.c Fri Nov 27 10:51:45 2009 (r1843) @@ -26,7 +26,6 @@ #include "libpisa/cfg.h" #include "libpisa/debug.h" #include "libpisa/global.h" -#include "common_headers.h" #include "common.h" #include "libconfig_wrapper.h" Modified: trunk/pairing/packet_handler.h ============================================================================== --- trunk/pairing/packet_handler.h Fri Nov 27 10:32:18 2009 (r1842) +++ trunk/pairing/packet_handler.h Fri Nov 27 10:51:45 2009 (r1843) @@ -14,7 +14,7 @@ #define PISA_PACKET_HANDLER_H #include <netinet/in.h> -#include "common_headers.h" +#include "common.h" // Function prototypes int handle_packet(struct sockaddr_in6 *socket_addr, header_general *gen_hdr, int *msg_type, int *return_value); Modified: trunk/pairing/send.c ============================================================================== --- trunk/pairing/send.c Fri Nov 27 10:32:18 2009 (r1842) +++ trunk/pairing/send.c Fri Nov 27 10:51:45 2009 (r1843) @@ -22,7 +22,6 @@ #include <netinet/in.h> #include "libpisa/global.h" -#include "common_headers.h" #include "common.h" #include "packet_handler.h"