1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/*
* $Id: flat_id.c,v 1.1.1.1 2005/06/13 16:47:38 bogdan_iancu Exp $
*
* Flatstore module connection identifier
*
* Copyright (C) 2004 FhG Fokus
*
* This file is part of openser, a free SIP server.
*
* openser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* openser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include "../../dprint.h"
#include "../../mem/mem.h"
#include "flat_id.h"
/*
* Create a new connection identifier
*/
struct flat_id* new_flat_id(char* dir, char* table)
{
struct flat_id* ptr;
if (!dir || !table) {
LOG(L_ERR, "new_flat_id: Invalid parameter(s)\n");
return 0;
}
ptr = (struct flat_id*)pkg_malloc(sizeof(struct flat_id));
if (!ptr) {
LOG(L_ERR, "new_flat_id: No memory left\n");
return 0;
}
memset(ptr, 0, sizeof(struct flat_id));
ptr->dir.s = dir;
ptr->dir.len = strlen(dir);
ptr->table.s = table;
ptr->table.len = strlen(table);
return ptr;
}
/*
* Compare two connection identifiers
*/
unsigned char cmp_flat_id(struct flat_id* id1, struct flat_id* id2)
{
if (!id1 || !id2) return 0;
if (id1->dir.len != id2->dir.len) return 0;
if (id1->table.len != id2->table.len) return 0;
if (memcmp(id1->dir.s, id2->dir.s, id1->dir.len)) return 0;
if (memcmp(id1->table.s, id2->table.s, id1->table.len)) return 0;
return 1;
}
/*
* Free a connection identifier
*/
void free_flat_id(struct flat_id* id)
{
if (!id) return;
pkg_free(id);
}
|