pua/event_list.c

Go to the documentation of this file.
00001 /*
00002  * $Id: event_list.c  2007-05-03 15:05:20Z anca_vamanu $
00003  *
00004  * pua module - presence user agent module
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * initial version 2007-05-03 (anca)
00025  */
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #include "../../str.h"
00031 #include "send_publish.h"
00032 #include "../../mem/shm_mem.h"
00033 #include "event_list.h"
00034 
00035 pua_event_t* init_pua_evlist(void)
00036 {
00037    pua_event_t* list= NULL;
00038 
00039    list= (pua_event_t*)shm_malloc(sizeof(pua_event_t));
00040    if(list== NULL)
00041    {
00042       LM_ERR("no more share memory\n");
00043       return NULL;
00044    }
00045    list->next= NULL;
00046    
00047    return list;
00048 
00049 }
00050 
00051 int add_pua_event(int ev_flag, char* name, char* content_type,
00052       evs_process_body_t* process_body)
00053 {
00054       
00055    pua_event_t* event= NULL;
00056    int size;
00057    int name_len;
00058    int ctype_len= 0;
00059    str str_name;  
00060 
00061    name_len= strlen(name);
00062    str_name.s= name;
00063    str_name.len= name_len;
00064 
00065    if(contains_pua_event(&str_name))
00066    {
00067       LM_DBG("Event already exists\n");
00068       return 0;
00069    }
00070    if(content_type)
00071       ctype_len= strlen(content_type);
00072 
00073    size= sizeof(pua_event_t)+ (name_len+ ctype_len)* sizeof(char);
00074 
00075    event= (pua_event_t*)shm_malloc(size);
00076    if(event== NULL)
00077    {
00078       LM_ERR("No more share memory\n");
00079       return -1;
00080    }  
00081    memset(event, 0, size);
00082    size= sizeof(pua_event_t);
00083 
00084    event->name.s= (char*)event+ size;
00085    memcpy(event->name.s, name, name_len);
00086    event->name.len= name_len;
00087    size+= name_len;
00088          
00089    if(content_type)
00090    {
00091       event->content_type.s= (char*)event+ size;
00092       memcpy(event->content_type.s, content_type, ctype_len);
00093       event->content_type.len= ctype_len;
00094       size+= ctype_len;    
00095    }
00096 
00097    event->process_body= process_body;
00098    event->ev_flag= ev_flag;
00099 
00100    event->next= pua_evlist->next;
00101    pua_evlist->next= event;
00102 
00103    return 0;
00104 }  
00105 
00106 pua_event_t* contains_pua_event(str* name)
00107 {
00108    pua_event_t* event;
00109    event= pua_evlist->next;
00110 
00111    while(event)
00112    {
00113       if(event->name.len== name->len &&
00114             strncmp(event->name.s, name->s, name->len)== 0)
00115       {
00116          return event;  
00117       }
00118       event= event->next;
00119    }  
00120 
00121    return NULL;   
00122 }
00123 
00124 pua_event_t* get_event(int ev_flag)
00125 {
00126    pua_event_t* event;
00127    event= pua_evlist->next;
00128 
00129    while(event)
00130    {
00131       if(event->ev_flag== ev_flag)
00132       {
00133          return event;  
00134       }
00135       event= event->next;
00136    }  
00137    return NULL;   
00138 }
00139 
00140 
00141 void destroy_pua_evlist(void)
00142 {
00143    pua_event_t* e1, *e2;
00144 
00145    if(pua_evlist)
00146    {
00147       e1= pua_evlist->next;
00148       while(e1)
00149       {
00150          e2= e1->next;
00151          shm_free(e1);
00152          e1= e2;
00153       }  
00154       shm_free(pua_evlist);
00155    }  
00156 
00157 }  

Generated on Thu May 24 08:00:49 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6