changeset 383:88e170a79627

Added new flag value to sess_new
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 28 May 2009 11:15:14 +0900
parents 8fdd47ce352a
children 2bb3642696ec
files include/waaad/session-api.h waaad/session.c
diffstat 2 files changed, 42 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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,	/* "<diameterId>;<high32>;<low32>[;opt]" opt may be NULL */
 	SESSION_NEW_SEQUENCE,		/* "<diameterId>;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		/* "<otherId>;<high32>;<low32>[;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 );
--- 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: 	/* "<otherId>;<high32>;<low32>[;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 */
"Welcome to our mercurial repository"