Module: kamailio
Branch: master
Commit: fedacebc49b5abf5ee1d7543ee966072d681ef57
URL: 
https://github.com/kamailio/kamailio/commit/fedacebc49b5abf5ee1d7543ee966072d681ef57

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2017-05-03T08:18:57+02:00

statistics: exported functions to kemi interface

---

Modified: src/modules/statistics/statistics.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/fedacebc49b5abf5ee1d7543ee966072d681ef57.diff
Patch: 
https://github.com/kamailio/kamailio/commit/fedacebc49b5abf5ee1d7543ee966072d681ef57.patch

---

diff --git a/src/modules/statistics/statistics.c 
b/src/modules/statistics/statistics.c
index 80f55ec..499b419 100644
--- a/src/modules/statistics/statistics.c
+++ b/src/modules/statistics/statistics.c
@@ -39,6 +39,7 @@
 #include "../../core/dprint.h"
 #include "../../core/ut.h"
 #include "../../core/mod_fix.h"
+#include "../../core/kemi.h"
 #include "../../core/counters.h"
 #include "../../core/mem/mem.h"
 #include "stats_funcs.h"
@@ -240,6 +241,18 @@ static int w_update_stat(struct sip_msg *msg, char 
*stat_p, char *long_p)
        return 1;
 }
 
+static int ki_update_stat(sip_msg_t *msg, str *sname, int sval)
+{
+       stat_var *stat;
+
+       stat = get_stat(sname);
+       if(stat == 0) {
+               LM_ERR("variable <%.*s> not defined\n", sname->len, sname->s);
+               return -1;
+       }
+       update_stat(stat, (long)sval);
+       return 1;
+}
 
 static int w_reset_stat(struct sip_msg *msg, char* stat_p, char *foo)
 {
@@ -264,8 +277,47 @@ static int w_reset_stat(struct sip_msg *msg, char* stat_p, 
char *foo)
                reset_stat( stat );
        }
 
+       return 1;
+}
 
+static int ki_reset_stat(sip_msg_t *msg, str* sname)
+{
+       stat_var *stat;
+
+       stat = get_stat(sname);
+       if(stat == 0) {
+               LM_ERR("variable <%.*s> not defined\n", sname->len, sname->s);
+               return -1;
+       }
+       reset_stat( stat );
        return 1;
 }
 
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_statistics_exports[] = {
+       { str_init("statistics"), str_init("update_stat"),
+               SR_KEMIP_INT, ki_update_stat,
+               { SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
+       { str_init("statistics"), str_init("reset_stat"),
+               SR_KEMIP_INT, ki_reset_stat,
+               { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
+
+       { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+/* clang-format on */
 
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+       sr_kemi_modules_add(sr_kemi_statistics_exports);
+       return 0;
+}
\ No newline at end of file


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to