summaryrefslogtreecommitdiff
path: root/comms/malsync/patches/patch-ad
blob: e6a44138d840c320b402f806f2372f1a11938587 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
$NetBSD: patch-ad,v 1.1 2007/01/26 01:50:54 markd Exp $

--- malsync.c.orig	2007-01-23 00:37:31.000000000 +1300
+++ malsync.c
@@ -100,8 +100,7 @@ typedef struct {
     int pilot_rHandle;
     int pilot_RecIndex;
     recordid_t id;
-    uint8  *pilot_buffer;
-    int pilot_buffer_size;
+    pi_buffer_t *pi_buf;
     
     /* Secure Network Library Stuff */
     AGBool          hasseclib;
@@ -266,8 +265,8 @@ syncInfoFree(PalmSyncInfo * pInfo)
         if (NULL != pInfo->userConfig)
             AGUserConfigFree(pInfo->userConfig);
 
-        if (NULL != pInfo->pilot_buffer)
-            free(pInfo->pilot_buffer);
+        if (NULL != pInfo->pi_buf)
+            pi_buffer_free (pInfo->pi_buf);
 
         if (NULL != pInfo->commandProcessor)
             AGCommandProcessorFree(pInfo->commandProcessor);
@@ -290,9 +289,8 @@ syncInfoNew()
 
         bzero(pInfo, sizeof(PalmSyncInfo));
 
-        pInfo->pilot_buffer_size    = pbs;
-        pInfo->pilot_buffer         = (uint8 *)malloc(pbs);
-        if (NULL == pInfo->pilot_buffer)
+        pInfo->pi_buf = pi_buffer_new (pbs);
+        if (NULL == pInfo->pi_buf)
             goto fail;
 
         /* Allocate the platform calls record. */
@@ -341,8 +339,7 @@ int16 readInt16(uint8 * p)
 /*---------------------------------------------------------------------------*/
 static void 
 readAndUseDeviceInfoDatabase(AGDeviceInfo * devInfo,
-                             uint8 *dev_db_info_buffer,
-                             uint32 dev_db_info_buffer_size)
+                             pi_buffer_t *pi_buf)
 {
     int database_id = 0;
     long result;
@@ -373,13 +370,13 @@ readAndUseDeviceInfoDatabase(AGDeviceInf
         int rc;
 
         rc = dlp_ReadRecordByIndex(sd, database_id, 0, 
-                                   (void *)dev_db_info_buffer, 
-                                   &id, &dev_db_info_buffer_size, 
+                                   pi_buf, 
+                                   &id,
                                    &attr, &cat);
     
 
         if (rc >= 0) {
-            uint8 *p = dev_db_info_buffer;
+            uint8 *p = pi_buf->data;
             int16 dev_db_info_version = readInt16(p);
             p+=sizeof(int16);
             devInfo->colorDepth = readInt32(p);
@@ -472,8 +469,7 @@ readDeviceInfo(PalmSyncInfo * pInfo)
     }
 
     readAndUseDeviceInfoDatabase(devInfo,
-                                 pInfo->pilot_buffer,
-                                 pInfo->pilot_buffer_size);
+                                 pInfo->pi_buf);
 
     /* Override the color depth if the user wants low res images. */
     if (lowres) {
@@ -663,31 +659,36 @@ static int32 
 readDeviceUserConfig32(int userConfigDBHandle, AGUserConfig **deviceUserConfig)
 {
     recordid_t id;
-    int bufferSize = BUFFERSIZE;
+    pi_buffer_t *pi_buf;
     int attr = 0;
     int cat  = 0;
     int rc;
-    uint8 buffer[BUFFERSIZE];
     AGBufferReader * r = NULL;
 
-    rc = dlp_ReadRecordByIndex(sd, userConfigDBHandle, 0, (void *)buffer, 
-                               &id, &bufferSize, &attr, &cat);
+    pi_buf = pi_buffer_new (BUFFERSIZE);
+
+    rc = dlp_ReadRecordByIndex(sd, userConfigDBHandle, 0, pi_buf, 
+                               &id, &attr, &cat);
     
     if (rc < 0) {
         if (verbose)
             printf("readDeviceUserConfig: dlp_ReadRecordByIndex , err = %d\n",
                    rc);
+        pi_buffer_free (pi_buf);
         return 0;
     }
     
-    r = AGBufferReaderNew(buffer);
+    r = AGBufferReaderNew(pi_buf->data);
     if (r) {
         *deviceUserConfig = AGUserConfigNew();
         AGUserConfigReadData(*deviceUserConfig, (AGReader*)r);
         AGBufferReaderFree(r);
+        pi_buffer_free (pi_buf);
         return id;
-    } else
+    } else {
+        pi_buffer_free (pi_buf);
         return 0;
+    }
 }
 #define BUFFERSIZE 0xFFFF
 /*---------------------------------------------------------------------------*/
@@ -695,31 +696,36 @@ static int32 readDeviceUserConfig31(int 
                                     AGUserConfig **deviceUserConfig)
 {
     recordid_t id;
-    int bufferSize = BUFFERSIZE;
     int attr = 0;
     int cat  = 0;
     int rc;
-    uint8 buffer[BUFFERSIZE];
+    pi_buffer_t *pi_buf;
     AGBufferReader * r = NULL;
 
-    rc = dlp_ReadRecordByIndex(sd, userConfigDBHandle, 0, (void *)buffer, 
-                               &id, &bufferSize, &attr, &cat);
+    pi_buf = pi_buffer_new (BUFFERSIZE);
+
+    rc = dlp_ReadRecordByIndex(sd, userConfigDBHandle, 0, pi_buf, 
+                               &id, &attr, &cat);
     
     if (rc < 0) {
         if (verbose)
             printf("readDeviceUserConfig: dlp_ReadRecordByIndex , err = %d\n",
                    rc);
+        pi_buffer_free (pi_buf);
         return 0;
     }
     
-    r = AGBufferReaderNew(buffer);
+    r = AGBufferReaderNew(pi_buf->data);
     if (r) {
         *deviceUserConfig = AGUserConfigNew();
         MAL31ReadUserData(*deviceUserConfig, (AGReader*)r);
         AGBufferReaderFree(r);
+        pi_buffer_free (pi_buf);
         return id;
-    } else
+    } else {
+        pi_buffer_free (pi_buf);
         return 0;
+    }
 }
 /*---------------------------------------------------------------------------*/
 static int32 readDeviceUserConfig(int userConfigDBHandle,
@@ -740,23 +746,25 @@ static void writeDeviceUserConfig(int us
 {
 
     recordid_t id;
-    int bufferSize = BUFFERSIZE;
     int attr = 0;
     int cat  = 0;
-    uint8 buffer[BUFFERSIZE];
     AGBufferWriter * w = NULL;
+
     w = AGBufferWriterNew(0);
     if (w) {
         long result;
+        pi_buffer_t *pi_buf;
         
+        pi_buf = pi_buffer_new (BUFFERSIZE);
+        
         if (threeone) {
             MAL31WriteUserData(deviceUserConfig, (AGWriter*)w);
         } else {
             AGUserConfigWriteData(deviceUserConfig, (AGWriter*)w);
         }
 
-        result = dlp_ReadRecordByIndex(sd, userConfigDBHandle, 0, (void *)buffer, 
-                                   &id, &bufferSize, &attr, &cat);
+        result = dlp_ReadRecordByIndex(sd, userConfigDBHandle, 0, pi_buf, 
+                                   &id, &attr, &cat);
         
         if (result < 0)
             id = 0;
@@ -766,7 +774,7 @@ static void writeDeviceUserConfig(int us
                                   AGBufferWriterGetBufferSize(w), 
                                   &id);
         AGBufferWriterFree(w);
-
+        pi_buffer_free (pi_buf);
     }
 }
 
@@ -1044,17 +1052,17 @@ getRecordBase(PalmSyncInfo * pInfo, AGBo
     int32 result;
     int att = 0;
     int cat = 0;
-    int size = pInfo->pilot_buffer_size;
+    //int size = pInfo->pi_buf->allocated;
     int idx   = pInfo->pilot_RecIndex++;
 
     result = (modonly) ?
-        dlp_ReadNextModifiedRec (sd, pInfo->pilot_rHandle, pInfo->pilot_buffer,
+        dlp_ReadNextModifiedRec (sd, pInfo->pilot_rHandle, pInfo->pi_buf,
                                  &pInfo->id, &idx,
-                                 &size, &att, &cat)
+                                 &att, &cat)
         :
         dlp_ReadRecordByIndex(sd, pInfo->pilot_rHandle, idx,
-                              pInfo->pilot_buffer, &pInfo->id,
-                              &size, &att, &cat);
+                              pInfo->pi_buf, &pInfo->id,
+                              &att, &cat);
     
     if (result < 0) {
         closeDatabase(pInfo);
@@ -1070,7 +1078,7 @@ getRecordBase(PalmSyncInfo * pInfo, AGBo
     }
     pInfo->record = AGRecordInit(pInfo->record, pInfo->id,
                                  AGPalmPilotAttribsToMALMod((uint8)att),
-                                 size, pInfo->pilot_buffer, 0, NULL);
+                                 pInfo->pi_buf->used, pInfo->pi_buf->data, 0, NULL);
 
     *record = pInfo->record;
     return AGCLIENT_CONTINUE;
@@ -1363,7 +1371,6 @@ main(int argc, char *argv[])
 static void 
 Connect(PalmSyncInfo *pi) 
 {
-    struct pi_sockaddr addr;
     int ret;
     
     if (sd != 0)
@@ -1609,7 +1616,6 @@ fill_in_versioninfo(int sd, AGExpansionV
                                    0, 
                                    (void *)version_buffer, 
                                    &id, 
-                                   &version_buffer_size, 
                                    &attr, 
                                    &cat);