libidav/davqlexec.c

branch
v1.1
changeset 341
7954fdacdb5c
parent 339
ad45ba74fe1b
equal deleted inserted replaced
340:9f37d0806200 341:7954fdacdb5c
64 } 64 }
65 65
66 return result; 66 return result;
67 } 67 }
68 68
69 sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, va_list *ap, davqlerror_t *error) { 69 sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, dav_valist ap, davqlerror_t *error) {
70 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); 70 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
71 71
72 int placeholder = 0; 72 int placeholder = 0;
73 for(int i=0;i<fstr.length;i++) { 73 for(int i=0;i<fstr.length;i++) {
74 char c = fstr.ptr[i]; 74 char c = fstr.ptr[i];
79 } else { 79 } else {
80 // detect placeholder type and insert arg 80 // detect placeholder type and insert arg
81 int err = 0; 81 int err = 0;
82 switch(c) { 82 switch(c) {
83 case 's': { 83 case 's': {
84 char *arg = va_arg(*ap, char*); 84 char *arg = dav_vaarg(ap, char*);
85 ucx_buffer_puts(buf, arg); 85 ucx_buffer_puts(buf, arg);
86 break; 86 break;
87 } 87 }
88 case 'd': { 88 case 'd': {
89 int arg = va_arg(*ap, int); 89 int arg = dav_vaarg(ap, int);
90 ucx_bprintf(buf, "%d", arg); 90 ucx_bprintf(buf, "%d", arg);
91 break; 91 break;
92 } 92 }
93 case 'u': { 93 case 'u': {
94 unsigned int arg = va_arg(*ap, unsigned int); 94 unsigned int arg = dav_vaarg(ap, unsigned int);
95 ucx_bprintf(buf, "%u", arg); 95 ucx_bprintf(buf, "%u", arg);
96 break; 96 break;
97 } 97 }
98 case 't': { 98 case 't': {
99 // time arguments not supported for strings 99 // time arguments not supported for strings
369 } 369 }
370 } 370 }
371 371
372 // get path string 372 // get path string
373 davqlerror_t error; 373 davqlerror_t error;
374 sstr_t path = dav_format_string(mp->allocator, st->path, &ap, &error); 374 sstr_t path = dav_fmt_str(mp->allocator, st->path, ap, &error);
375 if(error) { 375 if(error) {
376 // TODO: cleanup 376 // TODO: cleanup
377 ucx_mempool_destroy(mp); 377 ucx_mempool_destroy(mp);
378 return result; 378 return result;
379 } 379 }
638 638
639 break; 639 break;
640 } 640 }
641 case DAVQL_STRING: { 641 case DAVQL_STRING: {
642 cmd.type = DAVQL_CMD_STRING; 642 cmd.type = DAVQL_CMD_STRING;
643 cmd.data.string = dav_format_string(a, src, &ap, &error); 643 cmd.data.string = dav_fmt_str(a, src, ap, &error);
644 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode); 644 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
645 break; 645 break;
646 } 646 }
647 case DAVQL_TIMESTAMP: { 647 case DAVQL_TIMESTAMP: {
648 if(src.ptr[0] == '%') { 648 if(src.ptr[0] == '%') {

mercurial