Commit 72b6bdcd authored by Youness Alaoui's avatar Youness Alaoui

Port stun usage ice in stun_usage_ice_conncheck_create_reply to use a...

Port stun usage ice in stun_usage_ice_conncheck_create_reply to use a StunUsageIceReturn enum instead of errno values to communicate errors
parent 70edccc3
...@@ -42,18 +42,10 @@ ...@@ -42,18 +42,10 @@
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#define ENOENT -1
#define EINVAL -2
#define ENOBUFS -3
#define EAFNOSUPPORT -4
#define EPROTO -5
#define EACCES -6
#define EINPROGRESS -7
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h>
#endif #endif
...@@ -196,7 +188,7 @@ stun_bind_error (StunAgent *agent, StunMessage *msg, ...@@ -196,7 +188,7 @@ stun_bind_error (StunAgent *agent, StunMessage *msg,
return 1; return 1;
} }
int StunUsageIceReturn
stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req, stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req,
StunMessage *msg, uint8_t *buf, size_t *plen, StunMessage *msg, uint8_t *buf, size_t *plen,
const struct sockaddr *src, socklen_t srclen, const struct sockaddr *src, socklen_t srclen,
...@@ -207,7 +199,8 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req, ...@@ -207,7 +199,8 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req,
uint16_t username_len; uint16_t username_len;
size_t len = *plen; size_t len = *plen;
uint64_t q; uint64_t q;
int val = 0, ret = 0; StunMessageReturn val = STUN_MESSAGE_RETURN_SUCCESS;
StunUsageIceReturn ret = STUN_USAGE_ICE_RETURN_SUCCESS;
#define err( code ) \ #define err( code ) \
...@@ -221,7 +214,7 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req, ...@@ -221,7 +214,7 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req,
{ {
stun_debug (" Unhandled non-request (class %u) message.\n", stun_debug (" Unhandled non-request (class %u) message.\n",
stun_message_get_class (req)); stun_message_get_class (req));
return EINVAL; return STUN_USAGE_ICE_RETURN_INVALID_REQUEST;
} }
if (stun_message_get_method (req) != STUN_BINDING) if (stun_message_get_method (req) != STUN_BINDING)
...@@ -229,7 +222,7 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req, ...@@ -229,7 +222,7 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req,
stun_debug (" Bad request (method %u) message.\n", stun_debug (" Bad request (method %u) message.\n",
stun_message_get_method (req)); stun_message_get_method (req));
err (STUN_ERROR_BAD_REQUEST); err (STUN_ERROR_BAD_REQUEST);
return EPROTO; return STUN_USAGE_ICE_RETURN_INVALID_METHOD;
} }
/* Role conflict handling */ /* Role conflict handling */
...@@ -244,14 +237,14 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req, ...@@ -244,14 +237,14 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req,
stun_debug (" switching role from \"controll%s\" to \"controll%s\"\n", stun_debug (" switching role from \"controll%s\" to \"controll%s\"\n",
*control ? "ing" : "ed", *control ? "ed" : "ing"); *control ? "ing" : "ed", *control ? "ed" : "ing");
*control = !*control; *control = !*control;
ret = EACCES; ret = STUN_USAGE_ICE_RETURN_ROLE_CONFLICT;
} }
else else
{ {
stun_debug (" staying \"controll%s\" (sending error)\n", stun_debug (" staying \"controll%s\" (sending error)\n",
*control ? "ing" : "ed"); *control ? "ing" : "ed");
err (STUN_ERROR_ROLE_CONFLICT); err (STUN_ERROR_ROLE_CONFLICT);
return 0; return STUN_USAGE_ICE_RETURN_SUCCESS;
} }
} }
#ifndef NDEBUG #ifndef NDEBUG
...@@ -304,8 +297,18 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req, ...@@ -304,8 +297,18 @@ stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req,
failure: failure:
assert (*plen == 0); assert (*plen == 0);
stun_debug (" Fatal error formatting Response: %s\n", strerror (val)); stun_debug (" Fatal error formatting Response: %d\n", val);
return val;
switch (val)
{
case STUN_MESSAGE_RETURN_NOT_ENOUGH_SPACE:
return STUN_USAGE_ICE_RETURN_MEMORY_ERROR;
case STUN_MESSAGE_RETURN_INVALID:
case STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS:
return STUN_USAGE_ICE_RETURN_INVALID_ADDRESS;
default:
return STUN_USAGE_ICE_RETURN_ERROR;
}
} }
#undef err #undef err
......
...@@ -58,6 +58,10 @@ typedef enum { ...@@ -58,6 +58,10 @@ typedef enum {
STUN_USAGE_ICE_RETURN_ERROR, STUN_USAGE_ICE_RETURN_ERROR,
STUN_USAGE_ICE_RETURN_RETRY, STUN_USAGE_ICE_RETURN_RETRY,
STUN_USAGE_ICE_RETURN_ROLE_CONFLICT, STUN_USAGE_ICE_RETURN_ROLE_CONFLICT,
STUN_USAGE_ICE_RETURN_INVALID_REQUEST,
STUN_USAGE_ICE_RETURN_INVALID_METHOD,
STUN_USAGE_ICE_RETURN_MEMORY_ERROR,
STUN_USAGE_ICE_RETURN_INVALID_ADDRESS,
} StunUsageIceReturn; } StunUsageIceReturn;
...@@ -100,7 +104,7 @@ StunUsageIceReturn stun_usage_ice_conncheck_process (StunMessage *msg, ...@@ -100,7 +104,7 @@ StunUsageIceReturn stun_usage_ice_conncheck_process (StunMessage *msg,
* In case of error, the value at @a plen is set to the size of an error * In case of error, the value at @a plen is set to the size of an error
* response, or 0 if no error response should be sent. * response, or 0 if no error response should be sent.
*/ */
int StunUsageIceReturn
stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req, stun_usage_ice_conncheck_create_reply (StunAgent *agent, StunMessage *req,
StunMessage *msg, uint8_t *buf, size_t *plen, StunMessage *msg, uint8_t *buf, size_t *plen,
const struct sockaddr *src, socklen_t srclen, const struct sockaddr *src, socklen_t srclen,
......
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