flat_id.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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
00077
00078 void free_flat_id(struct flat_id* id)
00079 {
00080 if (!id) return;
00081 pkg_free(id);
00082 }