Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
meta_data.h File Reference

Go to the source code of this file.

Macros

#define METADATA_DLR_GROUP   "dlr"
 
#define METADATA_DLR_GROUP_DONETIME   "donetime"
 
#define METADATA_DLR_GROUP_SUBMITTIME   "submittime"
 
#define METADATA_DLR_GROUP_ERRORCODE   "errorcode"
 
#define METADATA_ORIG_MSG_GROUP   "orig_msg"
 
#define METADATA_ORIG_MSG_GROUP_DLR_MASK   "dlr_mask"
 
#define METADATA_SMPP_GROUP   "smpp"
 

Functions

Dictmeta_data_get_values (const Octstr *data, const char *group)
 
int meta_data_set_values (Octstr *data, const Dict *dict, const char *group, int replace)
 
int meta_data_set_value (Octstr *data, const char *group, const Octstr *key, const Octstr *value, int replace)
 
Octstrmeta_data_get_value (Octstr *data, const char *group, const Octstr *key)
 
Octstrmeta_data_merge (const Octstr *data, const Octstr *new_data, int replace)
 

Macro Definition Documentation

#define METADATA_DLR_GROUP   "dlr"

Definition at line 68 of file meta_data.h.

Referenced by generic_receive_sms(), and kannel_receive_sms().

#define METADATA_DLR_GROUP_DONETIME   "donetime"

Definition at line 69 of file meta_data.h.

#define METADATA_DLR_GROUP_ERRORCODE   "errorcode"

Definition at line 71 of file meta_data.h.

Referenced by generic_receive_sms(), and kannel_receive_sms().

#define METADATA_DLR_GROUP_SUBMITTIME   "submittime"

Definition at line 70 of file meta_data.h.

#define METADATA_ORIG_MSG_GROUP   "orig_msg"

Definition at line 73 of file meta_data.h.

Referenced by create_dlr_from_msg(), and dlr_find().

#define METADATA_ORIG_MSG_GROUP_DLR_MASK   "dlr_mask"

Definition at line 74 of file meta_data.h.

Referenced by create_dlr_from_msg(), and dlr_find().

#define METADATA_SMPP_GROUP   "smpp"

Definition at line 76 of file meta_data.h.

Referenced by msg_to_pdu().

Function Documentation

Octstr* meta_data_get_value ( Octstr data,
const char *  group,
const Octstr key 
)

Get value for a given group and key.

Definition at line 368 of file meta_data.c.

References dict_remove(), meta_data::group, meta_data_destroy(), meta_data_unpack(), meta_data::next, octstr_str_case_compare(), and meta_data::values.

Referenced by msg_to_pdu(), and urltrans_fill_escape_codes().

369 {
370  struct meta_data *mdata, *curr;
371  Octstr *ret = NULL;
372 
373  if (data == NULL || group == NULL || key == NULL)
374  return NULL;
375 
376  mdata = meta_data_unpack(data);
377  if (mdata == NULL)
378  return NULL;
379  for (curr = mdata; curr != NULL; curr = curr->next) {
380  if (octstr_str_case_compare(curr->group, group) == 0) {
381  ret = dict_remove(curr->values, (Octstr *) key);
382  break;
383  }
384  }
385 
386  meta_data_destroy(mdata);
387 
388  return ret;
389 }
Octstr * group
Definition: meta_data.c:70
int octstr_str_case_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:984
Dict * values
Definition: meta_data.c:71
struct meta_data * next
Definition: meta_data.c:72
void * dict_remove(Dict *dict, Octstr *key)
Definition: dict.c:307
static void meta_data_destroy(struct meta_data *meta)
Definition: meta_data.c:89
Definition: octstr.c:118
static struct meta_data * meta_data_unpack(const Octstr *data)
Definition: meta_data.c:107
Dict* meta_data_get_values ( const Octstr data,
const char *  group 
)

Get Dictionary with all values for this group.

Definition at line 248 of file meta_data.c.

References meta_data::group, meta_data_destroy(), meta_data_unpack(), meta_data::next, octstr_str_case_compare(), and meta_data::values.

Referenced by msg_to_pdu().

249 {
250  struct meta_data *mdata, *curr;
251  Dict *ret = NULL;
252 
253  if (data == NULL || group == NULL)
254  return NULL;
255 
256  mdata = meta_data_unpack(data);
257  if (mdata == NULL)
258  return NULL;
259  for (curr = mdata; curr != NULL; curr = curr->next) {
260  if (octstr_str_case_compare(curr->group, group) == 0) {
261  ret = curr->values;
262  curr->values = NULL;
263  break;
264  }
265  }
266 
267  meta_data_destroy(mdata);
268 
269  return ret;
270 }
Octstr * group
Definition: meta_data.c:70
int octstr_str_case_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:984
Dict * values
Definition: meta_data.c:71
struct meta_data * next
Definition: meta_data.c:72
Definition: dict.c:116
static void meta_data_destroy(struct meta_data *meta)
Definition: meta_data.c:89
static struct meta_data * meta_data_unpack(const Octstr *data)
Definition: meta_data.c:107
Octstr* meta_data_merge ( const Octstr data,
const Octstr new_data,
int  replace 
)

Merge two meta data strings into one

Definition at line 392 of file meta_data.c.

References dict_create(), dict_get(), dict_keys(), dict_put(), dict_put_once(), error(), meta_data::group, gwlist_consume(), gwlist_destroy(), meta_data_create(), meta_data_destroy(), meta_data_pack(), meta_data_unpack(), meta_data::next, octstr_compare(), octstr_create, octstr_destroy(), octstr_destroy_item(), octstr_duplicate, octstr_get_cstr, octstr_len(), and meta_data::values.

393 {
394  Octstr *ret = NULL;
395  struct meta_data *mdata, *new_mdata, *new_curr, *curr;
396 
397  if (octstr_len(data) < 1)
398  return octstr_duplicate(new_data);
399  if (octstr_len(new_data) < 1)
400  return octstr_duplicate(data);
401 
402  mdata = meta_data_unpack(data);
403  if (mdata == NULL) {
404  error(0, "meta_data_merge: Unable to parse data `%s'", octstr_get_cstr(data));
405  return octstr_duplicate(new_data);
406  }
407  new_mdata = meta_data_unpack(new_data);
408  if (new_mdata == NULL) {
409  meta_data_destroy(mdata);
410  error(0, "meta_data_merge: Unable to parse data `%s'", octstr_get_cstr(new_data));
411  return octstr_duplicate(data);
412  }
413  for (new_curr = new_mdata; new_curr != NULL; new_curr = new_curr->next) {
414  for (curr = mdata; curr != NULL; curr = curr->next) {
415  /* check group name */
416  if (octstr_compare(curr->group, new_curr->group) == 0) {
417  /* match */
418  List *keys;
419  Octstr *key;
420 
421  keys = dict_keys(new_curr->values);
422  while((key = gwlist_consume(keys)) != NULL) {
423  if (replace == 0) {
424  dict_put_once(curr->values, key, octstr_duplicate(dict_get(new_curr->values, key)));
425  } else {
426  /* remove if any */
427  dict_put(curr->values, key, NULL);
428  dict_put(curr->values, key, octstr_duplicate(dict_get(new_curr->values, key)));
429  }
430  octstr_destroy(key);
431  }
433  break; /* we found mdata group */
434  } else if (curr->next == NULL) {
435  /* do not match and this is last value -> add group */
436  curr->next = meta_data_create();
437  curr->next->group = octstr_duplicate(new_curr->group);
439  }
440  }
441  }
442  ret = octstr_create("");
443  if (meta_data_pack(mdata, ret) == -1) {
444  octstr_destroy(ret);
445  ret = NULL;
446  }
447  meta_data_destroy(new_mdata);
448  meta_data_destroy(mdata);
449 
450  return ret;
451 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
void error(int err, const char *fmt,...)
Definition: log.c:612
Octstr * group
Definition: meta_data.c:70
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
Dict * values
Definition: meta_data.c:71
struct meta_data * next
Definition: meta_data.c:72
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static void meta_data_destroy(struct meta_data *meta)
Definition: meta_data.c:89
static struct meta_data * meta_data_create(void)
Definition: meta_data.c:76
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
static int meta_data_pack(struct meta_data *mdata, Octstr *data)
Definition: meta_data.c:224
void * gwlist_consume(List *list)
Definition: list.c:427
List * dict_keys(Dict *dict)
Definition: dict.c:347
int dict_put_once(Dict *dict, Octstr *key, void *value)
Definition: dict.c:271
static struct meta_data * meta_data_unpack(const Octstr *data)
Definition: meta_data.c:107
Definition: list.c:102
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
int meta_data_set_value ( Octstr data,
const char *  group,
const Octstr key,
const Octstr value,
int  replace 
)

Set or replace value for a given group and key.

Definition at line 324 of file meta_data.c.

References dict_create(), dict_get(), dict_put(), meta_data::group, meta_data_create(), meta_data_destroy(), meta_data_pack(), meta_data_unpack(), meta_data::next, octstr_create, octstr_destroy_item(), octstr_duplicate, octstr_str_case_compare(), and meta_data::values.

Referenced by create_dlr_from_msg(), dlr_find(), generic_receive_sms(), handle_dlr(), and kannel_receive_sms().

325 {
326  struct meta_data *mdata, *curr;
327  int ret = 0;
328 
329  if (data == NULL || group == NULL || value == NULL)
330  return -1;
331 
332  mdata = meta_data_unpack(data);
333  for (curr = mdata; curr != NULL; curr = curr->next) {
334  if (octstr_str_case_compare(curr->group, group) == 0)
335  break;
336  }
337  if (curr == NULL) {
338  /* group doesn't exists */
339  curr = meta_data_create();
340  curr->group = octstr_create(group);
342  if (mdata != NULL) {
343  curr->next = mdata->next;
344  mdata->next = curr;
345  } else {
346  mdata = curr;
347  }
348  }
349  if (replace) {
350  /* delete old value if any */
351  dict_put(curr->values, (Octstr *) key, NULL);
352  /* put new value */
353  dict_put(curr->values, (Octstr *) key, octstr_duplicate(value));
354  } else if (dict_get(curr->values, (Octstr *) key) == NULL) {
355  /* put new value */
356  dict_put(curr->values, (Octstr *) key, octstr_duplicate(value));
357  }
358 
359  /* pack it */
360  ret = meta_data_pack(mdata, data);
361 
362  meta_data_destroy(mdata);
363 
364  return ret;
365 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
Octstr * group
Definition: meta_data.c:70
int octstr_str_case_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:984
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
Dict * values
Definition: meta_data.c:71
struct meta_data * next
Definition: meta_data.c:72
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static void meta_data_destroy(struct meta_data *meta)
Definition: meta_data.c:89
static struct meta_data * meta_data_create(void)
Definition: meta_data.c:76
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
Definition: octstr.c:118
static int meta_data_pack(struct meta_data *mdata, Octstr *data)
Definition: meta_data.c:224
static struct meta_data * meta_data_unpack(const Octstr *data)
Definition: meta_data.c:107
int meta_data_set_values ( Octstr data,
const Dict dict,
const char *  group,
int  replace 
)

Replace Dictionary for the given group.

Definition at line 273 of file meta_data.c.

References dict_destroy(), dict_get(), dict_keys(), dict_put_once(), meta_data::group, gwlist_destroy(), gwlist_extract_first(), meta_data_create(), meta_data_destroy(), meta_data_pack(), meta_data_unpack(), meta_data::next, octstr_create, octstr_destroy(), octstr_destroy_item(), octstr_duplicate, octstr_str_case_compare(), and meta_data::values.

Referenced by data_sm_to_msg(), handle_pdu(), and pdu_to_msg().

274 {
275  struct meta_data *mdata, *curr;
276  int i;
277  List *keys;
278  Octstr *key;
279 
280  if (data == NULL || group == NULL)
281  return -1;
282 
283  mdata = meta_data_unpack(data);
284  for (curr = mdata; curr != NULL; curr = curr->next) {
285  if (octstr_str_case_compare(curr->group, group) == 0) {
286  /*
287  * If we don't replace the values, copy the old Dict values to the new Dict
288  */
289  if (replace == 0) {
290  keys = dict_keys(curr->values);
291  while((key = gwlist_extract_first(keys)) != NULL) {
292  dict_put_once((Dict*)dict, key, octstr_duplicate(dict_get(curr->values, key)));
293  octstr_destroy(key);
294  }
296  }
297  dict_destroy(curr->values);
298  curr->values = (Dict*)dict;
299  break;
300  }
301  }
302 
303  if (curr == NULL) {
304  curr = meta_data_create();
305  curr->group = octstr_create(group);
306  curr->values = (Dict*)dict;
307  curr->next = NULL;
308  if (mdata == NULL) {
309  mdata = curr;
310  } else {
311  curr->next = mdata->next;
312  mdata->next = curr;
313  }
314  }
315  i = meta_data_pack(mdata, data);
316  curr->values = NULL;
317 
318  meta_data_destroy(mdata);
319 
320  return i;
321 }
Octstr * group
Definition: meta_data.c:70
int octstr_str_case_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:984
Dict * values
Definition: meta_data.c:71
struct meta_data * next
Definition: meta_data.c:72
void * gwlist_extract_first(List *list)
Definition: list.c:305
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
Definition: dict.c:116
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static void meta_data_destroy(struct meta_data *meta)
Definition: meta_data.c:89
static struct meta_data * meta_data_create(void)
Definition: meta_data.c:76
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
void dict_destroy(Dict *dict)
Definition: dict.c:215
Definition: octstr.c:118
static int meta_data_pack(struct meta_data *mdata, Octstr *data)
Definition: meta_data.c:224
List * dict_keys(Dict *dict)
Definition: dict.c:347
int dict_put_once(Dict *dict, Octstr *key, void *value)
Definition: dict.c:271
static struct meta_data * meta_data_unpack(const Octstr *data)
Definition: meta_data.c:107
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.