flat_id.c

Go to the documentation of this file.
00001 /* 
00002  * $Id: flat_id.c 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Flatstore module connection identifier
00005  *
00006  * Copyright (C) 2004 FhG Fokus
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 
00025 #include <string.h>
00026 #include "../../dprint.h"
00027 #include "../../mem/mem.h"
00028 #include "flat_id.h"
00029 
00030 
00031 
00032 /*
00033  * Create a new connection identifier
00034  */
00035 struct flat_id* new_flat_id(char* dir, char* table)
00036 {
00037    struct flat_id* ptr;
00038 
00039    if (!dir || !table) {
00040       LM_ERR("invalid parameter(s)\n");
00041       return 0;
00042    }
00043 
00044    ptr = (struct flat_id*)pkg_malloc(sizeof(struct flat_id));
00045    if (!ptr) {
00046       LM_ERR("no pkg memory left\n");
00047       return 0;
00048    }
00049    memset(ptr, 0, sizeof(struct flat_id));
00050 
00051    ptr->dir.s = dir;
00052    ptr->dir.len = strlen(dir);
00053    ptr->table.s = table;
00054    ptr->table.len = strlen(table);
00055 
00056    return ptr;
00057 }
00058 
00059 
00060 /*
00061  * Compare two connection identifiers
00062  */
00063 unsigned char cmp_flat_id(struct flat_id* id1, struct flat_id* id2)
00064 {
00065    if (!id1 || !id2) return 0;
00066    if (id1->dir.len != id2->dir.len) return 0;
00067    if (id1->table.len != id2->table.len) return 0;
00068 
00069    if (memcmp(id1->dir.s, id2->dir.s, id1->dir.len)) return 0;
00070    if (memcmp(id1->table.s, id2->table.s, id1->table.len)) return 0;
00071    return 1;
00072 }
00073 
00074 
00075 /*
00076  * Free a connection identifier
00077  */
00078 void free_flat_id(struct flat_id* id)
00079 {
00080    if (!id) return;
00081    pkg_free(id);
00082 }

Generated on Wed May 23 06:00:45 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6