/** * "pdt.list" parameters: * sdomain * prefix * domain * * - '.' (dot) means NULL value and will match anything * - the comparison operation is 'START WITH' -- if domain is 'a' then * all domains starting with 'a' are listed * * Examples * pdt_list o 2 . - lists the entries where sdomain is starting with 'o', * prefix is starting with '2' and domain is anything * * pdt_list . 2 open - lists the entries where sdomain is anything, prefix * starts with '2' and domain starts with 'open' */ static void pdt_rpc_list(rpc_t* rpc, void* ctx) { str sdomain = {0}; str tprefix = {0}; str tdomain = {0}; pdt_tree_t *pt; unsigned int i; static char code_buf[PDT_MAX_DEPTH+1]; int len; str *cl; pdt_tree_t **ptree; void* th; void* ih; ptree = pdt_get_ptree(); if(ptree==NULL || *ptree==NULL) { LM_ERR("empty domain list\n"); rpc->fault(ctx, 404, "No records"); return; } len = rpc->scan(ctx, "*S.SS", &sdomain, &tprefix, &tdomain); if(len<0) { rpc->fault(ctx, 500, "Error Reading Parameters"); return; } if(len<1 || sdomain.len==0 || (sdomain.len==1 && sdomain.s[0]=='.')) { sdomain.len = 0; sdomain.s = 0; } cl = pdt_get_char_list(); if(len<2 || tprefix.len==0 || (tprefix.len==1 && tprefix.s[0]=='.')) { tprefix.len = 0; tprefix.s = 0; } else if(tprefix.len>0) { /* validate prefix */ i = 0; while(tprefix.s!=NULL && i!=tprefix.len) { if(strpos(cl->s, tprefix.s[i]) < 0) { LM_ERR("bad prefix [%.*s]\n", tprefix.len, tprefix.s); rpc->fault(ctx, 400, "Bad Prefix"); return; } i++; } } if(len<3 || tdomain.len==0 || (tdomain.len==1 && tdomain.s[0]=='.')) { tdomain.len = 0; tdomain.s = 0; } pt = *ptree; if (rpc->add(ctx, "{", &th) < 0) { rpc->fault(ctx, 500, "Internal error root reply"); return; } while(pt!=NULL) { LM_ERR("---- 1 (%d [%.*s])\n", sdomain.len, sdomain.len, sdomain.s); if(sdomain.s==NULL || (sdomain.s!=NULL && pt->sdomain.len>=sdomain.len && strncmp(pt->sdomain.s, sdomain.s, sdomain.len)==0)) { LM_ERR("---- 2\n"); len = 0; if(rpc->struct_add(th, "S{", "SDOMAIN", &pt->sdomain, "RECORDS", &ih)<0) { rpc->fault(ctx, 500, "Internal error creating sdomain structure"); return; } if(pdt_rpc_print_node(rpc, ctx, ih, pt->head, code_buf, len, &pt->sdomain, &tdomain, &tprefix)<0) goto error; } pt = pt->next; } return; error: rpc->fault(ctx, 500, "Internal error printing records"); return; }
struct mi_root* pdt_mi_list(struct mi_root* cmd_tree, void* param) { str sd, sp, sdomain; pdt_tree_t *pt; struct mi_node* node = NULL; unsigned int i= 0; struct mi_root* rpl_tree = NULL; struct mi_node* rpl = NULL; static char code_buf[PDT_MAX_DEPTH+1]; int len; str *cl; pdt_tree_t **ptree; ptree = pdt_get_ptree(); if(ptree==NULL) { LM_ERR("empty domain list\n"); return init_mi_tree( 500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN); } cl = pdt_get_char_list(); /* read sdomain */ sdomain.s = 0; sdomain.len = 0; sp.s = 0; sp.len = 0; sd.s = 0; sd.len = 0; node = cmd_tree->node.kids; if(node != NULL) { sdomain = node->value; if(sdomain.s == NULL || sdomain.len== 0) return init_mi_tree( 404, "domain not found", 16); if(*sdomain.s=='.') sdomain.s = 0; /* read prefix */ node = node->next; if(node != NULL) { sp= node->value; if(sp.s== NULL || sp.len==0 || *sp.s=='.') sp.s = NULL; else { while(sp.s!=NULL && i!=sp.len) { if(strpos(cl->s, sp.s[i]) < 0) { LM_ERR("bad prefix [%.*s]\n", sp.len, sp.s); return init_mi_tree( 400, "bad prefix", 10); } i++; } } /* read domain */ node= node->next; if(node != NULL) { sd= node->value; if(sd.s== NULL || sd.len==0 || *sd.s=='.') sd.s = NULL; } } } rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN); if(rpl_tree == NULL) return 0; rpl = &rpl_tree->node; if(*ptree==0) return rpl_tree; pt = *ptree; while(pt!=NULL) { if(sdomain.s==NULL || (sdomain.s!=NULL && pt->sdomain.len>=sdomain.len && strncmp(pt->sdomain.s, sdomain.s, sdomain.len)==0)) { len = 0; if(pdt_print_mi_node(pt->head, rpl, code_buf, len, &pt->sdomain, &sd, &sp)<0) goto error; } pt = pt->next; } return rpl_tree; error: free_mi_tree(rpl_tree); return 0; }