# HG changeset patch # User Sebastien Decugis # Date 1243476914 -32400 # Node ID 88e170a796277a41a9e6a908946cb991ed4f6c49 # Parent 8fdd47ce352a11c9cdf7a282383872fdbcb389c2 Added new flag value to sess_new diff -r 8fdd47ce352a -r 88e170a79627 include/waaad/session-api.h --- a/include/waaad/session-api.h Tue May 26 17:19:43 2009 +0900 +++ b/include/waaad/session-api.h Thu May 28 11:15:14 2009 +0900 @@ -106,7 +106,8 @@ typedef enum { SESSION_NEW_DEFAULT = 0, /* ";;[;opt]" opt may be NULL */ SESSION_NEW_SEQUENCE, /* ";opt" opt must not be NULL and must be eternally unique */ - SESSION_NEW_FULL /* "opt" opt must not be NULL and must contain the sender's identity */ + SESSION_NEW_FULL, /* "opt" opt must not be NULL and must contain the sender's identity */ + SESSION_NEW_OTHER /* ";;[;opt]". opt points to an FQDN, optionnaly followed by [;opt]" */ } sess_flags_t; #ifndef IN_EXTENSION @@ -129,11 +130,13 @@ * the content of the opt string is added. Caller must ensure that opt is eternally unique. * - SESSION_NEW_FULL: the opt parameter contains the full string. It must start with the diameter id of the peer, * followed by a ";". + * - SESSION_NEW_OTHER: opt is an FQDN. The session is generated for another DiameterId. if opt contains a ';', + * the part following it is used as the opt parameter in DEFAULT case. This flag is used for example for gateway functions. * * RETURN VALUE: * 0 : The session is created. * EINVAL : A parameter is invalid. - * EALREADY : A session with the same name already exists (only for SESSION_NEW_SEQUENCE and SESSION_NEW_FULL) + * EALREADY : A session with the same name already exists * ENOMEM : Not enough memory to complete the operation */ int sess_new ( sess_id_t ** session, sess_flags_t flags, char * opt ); diff -r 8fdd47ce352a -r 88e170a79627 waaad/session.c --- a/waaad/session.c Tue May 26 17:19:43 2009 +0900 +++ b/waaad/session.c Thu May 28 11:15:14 2009 +0900 @@ -426,8 +426,44 @@ strsz = strlen(str); break; + case SESSION_NEW_OTHER: /* ";;[;opt]" */ + CHECK_PARAMS( (opt != NULL) ); + { + int len; + char * secopt = NULL; + + /* Compute the size of the new string */ + len = strlen(opt); + len += 2 * ( 1 /* ';' */ + 10 /* uint32_t max = 4294967295 = 10 digits */ ); + len++; /* for the final '\0' in the worst case */ + + /* Allocate the space for the buffer */ + CHECK_MALLOC( str = malloc(len) ); + mustfree = 1; + memset(str, 0, len); + + /* Increment the value of the low32 */ + CHECK_POSIX_DO( ret = pthread_mutex_lock(&g_sid_lock), goto end ); + ++g_sid_l; + + /* Search a ';' in opt */ + secopt = strchr(opt, ';'); + + /* Now write the new value */ + if (secopt) { + *secopt++ = '\0'; + strsz = snprintf(str, len, "%s;%u;%u;%s", opt, g_sid_h, g_sid_l, secopt); + } else { + strsz = snprintf(str, len, "%s;%u;%u", opt, g_sid_h, g_sid_l); + } + + CHECK_POSIX_DO( ret = pthread_mutex_unlock(&g_sid_lock), goto end ); + } + + break; + default: - CHECK_PARAMS( 0 ); + CHECK_PARAMS( (flags, 0) ); } /* Now str points to the new session string. Create the new session */