[or-cvs] Make dirserv_get_routerdescs() return better http 404 error...
Peter Palfrader
weasel at seul.org
Tue Oct 18 17:09:59 UTC 2005
Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv25672
Modified Files:
directory.c dirserv.c or.h
Log Message:
Make dirserv_get_routerdescs() return better http 404 error messages instead of a generic "Servers unavailable."
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.311
retrieving revision 1.312
diff -u -d -r1.311 -r1.312
--- directory.c 18 Oct 2005 14:57:46 -0000 1.311
+++ directory.c 18 Oct 2005 17:09:56 -0000 1.312
@@ -1326,14 +1326,16 @@
if (!strcmpstart(url,"/tor/server/")) {
size_t url_len = strlen(url);
int deflated = !strcmp(url+url_len-2, ".z");
+ int res;
+ const char *msg;
smartlist_t *descs = smartlist_create();
if (deflated)
url[url_len-2] = '\0';
- dirserv_get_routerdescs(descs, url);
+ res = dirserv_get_routerdescs(descs, url, &msg);
tor_free(url);
- if (!smartlist_len(descs)) {
- write_http_status_line(conn, 404, "Servers unavailable");
- } else {
+ if (res < 0)
+ write_http_status_line(conn, 404, msg);
+ else {
size_t len = 0;
format_rfc1123_time(date, time(NULL));
SMARTLIST_FOREACH(descs, routerinfo_t *, ri,
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.254
retrieving revision 1.255
diff -u -d -r1.254 -r1.255
--- dirserv.c 18 Oct 2005 15:58:40 -0000 1.254
+++ dirserv.c 18 Oct 2005 17:09:57 -0000 1.255
@@ -1393,13 +1393,23 @@
* hex identity digests; or
* - "/tor/server/d/D" where D is a plus-separated sequence
* of server descriptor digests, in hex.
+ *
+ * Return -1 if we do not have any descriptors, no matching descriptors,
+ * or if we did not recognize the key (URL), 0 otherwise (i.e. we found some
+ * matching descriptors). If -1 is returned <b>msg</b> will be set to
+ * an appropriate error message.
*/
-void
-dirserv_get_routerdescs(smartlist_t *descs_out, const char *key)
+int
+dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
+ const char **msg)
{
smartlist_t *complete_list = get_descriptor_list();
- if (!complete_list)
- return;
+ *msg = NULL;
+
+ if (!complete_list) {
+ *msg = "No server descriptors available";
+ return -1;
+ }
if (!strcmp(key, "/tor/server/all")) {
smartlist_add_all(descs_out, complete_list);
@@ -1435,7 +1445,16 @@
});
SMARTLIST_FOREACH(digests, char *, d, tor_free(d));
smartlist_free(digests);
+ } else {
+ *msg = "Key not recognized";
+ return -1;
}
+
+ if (!smartlist_len(descs_out)) {
+ *msg = "Servers unavailable";
+ return -1;
+ }
+ return 0;
}
/** Called when a TLS handshake has completed successfully with a
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.718
retrieving revision 1.719
diff -u -d -r1.718 -r1.719
--- or.h 17 Oct 2005 03:17:29 -0000 1.718
+++ or.h 18 Oct 2005 17:09:57 -0000 1.719
@@ -1781,7 +1781,8 @@
void dirserv_set_cached_networkstatus_v2(const char *directory, const char *fp,
time_t published);
int dirserv_get_networkstatus_v2(smartlist_t *result, const char *key);
-void dirserv_get_routerdescs(smartlist_t *descs_out, const char *key);
+int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
+ const char **msg);
void dirserv_orconn_tls_done(const char *address,
uint16_t or_port,
const char *digest_rcvd,
More information about the tor-commits
mailing list