[Devel] Registrar, save and flags

Jean-Michel Foucher jean-michel.foucher at wengo.fr
Mon Jul 31 18:56:10 CEST 2006


Hello,

At some point, i needed to  check if a contact could receive a MESSAGE, 
SUBSCRIBE or NOTIFY message.

Therefore i needed lookup("location") to check if a contact can support 
them.

i had a look at usrloc/ucontact.h and realized all the flags were not used :

/*
 * Flags that can be associated with a Contact
 */
typedef enum flags {
        FL_NONE        = 0,          /* No flags set */
        FL_NAT         = 1 << 0,     /* Contact is behind NAT */
        FL_INVITE      = 1 << 1,     /* Contact supports INVITE and 
related methods */
        FL_N_INVITE    = 1 << 2,     /* Contact doesn't support INVITE 
and related methods */
        FL_MESSAGE     = 1 << 3,     /* Contact supports MESSAGE */
        FL_N_MESSAGE   = 1 << 4,     /* Contact doesn't support MESSAGE */
        FL_SUBSCRIBE   = 1 << 5,     /* Contact supports SUBSCRIBE and 
NOTIFY */
        FL_N_SUBSCRIBE = 1 << 6,     /* Contact doesn't support 
SUBSCRIBE and NOTIFY */
        FL_PERMANENT   = 1 << 7,     /* Permanent contact (does not 
expire) */
        FL_MEM         = 1 << 8,     /* Update memory only -- used for 
REGISTER replication */
        FL_NAT_SIPPING = 1 << 9,     /* Use SIP ping if nated */
        FL_ALL         = 0xFFFFFFFF  /* All flags set */
} flags_t;

As far as i've checked, FL_NAT, FL_PERMANENT, FL_MEM and FL_NAT_SIPPING 
are really used, but not the flags from FL_INVITE to FL_PERMANENT.

i've added some code so that these flags can be used the same way as:

--
modparam("registrar","natflag",6)
setflag(6);
save("location");
--

The enclosed file is a diff between recently released version 1.1.0 and 
my code.
The modified files are :
registrar/reg_mod.h
registrar/reg_mod.c
registrar/save.c

i guess the main problem of my code is that it does not check if such a 
scenario occurs for instance :
(_m->flags&invite_flag == 1) && (_m->flags&n_invite_flag == 1)

Let me know what you think about it.

Best regards,

-- 
Jean-Michel Foucher
OpenWengo, the free and multiplatform VoIP client
http://dev.openwengo.com/


-------------- next part --------------
Index: save.c
===================================================================
--- save.c	(revision 507)
+++ save.c	(working copy)
@@ -395,6 +395,27 @@
 		flags = FL_NAT;
 	else
 		flags = FL_NONE;
+	/* is INVITE and related methods supported */
+	if (_m->flags&invite_flag)
+		flags |= FL_INVITE;
+	/* is INVITE and related methods NOT supported */
+	if (_m->flags&n_invite_flag)
+		flags |= FL_N_INVITE;
+	/* is MESSAGE supported */
+	if (_m->flags&message_flag)
+		flags |= FL_MESSAGE;
+	/* is MESSAGE NOT supported */
+	if (_m->flags&n_message_flag)
+		flags |= FL_N_MESSAGE;
+	/* are SUBSCRIBE and NOTIFY supported */
+	if (_m->flags&subscribe_flag)
+		flags |= FL_SUBSCRIBE;
+	/* are SUBSCRIBE and NOTIFY NOT supported */
+	if (_m->flags&n_subscribe_flag)
+		flags |= FL_N_SUBSCRIBE;
+	/* is contact permanent */
+//	if (_m->flags&permanent_flag)
+//		flags |= FL_PERMANENT;
 	/* nat type flag */
 	if (_m->flags&sip_natping_flag)
 		flags |= FL_NAT_SIPPING;
@@ -579,6 +600,27 @@
 		flags = FL_NAT;
 	else
 		flags = FL_NONE;
+	/* is INVITE and relative methods supported */
+	if (_m->flags&invite_flag)
+		flags |= FL_INVITE;
+	/* is INVITE and relative methods NOT supported */
+	if (_m->flags&n_invite_flag)
+		flags |= FL_N_INVITE;
+	/* is MESSAGE supported */
+	if (_m->flags&message_flag)
+		flags |= FL_MESSAGE;
+	/* is MESSAGE NOT supported */
+	if (_m->flags&n_message_flag)
+		flags |= FL_N_MESSAGE;
+	/* are SUBSCRIBE and NOTIFY supported */
+	if (_m->flags&subscribe_flag)
+		flags |= FL_SUBSCRIBE;
+	/* are SUBSCRIBE and NOTIFY NOT supported */
+	if (_m->flags&n_subscribe_flag)
+		flags |= FL_N_SUBSCRIBE;
+	/* is contact permanent */
+//	if (_m->flags&permanent_flag)
+//		flags |= FL_PERMANENT;
 	/* nat type flag */
 	if (_m->flags&sip_natping_flag)
 		flags |= FL_NAT_SIPPING;
Index: reg_mod.c
===================================================================
--- reg_mod.c	(revision 500)
+++ reg_mod.c	(working copy)
@@ -67,6 +67,20 @@
 int desc_time_order = 0;
 /* flag marking contacts behind NAT */
 int nat_flag        = -1;
+/* flag marking contacts supports INVITE and relative methods */
+int invite_flag    = -1;
+/* flag marking contacts doesn't support INVITE and relative methods */
+int n_invite_flag    = -1;
+/* flag marking contacts supports MESSAGE */
+int message_flag    = -1;
+/* flag marking contacts doesn't support MESSAGE */
+int n_message_flag    = -1;
+/* flag marking contacts supports SUBSCRIBE and NOTIFY */
+int subscribe_flag  = -1;
+/* flag marking contacts doesn't support SUBSCRIBE and NOTIFY */
+int n_subscribe_flag  = -1;
+/* flag marking contacts are permanent (does not expire) */
+//int permanent_flag = -1;
 /* if the TCP connection should be kept open */
 int tcp_persistent_flag = -1;
 /* flag marking nated contacts to be pinged with SIP method  */
@@ -147,6 +161,13 @@
 	{"case_sensitive",     INT_PARAM, &case_sensitive      },
 	{"desc_time_order",    INT_PARAM, &desc_time_order     },
 	{"nat_flag",           INT_PARAM, &nat_flag            },
+	{"invite_flag",        INT_PARAM, &invite_flag         },
+	{"n_invite_flag",      INT_PARAM, &n_invite_flag       },
+	{"message_flag",       INT_PARAM, &message_flag        },
+	{"n_message_flag",     INT_PARAM, &n_message_flag      },
+	{"subscribe_flag",     INT_PARAM, &subscribe_flag      },
+	{"n_subscribe_flag",   INT_PARAM, &n_subscribe_flag    },
+//	{"permanent_flag",     INT_PARAM, &permanent_flag      },
 	{"sip_natping_flag",   INT_PARAM, &sip_natping_flag    },
 	{"tcp_persistent_flag",INT_PARAM, &tcp_persistent_flag },
 	{"realm_prefix",       STR_PARAM, &realm_pref          },
@@ -263,6 +284,13 @@
 	/* fix the flags */
 	sock_flag = (sock_flag!=-1)?(1<<sock_flag):0;
 	nat_flag = (nat_flag!=-1)?(1<<nat_flag):0;
+	invite_flag = (invite_flag!=-1)?(1<<invite_flag):0;
+	n_invite_flag = (n_invite_flag!=-1)?(1<<n_invite_flag):0;
+	message_flag = (message_flag!=-1)?(1<<message_flag):0;
+	n_message_flag = (n_message_flag!=-1)?(1<<n_message_flag):0;
+	subscribe_flag = (subscribe_flag!=-1)?(1<<subscribe_flag):0;
+	n_subscribe_flag = (n_subscribe_flag!=-1)?(1<<n_subscribe_flag):0;
+//	permanent_flag = (permanent_flag!=-1)?(1<<permanent_flag):0;
 	sip_natping_flag = (sip_natping_flag!=-1)?(1<<sip_natping_flag):0;
 	tcp_persistent_flag = (tcp_persistent_flag!=-1)?(1<<tcp_persistent_flag):0;
 
Index: reg_mod.h
===================================================================
--- reg_mod.h	(revision 500)
+++ reg_mod.h	(working copy)
@@ -56,6 +56,13 @@
 extern int case_sensitive;
 extern int desc_time_order;
 extern int nat_flag;
+extern int invite_flag;
+extern int n_invite_flag;
+extern int message_flag;
+extern int n_message_flag;
+extern int subscribe_flag;
+extern int n_subscribe_flag;
+//extern int permanent_flag;
 extern int sip_natping_flag;
 extern int tcp_persistent_flag;
 extern int min_expires;


More information about the Devel mailing list