]> the.earth.li Git - onak.git/commitdiff
cscvs to tla changeset 133
authorJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:48:25 +0000 (23:48 +0000)
committerJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:48:25 +0000 (23:48 +0000)
Author: noodles
Date: 2004/05/27 21:58:18
Change getphoto over to returning the JPEG data rather than the OpenPGP packet.

lookup.c
onak.c
photoid.c
photoid.h

index 5d638eab6ef224100a691bff9f8c170ee9498be5..123ec5f1ee936aa91f9750fe5928031b89793407 100644 (file)
--- a/lookup.c
+++ b/lookup.c
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: lookup.c,v 1.15 2004/05/27 01:25:37 noodles Exp $
+ * $Id: lookup.c,v 1.16 2004/05/27 21:58:18 noodles Exp $
  */
 
 #include <inttypes.h>
@@ -160,7 +160,7 @@ int main(int argc, char *argv[])
                initdb(true);
                switch (op) {
                case OP_GET:
-                       logthing(LOGTHING_NOTICE, "Getting keyid %llX",
+                       logthing(LOGTHING_NOTICE, "Getting keyid 0x%llX",
                                        keyid);
                        if (fetch_key(keyid, &publickey, false)) {
                                puts("<pre>");
@@ -172,6 +172,8 @@ int main(int argc, char *argv[])
                                                packets);
                                puts("</pre>");
                        } else {
+                               logthing(LOGTHING_NOTICE,
+                                       "Failed to fetch key.");
                                puts("Key not found");
                        }
                        break;
@@ -185,12 +187,13 @@ int main(int argc, char *argv[])
                        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,
+                               unsigned char *photo = NULL;
+                               size_t         length = 0;
+
+                               if (getphoto(publickey, 0, &photo, &length)) {
+                                       fwrite(photo,
                                                        1,
-                                                       (photo->length - 19),
+                                                       length,
                                                        stdout);
                                }
                                free_publickey(publickey);
diff --git a/onak.c b/onak.c
index 3a4c4e8d01ecc3ac952e69dbdfcdb68fdc0f76a1..2a0376e4dbcdfa4a54a6427457912564c77408c1 100644 (file)
--- a/onak.c
+++ b/onak.c
@@ -7,7 +7,7 @@
  * 
  * Copyright 2002 Project Purple
  *
- * $Id: onak.c,v 1.20 2004/05/27 01:25:37 noodles Exp $
+ * $Id: onak.c,v 1.21 2004/05/27 21:58:18 noodles Exp $
  */
 
 #include <stdio.h>
@@ -179,16 +179,14 @@ int main(int argc, char *argv[])
                                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);
+                               unsigned char *photo = NULL;
+                               size_t         length = 0;
+
+                               if (getphoto(keys, 0, &photo, &length)) {
+                                       fwrite(photo,
+                                               1,
+                                               length,
+                                               stdout);
                                }
                                free_publickey(keys);
                                keys = NULL;
index 4416e3e35f7c17d1cd33242139da9fe3da4a9ae6..8da62cee2ff723fcb0d500446828d4b48d566b03 100644 (file)
--- a/photoid.c
+++ b/photoid.c
@@ -5,7 +5,7 @@
  *
  * Copyright 2004 Project Purple
  *
- * $Id: photoid.c,v 1.1 2004/05/27 01:25:37 noodles Exp $
+ * $Id: photoid.c,v 1.2 2004/05/27 21:58:18 noodles Exp $
  */
 
 #include <assert.h>
 #include "keyid.h"
 #include "keyindex.h"
 #include "keystructs.h"
+#include "log.h"
+#include "photoid.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.
+ *     @photo: The photo data.
+ *     @length: The length of the photo data.
  *
- *     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.
+ *     This function returns the photo data contained in a supplied key.
+ *     index specifies which photo id should be returned. If there's no such
+ *     photo id NULL is returned. The returned data pointer refers to the key
+ *     data supplied rather than a copy of it.
  */
-struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index)
+int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
+               size_t *length)
 {
        struct openpgp_signedpacket_list *curuid = NULL;
-       struct openpgp_packet            *photo = NULL;
        int                               i = 0;
+       int                               j = 0;
 
        assert(key != NULL);
+       assert(photo != NULL);
+       assert(length != NULL);
 
+       *photo = NULL;
+       
        curuid = key->uids;
        i = 0;
-       while (photo == NULL && curuid != NULL && i <= index) {
+       while (*photo == NULL && curuid != NULL && i <= index) {
                if (curuid->packet->tag == 17) {
                        if (i == index) {
-                               photo = curuid->packet;
+                               j = 0;
+                               *length = curuid->packet->data[j++];
+                               if (*length < 192) {
+                                       /* length is correct */
+                               } else if (*length < 255) {
+                                       *length -= 192;
+                                       *length <<= 8;
+                                       *length += curuid->packet->data[j++];
+                                       *length +=  192;
+                               } else {
+                                       *length = curuid->packet->data[j++];
+                                       *length <<= 8;
+                                       *length += curuid->packet->data[j++];
+                                       *length <<= 8;
+                                       *length += curuid->packet->data[j++];
+                                       *length <<= 8;
+                                       *length += curuid->packet->data[j++];
+                               }
+                               logthing(LOGTHING_DEBUG, "Got photo, size %d",
+                                               *length);
+                               j++;
+                               *length -= 17;
+                               *photo = &(curuid->packet->data[j+16]);
                        } else {
                                i++;
                        }
@@ -48,5 +80,5 @@ struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index)
                curuid = curuid->next;
        }
 
-       return photo;
+       return (*photo != NULL);
 }
index 03bbf32468098ba6f47884e82d060773db4541e4..49b685efce1b7c36248142bd205c4047c4d31fb8 100644 (file)
--- a/photoid.h
+++ b/photoid.h
@@ -5,7 +5,7 @@
  *
  * Copyright 2004 Project Purple
  *
- * $Id: photoid.h,v 1.1 2004/05/27 01:25:37 noodles Exp $
+ * $Id: photoid.h,v 1.2 2004/05/27 21:58:18 noodles Exp $
  */
 
 #ifndef __PHOTOID_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.
+ *     @photo: The photo data.
+ *     @length: The length of the photo data.
  *
- *     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.
+ *     This function returns the photo data contained in a supplied key.
+ *     index specifies which photo id should be returned. If there's no such
+ *     photo id NULL is returned. The returned data pointer refers to the key
+ *     data supplied rather than a copy of it.
  */
-struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index);
+int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
+               size_t *length);
 
 #endif /* __PHOTOID_H__ */