dav/main.c

changeset 194
1950f483d3c4
parent 191
0e45b04236a7
child 195
4b7823a58199
equal deleted inserted replaced
193:cd30c7a7baf8 194:1950f483d3c4
41 #include <libidav/utils.h> 41 #include <libidav/utils.h>
42 #include <libidav/crypto.h> 42 #include <libidav/crypto.h>
43 #include <libidav/session.h> 43 #include <libidav/session.h>
44 #include "config.h" 44 #include "config.h"
45 #include "error.h" 45 #include "error.h"
46 #include "assistant.h"
46 #include "main.h" 47 #include "main.h"
47 48
48 static DavContext *ctx; 49 static DavContext *ctx;
49 50
50 static int printxmlerror = 1; 51 static int printxmlerror = 1;
118 ret = cmd_set_property(args); 119 ret = cmd_set_property(args);
119 } else if(!strcasecmp(cmd, "get-property")) { 120 } else if(!strcasecmp(cmd, "get-property")) {
120 ret = cmd_get_property(args); 121 ret = cmd_get_property(args);
121 } else if(!strcasecmp(cmd, "info")) { 122 } else if(!strcasecmp(cmd, "info")) {
122 ret = cmd_info(args); 123 ret = cmd_info(args);
124 } else if(!strcasecmp(cmd, "create-repository")) {
125 ret = cmd_create_repository(args);
123 } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") || !strcasecmp(cmd, "--version")) { 126 } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") || !strcasecmp(cmd, "--version")) {
124 #ifdef DEBUG 127 #ifdef DEBUG
125 fprintf(stderr, "dav %s unstable\n", DAV_VERSION); 128 fprintf(stderr, "dav %s unstable\n", DAV_VERSION);
126 #else 129 #else
127 fprintf(stderr, "dav %s\n", DAV_VERSION); 130 fprintf(stderr, "dav %s\n", DAV_VERSION);
178 fprintf(stderr, " -t print content type\n"); 181 fprintf(stderr, " -t print content type\n");
179 fprintf(stderr, " -O override resources\n"); 182 fprintf(stderr, " -O override resources\n");
180 fprintf(stderr, " -n <uri> specify namespace uri\n"); 183 fprintf(stderr, " -n <uri> specify namespace uri\n");
181 fprintf(stderr, " -v verbose output\n"); 184 fprintf(stderr, " -v verbose output\n");
182 fprintf(stderr, "\n"); 185 fprintf(stderr, "\n");
186 fprintf(stderr, "Config Commands:\n");
187 fprintf(stderr, " add-repository\n");
188 fprintf(stderr, "\n");
183 fprintf(stderr, 189 fprintf(stderr,
184 "Instead of an url you can pass a repository name " 190 "Instead of an url you can pass a repository name "
185 "with an optional path:\n"); 191 "with an optional path:\n");
186 fprintf(stderr, " <repository>/path/\n"); 192 fprintf(stderr, " <repository>/path/\n");
187 fprintf(stderr, "\n"); 193 fprintf(stderr, "\n");
1148 free(buf); 1154 free(buf);
1149 return str; 1155 return str;
1150 } 1156 }
1151 } 1157 }
1152 1158
1159
1153 /* ---------- config commands ---------- */ 1160 /* ---------- config commands ---------- */
1154 1161
1155 static int getkeyvalue(char *arg, char **key, char **value) { 1162 int cmd_create_repository(CmdArgs *args) {
1156 // splits a key=value arg
1157
1158 *key = NULL;
1159 *value = NULL;
1160 if(!arg && !key && !value) {
1161 return -1;
1162 }
1163
1164 int haskey = 0;
1165 size_t len = strlen(arg);
1166
1167 if(len < 3) {
1168 return -1;
1169 }
1170
1171 int i;
1172 for(i=0;i<len;i++) {
1173 if(arg[i] == '=') {
1174 haskey = 1;
1175 break;
1176 }
1177 }
1178
1179 if(haskey) {
1180 sstr_t k = sstrn(arg, i);
1181 sstr_t v = sstrn(arg+i + 1, len - i - 1);
1182 if(k.length > 0 && v.length > 0) {
1183 *key = sstrdup(k).ptr;
1184 *value = sstrdup(v).ptr;
1185 return 0;
1186 }
1187 }
1188
1189 return -1;
1190 }
1191
1192 void repository_assistent(Repository *repo, int mode) {
1193 char *name = NULL;
1194 sstr_t line; 1163 sstr_t line;
1195 1164
1196 // name 1165 printf("Each repository must have an unique name.\n");
1197 while(!name) { 1166 char *name = assistant_getcfg("name");
1198 if(repo->name) { 1167 if(!name) {
1199 printf("repository name [%s]: ", repo->name); 1168 fprintf(stderr, "Abort\n");
1200 } else { 1169 return -1;
1201 printf("repository name: "); 1170 }
1202 } 1171 if(get_repository(sstr(name))) {
1203 fflush(stdout); 1172 fprintf(stderr, "Repository %s already exists.\nAbort\n");
1204 1173 return -1;
1205 line = util_readline(stdin); 1174 }
1206 if(line.length == 0 && repo->name) { 1175
1207 break; 1176 printf("\nSpecify the repository base url.\n");
1208 } else { 1177 char *url = assistant_getcfg("url");
1209 name = line.ptr; 1178 if(!url) {
1210 } 1179 fprintf(stderr, "Abort\n");
1211 } 1180 return -1;
1212 if(name) { 1181 }
1213 if(repo->name) { 1182
1214 free(repo->name); 1183 printf("\nUser for HTTP authentication.\n");
1215 } 1184 char *user = assistant_getoptcfg("user");
1216 repo->name = name; 1185
1217 } 1186 char *password = NULL;
1218 1187 if(user) {
1219 // TODO 1188 password = assistant_gethiddenoptcfg("password");
1220 1189 }
1221 return; 1190 printf("\n");
1222 } 1191
1192 Repository repo;
1193 memset(&repo, 0, sizeof(Repository));
1194 repo.name = name;
1195 repo.url = url;
1196 repo.user = user;
1197 repo.password = password;
1198
1199 int ret = 0;
1200 if(add_repository(&repo)) {
1201 fprintf(stderr, "Cannot write config.xml\n");
1202 ret = -1;
1203 } else {
1204 printf("Added repository: %s (%s)\n", name, url);
1205 }
1206
1207 return ret;
1208 }

mercurial