45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
appfs_os_t os;
appfs_cpuArch_t cpuArch;
int isLatest;
int counter;
struct appfs_package *_next;
};
static appfs_os_t appfs_convert_os_fromString(const char *os) {
if (strcasecmp(os, "Linux") == 0) {
return(APPFS_OS_LINUX);
}
if (strcasecmp(os, "Darwin") == 0 || strcasecmp(os, "Mac OS") == 0 || strcasecmp(os, "Mac OS X") == 0) {
|
>
>
>
>
>
>
>
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
appfs_os_t os;
appfs_cpuArch_t cpuArch;
int isLatest;
int counter;
struct appfs_package *_next;
};
struct appfs_site {
char name[256];
int counter;
struct appfs_site *_next;
};
static appfs_os_t appfs_convert_os_fromString(const char *os) {
if (strcasecmp(os, "Linux") == 0) {
return(APPFS_OS_LINUX);
}
if (strcasecmp(os, "Darwin") == 0 || strcasecmp(os, "Mac OS") == 0 || strcasecmp(os, "Mac OS X") == 0) {
|
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
|
retval = Tcl_EvalObjv(interp, objc, objv, 0);
ckfree((void *) objv);
return(retval);
}
int appfs_getindex_cb(void *_head, int columns, char **values, char **names) {
struct appfs_package **head = _head, *obj;
obj = (void *) ckalloc(sizeof(*obj));
snprintf(obj->name, sizeof(obj->name), "%s", values[0]);
snprintf(obj->version, sizeof(obj->version), "%s", values[1]);
snprintf(obj->sha1, sizeof(obj->sha1), "%s", values[2]);
obj->os = appfs_convert_os_fromString(values[3]);
obj->cpuArch = appfs_convert_cpuArch_fromString(values[4]);
if (values[5][0] == '1') {
obj->isLatest = 1;
} else {
obj->isLatest = 0;
}
if (*head == NULL) {
obj->counter = 0;
} else {
obj->counter = (*head)->counter + 1;
}
obj->_next = *head;
*head = obj;
return(0);
}
static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) {
struct appfs_package *head = NULL;
char *sql;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
|
|
|
|
|
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
|
retval = Tcl_EvalObjv(interp, objc, objv, 0);
ckfree((void *) objv);
return(retval);
}
static int appfs_getsites_cb(void *_head, int columns, char **values, char **names) {
struct appfs_site **head_p, *obj;
head_p = _head;
obj = (void *) ckalloc(sizeof(*obj));
snprintf(obj->name, sizeof(obj->name), "%s", values[0]);
if (*head_p == NULL) {
obj->counter = 0;
} else {
obj->counter = (*head_p)->counter + 1;
}
obj->_next = *head_p;
*head_p = obj;
return(0);
}
static struct appfs_site *appfs_getsites(int *site_count_p) {
struct appfs_site *head = NULL;
int sqlite_ret;
if (site_count_p == NULL) {
return(NULL);
}
sqlite_ret = sqlite3_exec(globalThread.db, "SELECT DISTINCT hostname FROM packages;", appfs_getsites_cb, &head, NULL);
if (sqlite_ret != SQLITE_OK) {
APPFS_DEBUG("Call to sqlite3_exec failed.");
return(NULL);
}
if (head != NULL) {
*site_count_p = head->counter + 1;
}
return(head);
}
static int appfs_getindex_cb(void *_head, int columns, char **values, char **names) {
struct appfs_package **head_p, *obj;
head_p = _head;
obj = (void *) ckalloc(sizeof(*obj));
snprintf(obj->name, sizeof(obj->name), "%s", values[0]);
snprintf(obj->version, sizeof(obj->version), "%s", values[1]);
snprintf(obj->sha1, sizeof(obj->sha1), "%s", values[2]);
obj->os = appfs_convert_os_fromString(values[3]);
obj->cpuArch = appfs_convert_cpuArch_fromString(values[4]);
if (values[5][0] == '1') {
obj->isLatest = 1;
} else {
obj->isLatest = 0;
}
if (*head_p == NULL) {
obj->counter = 0;
} else {
obj->counter = (*head_p)->counter + 1;
}
obj->_next = *head_p;
*head_p = obj;
return(0);
}
static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) {
struct appfs_package *head = NULL;
char *sql;
|
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
248
249
250
|
return(0);
}
static int appfs_getmanifest(const char *hostname, const char *sha1) {
return(0);
}
static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
char *hostname;
int res = 0;
if (path == NULL) {
return(-ENOENT);
}
APPFS_DEBUG("Enter (path = %s, ...)", path);
if (path[0] != '/') {
return(-ENOENT);
}
memset(stbuf, 0, sizeof(struct stat));
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
return res;
}
|
|
>
|
>
>
|
>
>
>
>
|
>
|
|
<
>
|
>
>
|
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
return(0);
}
static int appfs_getmanifest(const char *hostname, const char *sha1) {
return(0);
}
static int appfs_fuse_getattr(const char *_path, struct stat *stbuf) {
char *path;
char *hostname, *package;
int res = 0;
APPFS_DEBUG("Enter (path = %s, ...)", _path);
if (_path == NULL) {
return(-ENOENT);
}
if (_path[0] != '/') {
return(-ENOENT);
}
if (_path[1] == '\0') {
/* Request for the root directory */
}
path = strdup(_path);
hostname = path + 1;
package = strchr(hostname, '/');
memset(stbuf, 0, sizeof(struct stat));
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
return res;
}
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
static int appfs_fuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
return(-ENOENT);
}
#ifdef APPFS_TEST_DRIVER
static int appfs_test_driver(void) {
struct appfs_package *packages, *package;
int packages_count = 0;
packages = appfs_getindex("rkeene.org", &packages_count);
if (packages == NULL || packages_count == 0) {
fprintf(stderr, "Unable to fetch package index from rkeene.org.\n");
return(1);
}
|
>
|
>
>
>
>
>
>
|
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
static int appfs_fuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
return(-ENOENT);
}
#ifdef APPFS_TEST_DRIVER
static int appfs_test_driver(void) {
struct appfs_site *sites, *site;
struct appfs_package *packages, *package;
int packages_count = 0, sites_count = 0;
sites = appfs_getsites(&sites_count);
printf("Sites:\n");
for (site = sites; site; site = site->_next) {
printf("\tname = %s\n", site->name);
}
packages = appfs_getindex("rkeene.org", &packages_count);
if (packages == NULL || packages_count == 0) {
fprintf(stderr, "Unable to fetch package index from rkeene.org.\n");
return(1);
}
|