ソースを参照

registrar: New set_q_override function

The set_q_override function will override the value of the q parameter
from the Contact header in subsequent calls to the save() function for
the current request.
Currently exported as a C-API function
Hugh Waite 12 年 前
コミット
29f0779226
4 ファイル変更41 行追加1 行削除
  1. 15 0
      modules/registrar/api.c
  2. 4 0
      modules/registrar/api.h
  3. 21 1
      modules/registrar/save.c
  4. 1 0
      modules/registrar/save.h

+ 15 - 0
modules/registrar/api.c

@@ -108,6 +108,20 @@ int regapi_registered(struct sip_msg *msg, char *table)
 	return registered(msg, d, NULL);
 }
 
+/**
+ *
+ */
+int regapi_set_q_override(struct sip_msg *msg, str *new_q)
+{
+	int _q;
+	if (str2q(&_q, new_q->s, new_q->len) < 0)
+	{
+		LM_ERR("invalid q parameter\n");
+		return -1;
+	}
+	return set_q_override(msg, _q);
+}
+
 /**
  *
  */
@@ -122,6 +136,7 @@ int bind_registrar(registrar_api_t* api)
 	api->lookup     = regapi_lookup;
 	api->lookup_uri = regapi_lookup_uri;
 	api->registered = regapi_registered;
+	api->set_q_override = regapi_set_q_override;
 
 	return 0;
 }

+ 4 - 0
modules/registrar/api.h

@@ -43,6 +43,9 @@ int regapi_lookup(struct sip_msg *msg, char *table);
 typedef int (*regapi_lookup_uri_f)(struct sip_msg *msg, char *table, str *uri);
 int regapi_lookup_uri(struct sip_msg *msg, char *table, str *uri);
 
+typedef int (*regapi_set_q_override_f)(struct sip_msg *msg, str *new_q);
+int regapi_set_q_override(struct sip_msg *msg, str *new_q);
+
 /**
  * @brief REGISTRAR API structure
  */
@@ -52,6 +55,7 @@ typedef struct registrar_api {
 	regapi_lookup_f     lookup;
 	regapi_lookup_uri_f lookup_uri;
 	regapi_lookup_f     registered;
+	regapi_set_q_override_f set_q_override;
 } registrar_api_t;
 
 typedef int (*bind_registrar_f)(registrar_api_t* api);

+ 21 - 1
modules/registrar/save.c

@@ -81,6 +81,9 @@ static int mem_only = 0;
 
 extern sruid_t _reg_sruid;
 
+static int q_override_msg_id;
+static qvalue_t q_override_value;
+
 /*! \brief
  * Process request that contained a star, in that case, 
  * we will remove all bindings with the given username 
@@ -308,7 +311,11 @@ static inline ucontact_info_t* pack_ci( struct sip_msg* _m, contact_t* _c,
 			ci.c = &_c->uri;
 
 		/* Calculate q value of the contact */
-		if (calc_contact_q(_c->q, &ci.q) < 0) {
+		if (m && m->id == q_override_msg_id)
+		{
+			ci.q = q_override_value;
+		}
+		else if (calc_contact_q(_c->q, &ci.q) < 0) {
 			rerrno = R_INV_Q;
 			LM_ERR("failed to calculate q\n");
 			goto error;
@@ -914,3 +921,16 @@ int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri)
 	return 1;
 }
 
+int set_q_override(struct sip_msg* _m, int _q)
+{
+	if ((_q < 0) || (_q > 1000))
+	{
+		LM_ERR("Invalid q value\n");
+		return -1;
+	}
+	q_override_msg_id = _m->id;
+	q_override_value = _q;
+	return 1;
+}
+
+

+ 1 - 0
modules/registrar/save.h

@@ -48,6 +48,7 @@
  */
 int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str* _uri);
 int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri);
+int set_q_override(struct sip_msg* _m, int _q);
 
 
 #endif /* SAVE_H */