[or-cvs] Implement GETINFO(dir/server/foo); status will be harder.

Nick Mathewson nickm at seul.org
Wed Mar 15 05:06:59 UTC 2006


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv6261/src/or

Modified Files:
	control.c dirserv.c 
Log Message:
Implement GETINFO(dir/server/foo); status will be harder.

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -p -d -r1.178 -r1.179
--- control.c	12 Mar 2006 05:04:16 -0000	1.178
+++ control.c	15 Mar 2006 05:06:56 -0000	1.179
@@ -1455,6 +1455,27 @@ handle_getinfo_helper(const char *questi
     smartlist_free(mappings);
   } else if (!strcmp(question, "dir-usage")) {
     *answer = directory_dump_request_log();
+  } else if (!strcmpstart(question, "dir/server/")) {
+    size_t answer_len = 0, url_len = strlen(question)+2;
+    char *url = tor_malloc(url_len);
+    int res;
+    smartlist_t *descs = smartlist_create();
+    const char *msg;
+    char *cp;
+    tor_snprintf(url, url_len, "/tor/%s", question+4);
+    res = dirserv_get_routerdescs(descs, url, &msg);
+    SMARTLIST_FOREACH(descs, signed_descriptor_t *, sd,
+                      answer_len += sd->signed_descriptor_len);
+    cp = *answer = tor_malloc(answer_len+1);
+    SMARTLIST_FOREACH(descs, signed_descriptor_t *, sd,
+                      {
+                        memcpy(cp, signed_descriptor_get_body(sd),
+                               sd->signed_descriptor_len);
+                        cp += sd->signed_descriptor_len;
+                      });
+    *cp = '\0';
+    tor_free(url);
+    smartlist_free(descs);
   }
   return 0;
 }

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.306
retrieving revision 1.307
diff -u -p -d -r1.306 -r1.307
--- dirserv.c	14 Mar 2006 23:40:37 -0000	1.306
+++ dirserv.c	15 Mar 2006 05:06:56 -0000	1.307
@@ -1555,6 +1555,9 @@ dirserv_get_networkstatus_v2(smartlist_t
  * recognize the key (URL).
  * If -1 is returned *<b>msg</b> will be set to an appropriate error
  * message.
+ *
+ * (Despite its name, this function is also called from the controller, which
+ * exposes a similar means to fetch descriptors.)
  */
 int
 dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,



More information about the tor-commits mailing list