]> git.sommitrealweird.co.uk Git - onak.git/blobdiff - keydb_pg.c
cscvs to tla changeset 54
[onak.git] / keydb_pg.c
index 76129fa0b1565be42a39d46de3176e4cb097828b..adfbc69619a05bea2ed5e81d9c36989d3a628ceb 100644 (file)
@@ -23,7 +23,7 @@
 #include "hash.h"
 #include "keydb.h"
 #include "keyid.h"
 #include "hash.h"
 #include "keydb.h"
 #include "keyid.h"
-#include "keyindex.h"
+#include "decodekey.h"
 #include "keystructs.h"
 #include "mem.h"
 #include "onak-conf.h"
 #include "keystructs.h"
 #include "mem.h"
 #include "onak-conf.h"
@@ -132,7 +132,8 @@ void endtrans(void)
  *     in and then parse_keys() to parse the packets into a publickey
  *     structure.
  */
  *     in and then parse_keys() to parse the packets into a publickey
  *     structure.
  */
-int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, bool intrans)
+int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
+               bool intrans)
 {
        struct openpgp_packet_list *packets = NULL;
        PGresult *result = NULL;
 {
        struct openpgp_packet_list *packets = NULL;
        PGresult *result = NULL;
@@ -174,6 +175,8 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, bool intrans
                                                &packets);
                                parse_keys(packets, publickey);
                                lo_close(dbconn, fd);
                                                &packets);
                                parse_keys(packets, publickey);
                                lo_close(dbconn, fd);
+                               free_packet_list(packets);
+                               packets = NULL;
                        }
                }
        } else if (PQresultStatus(result) != PGRES_TUPLES_OK) {
                        }
                }
        } else if (PQresultStatus(result) != PGRES_TUPLES_OK) {
@@ -238,6 +241,8 @@ int fetch_key_text(const char *search, struct openpgp_publickey **publickey)
                                                &packets);
                                parse_keys(packets, publickey);
                                lo_close(dbconn, fd);
                                                &packets);
                                parse_keys(packets, publickey);
                                lo_close(dbconn, fd);
+                               free_packet_list(packets);
+                               packets = NULL;
                        }
                }
        } else if (PQresultStatus(result) != PGRES_TUPLES_OK) {
                        }
                }
        } else if (PQresultStatus(result) != PGRES_TUPLES_OK) {
@@ -308,6 +313,8 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update)
                write_openpgp_stream(keydb_putchar, &fd, packets);
                lo_close(dbconn, fd);
        }
                write_openpgp_stream(keydb_putchar, &fd, packets);
                lo_close(dbconn, fd);
        }
+       free_packet_list(packets);
+       packets = NULL;
 
        snprintf(statement, 1023, 
                        "INSERT INTO onak_keys (keyid, keydata) VALUES "
 
        snprintf(statement, 1023, 
                        "INSERT INTO onak_keys (keyid, keydata) VALUES "
@@ -499,9 +506,10 @@ struct ll *getkeysigs(uint64_t keyid)
        PGresult *result = NULL;
        uint64_t signer;
        char statement[1024];
        PGresult *result = NULL;
        uint64_t signer;
        char statement[1024];
-       int i = 0;
+       int i, j;
        int numsigs = 0;
        bool intrans = false;
        int numsigs = 0;
        bool intrans = false;
+       char *str;
 
        if (!intrans) {
                result = PQexec(dbconn, "BEGIN");
 
        if (!intrans) {
                result = PQexec(dbconn, "BEGIN");
@@ -509,14 +517,25 @@ struct ll *getkeysigs(uint64_t keyid)
        }
 
        snprintf(statement, 1023,
        }
 
        snprintf(statement, 1023,
-               "SELECT signer FROM onak_sigs WHERE signee = '%llX'",
+               "SELECT DISTINCT signer FROM onak_sigs WHERE signee = '%llX'",
                keyid);
        result = PQexec(dbconn, statement);
 
        if (PQresultStatus(result) == PGRES_TUPLES_OK) {
                numsigs = PQntuples(result);
                for (i = 0; i < numsigs;  i++) {
                keyid);
        result = PQexec(dbconn, statement);
 
        if (PQresultStatus(result) == PGRES_TUPLES_OK) {
                numsigs = PQntuples(result);
                for (i = 0; i < numsigs;  i++) {
-                       signer = strtol(PQgetvalue(result, i, 0), NULL, 16);
+                       j = 0;
+                       signer = 0;
+                       str = PQgetvalue(result, i, 0);
+                       while (str[j] != 0) {
+                               signer <<= 4;
+                               if (str[j] >= '0' && str[j] <= '9') {
+                                       signer += str[j] - '0';
+                               } else {
+                                       signer += str[j] - 'A' + 10;
+                               }
+                               j++;
+                       }
                        sigs = lladd(sigs, createandaddtohash(signer));
                }
        } else if (PQresultStatus(result) != PGRES_TUPLES_OK) {
                        sigs = lladd(sigs, createandaddtohash(signer));
                }
        } else if (PQresultStatus(result) != PGRES_TUPLES_OK) {