|
|
|
@ -87,3 +87,78 @@ int sxstream_generic_slist_additem(list_head_t *list, const char *value)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sxstream_generic_nmlist_additem(list_head_t *list, const char *name, int order)
|
|
|
|
|
{
|
|
|
|
|
struct _stream_named_order_node *entry = malloc(sizeof(struct _stream_named_order_node));
|
|
|
|
|
size_t name_len = 0;
|
|
|
|
|
|
|
|
|
|
if(!entry || !list) return -1;
|
|
|
|
|
if(!name) {
|
|
|
|
|
__enomem:
|
|
|
|
|
free(entry);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check up */
|
|
|
|
|
if(strchr(name, '"')) goto __enomem;
|
|
|
|
|
else name_len = strlen(name) + 2*sizeof(char);
|
|
|
|
|
|
|
|
|
|
if(!(entry->name = malloc(name_len))) goto __enomem;
|
|
|
|
|
else snprintf(entry->name, name_len, ":%s", name);
|
|
|
|
|
entry->order = order;
|
|
|
|
|
|
|
|
|
|
/* add to list */
|
|
|
|
|
list_init_node(&entry->node);
|
|
|
|
|
list_add2tail(list, &entry->node);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sxstream_generic_named_free(list_head_t *list)
|
|
|
|
|
{
|
|
|
|
|
struct _stream_named_order_node *entry;
|
|
|
|
|
list_node_t *iter, *siter;
|
|
|
|
|
|
|
|
|
|
if(!list) return;
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(list, iter, siter) {
|
|
|
|
|
entry = list_entry(iter, struct _stream_named_order_node, node);
|
|
|
|
|
list_del(iter);
|
|
|
|
|
free(entry->name);
|
|
|
|
|
free(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(list);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *sxstream_generic_named_lookupname(list_head_t *list, int order)
|
|
|
|
|
{
|
|
|
|
|
struct _stream_named_order_node *entry;
|
|
|
|
|
list_node_t *iter, *siter;
|
|
|
|
|
|
|
|
|
|
if(!list) return NULL;
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(list, iter, siter) {
|
|
|
|
|
entry = list_entry(iter, struct _stream_named_order_node, node);
|
|
|
|
|
if(entry->order == order) return entry->name + sizeof(char);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sxstream_generic_named_lookuporder(list_head_t *list, const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct _stream_named_order_node *entry;
|
|
|
|
|
list_node_t *iter, *siter;
|
|
|
|
|
|
|
|
|
|
if(!list || !name) return -1;
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(list, iter, siter) {
|
|
|
|
|
entry = list_entry(iter, struct _stream_named_order_node, node);
|
|
|
|
|
if(!strcmp(entry->name + sizeof(char), name)) return entry->order;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|