| 868 | } |
| 869 | |
| 870 | static int parse_collections(unsigned int type, void* val) |
| 871 | { |
| 872 | unsigned coll_size; |
| 873 | str collection_list, coll; |
| 874 | lcache_col_t *new_col, *it; |
| 875 | csv_record *cols, *col, *kv; |
| 876 | int replicated; |
| 877 | |
| 878 | if (!val) { |
| 879 | LM_ERR("null collection list!\n"); |
| 880 | return -1; |
| 881 | } |
| 882 | |
| 883 | init_str(&collection_list, (char *)val); |
| 884 | cols = __parse_csv_record(&collection_list, 0, ';'); |
| 885 | if (!cols) |
| 886 | goto bad_input; |
| 887 | |
| 888 | for (col = cols; col; col = col->next) { |
| 889 | kv = __parse_csv_record(&col->s, 0, '='); |
| 890 | if (!kv) |
| 891 | goto bad_input; |
| 892 | coll = kv->s; |
| 893 | |
| 894 | if (kv->next) { |
| 895 | if (str2int(&kv->next->s, &coll_size) < 0) { |
| 896 | LM_ERR("invalid hash size <%.*s>!\n", kv->next->s.len, kv->next->s.s); |
| 897 | goto bad_input; |
| 898 | } |
| 899 | } else { |
| 900 | coll_size = HASH_SIZE_DEFAULT; |
| 901 | } |
| 902 | |
| 903 | if (ZSTR(coll)) { |
| 904 | LM_DBG("skipping empty-string collection: ''!\n"); |
| 905 | continue; |
| 906 | } |
| 907 | |
| 908 | if (coll.s[coll.len-2] == '/' && coll.s[coll.len-1] == 'r') { |
| 909 | coll.len -= 2; |
| 910 | replicated = 1; |
| 911 | } else { |
| 912 | replicated = 0; |
| 913 | } |
| 914 | |
| 915 | LM_DBG("creating collection '%.*s' with hash_size %d\n", |
| 916 | coll.len, coll.s, coll_size); |
| 917 | |
| 918 | /* check if the collection was already defined */ |
| 919 | for ( it=lcache_collection; it; it = it->next ) { |
| 920 | if ( !str_strcmp( &coll, &it->col_name)) { |
| 921 | LM_ERR("collection <%.*s> defined more than once!\n", |
| 922 | coll.len, coll.s); |
| 923 | return -1; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | /* create the new collection */ |
nothing calls this directly
no test coverage detected