presence: add parameter startup_mode 854/head
authorEmmanuel Schmidbauer <emmanuel@getweave.com>
Wed, 9 Nov 2016 13:30:37 +0000 (08:30 -0500)
committerEmmanuel Schmidbauer <emmanuel@getweave.com>
Wed, 9 Nov 2016 13:30:37 +0000 (08:30 -0500)
modules/presence/doc/presence_admin.xml
modules/presence/notify.c
modules/presence/presence.c
modules/presence/presence.h
modules/presence/presentity.c

index 525d324..3a20354 100644 (file)
@@ -300,6 +300,28 @@ modparam("presence", "force_delete", 1)
                </example>
        </section>
 
+       <section id="presence.p.startup_mode">
+               <title><varname>startup_mode</varname> (int)</title>
+               <para>
+               Setting this parameter to 0 will provide startup related backward compatibility for some modules. Setting to 0 fixes presentity requests with low expires (e.g. time() + 1)
+               </para>
+               <para>
+               Set this parameter to <quote>0</quote> to enable backward compatibility.
+               </para>
+               <para>
+               <emphasis>Default value is <quote>1</quote>.
+               </emphasis>
+               </para>
+               <example>
+               <title>Set <varname>startup_mode</varname> parameter</title>
+               <programlisting format="linespecific">
+...
+modparam("presence", "startup_mode", 0)
+...
+</programlisting>
+               </example>
+       </section>
+
        <section id="presence.p.to_tag_pref">
                <title><varname>to_tag_pref</varname> (str)</title>
                <para>
index 17bf1dd..d9a51ef 100644 (file)
@@ -653,12 +653,14 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
        query_ops[n_query_cols] = OP_EQ;
        n_query_cols++;
 
-       query_cols[n_query_cols] = &str_expires_col;
-       query_vals[n_query_cols].type = DB1_INT;
-       query_vals[n_query_cols].nul = 0;
-       query_vals[n_query_cols].val.int_val= (int)time(NULL);
-       query_ops[n_query_cols] = OP_GT;
-       n_query_cols++;
+       if (pres_fix_startup) {
+               query_cols[n_query_cols] = &str_expires_col;
+               query_vals[n_query_cols].type = DB1_INT;
+               query_vals[n_query_cols].nul = 0;
+               query_vals[n_query_cols].val.int_val= (int)time(NULL);
+               query_ops[n_query_cols] = OP_GT;
+               n_query_cols++;
+       }
 
        result_cols[body_col=n_result_cols++] = &str_body_col;
        result_cols[etag_col=n_result_cols++] = &str_etag_col;
@@ -675,13 +677,24 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
        } else {
                query_str = str_received_time_col;
        }
-       if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
-                result_cols, n_query_cols, n_result_cols, &query_str ,  &result) < 0)
-       {
-               LM_ERR("failed to query %.*s table\n", presentity_table.len, presentity_table.s);
-               if(result)
-                       pa_dbf.free_result(pa_db, result);
-               return NULL;
+       if (pres_fix_startup) {
+               if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
+                        result_cols, n_query_cols, n_result_cols, &query_str ,  &result) < 0)
+               {
+                       LM_ERR("failed to query %.*s table\n", presentity_table.len, presentity_table.s);
+                       if(result)
+                               pa_dbf.free_result(pa_db, result);
+                       return NULL;
+               }
+       } else {
+               if (pa_dbf.query (pa_db, query_cols, 0, query_vals,
+                        result_cols, n_query_cols, n_result_cols, &query_str ,  &result) < 0)
+               {
+                       LM_ERR("failed to query %.*s table\n", presentity_table.len, presentity_table.s);
+                       if(result)
+                               pa_dbf.free_result(pa_db, result);
+                       return NULL;
+               }
        }
 
        if(result== NULL)
index 051b1b5..bd46219 100644 (file)
@@ -160,6 +160,8 @@ int pres_waitn_time = 5;
 int pres_notifier_poll_rate = 10;
 int pres_notifier_processes = 1;
 int pres_force_delete = 0;
+int startup_mode = 1; // enable by default
+int pres_fix_startup = 0;
 str pres_xavp_cfg = {0};
 int pres_retrieve_order = 0;
 str pres_retrieve_order_by = str_init("priority");
@@ -206,6 +208,7 @@ static param_export_t params[]={
        { "notifier_poll_rate",     INT_PARAM, &pres_notifier_poll_rate },
        { "notifier_processes",     INT_PARAM, &pres_notifier_processes },
        { "force_delete",           INT_PARAM, &pres_force_delete },
+       { "startup_mode",           INT_PARAM, &startup_mode },
        { "to_tag_pref",            PARAM_STRING, &to_tag_pref },
        { "expires_offset",         INT_PARAM, &expires_offset },
        { "max_expires",            INT_PARAM, &max_expires },
@@ -443,6 +446,10 @@ static int mod_init(void)
        if (pres_force_delete > 0)
                pres_force_delete = 1;
 
+       if (startup_mode > 0) {
+               pres_fix_startup = 1;  // startup_mode fixes presence on startup (commit: 1dceaa24ded727aba5870f28fb63e26ed98464f3)
+       }
+
        if (pres_log_facility_str) {
                int tmp = str2facility(pres_log_facility_str);
 
index 0068c9b..92cc6b3 100644 (file)
@@ -89,6 +89,7 @@ extern int pres_waitn_time;
 extern int pres_notifier_poll_rate;
 extern int pres_notifier_processes;
 extern int pres_force_delete;
+extern int pres_fix_startup;
 extern str pres_xavp_cfg;
 extern int pres_retrieve_order;
 extern str pres_retrieve_order_by;
index 3f79cfa..c59af2b 100644 (file)
@@ -1253,6 +1253,9 @@ int pres_htable_restore(void)
                        row = &result->rows[i];
                        row_vals = ROW_VALUES(row);
 
+                       if (!pres_fix_startup && (row_vals[expires_col].val.int_val< (int)time(NULL)))
+                               continue;
+
                        sphere= NULL;
                        user.s= (char*)row_vals[user_col].val.string_val;
                        user.len= strlen(user.s);