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