Module: sip-router
Branch: master
Commit: d54bde96285f8b0d24f00223da96e8526143a298
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d54bde9…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Apr 10 23:23:12 2012 +0200
ndb_redis: support for redis array reply
- replies from redis holding arrays can be accessed now from config
file, the values in array being accessible via index
- the size of the array is give as a new property of the reply
- patch by Vicente Hernando
---
modules/ndb_redis/README | 14 ++
modules/ndb_redis/doc/ndb_redis_admin.xml | 29 +++++
modules/ndb_redis/ndb_redis_mod.c | 197 +++++++++++++++++++++++++----
modules/ndb_redis/redis_client.h | 2 +
4 files changed, 220 insertions(+), 22 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=d54…
Module: sip-router
Branch: master
Commit: 0d544f04bb17b671341f8bff5c51cea1dba4dd35
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0d544f0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Apr 10 12:18:35 2012 +0200
lib/srutils: added small api for internal unique id generator
- uses prefix, server id, timestamp, pid and a counter for an unique
string
---
lib/srutils/sruid.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/srutils/sruid.h | 42 ++++++++++++++++++++
2 files changed, 147 insertions(+), 0 deletions(-)
diff --git a/lib/srutils/sruid.c b/lib/srutils/sruid.c
new file mode 100644
index 0000000..682a244
--- /dev/null
+++ b/lib/srutils/sruid.c
@@ -0,0 +1,105 @@
+/*
+ * $Id$
+ *
+ * sruid - unique id generator
+ *
+ * Copyright (C) 2012 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "../../dprint.h"
+#include "../../globals.h"
+#include "../../pt.h"
+
+#include "sruid.h"
+
+/**
+ *
+ */
+int sruid_init(sruid_t *sid, char sep, char *cid)
+{
+ int i;
+
+ if(sid==NULL)
+ return -1;
+ memset(sid, 0, sizeof(sruid_t));
+ memcpy(sid->buf, "srid", 4);
+ if(cid!=NULL)
+ {
+ for(i=0; i<4 && cid[i]!='\0'; i++)
+ sid->buf[i] = cid[i];
+ }
+ sid->buf[4] = sep;
+
+ if(server_id!=0)
+ i = snprintf(sid->buf+5, SRUID_SIZE - 5 /*so far*/ - 8 /* extra int */,
+ "%x%c%x%c%x%c", (unsigned int)server_id, sep,
+ (unsigned int)time(NULL), sep, (unsigned int)my_pid(), sep);
+ else
+ i = snprintf(sid->buf+5, SRUID_SIZE - 5 /*so far*/ - 8 /* extra int */,
+ "%x%c%x%c",
+ (unsigned int)time(NULL), sep, (unsigned int)my_pid(), sep);
+ if(i<=0 || i>SRUID_SIZE-13)
+ {
+ LM_ERR("could not initialize sruid struct - output len: %d\n", i);
+ return -1;
+ }
+ sid->out = sid->buf + i + 5;
+ sid->uid.s = sid->buf;
+ LM_DBG("root for sruid is [%.*s] (%u / %d)\n", i+5, sid->uid.s,
+ sid->counter, i+5);
+ return 0;
+}
+
+/**
+ *
+ */
+int sruid_next(sruid_t *sid)
+{
+ unsigned short digit;
+ int i;
+ unsigned int val;
+
+ if(sid==NULL)
+ return -1;
+
+ sid->counter++;
+ if(sid->counter==0)
+ sid->counter=1;
+
+ val = sid->counter;
+ i = 0;
+ while(val!=0)
+ {
+ digit = val & 0x0f;
+ sid->out[i++] = (digit >= 10) ? digit + 'a' - 10 : digit + '0';
+ val >>= 4;
+ }
+ sid->out[i] = '\0';
+ sid->uid.len = sid->out + i - sid->buf;
+ LM_DBG("new sruid is [%.*s] (%u / %d)\n", sid->uid.len, sid->uid.s,
+ sid->counter, sid->uid.len);
+ return 0;
+}
+
diff --git a/lib/srutils/sruid.h b/lib/srutils/sruid.h
new file mode 100644
index 0000000..b7c49ee
--- /dev/null
+++ b/lib/srutils/sruid.h
@@ -0,0 +1,42 @@
+/*
+ * $Id$
+ *
+ * sruid - unique id generator
+ *
+ * Copyright (C) 2012 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _SRUID_H_
+#define _SRUID_H_
+
+#include "../../str.h"
+
+#define SRUID_SIZE 40
+
+typedef struct sruid {
+ char buf[SRUID_SIZE];
+ char *out;
+ str uid;
+ unsigned int counter;
+} sruid_t;
+
+int sruid_init(sruid_t *sid, char sep, char *cid);
+int sruid_next(sruid_t *sid);
+
+#endif
in order to avoid repeatedly trying dead cluster connection, how about
the following:
- define by cluster module param the default order in which connections
with same priority are tried
- if first connection in the list fails, move that connection to the end
of the list
advantage would be that there is no need to periodically (by counting or
timer) re-try dead connection.
default order could be taken from the order in which connections having
the same priority are listed in cluster param value.
comments?
-- juha