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