| 177 return result; |
177 return result; |
| 178 } |
178 } |
| 179 |
179 |
| 180 cxmutstr dav_format_string(const CxAllocator *a, cxstring fstr, DavQLArgList *ap, davqlerror_t *error) { |
180 cxmutstr dav_format_string(const CxAllocator *a, cxstring fstr, DavQLArgList *ap, davqlerror_t *error) { |
| 181 CxBuffer buf; |
181 CxBuffer buf; |
| 182 cxBufferInit(&buf, NULL, 128, a, CX_BUFFER_AUTO_EXTEND); |
182 cxBufferInit(&buf, a, NULL, 128, CX_BUFFER_AUTO_EXTEND); |
| 183 |
183 |
| 184 int placeholder = 0; |
184 int placeholder = 0; |
| 185 for(int i=0;i<fstr.length;i++) { |
185 for(int i=0;i<fstr.length;i++) { |
| 186 char c = fstr.ptr[i]; |
186 char c = fstr.ptr[i]; |
| 187 if(placeholder) { |
187 if(placeholder) { |
| 283 CxMap *properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); |
283 CxMap *properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); |
| 284 *isallprop = 0; |
284 *isallprop = 0; |
| 285 |
285 |
| 286 CxIterator i = cxListIterator(fields); |
286 CxIterator i = cxListIterator(fields); |
| 287 cx_foreach(DavQLField*, field, i) { |
287 cx_foreach(DavQLField*, field, i) { |
| 288 if(!cx_strcmp(field->name, CX_STR("*"))) { |
288 if(!cx_strcmp(field->name, cx_str("*"))) { |
| 289 cxMapFree(properties); |
289 cxMapFree(properties); |
| 290 *isallprop = 1; |
290 *isallprop = 1; |
| 291 return create_allprop_propfind_request(); |
291 return create_allprop_propfind_request(); |
| 292 } else if(!cx_strcmp(field->name, CX_STR("-"))) { |
292 } else if(!cx_strcmp(field->name, cx_str("-"))) { |
| 293 cxMapFree(properties); |
293 cxMapFree(properties); |
| 294 return create_propfind_request(sn, NULL, "propfind", 0); |
294 return create_propfind_request(sn, NULL, "propfind", 0); |
| 295 } else { |
295 } else { |
| 296 if(fl_add_properties(sn, a, properties, field->expr)) { |
296 if(fl_add_properties(sn, a, properties, field->expr)) { |
| 297 // TODO: set error |
297 // TODO: set error |
| 300 } |
300 } |
| 301 } |
301 } |
| 302 } |
302 } |
| 303 |
303 |
| 304 CxMapIterator mi = cxMapIteratorValues(properties); |
304 CxMapIterator mi = cxMapIteratorValues(properties); |
| 305 CxList *list = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
305 CxList *list = cxLinkedListCreate(NULL, CX_STORE_POINTERS); |
| 306 cx_foreach(DavProperty*, value, mi) { |
306 cx_foreach(DavProperty*, value, mi) { |
| 307 cxListAdd(list, value); |
307 cxListAdd(list, value); |
| 308 } |
308 } |
| 309 |
309 |
| 310 CxBuffer *reqbuf = create_propfind_request(sn, list, "propfind", 0); |
310 CxBuffer *reqbuf = create_propfind_request(sn, list, "propfind", 0); |
| 481 return result; |
481 return result; |
| 482 } |
482 } |
| 483 cxMempoolRegister(mp, rqbuf, (cx_destructor_func)cxBufferFree); |
483 cxMempoolRegister(mp, rqbuf, (cx_destructor_func)cxBufferFree); |
| 484 |
484 |
| 485 // compile field list |
485 // compile field list |
| 486 CxList *cfieldlist = cxLinkedListCreate(mp->allocator, NULL, CX_STORE_POINTERS); |
486 CxList *cfieldlist = cxLinkedListCreate(mp->allocator, CX_STORE_POINTERS); |
| 487 if(st->fields) { |
487 if(st->fields) { |
| 488 CxIterator i = cxListIterator(st->fields); |
488 CxIterator i = cxListIterator(st->fields); |
| 489 cx_foreach(DavQLField*, field, i) { |
489 cx_foreach(DavQLField*, field, i) { |
| 490 if(cx_strcmp(field->name, CX_STR("*")) && cx_strcmp(field->name, CX_STR("-"))) { |
490 if(cx_strcmp(field->name, cx_str("*")) && cx_strcmp(field->name, cx_str("-"))) { |
| 491 // compile field expression |
491 // compile field expression |
| 492 CxBuffer *code = dav_compile_expr( |
492 CxBuffer *code = dav_compile_expr( |
| 493 sn->context, |
493 sn->context, |
| 494 mp->allocator, |
494 mp->allocator, |
| 495 field->expr, |
495 field->expr, |
| 541 } |
541 } |
| 542 |
542 |
| 543 // compile order criterion |
543 // compile order criterion |
| 544 CxList *ordercr = NULL; |
544 CxList *ordercr = NULL; |
| 545 if(st->orderby) { |
545 if(st->orderby) { |
| 546 ordercr = cxLinkedListCreate(mp->allocator, NULL, sizeof(DavOrderCriterion)); |
546 ordercr = cxLinkedListCreate(mp->allocator, sizeof(DavOrderCriterion)); |
| 547 CxIterator i = cxListIterator(st->orderby); |
547 CxIterator i = cxListIterator(st->orderby); |
| 548 cx_foreach(DavQLOrderCriterion*, oc, i) { |
548 cx_foreach(DavQLOrderCriterion*, oc, i) { |
| 549 DavQLExpression *column = oc->column; |
549 DavQLExpression *column = oc->column; |
| 550 //printf("%.*s %s\n", column->srctext.length, column->srctext.ptr, oc->descending ? "desc" : "asc"); |
550 //printf("%.*s %s\n", column->srctext.length, column->srctext.ptr, oc->descending ? "desc" : "asc"); |
| 551 if(column->type == DAVQL_IDENTIFIER) { |
551 if(column->type == DAVQL_IDENTIFIER) { |
| 599 } |
599 } |
| 600 } |
600 } |
| 601 |
601 |
| 602 DavResource *selroot = dav_resource_new(sn, path.ptr); |
602 DavResource *selroot = dav_resource_new(sn, path.ptr); |
| 603 |
603 |
| 604 CxList *stack = cxLinkedListCreateSimple(sizeof(DavQLRes)); |
604 CxList *stack = cxLinkedListCreate(NULL, sizeof(DavQLRes)); |
| 605 // initialize the stack with the requested resource |
605 // initialize the stack with the requested resource |
| 606 DavQLRes res; |
606 DavQLRes res; |
| 607 res.resource = selroot; |
607 res.resource = selroot; |
| 608 res.depth = 0; |
608 res.depth = 0; |
| 609 cxListInsert(stack, 0, &res); |
609 cxListInsert(stack, 0, &res); |
| 610 |
610 |
| 611 // reuseable response buffer |
611 // reuseable response buffer |
| 612 CxBuffer *rpbuf = cxBufferCreate(NULL, 4096, mp->allocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
612 CxBuffer *rpbuf = cxBufferCreate(mp->allocator, NULL, 4096, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
| 613 if(!rpbuf) { |
613 if(!rpbuf) { |
| 614 // TODO: cleanup |
614 // TODO: cleanup |
| 615 cxMempoolFree(mp); |
615 cxMempoolFree(mp); |
| 616 return result; |
616 return result; |
| 617 } |
617 } |
| 748 } |
748 } |
| 749 return count; |
749 return count; |
| 750 } |
750 } |
| 751 |
751 |
| 752 int dav_identifier2resprop(cxstring src, davqlresprop_t *prop) { |
752 int dav_identifier2resprop(cxstring src, davqlresprop_t *prop) { |
| 753 if(!cx_strcmp(src, CX_STR("name"))) { |
753 if(!cx_strcmp(src, cx_str("name"))) { |
| 754 *prop = DAVQL_RES_NAME; |
754 *prop = DAVQL_RES_NAME; |
| 755 } else if(!cx_strcmp(src, CX_STR("path"))) { |
755 } else if(!cx_strcmp(src, cx_str("path"))) { |
| 756 *prop = DAVQL_RES_PATH; |
756 *prop = DAVQL_RES_PATH; |
| 757 } else if(!cx_strcmp(src, CX_STR("href"))) { |
757 } else if(!cx_strcmp(src, cx_str("href"))) { |
| 758 *prop = DAVQL_RES_HREF; |
758 *prop = DAVQL_RES_HREF; |
| 759 } else if(!cx_strcmp(src, CX_STR("contentlength"))) { |
759 } else if(!cx_strcmp(src, cx_str("contentlength"))) { |
| 760 *prop = DAVQL_RES_CONTENTLENGTH; |
760 *prop = DAVQL_RES_CONTENTLENGTH; |
| 761 } else if(!cx_strcmp(src, CX_STR("contenttype"))) { |
761 } else if(!cx_strcmp(src, cx_str("contenttype"))) { |
| 762 *prop = DAVQL_RES_CONTENTTYPE; |
762 *prop = DAVQL_RES_CONTENTTYPE; |
| 763 } else if(!cx_strcmp(src, CX_STR("creationdate"))) { |
763 } else if(!cx_strcmp(src, cx_str("creationdate"))) { |
| 764 *prop = DAVQL_RES_CREATIONDATE; |
764 *prop = DAVQL_RES_CREATIONDATE; |
| 765 } else if(!cx_strcmp(src, CX_STR("lastmodified"))) { |
765 } else if(!cx_strcmp(src, cx_str("lastmodified"))) { |
| 766 *prop = DAVQL_RES_LASTMODIFIED; |
766 *prop = DAVQL_RES_LASTMODIFIED; |
| 767 } else if(!cx_strcmp(src, CX_STR("iscollection"))) { |
767 } else if(!cx_strcmp(src, cx_str("iscollection"))) { |
| 768 *prop = DAVQL_RES_ISCOLLECTION; |
768 *prop = DAVQL_RES_ISCOLLECTION; |
| 769 } else { |
769 } else { |
| 770 return 0; |
770 return 0; |
| 771 } |
771 } |
| 772 return 1; |
772 return 1; |
| 833 } else { |
833 } else { |
| 834 // error |
834 // error |
| 835 return -1; |
835 return -1; |
| 836 } |
836 } |
| 837 } else if(!dav_identifier2resprop(src, &cmd.data.resprop)) { |
837 } else if(!dav_identifier2resprop(src, &cmd.data.resprop)) { |
| 838 if(!cx_strcmp(src, CX_STR("true"))) { |
838 if(!cx_strcmp(src, cx_str("true"))) { |
| 839 cmd.type = DAVQL_CMD_INT; |
839 cmd.type = DAVQL_CMD_INT; |
| 840 cmd.data.integer = 1; |
840 cmd.data.integer = 1; |
| 841 } else if(!cx_strcmp(src, CX_STR("false"))) { |
841 } else if(!cx_strcmp(src, cx_str("false"))) { |
| 842 cmd.type = DAVQL_CMD_INT; |
842 cmd.type = DAVQL_CMD_INT; |
| 843 cmd.data.integer = 0; |
843 cmd.data.integer = 0; |
| 844 } else { |
844 } else { |
| 845 // error, unknown identifier |
845 // error, unknown identifier |
| 846 return -1; |
846 return -1; |
| 1030 } |
1030 } |
| 1031 return numcmd; |
1031 return numcmd; |
| 1032 } |
1032 } |
| 1033 |
1033 |
| 1034 CxBuffer* dav_compile_expr(DavContext *ctx, const CxAllocator *a, DavQLExpression *lexpr, DavQLArgList *ap) { |
1034 CxBuffer* dav_compile_expr(DavContext *ctx, const CxAllocator *a, DavQLExpression *lexpr, DavQLArgList *ap) { |
| 1035 CxBuffer *bcode = cxBufferCreate(NULL, 512, a, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
1035 CxBuffer *bcode = cxBufferCreate(a, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
| 1036 if(!bcode) { |
1036 if(!bcode) { |
| 1037 return NULL; |
1037 return NULL; |
| 1038 } |
1038 } |
| 1039 |
1039 |
| 1040 if(add_cmd(ctx, a, bcode, lexpr, ap) <= 0) { |
1040 if(add_cmd(ctx, a, bcode, lexpr, ap) <= 0) { |