Browse Source

uac: uac_reg: add uac_reg_status() function

New function to obtain registration status from within configuration script
Alex Hermann 14 years ago
parent
commit
3f6b6325e9
4 changed files with 119 additions and 0 deletions
  1. 51 0
      modules/uac/doc/uac_admin.xml
  2. 24 0
      modules/uac/uac.c
  3. 43 0
      modules/uac/uac_reg.c
  4. 1 0
      modules/uac/uac_reg.h

+ 51 - 0
modules/uac/doc/uac_admin.xml

@@ -765,6 +765,57 @@ if(uac_reg_lookup("$rU", "$ru"))
 {
     lookup("location");
 }
+...
+				</programlisting>
+			</example>
+		</section>
+		<section id="uac.f.uac_reg_status(uuid)">
+			<title>
+				<function moreinfo="none">uac_reg_status(uuid)</function>
+			</title>
+			<para>
+			This function returns the current registration status for the uuid.
+			</para>
+			<para>
+			Return values:
+			<itemizedlist>
+			<listitem>
+				<para>
+				1 - a valid registration exists.
+				</para>
+			</listitem>
+			<listitem>
+				<para>
+				-1 - uuid does not exist or an error occurred while executing
+				the function.
+				</para>
+			</listitem>
+			<listitem>
+				<para>
+				-2 - a registration attempt is ongoing (and currently there is
+				no valid registration).
+				</para>
+			</listitem>
+			<listitem>
+				<para>
+				-3 - registration is disabled.
+				</para>
+			</listitem>
+			<listitem>
+				<para>
+				-99 - no valid registration, waiting for new registration attempt.
+				</para>
+			</listitem>
+			</itemizedlist>
+			</para>
+			<para>
+			This function can be used from ANY_ROUTE.
+			</para>
+			<example>
+				<title><function>uac_reg_status</function> usage</title>
+				<programlisting format="linespecific">
+...
+$var(status) = uac_reg_status("$rU");
 ...
 				</programlisting>
 			</example>

+ 24 - 0
modules/uac/uac.c

@@ -95,6 +95,7 @@ static int w_replace_to(struct sip_msg* msg, char* p1, char* p2);
 static int w_restore_to(struct sip_msg* msg);
 static int w_uac_auth(struct sip_msg* msg, char* str, char* str2);
 static int w_uac_reg_lookup(struct sip_msg* msg,  char* src, char* dst);
+static int w_uac_reg_status(struct sip_msg* msg,  char* src, char* dst);
 static int w_uac_reg_request_to(struct sip_msg* msg,  char* src, char* mode_s);
 static int fixup_replace_uri(void** param, int param_no);
 static int mod_init(void);
@@ -127,6 +128,8 @@ static cmd_export_t cmds[]={
 	{"uac_req_send",  (cmd_function)w_uac_req_send,   0, 0, 0, ANY_ROUTE},
 	{"uac_reg_lookup",  (cmd_function)w_uac_reg_lookup,  2, fixup_pvar_pvar,
 		fixup_free_pvar_pvar, ANY_ROUTE },
+	{"uac_reg_status",  (cmd_function)w_uac_reg_status,  1, fixup_pvar_pvar, 0,
+		ANY_ROUTE },
 	{"uac_reg_request_to",  (cmd_function)w_uac_reg_request_to,  2, fixup_pvar_uint, fixup_free_pvar_uint,
 		REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE },
 	{"bind_uac", (cmd_function)bind_uac,		  1,  0, 0, 0},
@@ -569,6 +572,27 @@ static int w_uac_reg_lookup(struct sip_msg* msg,  char* src, char* dst)
 }
 
 
+static int w_uac_reg_status(struct sip_msg* msg,  char* src, char* dst)
+{
+	pv_spec_t *spv;
+	pv_value_t val;
+
+	spv = (pv_spec_t*)src;
+	if(pv_get_spec_value(msg, spv, &val) != 0)
+	{
+		LM_ERR("cannot get src uri value\n");
+		return -1;
+	}
+
+	if (!(val.flags & PV_VAL_STR))
+	{
+	    LM_ERR("src pv value is not string\n");
+	    return -1;
+	}
+	return uac_reg_status(msg, &val.rs, 0);
+}
+
+
 static int w_uac_reg_request_to(struct sip_msg* msg, char* src, char* mode_s)
 {
 	pv_spec_t *spv;

+ 43 - 0
modules/uac/uac_reg.c

@@ -1436,6 +1436,49 @@ int  uac_reg_lookup(struct sip_msg *msg, str *src, pv_spec_t *dst, int mode)
 	return 1;
 }
 
+/**
+ *
+ */
+int uac_reg_status(struct sip_msg *msg, str *src, int mode)
+{
+	struct sip_uri puri;
+	reg_uac_t *reg = NULL;
+	int ret;
+
+	if(mode==0)
+	{
+		reg = reg_ht_get_byuuid(src);
+		if(reg==NULL)
+		{
+			LM_DBG("no uuid: %.*s\n", src->len, src->s);
+			return -1;
+		}
+	} else {
+		if(parse_uri(src->s, src->len, &puri)!=0)
+		{
+			LM_ERR("failed to parse uri\n");
+			return -1;
+		}
+		reg = reg_ht_get_byuser(&puri.user, (reg_use_domain)?&puri.host:NULL);
+		if(reg==NULL)
+		{
+			LM_DBG("no user: %.*s\n", src->len, src->s);
+			return -1;
+		}
+	}
+
+	if ((reg->flags & UAC_REG_ONLINE) && (reg->timer_expires > time(NULL)))
+		ret = 1;
+	else if (reg->flags & UAC_REG_ONGOING)
+		ret = -2;
+	else if (reg->flags & UAC_REG_DISABLED)
+		ret = -3;
+	else
+		ret = -99;
+
+	return ret;
+}
+
 /**
  *
  */

+ 1 - 0
modules/uac/uac_reg.h

@@ -50,5 +50,6 @@ void uac_reg_timer(unsigned int ticks);
 int uac_reg_init_rpc(void);
 
 int  uac_reg_lookup(struct sip_msg *msg, str *src, pv_spec_t *dst, int mode);
+int  uac_reg_status(struct sip_msg *msg, str *src, int mode);
 int  uac_reg_request_to(struct sip_msg *msg, str *src, unsigned int mode);
 #endif