Explorar o código

registrar(k): different return codes for successful save

- save(...) returns different return codes
	- -1: error
	-  1: insert
	-  2: update
	-  3: delete
	-  4: contacts list replied
Daniel-Constantin Mierla %!s(int64=16) %!d(string=hai) anos
pai
achega
e45ac57e67
Modificáronse 3 ficheiros con 439 adicións e 309 borrados
  1. 400 304
      modules_k/registrar/README
  2. 20 0
      modules_k/registrar/doc/registrar_admin.xml
  3. 19 5
      modules_k/registrar/save.c

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 400 - 304
modules_k/registrar/README


+ 20 - 0
modules_k/registrar/doc/registrar_admin.xml

@@ -640,6 +640,26 @@ modparam("registrar", "reg_callid_avp", "$avp(s:avp)")
 			</para>
 		</listitem>
 		</itemizedlist>
+		<para>Return codes:</para>
+		<itemizedlist>
+		<listitem>
+			<para>
+			<emphasis>-1</emphasis> - error.
+			</para>
+			<para>
+			<emphasis>1</emphasis> - contacts inserted.
+			</para>
+			<para>
+			<emphasis>2</emphasis> - contacts updated.
+			</para>
+			<para>
+			<emphasis>3</emphasis> - contacts deleted.
+			</para>
+			<para>
+			<emphasis>4</emphasis> - contacts returned.
+			</para>
+		</listitem>
+		</itemizedlist>
 		<para>
 		This function can be used from REQUEST_ROUTE and REPLY_ROUTE.
 		</para>

+ 19 - 5
modules_k/registrar/save.c

@@ -541,10 +541,12 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 	int e_max, tcp_check;
 	struct sip_uri uri;
 #endif
+	int rc;
 
 	/* mem flag */
 	flags = mem_only;
 
+	rc = 0;
 	/* pack the contact_info */
 	if ( (ci=pack_ci( _m, 0, 0, flags))==0 ) {
 		LM_ERR("failed to initial pack contact info\n");
@@ -597,6 +599,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 				LM_ERR("failed to insert contact\n");
 				goto error;
 			}
+			rc = 1;
 			if(_mode)
 			{
 				ptr=_r->contacts;
@@ -624,6 +627,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 					LM_ERR("failed to delete contact\n");
 					goto error;
 				}
+				rc = 3;
 			} else {
 				/* do update */
 				/* pack the contact specific info */
@@ -649,6 +653,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 					LM_ERR("failed to update contact\n");
 					goto error;
 				}
+				rc = 2;
 			}
 		}
 #ifdef USE_TCP
@@ -678,7 +683,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 	}
 #endif
 
-	return 0;
+	return rc;
 error:
 	return -1;
 }
@@ -692,8 +697,10 @@ static inline int add_contacts(struct sip_msg* _m, contact_t* _c,
 								udomain_t* _d, str* _a, int _mode)
 {
 	int res;
+	int ret;
 	urecord_t* r;
 
+	ret = 0;
 	ul.lock_udomain(_d, _a);
 	res = ul.get_urecord(_d, _a, &r);
 	if (res < 0) {
@@ -704,7 +711,7 @@ static inline int add_contacts(struct sip_msg* _m, contact_t* _c,
 	}
 
 	if (res == 0) { /* Contacts found */
-		if (update_contacts(_m, r, _c, _mode) < 0) {
+		if ((ret=update_contacts(_m, r, _c, _mode)) < 0) {
 			build_contact(r->contacts);
 			ul.release_urecord(r);
 			ul.unlock_udomain(_d, _a);
@@ -717,9 +724,10 @@ static inline int add_contacts(struct sip_msg* _m, contact_t* _c,
 			ul.unlock_udomain(_d, _a);
 			return -4;
 		}
+		ret = 1;
 	}
 	ul.unlock_udomain(_d, _a);
-	return 0;
+	return ret;
 }
 
 
@@ -732,8 +740,10 @@ int save(struct sip_msg* _m, char* _d, char* _cflags)
 	contact_t* c;
 	int st, mode;
 	str aor;
+	int ret;
 
 	rerrno = R_FINE;
+	ret = 1;
 
 	if (parse_message(_m) < 0) {
 		goto error;
@@ -756,12 +766,16 @@ int save(struct sip_msg* _m, char* _d, char* _cflags)
 	if (c == 0) {
 		if (st) {
 			if (star((udomain_t*)_d, &aor) < 0) goto error;
+			else ret=3;
 		} else {
 			if (no_contacts((udomain_t*)_d, &aor) < 0) goto error;
+			else ret=4;
 		}
 	} else {
 		mode = is_cflag_set(REG_SAVE_REPL_FL)?1:0;
-		if (add_contacts(_m, c, (udomain_t*)_d, &aor, mode) < 0) goto error;
+		if ((ret=add_contacts(_m, c, (udomain_t*)_d, &aor, mode)) < 0)
+			goto error;
+		ret = (ret==0)?1:ret;
 	}
 
 	update_stat(accepted_registrations, 1);
@@ -769,7 +783,7 @@ int save(struct sip_msg* _m, char* _d, char* _cflags)
 	if ((route_type == REQUEST_ROUTE) && !is_cflag_set(REG_SAVE_NORPL_FL) && (send_reply(_m) < 0))
 		return -1;
 
-	return 1;
+	return ret;
 error:
 	update_stat(rejected_registrations, 1);
 

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio