Commit 990b8530 authored by Sebastien Decugis's avatar Sebastien Decugis
Browse files

Fix erroneous %g specifiers for size_t (correct is %z)

parent 92fdb242
......@@ -503,7 +503,7 @@ static void * rcvthr_notls_tcp(void * arg)
if ((header[0] != DIAMETER_VERSION) /* defined in <libfreeDiameter.h> */
|| (length > DIAMETER_MSG_SIZE_MAX)) { /* to avoid too big mallocs */
/* The message is suspect */
TRACE_DEBUG(INFO, "Received suspect header [ver: %d, size: %g], assume disconnection", (int)header[0], length);
TRACE_DEBUG(INFO, "Received suspect header [ver: %d, size: %z], assume disconnection", (int)header[0], length);
goto error; /* Stop the thread, the recipient of the event will cleanup */
}
......@@ -629,7 +629,7 @@ int fd_tls_rcvthr_core(struct cnxctx * conn, gnutls_session_t session)
if ((header[0] != DIAMETER_VERSION) /* defined in <libfreeDiameter.h> */
|| (length > DIAMETER_MSG_SIZE_MAX)) { /* to avoid too big mallocs */
/* The message is suspect */
TRACE_DEBUG(INFO, "Received suspect header [ver: %d, size: %g], assume disconnection", (int)header[0], length);
TRACE_DEBUG(INFO, "Received suspect header [ver: %d, size: %z], assume disconnection", (int)header[0], length);
goto out;
}
......@@ -894,7 +894,7 @@ static int send_simple(struct cnxctx * conn, unsigned char * buf, size_t len)
{
ssize_t ret;
size_t sent = 0;
TRACE_ENTRY("%p %p %g", conn, buf, len);
TRACE_ENTRY("%p %p %z", conn, buf, len);
do {
if (conn->cc_tls) {
CHECK_GNUTLS_DO( ret = gnutls_record_send (conn->cc_tls_para.session, buf + sent, len - sent), return ENOTCONN );
......@@ -909,11 +909,11 @@ static int send_simple(struct cnxctx * conn, unsigned char * buf, size_t len)
/* Send a message -- this is synchronous -- and we assume it's never called by several threads at the same time, so we don't protect. */
int fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len)
{
TRACE_ENTRY("%p %p %g", conn, buf, len);
TRACE_ENTRY("%p %p %z", conn, buf, len);
CHECK_PARAMS(conn && (conn->cc_socket > 0) && buf && len);
TRACE_DEBUG(FULL, "Sending %gb %sdata on connection %s", len, conn->cc_tls ? "TLS-protected ":"", conn->cc_id);
TRACE_DEBUG(FULL, "Sending %zb %sdata on connection %s", len, conn->cc_tls ? "TLS-protected ":"", conn->cc_id);
switch (conn->cc_proto) {
case IPPROTO_TCP:
......
......@@ -163,7 +163,7 @@ static void * p_psm_th( void * arg )
psm_loop:
/* Get next event */
CHECK_FCT_DO( fd_event_timedget(peer->p_events, &peer->p_psm_timer, FDEVP_PSM_TIMEOUT, &event, &ev_sz, &ev_data), goto psm_end );
TRACE_DEBUG(FULL, "'%s'\t<-- '%s'\t(%p,%g)\t'%s'",
TRACE_DEBUG(FULL, "'%s'\t<-- '%s'\t(%p,%z)\t'%s'",
STATE_STR(peer->p_hdr.info.pi_state),
fd_pev_str(event), ev_data, ev_sz,
peer->p_hdr.info.pi_diamid);
......
......@@ -763,7 +763,7 @@ int fd_sctp_get_str_info( int sock, uint16_t *in, uint16_t *out, sSS *primary )
CHECK_SYS( getsockopt(sock, IPPROTO_SCTP, SCTP_STATUS, &status, &sz) );
if (sz != sizeof(status))
{
TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %g", sz, sizeof(status));
TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %z", sz, sizeof(status));
return ENOTSUP;
}
#ifdef DEBUG_SCTP
......@@ -910,7 +910,7 @@ int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len)
} anci;
ssize_t ret;
TRACE_ENTRY("%d %hu %p %g", sock, strid, buf, len);
TRACE_ENTRY("%d %hu %p %z", sock, strid, buf, len);
memset(&mhdr, 0, sizeof(mhdr));
memset(&iov, 0, sizeof(iov));
......
......@@ -135,7 +135,7 @@ static ssize_t sctps_push(gnutls_transport_ptr_t tr, const void * data, size_t l
{
struct sctps_ctx * ctx = (struct sctps_ctx *) tr;
TRACE_ENTRY("%p %p %g", tr, data, len);
TRACE_ENTRY("%p %p %z", tr, data, len);
CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } );
CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent->cc_socket, ctx->strid, (uint8_t *)data, len), /* errno is already set */ return -1 );
......@@ -150,7 +150,7 @@ static ssize_t sctps_pull(gnutls_transport_ptr_t tr, void * buf, size_t len)
size_t pulled = 0;
int emptied;
TRACE_ENTRY("%p %p %g", tr, buf, len);
TRACE_ENTRY("%p %p %z", tr, buf, len);
CHECK_PARAMS_DO( tr && buf, { errno = EINVAL; return -1; } );
/* If we don't have data available now, pull new message from the fifo -- this is blocking */
......
......@@ -99,6 +99,10 @@ static void * client_sm(void * arg)
{
struct client * c = arg;
struct server * s = NULL;
uint8_t * buf = NULL;
size_t bufsz;
struct msg * msg = NULL;
struct msg_hdr *hdr = NULL;
TRACE_ENTRY("%p", c);
......@@ -126,11 +130,29 @@ static void * client_sm(void * arg)
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &c->ts), goto fatal_error );
c->ts.tv_sec += INCNX_TIMEOUT;
TODO("receive message until c->ts");
/* Receive the first Diameter message on the connection -- cleanup in case of timeout */
CHECK_FCT_DO( fd_cnx_receive(c->conn, &c->ts, &buf, &bufsz), goto cleanup );
TRACE_DEBUG(FULL, "Received %zb from new client '%s'", bufsz, fd_cnx_getid(c->conn));
/* Try parsing this message */
CHECK_FCT_DO( fd_msg_parse_buffer( &buf, bufsz, &msg ), /* Parsing failed */ goto cleanup );
/* We expect a CER, it must parse with our dictionary */
CHECK_FCT_DO( fd_msg_parse_dict( msg, fd_g_config->cnf_dict ), /* Parsing failed */ goto cleanup );
if (TRACE_BOOL(FULL)) {
fd_log_debug("Received Diameter message from new client '%s':\n", fd_cnx_getid(c->conn));
fd_msg_dump_walk(FULL, msg);
}
/* Now check we received a CER */
CHECK_FCT_DO( fd_msg_hdr ( msg, &hdr ), goto fatal_error );
CHECK_PARAMS_DO( (hdr->msg_appl == 0) && (hdr->msg_flags & CMD_FLAG_REQUEST) && (hdr->msg_code == CC_CAPABILITIES_EXCHANGE),
{ fd_log_debug("Connection '%s', expecting CER, received something else, closing...\n", fd_cnx_getid(c->conn)); goto cleanup; } );
TODO("Timeout => close");
TODO("Message != CER => close");
TODO("Message == CER : ");
TODO("Search matching peer");
TODO("Send event to the peer");
......@@ -146,6 +168,14 @@ cleanup:
if (c->conn)
fd_cnx_destroy(c->conn);
/* Cleanup the received buffer if any */
free(buf);
/* Cleanup the parsed message if any */
if (msg) {
CHECK_FCT_DO( fd_msg_free(msg), /* continue */);
}
/* Detach the thread, cleanup the client structure */
pthread_detach(pthread_self());
free(c);
......
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