[SR-Users] [Fwd: Re: Deleting the expired contacts using the Rtimer module]

kiran bhosale kbhosale at synteltelecom.com
Thu Feb 7 06:05:47 CET 2013


he array values that  we are modifying and the function that  we  call 
periodically  are   from our  module  . to exemplify i have put  the 
code below .our requirement is that we want to delete the expired  
contacts without  relying on usrloc module as "we  have  not used  any 
DB for  contact  storage" but developed our own module for storing  them 
in a  file.even we  had installed  the  SIGALRM handler  in our  module 
for decrementing  the contacts  but the values of array (that stores the 
expires) elements were zero. we thought  of workaround to store  the 
expires values  to file  and  decrement them periodically. but frequent  
I/O  is very consuming. whats  the solution for deleting the expired  
contacts .


#define DB_PATH "/usr/local/etc/kamailio/dbtext/syntel"
#define DB_PATH1 "/usr/local/etc/kamailio/dbtext/temp"
#define MAX_BUFFER 128
#define MAX_USERS 128
typedef struct
{
 int max_bindings;
  int  syntel_index;
  int  expires[8];
 char ip_addr[8][16];
} Syntel_users;


Syntel_users syntel_database[16]={{0}};



//this  is  function used for  storing the contacts

int
write_to_file (char *uri, char *user, int locator,int expires)
{
 int Retval = 0;
 int fd;
 int bytes;
 char ip[13];
 strncpy (ip, &uri[9], 12);
 ip[12] = '\0';
 fd = open (DB_PATH, O_CREAT | O_RDWR | O_APPEND, 0777);
 if (syntel_database[locator].max_bindings < 8)
   {
     strcpy 
(syntel_database[locator].ip_addr[syntel_database[locator].max_bindings], 
uri);
     
syntel_database[locator].expires[syntel_database[locator].max_bindings]=expires; 

     syntel_database[locator].max_bindings++;
     bytes = write (fd, uri, strlen (uri));
     Retval = 1;
   }
 return Retval;
}

//AND THIS IS  FUNCTION WE CALL FROM  kamailio.conf WITH RTIMER MODULE 
AFTER INTERVAL OF  1  SECOND.


int syntel_delete (void)
{
 int counter;
 int j;
 for (counter = 0; counter < 16; counter++)
   {
       for (j = 0; j < syntel_database[counter].max_bindings; j++)
       {

           if(syntel_database[counter].expires[j]<=0)
           {
                            
memset(syntel_database[counter].ip_addr[j],0,strlen(syntel_database[counter].ip_addr[j])); 

              syntel_database[counter].max_bindings--;
           }
           else
           syntel_database[counter].expires[j]--;
                 }
 
   }
   return 0;
}

BUT WHAT  THIS  FUNCTION GETS  IS  ZERO VALUES  FOR  EXPIRES AND NOT 
MODIFIED IN  SYNTEL_WRITE_TO_FILE


HOW  TO DECREMENT THESE VALUES PERIODICALLY THEN ??






-------------- next part --------------
An embedded message was scrubbed...
From: kiran bhosale <kbhosale at synteltelecom.com>
Subject: Re: [SR-Users] Deleting the expired contacts  using the Rtimer module
Date: Thu, 07 Feb 2013 10:30:39 +0530
Size: 4639
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20130207/53dcae06/attachment.eml>


More information about the sr-users mailing list