cscvs to tla changeset 99
authorJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:47:58 +0000 (23:47 +0000)
committerJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:47:58 +0000 (23:47 +0000)
Author: noodles
Date: 2003/09/30 20:40:10
Allow a limit on the number of keys returned by read_openpgp_stream.

armor.c
keydb_db2.c
keydb_db3.c
keydb_file.c
keydb_pg.c
main.c
onak.c
parsekey.c
parsekey.h

diff --git a/armor.c b/armor.c
index 3f47f64f01637a46b14390a658f557e71a555ea6..f2e97fcd791e04c1c8698c7824b32c61984a00d2 100644 (file)
--- a/armor.c
+++ b/armor.c
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: armor.c,v 1.6 2003/06/07 13:45:34 noodles Exp $
+ * $Id: armor.c,v 1.7 2003/09/30 20:40:10 noodles Exp $
  */
 
 #include <assert.h>
@@ -396,7 +396,8 @@ int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                dearmor_init(&dearmor_ctx);
                dearmor_ctx.getchar_func = getchar_func;
                dearmor_ctx.ctx = ctx;
-               read_openpgp_stream(dearmor_getchar_c, &dearmor_ctx, packets);
+               read_openpgp_stream(dearmor_getchar_c, &dearmor_ctx,
+                       packets, 0);
                dearmor_finish(&dearmor_ctx);
                /*
                 * TODO: Look for armor footer
index 0ff31cbe308d1f9a0c8137f83632822943530f79..77a6f8b4b7c5471e2b63b4ca1da00fb22434e5fe 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: keydb_db2.c,v 1.9 2003/06/04 20:57:08 noodles Exp $
+ * $Id: keydb_db2.c,v 1.10 2003/09/30 20:40:10 noodles Exp $
  */
 
 #include <sys/types.h>
@@ -200,7 +200,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
                fetchbuf.buffer = data.data;
                fetchbuf.offset = 0;
                fetchbuf.size = data.size;
-               read_openpgp_stream(buffer_fetchchar, &fetchbuf, &packets);
+               read_openpgp_stream(buffer_fetchchar, &fetchbuf, &packets, 0);
                parse_keys(packets, publickey);
                free_packet_list(packets);
                packets = NULL;
index f6867709bc3dbda7fa7c2b1b90db823310f73cc9..56f4bed5a0cc11d60759c5a4ae8837df2bec04fe 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: keydb_db3.c,v 1.19 2003/09/28 16:12:47 noodles Exp $
+ * $Id: keydb_db3.c,v 1.20 2003/09/30 20:40:10 noodles Exp $
  */
 
 #include <assert.h>
@@ -340,7 +340,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
                fetchbuf.offset = 0;
                fetchbuf.size = data.size;
                read_openpgp_stream(buffer_fetchchar, &fetchbuf,
-                               &packets);
+                               &packets, 0);
                parse_keys(packets, publickey);
                free_packet_list(packets);
                packets = NULL;
index 0ca39ae8ad2676e6d64bc68838045a9ab17f052c..742636992c5945d68c20769402d7eca5aa899cc1 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: keydb_file.c,v 1.9 2003/06/05 07:31:59 noodles Exp $
+ * $Id: keydb_file.c,v 1.10 2003/09/30 20:40:10 noodles Exp $
  */
 
 #include <sys/types.h>
@@ -88,7 +88,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
        fd = open(keyfile, O_RDONLY); // | O_SHLOCK);
 
        if (fd > -1) {
-               read_openpgp_stream(file_fetchchar, &fd, &packets);
+               read_openpgp_stream(file_fetchchar, &fd, &packets, 0);
                parse_keys(packets, publickey);
                free_packet_list(packets);
                packets = NULL;
index cdfbe63d4fbeb8f6103c31aed7be56bad1e8823c..b424b7f9814fd4b170c7ccf0ec95f2ec50303506 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: keydb_pg.c,v 1.12 2003/06/08 21:11:01 noodles Exp $
+ * $Id: keydb_pg.c,v 1.13 2003/09/30 20:40:11 noodles Exp $
  */
 
 #include <postgresql/libpq-fe.h>
@@ -176,7 +176,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
                                                "Can't open large object.");
                        } else {
                                read_openpgp_stream(keydb_fetchchar, &fd,
-                                               &packets);
+                                               &packets, 0);
                                parse_keys(packets, publickey);
                                lo_close(dbconn, fd);
                                free_packet_list(packets);
diff --git a/main.c b/main.c
index b140c8edc9b7ac3740a50a834329f98aa003b5da..9580e018519937647bed293a40039fefc8c60bb7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
        void *ctx = NULL;
 
        fputs("Doing read_openpgp_stream():\n", stderr);
-       read_openpgp_stream(getnextchar, ctx, &packets);
+       read_openpgp_stream(getnextchar, ctx, &packets, 0);
 */
        fputs("Doing dearmor_openpgp_stream():\n", stderr);
        dearmor_openpgp_stream(getnextchar, NULL, &packets);
diff --git a/onak.c b/onak.c
index b69c594f527445525c2113ea98411d914873ca8f..2da86c915cae8708a192c7f0668cda6bc6eb6076 100644 (file)
--- a/onak.c
+++ b/onak.c
@@ -7,7 +7,7 @@
  * 
  * Copyright 2002 Project Purple
  *
- * $Id: onak.c,v 1.16 2003/09/30 17:15:39 noodles Exp $
+ * $Id: onak.c,v 1.17 2003/09/30 20:40:11 noodles Exp $
  */
 
 #include <stdio.h>
@@ -113,7 +113,7 @@ int main(int argc, char *argv[])
        } else if (!strcmp("add", argv[optind])) {
                if (binary) {
                        result = read_openpgp_stream(stdin_getchar, NULL,
-                                &packets);
+                                &packets, 0);
                        logthing(LOGTHING_INFO,
                                        "read_openpgp_stream: %d", result);
                } else {
index 9cdb90cc514d4e825d430b951ba4ea8a8ba3657d..b9211863111cb3c00d2686efc8f2313115192589 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: parsekey.c,v 1.12 2003/09/30 17:40:41 noodles Exp $
+ * $Id: parsekey.c,v 1.13 2003/09/30 20:40:11 noodles Exp $
  */
 
 #include <assert.h>
@@ -162,6 +162,7 @@ int debug_packet(struct openpgp_packet *packet)
  *     @getchar_func: The function to get the next character from the stream.
  *     @ctx: A pointer to the context structure for getchar_func.
  *     @packets: The outputted list of packets.
+ *     @maxnum: The maximum number of keys to read. 0 means unlimited.
  *
  *     This function uses getchar_func to read characters from an OpenPGP
  *     packet stream and reads the packets into a linked list of packets
@@ -170,12 +171,14 @@ int debug_packet(struct openpgp_packet *packet)
 int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                unsigned char *c),
                                void *ctx,
-                               struct openpgp_packet_list **packets)
+                               struct openpgp_packet_list **packets,
+                               int maxnum)
 {
        unsigned char                    curchar = 0;
        unsigned long                    count = 0;
        struct openpgp_packet_list      *curpacket = NULL;
        int                              rc = 0;
+       int                              keys = 0;
        bool                             inpacket = false;
 
        assert(packets != NULL);
@@ -186,7 +189,8 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                }
        }
 
-       while (!rc && !getchar_func(ctx, 1, &curchar)) {
+       while (!rc && !getchar_func(ctx, 1, &curchar) &&
+                       (maxnum == 0 || keys < maxnum)) {
                if (!inpacket && (curchar & 0x80)) {
                        /*
                         * New packet. Record the fact we're in a packet and
@@ -283,6 +287,9 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                        }
 
                        if (rc == 0) {
+                               if (curpacket->packet->tag == 6) {
+                                       keys++;
+                               }
                                curpacket->packet->data =
                                        malloc(curpacket->packet->length *
                                        sizeof(unsigned char));
index 682629c9fc8e0e8e3c70f326e47624d11d66bcd3..ed7e3a0daf2c8200deff01f7b61346a3755babac 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
- * $Id: parsekey.h,v 1.4 2003/06/04 20:57:12 noodles Exp $
+ * $Id: parsekey.h,v 1.5 2003/09/30 20:40:11 noodles Exp $
  */
 
 #ifndef __PARSEKEY_H__
@@ -53,15 +53,20 @@ int debug_packet(struct openpgp_packet *packet);
  *     @getchar_func: The function to get the next character from the stream.
  *     @ctx: A pointer to the context structure for getchar_func.
  *     @packets: The outputted list of packets.
+ *     @maxnum: The maximum number of keys to read. 0 means unlimited.
  *
  *     This function uses getchar_func to read characters from an OpenPGP
  *     packet stream and reads the packets into a linked list of packets
- *     ready for parsing as a public key or whatever.
+ *     ready for parsing as a public key or whatever. maxnum allows you to
+ *     specify the maximum number of keys to read. Note that if this is used
+ *     then only the public key component of the last key will be returned,
+ *     none of the other packets of the key will be read.
  */
 int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                unsigned char *c),
                                void *ctx,
-                               struct openpgp_packet_list **packets);
+                               struct openpgp_packet_list **packets,
+                               int maxnum);
 
 /**
  *     write_openpgp_stream - Reads a stream of OpenPGP packets.