command/commit

Testing with .netrc

authorJan Wielemaker
Thu Mar 10 16:57:21 2011 +0100
committerJan Wielemaker
Thu Mar 10 16:57:21 2011 +0100
commit72e89013e976e2c23d34a2d5f03303f2b2b9ea95
treef19396788300e949ffbe2bbc7484ae4141508b18
parent36eada48a8eb8617400f1daed4e63a827c9cb15b
Diff style: patch stat
diff --git a/api/command.pl b/api/command.pl
index 98a74f0..cdd44c8 100644
--- a/api/command.pl
+++ b/api/command.pl
@@ -33,6 +33,7 @@
 :- use_module(library(http/http_dispatch)).
 :- use_module(library(http/http_path)).
 :- use_module(library(http/http_parameters)).
+:- use_module(user(user_db)).
 
 /** <module> ClioPatria command line interface
 
@@ -66,10 +67,11 @@ ping(_Request) :-
 load(Request) :-
 	memberchk(method(get), Request), !,
 	http_parameters(Request,
-			[ url(Data,
+			[ url(URL,
 			      [ description('URL of data to load')])
 			]),
-	text_output(rdf_load(Data), []).
+	authorized(write(default, load(url(URL)))),
+	text_output(rdf_load(URL), []).
 
 
 		 /*******************************
diff --git a/script/cp-client.c b/script/cp-client.c
index 9d9acb6..4832718 100644
--- a/script/cp-client.c
+++ b/script/cp-client.c
@@ -31,6 +31,9 @@
 char *program = NULL;
 char *prefix  = "";
 char *host    = "localhost";
+char *user    = NULL;
+char *passwd  = NULL;
+char *netrc   = NULL;
 int   port    = 3020;
 CURL *curl    = NULL;
 int   debug   = 0;
@@ -43,7 +46,7 @@ isoption(const char *arg, const char *name, const char **val)
 { size_t len = strlen(name);
 
   if ( arg[0] == '-' && arg[1] == '-' &&
-       strncmp(arg, name, len) == 0 &&
+       strncmp(&arg[2], name, len) == 0 &&
        arg[2+len] == '=' )
   { *val = &arg[3+len];
     return TRUE;
@@ -72,6 +75,9 @@ usage(int code)
   fprintf(stderr, "Options:\n");
   fprintf(stderr, "  --host=host      Specify ClioPatria host (localhost)\n");
   fprintf(stderr, "  --port=port      Specify ClioPatria port (3020)\n");
+  fprintf(stderr, "  --user=user      User name for authentication\n");
+  fprintf(stderr, "  --passwd=passwd  Password for authentication\n");
+  fprintf(stderr, "  --netrc=netrc    Use given netrc file\n");
   fprintf(stderr, "\n");
   fprintf(stderr, "Commands:\n");
   fprintf(stderr, "  ping             Check that server is alive\n");
@@ -205,6 +211,12 @@ main(int argc, char **argv)
       host = (char*)val;
     else if ( isoption(s, "port", &val) )
       port = atoi(val);
+    else if ( isoption(s, "user", &val) )
+      user = (char*)val;
+    else if ( isoption(s, "passwd", &val) )
+      passwd = (char*)val;
+    else if ( isoption(s, "netrc", &val) )
+      netrc = (char*)val;
     else if ( s[0] == '-' )
       usage(1);
     else
@@ -222,10 +234,18 @@ main(int argc, char **argv)
   { perror("curl");
     exit(1);
   }
+  if ( user )
+    curl_easy_setopt(curl, CURLOPT_USERNAME, user);
+  if ( passwd )
+    curl_easy_setopt(curl, CURLOPT_PASSWORD, passwd);
+  if ( netrc )
+  { curl_easy_setopt(curl, CURLOPT_NETRC_FILE, netrc);
+    curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
+  }
 
   if ( strcmp(command, "ping") == 0 && cmdac == 0 )
     rc = ping();
-  if ( strcmp(command, "load") == 0 )
+  else if ( strcmp(command, "load") == 0 )
     rc = load(cmdac, cmdav);
   else
     usage(1);