]> git.sommitrealweird.co.uk Git - onak.git/commitdiff
cscvs to tla changeset 125
authorJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:48:19 +0000 (23:48 +0000)
committerJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:48:19 +0000 (23:48 +0000)
Author: noodles
Date: 2004/05/27 01:25:37
First cut of photo ID uid support.

Makefile
keyindex.c
lookup.c
onak.c
photoid.c [new file with mode: 0644]
photoid.h [new file with mode: 0644]

index 557e92111759dfe244478f25d0966e4dcbbd6c31..c980e4c6c88cb4d750e465e802591ed624c4af7e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 #
 # Makefile for onak.
 #
-# $Id: Makefile,v 1.18 2003/10/03 23:07:31 noodles Exp $
+# $Id: Makefile,v 1.19 2004/05/27 01:25:37 noodles Exp $
 #
 
 CC = gcc
@@ -17,11 +17,12 @@ LIBS = -L/usr/local/lib -ldb3
 
 PROGS = add lookup gpgwww onak splitkeys
 CORE_OBJS = armor.o charfuncs.o decodekey.o getcgi.o hash.o keydb_$(DBTYPE).o \
-       keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha.o md5.o log.o
+       keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha.o md5.o \
+       log.o photoid.o
 OBJS = merge.o stats.o sendsync.o $(CORE_OBJS)
 SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha.c main.c getcgi.c stats.c \
        keyindex.c mem.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \
-       gpgwww.c onak-conf.c charfuncs.c sendsync.c log.c
+       gpgwww.c onak-conf.c charfuncs.c sendsync.c log.c photoid.c
 
 all: .depend $(PROGS) testparse maxpath sixdegrees splitkeys
 
index 1f138517849800171d0022ef057d8dd5073f0013..9210cc8cfc535e69a3cdc02cb52471ff13fecfbe 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: keyindex.c,v 1.14 2004/05/26 17:48:02 noodles Exp $
+ * $Id: keyindex.c,v 1.15 2004/05/27 01:25:37 noodles Exp $
  */
 
 #include <assert.h>
@@ -63,9 +63,11 @@ int list_sigs(struct openpgp_packet_list *sigs, bool html)
        return 0;
 }
 
-int list_uids(struct openpgp_signedpacket_list *uids, bool verbose, bool html)
+int list_uids(uint64_t keyid, struct openpgp_signedpacket_list *uids,
+               bool verbose, bool html)
 {
        char buf[1024];
+       int  imgindx = 0;
 
        while (uids != NULL) {
                if (uids->packet->tag == 13) {
@@ -75,8 +77,15 @@ int list_uids(struct openpgp_signedpacket_list *uids, bool verbose, bool html)
                        printf("                                %s\n",
                                (html) ? txt2html(buf) : buf);
                } else if (uids->packet->tag == 17) {
-                       printf("                                "
-                               "[photo id]\n");
+                       printf("                                ");
+                       if (html) {
+                               printf("<img src=\"lookup?op=photo&search=0x%llX&idx=%d\" alt=\"[photo id]\">\n",
+                                               keyid,
+                                               imgindx);
+                               imgindx++;
+                       } else {
+                               printf("[photo id]\n");
+                       }
                }
                if (verbose) {
                        list_sigs(uids->sigs, html);
@@ -184,6 +193,7 @@ int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
        int                                      type = 0;
        int                                      length = 0;
        char                                     buf[1024];
+       uint64_t                                 keyid;
 
        if (html) {
                puts("<pre>");
@@ -213,11 +223,12 @@ int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
                                keys->publickey->data[0]);
                }
                
+               keyid = (get_keyid(keys) & 0xFFFFFFFF),
                printf("pub  %5d%c/%08X %04d/%02d/%02d ",
                        length,
                        (type == 1) ? 'R' : ((type == 16) ? 'g' : 
                                ((type == 17) ? 'D' : '?')),
-                       (uint32_t) (get_keyid(keys) & 0xFFFFFFFF),
+                       (uint32_t) keyid,
                        created->tm_year + 1900,
                        created->tm_mon + 1,
                        created->tm_mday);
@@ -247,7 +258,7 @@ int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
                        }
                }
 
-               list_uids(curuid, verbose, html);
+               list_uids(keyid, curuid, verbose, html);
                if (verbose) {
                        list_subkeys(keys->subkeys, verbose, html);
                }
index 67eac5904be420e8d4142b4bd712b80fdc0129b1..5d638eab6ef224100a691bff9f8c170ee9498be5 100644 (file)
--- a/lookup.c
+++ b/lookup.c
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: lookup.c,v 1.14 2004/05/26 18:53:14 noodles Exp $
+ * $Id: lookup.c,v 1.15 2004/05/27 01:25:37 noodles Exp $
  */
 
 #include <inttypes.h>
 #include "mem.h"
 #include "onak-conf.h"
 #include "parsekey.h"
+#include "photoid.h"
 
 #define OP_UNKNOWN 0
 #define OP_GET     1
 #define OP_INDEX   2
 #define OP_VINDEX  3
+#define OP_PHOTO   4
 
 void find_keys(char *search, uint64_t keyid, bool ishex,
                bool fingerprint, bool exact, bool verbose, bool mrhkp)
@@ -73,6 +75,7 @@ int main(int argc, char *argv[])
        char **params = NULL;
        int op = OP_UNKNOWN;
        int i;
+       int indx = 0;
        bool fingerprint = false;
        bool exact = false;
        bool ishex = false;
@@ -93,6 +96,8 @@ int main(int argc, char *argv[])
                                op = OP_INDEX;
                        } else if (!strcmp(params[i+1], "vindex")) {
                                op = OP_VINDEX;
+                       } else if (!strcmp(params[i+1], "photo")) {
+                               op = OP_PHOTO;
                        }
                } else if (!strcmp(params[i], "search")) {
                        search = params[i+1];
@@ -105,6 +110,8 @@ int main(int argc, char *argv[])
                                        ishex = true;
                                }
                        }
+               } else if (!strcmp(params[i], "idx")) {
+                       indx = atoi(params[i+1]);
                } else if (!strcmp(params[i], "fingerprint")) {
                        if (!strcmp(params[i+1], "on")) {
                                fingerprint = true;
@@ -137,6 +144,8 @@ int main(int argc, char *argv[])
 
        if (mrhkp) {
                puts("Content-Type: text/plain\n");
+       } else if (op == OP_PHOTO) {
+               puts("Content-Type: image/jpeg\n");
        } else {
                start_html("Lookup of key");
        }
@@ -174,6 +183,20 @@ int main(int argc, char *argv[])
                        find_keys(search, keyid, ishex, fingerprint, exact,
                                        true, mrhkp);
                        break;
+               case OP_PHOTO:
+                       if (fetch_key(keyid, &publickey, false)) {
+                               struct openpgp_packet *photo = NULL;
+                               photo = getphoto(publickey, 0);
+                               if (photo != NULL) {
+                                       fwrite(photo->data+19,
+                                                       1,
+                                                       (photo->length - 19),
+                                                       stdout);
+                               }
+                               free_publickey(publickey);
+                               publickey = NULL;
+                       }
+                       break;
                default:
                        puts("Unknown operation!");
                }
diff --git a/onak.c b/onak.c
index 0fdb7e4bf7510456cd9498422b808cc4e773201b..3a4c4e8d01ecc3ac952e69dbdfcdb68fdc0f76a1 100644 (file)
--- a/onak.c
+++ b/onak.c
@@ -7,7 +7,7 @@
  * 
  * Copyright 2002 Project Purple
  *
- * $Id: onak.c,v 1.19 2004/03/23 12:33:47 noodles Exp $
+ * $Id: onak.c,v 1.20 2004/05/27 01:25:37 noodles Exp $
  */
 
 #include <stdio.h>
@@ -26,6 +26,7 @@
 #include "merge.h"
 #include "onak-conf.h"
 #include "parsekey.h"
+#include "photoid.h"
 
 void find_keys(char *search, uint64_t keyid, bool ishex,
                bool fingerprint, bool exact, bool verbose)
@@ -173,6 +174,27 @@ int main(int argc, char *argv[])
                } else if (!strcmp("vindex", argv[optind])) {
                        find_keys(search, keyid, ishex, fingerprint,
                                        false, true);
+               } else if (!strcmp("getphoto", argv[optind])) {
+                       if (!ishex) {
+                               puts("Can't get a key on uid text."
+                                       " You must supply a keyid.");
+                       } else if (fetch_key(keyid, &keys, false)) {
+                               struct openpgp_packet *photo = NULL;
+                               FILE *photof = NULL;
+                               photo = getphoto(keys, 0);
+                               if (photo != NULL) {
+                                       photof = fopen("keyphoto.jpg", "w");
+                                       fwrite(photo->data+19,
+                                                       1,
+                                                       (photo->length - 19),
+                                                       photof);
+                                       fclose(photof);
+                               }
+                               free_publickey(keys);
+                               keys = NULL;
+                       } else {
+                               puts("Key not found");
+                       }
                } else if (!strcmp("delete", argv[optind])) {
                        delete_key(getfullkeyid(keyid), false);
                } else if (!strcmp("get", argv[optind])) {
diff --git a/photoid.c b/photoid.c
new file mode 100644 (file)
index 0000000..4416e3e
--- /dev/null
+++ b/photoid.c
@@ -0,0 +1,52 @@
+/*
+ * photoid.c - Routines for OpenPGP id photos.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2004 Project Purple
+ *
+ * $Id: photoid.c,v 1.1 2004/05/27 01:25:37 noodles Exp $
+ */
+
+#include <assert.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "keyid.h"
+#include "keyindex.h"
+#include "keystructs.h"
+
+/**
+ *     getphoto - returns an OpenPGP packet containing a photo id.
+ *     @key: The key to return the photo id from.
+ *     @index: The index of the photo to return.
+ *
+ *     This function returns the OpenPGP packet containing a photo id from a
+ *     supplied key. index specifies which photo id should be returned. If
+ *     there's no such photo id NULL is returned.
+ */
+struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index)
+{
+       struct openpgp_signedpacket_list *curuid = NULL;
+       struct openpgp_packet            *photo = NULL;
+       int                               i = 0;
+
+       assert(key != NULL);
+
+       curuid = key->uids;
+       i = 0;
+       while (photo == NULL && curuid != NULL && i <= index) {
+               if (curuid->packet->tag == 17) {
+                       if (i == index) {
+                               photo = curuid->packet;
+                       } else {
+                               i++;
+                       }
+               }
+               curuid = curuid->next;
+       }
+
+       return photo;
+}
diff --git a/photoid.h b/photoid.h
new file mode 100644 (file)
index 0000000..03bbf32
--- /dev/null
+++ b/photoid.h
@@ -0,0 +1,27 @@
+/*
+ * photoid.h - Routines for OpenPGP id photos.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2004 Project Purple
+ *
+ * $Id: photoid.h,v 1.1 2004/05/27 01:25:37 noodles Exp $
+ */
+
+#ifndef __PHOTOID_H__
+#define __PHOTOID_H__
+
+#include "keystructs.h"
+
+/**
+ *     getphoto - returns an OpenPGP packet containing a photo id.
+ *     @key: The key to return the photo id from.
+ *     @index: The index of the photo to return.
+ *
+ *     This function returns the OpenPGP packet containing a photo id from a
+ *     supplied key. index specifies which photo id should be returned. If
+ *     there's no such photo id NULL is returned.
+ */
+struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index);
+
+#endif /* __PHOTOID_H__ */