<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    The problem is that you declare the array in the private space of
    each process.<br>
    <br>
    Kamailio is a multi process application, a running instance starting
    several processes. Because you want to work on the same array from
    different processes, you must allocate that array in shared memory:<br>
    <br>
    When your module is initialized, you have to use shm_malloc()... to
    allocate the array. Some details about memory manager functions in
    kamailio at:<br>
    - <a class="moz-txt-link-freetext" href="http://www.asipto.com/pub/kamailio-devel-guide/#c04memory">http://www.asipto.com/pub/kamailio-devel-guide/#c04memory</a><br>
    <br>
    Also, you have to use locks to access the array, because many
    processes can try to read/write from same location, due to parallel
    processing.<br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <div class="moz-cite-prefix">On 2/7/13 6:05 AM, kiran bhosale wrote:<br>
    </div>
    <blockquote cite="mid:5113362B.1070903@synteltelecom.com"
      type="cite">he array values that&nbsp; we are modifying and the
      function that&nbsp; we&nbsp; call periodically&nbsp; are&nbsp;&nbsp; from our&nbsp; module&nbsp; . to
      exemplify i have put&nbsp; the code below .our requirement is that we
      want to delete the expired&nbsp; contacts without&nbsp; relying on usrloc
      module as "we&nbsp; have&nbsp; not used&nbsp; any DB for&nbsp; contact&nbsp; storage" but
      developed our own module for storing&nbsp; them in a&nbsp; file.even we&nbsp; had
      installed&nbsp; the&nbsp; SIGALRM handler&nbsp; in our&nbsp; module for decrementing&nbsp;
      the contacts&nbsp; but the values of array (that stores the expires)
      elements were zero. we thought&nbsp; of workaround to store&nbsp; the
      expires values&nbsp; to file&nbsp; and&nbsp; decrement them periodically. but
      frequent&nbsp; I/O&nbsp; is very consuming. whats&nbsp; the solution for deleting
      the expired&nbsp; contacts .
      <br>
      <br>
      <br>
      #define DB_PATH "/usr/local/etc/kamailio/dbtext/syntel"
      <br>
      #define DB_PATH1 "/usr/local/etc/kamailio/dbtext/temp"
      <br>
      #define MAX_BUFFER 128
      <br>
      #define MAX_USERS 128
      <br>
      typedef struct
      <br>
      {
      <br>
      int max_bindings;
      <br>
      &nbsp;int&nbsp; syntel_index;
      <br>
      &nbsp;int&nbsp; expires[8];
      <br>
      char ip_addr[8][16];
      <br>
      } Syntel_users;
      <br>
      <br>
      <br>
      Syntel_users syntel_database[16]={{0}};
      <br>
      <br>
      <br>
      <br>
      //this&nbsp; is&nbsp; function used for&nbsp; storing the contacts
      <br>
      <br>
      int
      <br>
      write_to_file (char *uri, char *user, int locator,int expires)
      <br>
      {
      <br>
      int Retval = 0;
      <br>
      int fd;
      <br>
      int bytes;
      <br>
      char ip[13];
      <br>
      strncpy (ip, &amp;uri[9], 12);
      <br>
      ip[12] = '\0';
      <br>
      fd = open (DB_PATH, O_CREAT | O_RDWR | O_APPEND, 0777);
      <br>
      if (syntel_database[locator].max_bindings &lt; 8)
      <br>
      &nbsp; {
      <br>
      &nbsp;&nbsp;&nbsp; strcpy
      (syntel_database[locator].ip_addr[syntel_database[locator].max_bindings],
      uri);
      <br>
      &nbsp;&nbsp;&nbsp;
      syntel_database[locator].expires[syntel_database[locator].max_bindings]=expires;
      <br>
      &nbsp;&nbsp;&nbsp; syntel_database[locator].max_bindings++;
      <br>
      &nbsp;&nbsp;&nbsp; bytes = write (fd, uri, strlen (uri));
      <br>
      &nbsp;&nbsp;&nbsp; Retval = 1;
      <br>
      &nbsp; }
      <br>
      return Retval;
      <br>
      }
      <br>
      <br>
      //AND THIS IS&nbsp; FUNCTION WE CALL FROM&nbsp; kamailio.conf WITH RTIMER
      MODULE AFTER INTERVAL OF&nbsp; 1&nbsp; SECOND.
      <br>
      <br>
      <br>
      int syntel_delete (void)
      <br>
      {
      <br>
      int counter;
      <br>
      int j;
      <br>
      for (counter = 0; counter &lt; 16; counter++)
      <br>
      &nbsp; {
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (j = 0; j &lt; syntel_database[counter].max_bindings;
      j++)
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
      <br>
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(syntel_database[counter].expires[j]&lt;=0)
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      memset(syntel_database[counter].ip_addr[j],0,strlen(syntel_database[counter].ip_addr[j]));
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; syntel_database[counter].max_bindings--;
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; syntel_database[counter].expires[j]--;
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
      <br>
      <br>
      &nbsp; }
      <br>
      &nbsp; return 0;
      <br>
      }
      <br>
      <br>
      BUT WHAT&nbsp; THIS&nbsp; FUNCTION GETS&nbsp; IS&nbsp; ZERO VALUES&nbsp; FOR&nbsp; EXPIRES AND
      NOT MODIFIED IN&nbsp; SYNTEL_WRITE_TO_FILE
      <br>
      <br>
      <br>
      HOW&nbsp; TO DECREMENT THESE VALUES PERIODICALLY THEN ??
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>
<a class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla - <a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a>
<a class="moz-txt-link-freetext" href="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</a> - <a class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a>
Kamailio World Conference, April 16-17, 2013, Berlin
 - <a class="moz-txt-link-freetext" href="http://conference.kamailio.com">http://conference.kamailio.com</a> -</pre>
  </body>
</html>