Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -1,8 +1,8 @@ CC = gcc PKG_CONFIG = pkg-config -CFLAGS = -Wall -g3 $(shell $(PKG_CONFIG) --cflags fuse) $(shell $(PKG_CONFIG) --cflags sqlite3) $(TCL_CFLAGS) +CFLAGS = -Wall -g3 -ggdb3 $(shell $(PKG_CONFIG) --cflags fuse) $(shell $(PKG_CONFIG) --cflags sqlite3) $(TCL_CFLAGS) LDFLAGS = $(TCL_LDFLAGS) LIBS = $(shell $(PKG_CONFIG) --libs fuse) $(shell $(PKG_CONFIG) --libs sqlite3) $(TCL_LIBS) PREFIX = /usr/local prefix = $(PREFIX) bindir = $(prefix)/bin Index: appfs.c ================================================================== --- appfs.c +++ appfs.c @@ -47,10 +47,17 @@ 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); } @@ -150,12 +157,56 @@ ckfree((void *) objv); return(retval); } -int appfs_getindex_cb(void *_head, int columns, char **values, char **names) { - struct appfs_package **head = _head, *obj; +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]); @@ -166,18 +217,18 @@ obj->isLatest = 1; } else { obj->isLatest = 0; } - if (*head == NULL) { + if (*head_p == NULL) { obj->counter = 0; } else { - obj->counter = (*head)->counter + 1; + obj->counter = (*head_p)->counter + 1; } - obj->_next = *head; - *head = obj; + obj->_next = *head_p; + *head_p = obj; return(0); } static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) { @@ -225,24 +276,34 @@ 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; +static int appfs_fuse_getattr(const char *_path, struct stat *stbuf) { + char *path; + char *hostname, *package; int res = 0; - if (path == NULL) { + APPFS_DEBUG("Enter (path = %s, ...)", _path); + + if (_path == NULL) { + return(-ENOENT); + } + + if (_path[0] != '/') { return(-ENOENT); } - APPFS_DEBUG("Enter (path = %s, ...)", path); - - 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; @@ -266,12 +327,19 @@ 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; + 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");