Commit 994f4ae9 authored by Youness Alaoui's avatar Youness Alaoui

Move functions and prototypes from one file to another to avoid having to...

Move functions and prototypes from one file to another to avoid having to install non public headers
parent 494d8a0b
......@@ -63,7 +63,6 @@
#define STUN_MAX_MESSAGE_SIZE_IPV4 576
#define STUN_MAX_MESSAGE_SIZE_IPV6 1280
/* #define STUN_MAX_MESSAGE_SIZE STUN_MAX_MESSAGE_SIZE_IPV4 */
#define STUN_MAX_MESSAGE_SIZE 65552
#define STUN_ID_LEN 16
......
......@@ -60,16 +60,6 @@
uint32_t stun_fingerprint (const uint8_t *msg, size_t len,
bool wlm2009_stupid_crc32_typo);
/**
* stun_message_has_cookie:
* @msg: The #StunMessage
*
* Checks if the STUN message has a RFC5389 compatible cookie
*
* Returns: %TRUE if the cookie is present, %FALSE otherwise
*/
bool stun_message_has_cookie (const StunMessage *msg);
StunMessageReturn stun_message_append_software (StunMessage *msg);
......
......@@ -604,3 +604,53 @@ bool stun_message_has_attribute (const StunMessage *msg, StunAttribute type)
uint16_t dummy;
return stun_message_find (msg, type, &dummy) != NULL;
}
bool stun_optional (uint16_t t)
{
return (t >> 15) == 1;
}
const char *stun_strerror (StunError code)
{
static const struct
{
StunError code;
char phrase[32];
} tab[] =
{
{ STUN_ERROR_TRY_ALTERNATE, "Try alternate server" },
{ STUN_ERROR_BAD_REQUEST, "Bad request" },
{ STUN_ERROR_UNAUTHORIZED, "Unauthorized" },
{ STUN_ERROR_UNKNOWN_ATTRIBUTE, "Unknown Attribute" },
{ STUN_ERROR_ALLOCATION_MISMATCH, "Allocation Mismatch" },
{ STUN_ERROR_STALE_NONCE, "Stale Nonce" },
{ STUN_ERROR_ACT_DST_ALREADY, "Active Destination Already Set" },
{ STUN_ERROR_UNSUPPORTED_FAMILY, "Address Family not Supported" },
{ STUN_ERROR_UNSUPPORTED_TRANSPORT, "Unsupported Transport Protocol" },
{ STUN_ERROR_INVALID_IP, "Invalid IP Address" },
{ STUN_ERROR_INVALID_PORT, "Invalid Port" },
{ STUN_ERROR_OP_TCP_ONLY, "Operation for TCP Only" },
{ STUN_ERROR_CONN_ALREADY, "Connection Already Exists" },
{ STUN_ERROR_ALLOCATION_QUOTA_REACHED, "Allocation Quota Reached" },
{ STUN_ERROR_ROLE_CONFLICT, "Role conflict" },
{ STUN_ERROR_SERVER_ERROR, "Server Error" },
{ STUN_ERROR_SERVER_CAPACITY, "Insufficient Capacity" },
{ STUN_ERROR_INSUFFICIENT_CAPACITY, "Insufficient Capacity" },
};
const char *str = "Unknown error";
size_t i;
for (i = 0; i < (sizeof (tab) / sizeof (tab[0])); i++)
{
if (tab[i].code == code)
{
str = tab[i].phrase;
break;
}
}
/* Maximum allowed error message length */
// assert (strlen (str) < 128);
return str;
}
......@@ -864,4 +864,39 @@ StunMethod stun_message_get_method (const StunMessage *msg);
*/
bool stun_message_has_attribute (const StunMessage *msg, StunAttribute type);
/* Defined in stun5389.c */
/**
* stun_message_has_cookie:
* @msg: The #StunMessage
*
* Checks if the STUN message has a RFC5389 compatible cookie
*
* Returns: %TRUE if the cookie is present, %FALSE otherwise
*/
bool stun_message_has_cookie (const StunMessage *msg);
/**
* stun_optional:
* @t: An attribute type
*
* Helper function that checks whether a STUN attribute is a mandatory
* or an optional attribute
*
* Returns: %TRUE if the attribute is an optional one
*/
bool stun_optional (uint16_t t);
/**
* stun_strerror:
* @code: host-byte order error code
*
* Transforms a STUN error-code into a human readable string
*
* Returns: A static pointer to a NULL-terminated error message string.
*/
const char *stun_strerror (StunError code);
#endif /* _STUN_MESSAGE_H */
......@@ -44,12 +44,6 @@
#include "utils.h"
bool stun_optional (uint16_t t)
{
return (t >> 15) == 1;
}
size_t stun_padding (size_t l)
{
return (4 - (l & 3)) & 3;
......@@ -88,49 +82,6 @@ void stun_set_type (uint8_t *h, StunClass c, StunMethod m)
/* assert (stun_get_method (h) == m); */
}
const char *stun_strerror (StunError code)
{
static const struct
{
StunError code;
char phrase[32];
} tab[] =
{
{ STUN_ERROR_TRY_ALTERNATE, "Try alternate server" },
{ STUN_ERROR_BAD_REQUEST, "Bad request" },
{ STUN_ERROR_UNAUTHORIZED, "Unauthorized" },
{ STUN_ERROR_UNKNOWN_ATTRIBUTE, "Unknown Attribute" },
{ STUN_ERROR_ALLOCATION_MISMATCH, "Allocation Mismatch" },
{ STUN_ERROR_STALE_NONCE, "Stale Nonce" },
{ STUN_ERROR_ACT_DST_ALREADY, "Active Destination Already Set" },
{ STUN_ERROR_UNSUPPORTED_FAMILY, "Address Family not Supported" },
{ STUN_ERROR_UNSUPPORTED_TRANSPORT, "Unsupported Transport Protocol" },
{ STUN_ERROR_INVALID_IP, "Invalid IP Address" },
{ STUN_ERROR_INVALID_PORT, "Invalid Port" },
{ STUN_ERROR_OP_TCP_ONLY, "Operation for TCP Only" },
{ STUN_ERROR_CONN_ALREADY, "Connection Already Exists" },
{ STUN_ERROR_ALLOCATION_QUOTA_REACHED, "Allocation Quota Reached" },
{ STUN_ERROR_ROLE_CONFLICT, "Role conflict" },
{ STUN_ERROR_SERVER_ERROR, "Server Error" },
{ STUN_ERROR_SERVER_CAPACITY, "Insufficient Capacity" },
{ STUN_ERROR_INSUFFICIENT_CAPACITY, "Insufficient Capacity" },
};
const char *str = "Unknown error";
size_t i;
for (i = 0; i < (sizeof (tab) / sizeof (tab[0])); i++)
{
if (tab[i].code == code)
{
str = tab[i].phrase;
break;
}
}
/* Maximum allowed error message length */
// assert (strlen (str) < 128);
return str;
}
StunMessageReturn stun_xor_address (const StunMessage *msg,
struct sockaddr *addr, socklen_t addrlen,
......@@ -165,32 +116,3 @@ StunMessageReturn stun_xor_address (const StunMessage *msg,
}
return STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS;
}
static int debug_enabled = 1;
void stun_debug_enable (void) {
debug_enabled = 1;
}
void stun_debug_disable (void) {
debug_enabled = 0;
}
void stun_debug (const char *fmt, ...)
{
va_list ap;
if (debug_enabled) {
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
}
}
void stun_debug_bytes (const void *data, size_t len)
{
size_t i;
stun_debug ("0x");
for (i = 0; i < len; i++)
stun_debug ("%02x", ((const unsigned char *)data)[i]);
}
......@@ -55,21 +55,8 @@
extern "C" {
# endif
/**
* stun_optional:
* @t: An attribute type
*
* Helper function that checks whether a STUN attribute is a mandatory
* or an optional attribute
*
* Returns: %TRUE if the attribute is an optional one
*/
bool stun_optional (uint16_t t);
size_t stun_padding (size_t l);
size_t stun_align (size_t l);
uint16_t stun_getw (const uint8_t *ptr);
......@@ -82,37 +69,9 @@ StunMessageReturn stun_xor_address (const StunMessage *msg,
struct sockaddr *addr, socklen_t addrlen,
uint32_t magic_cookie);
/**
* stun_strerror:
* @code: host-byte order error code
*
* Transforms a STUN error-code into a human readable string
*
* Returns: A static pointer to a NULL-terminated error message string.
*/
const char *stun_strerror (StunError code);
/**
* stun_debug_enable:
*
* Enable debug messages to stderr
*/
void stun_debug_enable (void);
/**
* stun_debug_disable:
*
* Disable debug messages to stderr
*/
void stun_debug_disable (void);
void stun_debug (const char *fmt, ...);
void stun_debug_bytes (const void *data, size_t len);
# ifdef __cplusplus
}
# endif
#endif /* !STUN_UTILS_H */
#endif /* STUN_UTILS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment