1010 property->namespace = &dav_namespace; |
1010 property->namespace = &dav_namespace; |
1011 property->name = name; |
1011 property->name = name; |
1012 return property; |
1012 return property; |
1013 } |
1013 } |
1014 |
1014 |
|
1015 int webdav_resource_add_dav_stringproperty( |
|
1016 WebdavResource *res, |
|
1017 pool_handle_t pool, |
|
1018 const char *name, |
|
1019 const char *str, |
|
1020 size_t len) |
|
1021 { |
|
1022 WebdavProperty *property = webdav_dav_property(pool, name); |
|
1023 if(!property) { |
|
1024 return 1; |
|
1025 } |
|
1026 |
|
1027 property->name = pool_strdup(pool, name); |
|
1028 if(!property->name) { |
|
1029 return 1; |
|
1030 } |
|
1031 |
|
1032 char *value = pool_malloc(pool, len+1); |
|
1033 if(!value) { |
|
1034 return 1; |
|
1035 } |
|
1036 memcpy(value, str, len); |
|
1037 value[len] = '\0'; |
|
1038 property->value.text.str = value; |
|
1039 property->value.text.length = len; |
|
1040 property->vtype = WS_VALUE_TEXT; |
|
1041 |
|
1042 return res->addproperty(res, property, 200); |
|
1043 } |
|
1044 |
|
1045 int webdav_resource_add_stringproperty( |
|
1046 WebdavResource *res, |
|
1047 pool_handle_t pool, |
|
1048 const char *xmlns_prefix, |
|
1049 const char *xmlns_href, |
|
1050 const char *name, |
|
1051 const char *str, |
|
1052 size_t len) |
|
1053 { |
|
1054 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty)); |
|
1055 if(!property) { |
|
1056 return 1; |
|
1057 } |
|
1058 memset(property, 0, sizeof(WebdavProperty)); |
|
1059 |
|
1060 property->name = pool_strdup(pool, name); |
|
1061 if(!property->name) { |
|
1062 return 1; |
|
1063 } |
|
1064 |
|
1065 xmlNs *ns = pool_malloc(pool, sizeof(xmlNs)); |
|
1066 if(!ns) { |
|
1067 return 1; |
|
1068 } |
|
1069 memset(ns, 0, sizeof(xmlNs)); |
|
1070 ns->prefix = (const xmlChar*)pool_strdup(pool, xmlns_prefix); |
|
1071 ns->href = (const xmlChar*)pool_strdup(pool, xmlns_href); |
|
1072 if(!ns->prefix || !ns->href) { |
|
1073 return 1; |
|
1074 } |
|
1075 |
|
1076 char *value = pool_malloc(pool, len+1); |
|
1077 if(!value) { |
|
1078 return 1; |
|
1079 } |
|
1080 memcpy(value, str, len); |
|
1081 value[len] = '\0'; |
|
1082 property->value.text.str = value; |
|
1083 property->value.text.length = len; |
|
1084 property->vtype = WS_VALUE_TEXT; |
|
1085 |
|
1086 property->value.text.str = value; |
|
1087 property->value.text.length = len; |
|
1088 property->vtype = WS_VALUE_TEXT; |
|
1089 |
|
1090 return res->addproperty(res, property, 200); |
|
1091 } |
|
1092 |
1015 int webdav_property_set_value( |
1093 int webdav_property_set_value( |
1016 WebdavProperty *p, |
1094 WebdavProperty *p, |
1017 pool_handle_t *pool, |
1095 pool_handle_t *pool, |
1018 char *value) |
1096 char *value) |
1019 { |
1097 { |
1070 } |
1148 } |
1071 |
1149 |
1072 return ret; |
1150 return ret; |
1073 } |
1151 } |
1074 |
1152 |
1075 static inline int w_addprop( |
|
1076 WebdavResource *res, |
|
1077 pool_handle_t *pool, |
|
1078 const char *name, |
|
1079 char *value) |
|
1080 { |
|
1081 WebdavProperty *p = webdav_dav_property(pool, name); |
|
1082 if(!p) { |
|
1083 return 1; |
|
1084 } |
|
1085 if(webdav_property_set_value(p, pool, value)) { |
|
1086 return 1; |
|
1087 } |
|
1088 return res->addproperty(res, p, 200); |
|
1089 } |
|
1090 |
|
1091 int webdav_add_vfs_properties( |
1153 int webdav_add_vfs_properties( |
1092 WebdavResource *res, |
1154 WebdavResource *res, |
1093 pool_handle_t *pool, |
1155 pool_handle_t *pool, |
1094 WebdavVFSProperties properties, |
1156 WebdavVFSProperties properties, |
1095 struct stat *s) |
1157 struct stat *s) |
1106 if(!buf) { |
1168 if(!buf) { |
1107 return 1; |
1169 return 1; |
1108 } |
1170 } |
1109 uint64_t contentlength = s->st_size; |
1171 uint64_t contentlength = s->st_size; |
1110 snprintf(buf, 64, "%" PRIu64, contentlength); |
1172 snprintf(buf, 64, "%" PRIu64, contentlength); |
1111 if(w_addprop(res, pool, "getcontentlength", buf)) { |
1173 if(webdav_resource_add_dav_stringproperty(res, pool, "getcontentlength", buf, strlen(buf))) { |
1112 return 1; |
1174 return 1; |
1113 } |
1175 } |
1114 } |
1176 } |
1115 if(properties.getlastmodified) { |
1177 if(properties.getlastmodified) { |
1116 char *buf = pool_malloc(pool, HTTP_DATE_LEN+1); |
1178 char *buf = pool_malloc(pool, HTTP_DATE_LEN+1); |
1122 struct tm mtms; |
1184 struct tm mtms; |
1123 struct tm *mtm = system_gmtime(&s->st_mtim.tv_sec, &mtms); |
1185 struct tm *mtm = system_gmtime(&s->st_mtim.tv_sec, &mtms); |
1124 |
1186 |
1125 if(mtm) { |
1187 if(mtm) { |
1126 strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, mtm); |
1188 strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, mtm); |
1127 if(w_addprop(res, pool, "getlastmodified", buf)) { |
1189 if(webdav_resource_add_dav_stringproperty(res, pool, "getlastmodified", buf, strlen(buf))) { |
1128 return 1; |
1190 return 1; |
1129 } |
1191 } |
1130 } else { |
1192 } else { |
1131 return 1; |
1193 return 1; |
1132 } |
1194 } |