cscvs to tla changeset 2
[onak.git] / gpgwww.c
1 /*
2  * gpgwww.c - www interface to path finder.
3  * 
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2001-2002 Project Purple.
7  */
8
9 // #include <stdint.h>
10 #include <inttypes.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "getcgi.h"
15 #include "hash.h"
16 #include "keydb.h"
17 #include "onak_conf.h"
18 #include "stats.h"
19
20 void dofindpath(uint64_t have, uint64_t want, bool html)
21 {
22         struct stats_key *keyinfoa, *keyinfob, *curkey;
23         int rec;
24         char *uid;
25
26         /*
27          * Make sure the keys we have and want are in the cache.
28          */
29         hash_getkeysigs(have);
30         hash_getkeysigs(want);
31
32         if ((keyinfoa = findinhash(have)) == NULL) {
33                 printf("Couldn't find key 0x%llX.\n", have);
34                 return;
35         }
36         if ((keyinfob = findinhash(want)) == NULL) {
37                 printf("Couldn't find key 0x%llX.\n", want);
38                 return;
39         }
40         
41         /*
42          * Fill the tree info up.
43          */
44         initcolour(true);
45         rec = findpath(keyinfoa, keyinfob);
46         keyinfob->parent = 0;
47
48         printf("%d nodes examined. %ld elements in the hash\n", rec,
49                         hashelements());
50         if (keyinfoa->colour == 0) {
51                 printf("Can't find a link from 0x%llX to 0x%llX\n",
52                                 have,
53                                 want);
54         } else {
55                 printf("%d steps from 0x%llX to 0x%llX\n",
56                                 keyinfoa->colour, have, want);
57                 curkey = keyinfoa;
58                 while (curkey != NULL && curkey->keyid != 0) {
59                         uid = keyid2uid(curkey->keyid);
60                         if (html && uid == NULL) {
61                                 printf("<a href=\"lookup?op=get&search=%llX\">"
62                                         "0x%llX</a> ([User id not found])%s)%s\n",
63                                         curkey->keyid,
64                                         curkey->keyid,
65                                         (curkey->keyid == want) ? "" :
66                                          " signs");
67                         } else if (html && uid != NULL) {
68                                 printf("<a href=\"lookup?op=get&search=%llX\">"
69                                         "0x%llX</a> (<a href=\"lookup?op=vindex"
70                                         "&search=0x%llX\">%s</a>)%s\n",
71                                         curkey->keyid,
72                                         curkey->keyid,
73                                         curkey->keyid,
74                                         txt2html(keyid2uid(curkey->keyid)),
75                                         (curkey->keyid == want) ? "" :
76                                          " signs");
77                         } else {
78                                 printf("0x%llX (%s)%s\n",
79                                         curkey->keyid,
80                                         (uid == NULL) ? "[User id not found]" :
81                                                 uid,
82                                         (curkey->keyid == want) ? "" :
83                                          " signs");
84                         }
85                         curkey = findinhash(curkey->parent);
86                 }
87         }
88 }
89
90 void parsecgistuff(char **cgiparams, uint64_t *from, uint64_t *to)
91 {
92         int i = 0;
93
94         if (cgiparams != NULL) {
95                 i = 0;
96                 while (cgiparams[i] != NULL) {
97                         if (!strcmp(cgiparams[i], "to")) {
98                                 *to = strtoul(cgiparams[i+1], NULL, 16);
99                         } else if (!strcmp(cgiparams[i], "from")) {
100                                 *from = strtoul(cgiparams[i+1], NULL, 16);
101                         }
102                         i += 2;
103                 }
104         }
105
106         return;
107 }
108
109 int main(int argc, char *argv[])
110 {
111         char **cgiparams = NULL;        /* Our CGI parameter block */
112         uint64_t from = 0, to = 0;
113
114         cgiparams = getcgivars(argc, argv);
115
116         puts("Content-Type: text/html\n");
117         puts("<HTML>");
118         puts("<HEAD>");
119         puts("<TITLE>Experimental PGP key path finder results</TITLE>");
120         puts("</HEAD>");
121         puts("<BODY>");
122         puts("</BODY>");
123
124         parsecgistuff(cgiparams, &from, &to);
125
126         if (from == 0 || to == 0) {
127                 printf("Must pass from & to\n");
128                 puts("</HTML>");
129                 exit(1);
130         }
131
132         printf("<P>Looking for path from 0x%llX to 0x%llX</P>\n", from, to);
133         puts("<PRE>");
134         initdb();
135         inithash();
136         dofindpath(from, to, true);
137         cleanupdb();
138         puts("</PRE>");
139
140         puts("<HR>");
141         puts("Produced by gpgwww " VERSION ", part of onak. <A HREF=\"mailto:noodles-onak@earth.li\">Jonathan McDowell</A>");
142         puts("</HTML>");
143
144         return EXIT_SUCCESS;
145 }