Mercurial > hg > freeDiameter
changeset 26:b4684b76c6ab
Fix erroneous %g specifiers for size_t (correct is %z)
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Mon, 26 Oct 2009 16:44:16 +0900 |
parents | 67ca08d5bc48 |
children | b3a1773e9f46 |
files | freeDiameter/cnxctx.c freeDiameter/p_psm.c freeDiameter/sctp.c freeDiameter/sctps.c freeDiameter/server.c |
diffstat | 5 files changed, 44 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/freeDiameter/cnxctx.c Mon Oct 26 16:00:49 2009 +0900 +++ b/freeDiameter/cnxctx.c Mon Oct 26 16:44:16 2009 +0900 @@ -503,7 +503,7 @@ 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 @@ 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 @@ { 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 @@ /* 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:
--- a/freeDiameter/p_psm.c Mon Oct 26 16:00:49 2009 +0900 +++ b/freeDiameter/p_psm.c Mon Oct 26 16:44:16 2009 +0900 @@ -163,7 +163,7 @@ 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);
--- a/freeDiameter/sctp.c Mon Oct 26 16:00:49 2009 +0900 +++ b/freeDiameter/sctp.c Mon Oct 26 16:44:16 2009 +0900 @@ -763,7 +763,7 @@ 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 @@ } 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));
--- a/freeDiameter/sctps.c Mon Oct 26 16:00:49 2009 +0900 +++ b/freeDiameter/sctps.c Mon Oct 26 16:44:16 2009 +0900 @@ -135,7 +135,7 @@ { 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 @@ 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 */
--- a/freeDiameter/server.c Mon Oct 26 16:00:49 2009 +0900 +++ b/freeDiameter/server.c Mon Oct 26 16:44:16 2009 +0900 @@ -99,6 +99,10 @@ { 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 @@ 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 ); - TODO("Timeout => close"); - TODO("Message != CER => close"); - TODO("Message == CER : "); + 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("Search matching peer"); TODO("Send event to the peer"); @@ -146,6 +168,14 @@ 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);