Check-in [e37bc482a9]
Overview
Comment:More work towards reading package data
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e37bc482a978d0b4e19b06ed8f612a4e2818e560
User & Date: rkeene on 2014-09-08 06:48:44
Other Links: manifest | tags
Context
2014-09-08
07:17
More work towards parsing directory entries check-in: 85bda525b9 user: rkeene tags: trunk
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
Changes

Modified Makefile from [bf41e80612] to [51fd163395].

     1      1   CC = gcc
     2      2   PKG_CONFIG = pkg-config
     3         -CFLAGS = -Wall -g3 $(shell $(PKG_CONFIG) --cflags fuse) $(shell $(PKG_CONFIG) --cflags sqlite3) $(TCL_CFLAGS)
            3  +CFLAGS = -Wall -g3 -ggdb3 $(shell $(PKG_CONFIG) --cflags fuse) $(shell $(PKG_CONFIG) --cflags sqlite3) $(TCL_CFLAGS)
     4      4   LDFLAGS = $(TCL_LDFLAGS)
     5      5   LIBS = $(shell $(PKG_CONFIG) --libs fuse) $(shell $(PKG_CONFIG) --libs sqlite3) $(TCL_LIBS)
     6      6   PREFIX = /usr/local
     7      7   prefix = $(PREFIX)
     8      8   bindir = $(prefix)/bin
     9      9   
    10     10   ifneq ($(TCLKIT_SDK_DIR),)

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

    45     45   	appfs_os_t os;
    46     46   	appfs_cpuArch_t cpuArch;
    47     47   	int isLatest;
    48     48   
    49     49   	int counter;
    50     50   	struct appfs_package *_next;
    51     51   };
           52  +
           53  +struct appfs_site {
           54  +	char name[256];
           55  +
           56  +	int counter;
           57  +	struct appfs_site *_next;
           58  +};
    52     59   
    53     60   static appfs_os_t appfs_convert_os_fromString(const char *os) {
    54     61   	if (strcasecmp(os, "Linux") == 0) {
    55     62   		return(APPFS_OS_LINUX);
    56     63   	}
    57     64   
    58     65   	if (strcasecmp(os, "Darwin") == 0 || strcasecmp(os, "Mac OS") == 0 || strcasecmp(os, "Mac OS X") == 0) {
................................................................................
   148    155   	retval = Tcl_EvalObjv(interp, objc, objv, 0);
   149    156   
   150    157   	ckfree((void *) objv);
   151    158   
   152    159   	return(retval);
   153    160   }
   154    161   
   155         -int appfs_getindex_cb(void *_head, int columns, char **values, char **names) {
   156         -	struct appfs_package **head = _head, *obj;
          162  +static int appfs_getsites_cb(void *_head, int columns, char **values, char **names) {
          163  +	struct appfs_site **head_p, *obj;
          164  +
          165  +	head_p = _head;
          166  +
          167  +	obj = (void *) ckalloc(sizeof(*obj));
          168  +	snprintf(obj->name, sizeof(obj->name), "%s", values[0]);
          169  +
          170  +	if (*head_p == NULL) {
          171  +		obj->counter = 0;
          172  +	} else {
          173  +		obj->counter = (*head_p)->counter + 1;
          174  +	}
          175  +
          176  +	obj->_next = *head_p;
          177  +	*head_p = obj;
          178  +
          179  +	return(0);
          180  +}
          181  +
          182  +static struct appfs_site *appfs_getsites(int *site_count_p) {
          183  +	struct appfs_site *head = NULL;
          184  +	int sqlite_ret;
          185  +
          186  +	if (site_count_p == NULL) {
          187  +		return(NULL);
          188  +	}
          189  +
          190  +	sqlite_ret = sqlite3_exec(globalThread.db, "SELECT DISTINCT hostname FROM packages;", appfs_getsites_cb, &head, NULL);
          191  +	if (sqlite_ret != SQLITE_OK) {
          192  +		APPFS_DEBUG("Call to sqlite3_exec failed.");
          193  +
          194  +		return(NULL);
          195  +	}
          196  +
          197  +	if (head != NULL) {
          198  +		*site_count_p = head->counter + 1;
          199  +	}
          200  +
          201  +	return(head);
          202  +}
          203  +
          204  +static int appfs_getindex_cb(void *_head, int columns, char **values, char **names) {
          205  +	struct appfs_package **head_p, *obj;
          206  +
          207  +	head_p = _head;
   157    208   
   158    209   	obj = (void *) ckalloc(sizeof(*obj));
   159    210   
   160    211   	snprintf(obj->name, sizeof(obj->name), "%s", values[0]);
   161    212   	snprintf(obj->version, sizeof(obj->version), "%s", values[1]);
   162    213   	snprintf(obj->sha1, sizeof(obj->sha1), "%s", values[2]);
   163    214   	obj->os = appfs_convert_os_fromString(values[3]);
................................................................................
   164    215   	obj->cpuArch = appfs_convert_cpuArch_fromString(values[4]);
   165    216   	if (values[5][0] == '1') {
   166    217   		obj->isLatest = 1;
   167    218   	} else {
   168    219   		obj->isLatest = 0;
   169    220   	}
   170    221   
   171         -	if (*head == NULL) {
          222  +	if (*head_p == NULL) {
   172    223   		obj->counter = 0;
   173    224   	} else {
   174         -		obj->counter = (*head)->counter + 1;
          225  +		obj->counter = (*head_p)->counter + 1;
   175    226   	}
   176    227   
   177         -	obj->_next = *head;
   178         -	*head = obj;
          228  +	obj->_next = *head_p;
          229  +	*head_p = obj;
   179    230   
   180    231   	return(0);
   181    232   }
   182    233   
   183    234   static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) {
   184    235   	struct appfs_package *head = NULL;
   185    236   	char *sql;
................................................................................
   223    274   	return(0);
   224    275   }
   225    276   
   226    277   static int appfs_getmanifest(const char *hostname, const char *sha1) {
   227    278   	return(0);
   228    279   }
   229    280   
   230         -static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
   231         -	char *hostname;
          281  +static int appfs_fuse_getattr(const char *_path, struct stat *stbuf) {
          282  +	char *path;
          283  +	char *hostname, *package;
   232    284   	int res = 0;
   233    285   
   234         -	if (path == NULL) {
          286  +	APPFS_DEBUG("Enter (path = %s, ...)", _path);
          287  +
          288  +	if (_path == NULL) {
          289  +		return(-ENOENT);
          290  +	}
          291  +
          292  +	if (_path[0] != '/') {
   235    293   		return(-ENOENT);
   236    294   	}
   237    295   
   238         -	APPFS_DEBUG("Enter (path = %s, ...)", path);
   239         -
   240         -	if (path[0] != '/') {
   241         -		return(-ENOENT);
          296  +	if (_path[1] == '\0') {
          297  +		/* Request for the root directory */
   242    298   	}
   243    299   
          300  +	path = strdup(_path);
          301  +
          302  +	hostname = path + 1;
          303  +	package = strchr(hostname, '/');
          304  +
   244    305   	memset(stbuf, 0, sizeof(struct stat));
   245    306   
   246    307   	stbuf->st_mode = S_IFDIR | 0755;
   247    308   	stbuf->st_nlink = 2;
   248    309   
   249    310   	return res;
   250    311   }
................................................................................
   264    325   
   265    326   static int appfs_fuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
   266    327   	return(-ENOENT);
   267    328   }
   268    329   
   269    330   #ifdef APPFS_TEST_DRIVER
   270    331   static int appfs_test_driver(void) {
          332  +	struct appfs_site *sites, *site;
   271    333   	struct appfs_package *packages, *package;
   272         -	int packages_count = 0;
          334  +	int packages_count = 0, sites_count = 0;
          335  +
          336  +	sites = appfs_getsites(&sites_count);
          337  +	printf("Sites:\n");
          338  +	for (site = sites; site; site = site->_next) {
          339  +		printf("\tname = %s\n", site->name);
          340  +	}
   273    341   
   274    342   	packages = appfs_getindex("rkeene.org", &packages_count);
   275    343   	if (packages == NULL || packages_count == 0) {
   276    344   		fprintf(stderr, "Unable to fetch package index from rkeene.org.\n");
   277    345   
   278    346   		return(1);
   279    347   	}