487 // 3: nodename |
495 // 3: nodename |
488 // 4: iscollection |
496 // 4: iscollection |
489 // 5: lastmodified |
497 // 5: lastmodified |
490 // 6: creationdate |
498 // 6: creationdate |
491 // 7: contentlength |
499 // 7: contentlength |
492 // 8: property prefix |
500 // 8: etag |
493 // 9: property xmlns |
501 // 9: property prefix |
494 // 10: property name |
502 // 10: property xmlns |
495 // 11: property lang |
503 // 11: property name |
496 // 12: property nsdeflist |
504 // 12: property lang |
497 // 13: property value |
505 // 13: property nsdeflist |
|
506 // 14: property value |
498 |
507 |
499 char *path = PQgetvalue(result, r, 0); |
508 char *path = PQgetvalue(result, r, 0); |
500 char *res_id = PQgetvalue(result, r, 1); |
509 char *res_id = PQgetvalue(result, r, 1); |
501 char *iscollection_str = PQgetvalue(result, r, 4); |
510 char *iscollection_str = PQgetvalue(result, r, 4); |
502 WSBool iscollection = iscollection_str && iscollection_str[0] == 't'; |
511 WSBool iscollection = iscollection_str && iscollection_str[0] == 't'; |
534 resource->addproperty(resource, webdav_resourcetype_collection(), 200); |
543 resource->addproperty(resource, webdav_resourcetype_collection(), 200); |
535 } else { |
544 } else { |
536 resource->addproperty(resource, webdav_resourcetype_empty(), 200); |
545 resource->addproperty(resource, webdav_resourcetype_empty(), 200); |
537 } |
546 } |
538 } |
547 } |
|
548 |
|
549 char *lastmodified = PQgetvalue(result, r, 5); |
|
550 char *contentlength = PQgetvalue(result, r, 7); |
|
551 time_t t = pg_convert_timestamp(lastmodified); |
|
552 |
539 if(vfsprops.getlastmodified) { |
553 if(vfsprops.getlastmodified) { |
540 char *lastmodified = PQgetvalue(result, r, 5); |
|
541 time_t t = pg_convert_timestamp(lastmodified); |
|
542 struct tm tm; |
554 struct tm tm; |
543 gmtime_r(&t, &tm); |
555 gmtime_r(&t, &tm); |
544 |
556 |
545 char buf[HTTP_DATE_LEN+1]; |
557 char buf[HTTP_DATE_LEN+1]; |
546 strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, &tm); |
558 strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, &tm); |
549 if(vfsprops.creationdate) { |
561 if(vfsprops.creationdate) { |
550 char *creationdate = PQgetvalue(result, r, 6); |
562 char *creationdate = PQgetvalue(result, r, 6); |
551 webdav_resource_add_dav_stringproperty(resource, pool, "creationdate", creationdate, strlen(creationdate)); |
563 webdav_resource_add_dav_stringproperty(resource, pool, "creationdate", creationdate, strlen(creationdate)); |
552 } |
564 } |
553 if(vfsprops.getcontentlength && !iscollection) { |
565 if(vfsprops.getcontentlength && !iscollection) { |
554 char *contentlength = PQgetvalue(result, r, 7); |
|
555 webdav_resource_add_dav_stringproperty(resource, pool, "getcontentlength", contentlength, strlen(contentlength)); |
566 webdav_resource_add_dav_stringproperty(resource, pool, "getcontentlength", contentlength, strlen(contentlength)); |
556 } |
567 } |
557 if(vfsprops.getetag) { |
568 if(vfsprops.getetag) { |
558 |
569 char *etag = PQgetvalue(result, r, 8); |
|
570 if(!PQgetisnull(result, r, 8)) { |
|
571 webdav_resource_add_dav_stringproperty(resource, pool, "getetag", etag, strlen(etag)); |
|
572 } else { |
|
573 int64_t ctlen; |
|
574 if(util_strtoint(contentlength, &ctlen)) { |
|
575 char etag[MAX_ETAG]; |
|
576 http_format_etag(rq->sn, rq->rq, etag, MAX_ETAG, ctlen, t); |
|
577 webdav_resource_add_dav_stringproperty(resource, pool, "getetag", etag, strlen(etag)); |
|
578 } |
|
579 } |
559 } |
580 } |
560 |
581 |
561 vfsprops_set = TRUE; |
582 vfsprops_set = TRUE; |
562 } |
583 } |
563 |
584 |
564 // dead properties |
585 // dead properties |
565 if(!PQgetisnull(result, r, 9)) { |
586 if(!PQgetisnull(result, r, 9)) { |
566 char *prefix = PQgetvalue(result, r, 8); |
587 char *prefix = PQgetvalue(result, r, 9); |
567 char *xmlns = PQgetvalue(result, r, 9); |
588 char *xmlns = PQgetvalue(result, r, 10); |
568 char *pname = PQgetvalue(result, r, 10); |
589 char *pname = PQgetvalue(result, r, 11); |
569 char *lang = PQgetvalue(result, r, 11); |
590 char *lang = PQgetvalue(result, r, 12); |
570 char *nsdef = PQgetvalue(result, r, 12); |
591 char *nsdef = PQgetvalue(result, r, 13); |
571 char *pvalue = PQgetvalue(result, r, 13); |
592 char *pvalue = PQgetvalue(result, r, 14); |
572 |
593 |
573 int pvalue_len = PQgetlength(result, r, 13); |
594 int pvalue_len = PQgetlength(result, r, 14); |
574 WSBool lang_isnull = PQgetisnull(result, r, 11); |
595 WSBool lang_isnull = PQgetisnull(result, r, 12); |
575 WSBool nsdef_isnull = PQgetisnull(result, r, 12); |
596 WSBool nsdef_isnull = PQgetisnull(result, r, 13); |
576 WSBool pvalue_isnull = PQgetisnull(result, r, 13); |
597 WSBool pvalue_isnull = PQgetisnull(result, r, 14); |
577 |
598 |
578 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty)); |
599 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty)); |
579 property->lang = NULL; |
600 property->lang = NULL; |
580 property->name = pool_strdup(pool, pname); |
601 property->name = pool_strdup(pool, pname); |
581 |
602 |