Check-in [654957c655]
Overview
Comment:Updated to print packages
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 654957c65509f97c65b189fc808abe2d3fbc79e4
User & Date: rkeene on 2014-09-08 06:12:46
Other Links: manifest | tags
Context
2014-09-08
06:48
More work towards reading package data check-in: e37bc482a9 user: rkeene tags: trunk
06:12
Updated to print packages check-in: 654957c655 user: rkeene tags: trunk
04:34
More work towards SQLite3 integration check-in: 76ac4557f6 user: rkeene tags: trunk
Changes

Modified appfs.c from [d2a493f839] to [0ffa90a2b2].

37
38
39
40
41
42
43

44
45
46



47
48
49
50
51
52
53
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57







+



+
+
+







	APPFS_CPU_I386,
	APPFS_CPU_ARM
} appfs_cpuArch_t;

struct appfs_package {
	char name[128];
	char version[64];
	char sha1[41];
	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);
	}

79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97







-
+







		case APPFS_CPU_UNKNOWN:
			return("unknown");
	}

	return("unknown");
}

static appfs_cpuArch_t appfs_convert_cpu_fromString(const char *cpu) {
static appfs_cpuArch_t appfs_convert_cpuArch_fromString(const char *cpu) {
	if (strcasecmp(cpu, "amd64") == 0 || strcasecmp(cpu, "x86_64") == 0) {
		return(APPFS_CPU_AMD64);
	}

	if (strcasecmp(cpu, "i386") == 0 || \
	    strcasecmp(cpu, "i486") == 0 || \
	    strcasecmp(cpu, "i586") == 0 || \
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
107
108
109
110
111
112
113

114
115
116
117
118
119
120
121







-
+







	if (strcasecmp(cpu, "noarch") == 0) {
		return(APPFS_CPU_ALL);
	}

	return(APPFS_CPU_UNKNOWN);
}

static const char *appfs_convert_cpu_toString(appfs_cpuArch_t cpu) {
static const char *appfs_convert_cpuArch_toString(appfs_cpuArch_t cpu) {
	switch (cpu) {
		case APPFS_CPU_ALL:
			return("noarch");
		case APPFS_CPU_AMD64:
			return("amd64");
		case APPFS_CPU_I386:
			return("ix86");
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
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
248
249








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
+












+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



+



+



+


+
+
+
+

+
+
+
+








	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;
	int tcl_ret;
	int tcl_ret, sqlite_ret;

	if (package_count_p == NULL) {
		return(NULL);
	}

	tcl_ret = appfs_Tcl_Eval(globalThread.interp, 2, "::appfs::getindex", hostname);
	if (tcl_ret != TCL_OK) {
		APPFS_DEBUG("Call to ::appfs::getindex failed: %s", Tcl_GetStringResult(globalThread.interp));

		return(NULL);
	}

	sql = sqlite3_mprintf("SELECT package, version, sha1, os, cpuArch, isLatest FROM packages WHERE hostname = %Q;", hostname);
	if (sql == NULL) {
		APPFS_DEBUG("Call to sqlite3_mprintf failed.");

	return(NULL);
		return(NULL);
	}

	sqlite_ret = sqlite3_exec(globalThread.db, sql, appfs_getindex_cb, &head, NULL);
	sqlite3_free(sql);

	if (sqlite_ret != SQLITE_OK) {
		APPFS_DEBUG("Call to sqlite3_exec failed.");

		return(NULL);
	}

	if (head != NULL) {
		*package_count_p = head->counter + 1;
	}

	return(head);
}

static int appfs_getfile(const char *hostname, const char *sha1) {
	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;
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
264
265
266
267
268
269
270

271
272
273
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







-
+








+
+
+
+
+
+
+
+
+
+



-
+
-






+








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;
	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);
	}

	for (package = packages; package; package = package->_next) {
		printf("Package:\n\tname = %s\n\tversion = %s\n\tsha1 = %s\n\tos = %s\n\tcpuArch = %s\n",
			package->name,
			package->version,
			package->sha1,
			appfs_convert_os_toString(package->os),
			appfs_convert_cpuArch_toString(package->cpuArch)
		);
	}

	return(0);
}
#endif
#else

static struct fuse_operations appfs_oper = {
	.getattr	= appfs_fuse_getattr,
	.readdir	= appfs_fuse_readdir,
	.open		= appfs_fuse_open,
	.read		= appfs_fuse_read
};
#endif

int main(int argc, char **argv) {
	const char *cachedir = APPFS_CACHEDIR;
	char dbfilename[1024];
	int tcl_ret, snprintf_ret, sqlite_ret;

	globalThread.interp = Tcl_CreateInterp();