<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    Sorry guys,<br>
    <br>
    Wrong email address, wanted to email only Daniel<br>
    <br>
    Please ignore,<br>
    <br>
    Marius<br>
    -------- Original Message --------
    <table class="moz-email-headers-table" border="0" cellpadding="0"
      cellspacing="0">
      <tbody>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">Subject: </th>
          <td>Re: [sr-dev] git:master: lib/srutils: added small api for
            internal unique id generator</td>
        </tr>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">Date: </th>
          <td>Tue, 10 Apr 2012 14:33:36 +0300</td>
        </tr>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">From: </th>
          <td>Marius Zbihlei <a class="moz-txt-link-rfc2396E" href="mailto:marius.zbihlei@1and1.ro">&lt;marius.zbihlei@1and1.ro&gt;</a></td>
        </tr>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">To: </th>
          <td>Development mailing list of the sip-router project
            <a class="moz-txt-link-rfc2396E" href="mailto:sr-dev@lists.sip-router.org">&lt;sr-dev@lists.sip-router.org&gt;</a></td>
        </tr>
      </tbody>
    </table>
    <br>
    <br>
    <pre>Salut Daniel,

Am testat acest sruid si ma gandeam la o simpla modificare ... as vrea 
sa generez numere intr-adevar pseudorandom, asa ca am folosit un LFSR 
(Linear Feedback Shift Register) pentru a genera sruid-uri de genul :

new sruid is [srid.1.4f84198d.42f4.fbcd] (94 / 25)
new sruid is [srid.1.4f84198d.42f4.30d3] (95 / 25)
new sruid is [srid.1.4f84198d.42f4.ddd4] (96 / 25)
new sruid is [srid.1.4f84198d.42f4.2b5f] (97 / 25)
new sruid is [srid.1.4f84198d.42f4.66b6] (98 / 25)
new sruid is [srid.1.4f84198d.42f4.3b53] (99 / 25)
new sruid is [srid.1.4f84198d.42f4.589c] (100 / 25)

Codul e ff putin si optim (cateva linii de shift-uri pe biti si un XOR). 
Ce parerea ai , commit ?! sau e un motiv pt care doresti uid-uri sub forma ?

new sruid is [srid.1.4f8416f0.42c3.f5] (95 / 23)
new sruid is [srid.1.4f8416f0.42c3.06] (96 / 23)
new sruid is [srid.1.4f8416f0.42c3.16] (97 / 23)
new sruid is [srid.1.4f8416f0.42c3.26] (98 / 23)
new sruid is [srid.1.4f8416f0.42c3.36] (99 / 23)
new sruid is [srid.1.4f8416f0.42c3.46] (100 / 23)

Salutari,

M.
&gt; Module: sip-router
&gt; Branch: master
&gt; Commit: 0d544f04bb17b671341f8bff5c51cea1dba4dd35
&gt; URL:    <a class="moz-txt-link-freetext" href="http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0d544f04bb17b671341f8bff5c51cea1dba4dd35">http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0d544f04bb17b671341f8bff5c51cea1dba4dd35</a>
&gt;
&gt; Author: Daniel-Constantin Mierla<a class="moz-txt-link-rfc2396E" href="mailto:miconda@gmail.com">&lt;miconda@gmail.com&gt;</a>
&gt; Committer: Daniel-Constantin Mierla<a class="moz-txt-link-rfc2396E" href="mailto:miconda@gmail.com">&lt;miconda@gmail.com&gt;</a>
&gt; Date:   Tue Apr 10 12:18:35 2012 +0200
&gt;
&gt; lib/srutils: added small api for internal unique id generator
&gt;
&gt; - uses prefix, server id, timestamp, pid and a counter for an unique
&gt;    string
&gt;
&gt; ---
&gt;
&gt;   lib/srutils/sruid.c |  105 +++++++++++++++++++++++++++++++++++++++++++++++++++
&gt;   lib/srutils/sruid.h |   42 ++++++++++++++++++++
&gt;   2 files changed, 147 insertions(+), 0 deletions(-)
&gt;
&gt; diff --git a/lib/srutils/sruid.c b/lib/srutils/sruid.c
&gt; new file mode 100644
&gt; index 0000000..682a244
&gt; --- /dev/null
&gt; +++ b/lib/srutils/sruid.c
&gt; @@ -0,0 +1,105 @@
&gt; +/*new sruid is [srid.1.4f84198d.42f4.fbcd] (94 / 25)
&gt; new sruid is [srid.1.4f84198d.42f4.30d3] (95 / 25)
&gt; new sruid is [srid.1.4f84198d.42f4.ddd4] (96 / 25)
&gt; new sruid is [srid.1.4f84198d.42f4.2b5f] (97 / 25)
&gt; new sruid is [srid.1.4f84198d.42f4.66b6] (98 / 25)
&gt; new sruid is [srid.1.4f84198d.42f4.3b53] (99 / 25)
&gt; new sruid is [srid.1.4f84198d.42f4.589c]
&gt; + * $Id$
&gt; + *
&gt; + * sruid - unique id generator
&gt; + *
&gt; + * Copyright (C) 2012 Daniel-Constantin Mierla (asipto.com)
&gt; + *
&gt; + * This file is part of Kamailio, a free SIP server.
&gt; + *
&gt; + * Kamailio is free software; you can redistribute it and/or modify
&gt; + * it under the terms of the GNU General Public License as published by
&gt; + * the Free Software Foundation; either version 2 of the License, or
&gt; + * (at your option) any later version
&gt; + *
&gt; + * Kamailio is distributed in the hope that it will be useful,
&gt; + * but WITHOUT ANY WARRANTY; without even the implied warranty of
&gt; + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
&gt; + * GNU General Public License for more details.
&gt; + *
&gt; + * You should have received a copy of the GNU General Public License
&gt; + * along with this program; if not, write to the Free Software
&gt; + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
&gt; + */
&gt; +
&gt; +#include&lt;stdio.h&gt;
&gt; +#include&lt;unistd.h&gt;
&gt; +#include&lt;stdlib.h&gt;
&gt; +#include&lt;string.h&gt;
&gt; +#include&lt;time.h&gt;
&gt; +
&gt; +#include "../../dprint.h"
&gt; +#include "../../globals.h"
&gt; +#include "../../pt.h"
&gt; +
&gt; +#include "sruid.h"
&gt; +
&gt; +/**
&gt; + *
&gt; + */
&gt; +int sruid_init(sruid_t *sid, char sep, char *cid)
&gt; +{
&gt; +        int i;
&gt; +
&gt; +        if(sid==NULL)
&gt; +                return -1;
&gt; +        memset(sid, 0, sizeof(sruid_t));
&gt; +        memcpy(sid-&gt;buf, "srid", 4);
&gt; +        if(cid!=NULL)
&gt; +        {
&gt; +                for(i=0; i&lt;4&amp;&amp;  cid[i]!='\0'; i++)
&gt; +                        sid-&gt;buf[i] = cid[i];
&gt; +        }
&gt; +        sid-&gt;buf[4] = sep;
&gt; +
&gt; +        if(server_id!=0)
&gt; +                i = snprintf(sid-&gt;buf+5, SRUID_SIZE - 5 /*so far*/ - 8 /* extra int */,
&gt; +                        "%x%c%x%c%x%c", (unsigned int)server_id, sep,
&gt; +                        (unsigned int)time(NULL), sep, (unsigned int)my_pid(), sep);
&gt; +        else
&gt; +                i = snprintf(sid-&gt;buf+5, SRUID_SIZE - 5 /*so far*/ - 8 /* extra int */,
&gt; +                        "%x%c%x%c",
&gt; +                        (unsigned int)time(NULL), sep, (unsigned int)my_pid(), sep);
&gt; +        if(i&lt;=0 || i&gt;SRUID_SIZE-13)
&gt; +        {
&gt; +                LM_ERR("could not initialize sruid struct - output len: %d\n", i);
&gt; +                return -1;
&gt; +        }
&gt; +        sid-&gt;out = sid-&gt;buf + i + 5;
&gt; +        sid-&gt;uid.s = sid-&gt;buf;
&gt; +        LM_DBG("root for sruid is [%.*s] (%u / %d)\n", i+5, sid-&gt;uid.s,
&gt; +                        sid-&gt;counter, i+5);
&gt; +        return 0;
&gt; +}
&gt; +
&gt; +/**
&gt; + *
&gt; + */
&gt; +int sruid_next(sruid_t *sid)
&gt; +{
&gt; +        unsigned short digit;
&gt; +        int i;
&gt; +        unsigned int val;
&gt; +
&gt; +        if(sid==NULL)
&gt; +                return -1;
&gt; +
&gt; +        sid-&gt;counter++;
&gt; +        if(sid-&gt;counter==0)
&gt; +                sid-&gt;counter=1;
&gt; +
&gt; +        val = sid-&gt;counter;
&gt; +        i = 0;
&gt; +        while(val!=0)
&gt; +        {
&gt; +                digit =  val&amp;  0x0f;
&gt; +                sid-&gt;out[i++] = (digit&gt;= 10) ? digit + 'a' - 10 : digit + '0';
&gt; +                val&gt;&gt;= 4;
&gt; +        }
&gt; +        sid-&gt;out[i] = '\0';
&gt; +        sid-&gt;uid.len = sid-&gt;out + i - sid-&gt;buf;
&gt; +        LM_DBG("new sruid is [%.*s] (%u / %d)\n", sid-&gt;uid.len, sid-&gt;uid.s,
&gt; +                        sid-&gt;counter, sid-&gt;uid.len);
&gt; +        return 0;
&gt; +}
&gt; +
&gt; diff --git a/lib/srutils/sruid.h b/lib/srutils/sruid.h
&gt; new file mode 100644
&gt; index 0000000..b7c49ee
&gt; --- /dev/null
&gt; +++ b/lib/srutils/sruid.h
&gt; @@ -0,0 +1,42 @@
&gt; +/*
&gt; + * $Id$
&gt; + *
&gt; + * sruid - unique id generator
&gt; + *
&gt; + * Copyright (C) 2012 Daniel-Constantin Mierla (asipto.com)
&gt; + *
&gt; + * This file is part of Kamailio, a free SIP server.
&gt; + *
&gt; + * Kamailio is free software; you can redistribute it and/or modify
&gt; + * it under the terms of the GNU General Public License as published by
&gt; + * the Free Software Foundation; either version 2 of the License, or
&gt; + * (at your option) any later version
&gt; + *
&gt; + * Kamailio is distributed in the hope that it will be useful,
&gt; + * but WITHOUT ANY WARRANTY; without even the implied warranty of
&gt; + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
&gt; + * GNU General Public License for more details.
&gt; + *
&gt; + * You should have received a copy of the GNU General Public License
&gt; + * along with this program; if not, write to the Free Software
&gt; + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
&gt; + */
&gt; +
&gt; +#ifndef _SRUID_H_
&gt; +#define _SRUID_H_
&gt; +
&gt; +#include "../../str.h"
&gt; +
&gt; +#define SRUID_SIZE        40
&gt; +
&gt; +typedef struct sruid {
&gt; +        char buf[SRUID_SIZE];
&gt; +        char *out;
&gt; +        str uid;
&gt; +        unsigned int counter;
&gt; +} sruid_t;
&gt; +
&gt; +int sruid_init(sruid_t *sid, char sep, char *cid);
&gt; +int sruid_next(sruid_t *sid);
&gt; +
&gt; +#endif
&gt;
&gt;
&gt; _______________________________________________
&gt; sr-dev mailing list
&gt; <a class="moz-txt-link-abbreviated" href="mailto:sr-dev@lists.sip-router.org">sr-dev@lists.sip-router.org</a>
&gt; <a class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a>
&gt;


-- 
Zbihlei Marius

Head of
Linux Development Services Romania

1&amp;1 Internet Development srl    Tel KA: 754-9152
Str Mircea Eliade 18            Tel RO: +40-31-223-9152
Sect 1, Bucuresti               mailto: <a class="moz-txt-link-abbreviated" href="mailto:marius.zbihlei@1and1.ro">marius.zbihlei@1and1.ro</a>
71295, Romania

</pre>
  </body>
</html>