summaryrefslogtreecommitdiff
blob: 46a29608814a8e0549645a766bfec523246beebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--- KeyRing/keyring.c.original	2006-06-24 21:49:51.000000000 -0700
+++ KeyRing/keyring.c	2006-12-17 20:02:08.000000000 -0800
@@ -160,6 +160,8 @@
 
 static int keyring_find(int unique_id);
 
+int plugin_unpack_cai_from_ai(struct CategoryAppInfo *cai, unsigned char *ai_raw, int len);
+
 /****************************** Main Code *************************************/
 static int pack_KeyRing(struct KeyRing *kr, unsigned char *buf, int buf_size,
 			int *wrote_size)
@@ -1348,17 +1350,12 @@
 
    /* This gets the application specific data out of the database for us.
     * We still need to write a function to unpack it from its blob form. */
+
+   memset (&ai, 0, sizeof (ai));
    
    jp_get_app_info("Keys-Gtkr", &buf, &buf_size);
 
-   /* This call should work, but the appinfo is too small, so we do it */
-   /* Keyring is not using a legal category app info structure */
-   /* unpack_CategoryAppInfo(&ai, buf, buf_size+4); */
-   
-   /* I'm going to be lazy and only get the names, since that's all I use */
-   for (i=0; i<NUM_KEYRING_CAT_ITEMS; i++) {
-      memcpy(&ai.name[i][0], buf+i*16+2, 16);
-   }
+   plugin_unpack_cai_from_ai (&ai, buf, buf_size);
 
    free(buf);
    
@@ -2238,3 +2235,62 @@
 
    return EXIT_SUCCESS;
 }
+
+/* Stolen from pilot-link and modified slightly. */
+int plugin_unpack_cai_from_ai(struct CategoryAppInfo *ai, unsigned char *record, int len)
+{
+	int 	i, rec;
+
+	if (len < 2 + 16 * 16 + 16 + 2)
+		return 0;
+	rec = get_short(record);
+	for (i = 0; i < 16; i++) {
+		if (rec & (1 << i))
+			ai->renamed[i] = 1;
+		else
+			ai->renamed[i] = 0;
+	}
+	record += 2;
+	for (i = 0; i < 16; i++) {
+		memcpy(ai->name[i], record, 16);
+		record += 16;
+	}
+	memcpy(ai->ID, record, 16);
+	record += 16;
+	ai->lastUniqueID = get_byte(record);
+	record += 2;
+
+	return 2 + 16 * 16 + 16 + 2;
+}
+
+int plugin_pack_cai_into_ai(struct CategoryAppInfo *ai, unsigned char *record, int len)
+{
+	int 	i, rec;
+	
+	unsigned char *start = record;
+
+	if (!record) {
+		return 2 + 16 * 16 + 16 + 2;
+	}
+	if (len < (2 + 16 * 16 + 16 + 2))
+		return 0;	/* not enough room */
+	rec = 0;
+	for (i = 0; i < 16; i++) {
+		if (ai->renamed[i])
+			rec |= (1 << i);
+	}
+	set_short(record, rec);
+	record += 2;
+	for (i = 0; i < 16; i++) {
+		memcpy(record, ai->name[i], 16);
+		record += 16;
+	}
+	memcpy(record, ai->ID, 16);
+	record += 16;
+	set_byte(record, ai->lastUniqueID);
+	record++;
+	set_byte(record, 0);		/* gapfill */
+	record++;
+
+	return (record - start);
+}