Example #1
0
const char *jsonParse(PJsonObject object,const char *jsonString){
    if(*jsonString=='{'){
        jsonString++;
        jsonString=getItem(object,jsonString);
    }else if(*jsonString=='['){
        jsonString++;
        object->type=ARRAY;
        jsonString=getArrayItem(object,jsonString);
    }else{
        showErrorMessage(jsonString,NO_START);
    }
    if(*jsonString!=']'&&*jsonString!='}')
        showErrorMessage(jsonString,NO_END);
    jsonString++;
    return jsonString;
}
Example #2
0
int recvResult(int fd, struct actionParameters *ap,struct array * results){
	int counter=0, res;
	struct flEntry file;///, *f;
	struct array * results2;
	char port[7];
	char ipstr[56];
	flushBuf(&ap->combuf);
	/* I don't flush results on purpose  */
	/* get a line */
	logmsg(ap->semid, ap->logfd, LOGLEVEL_WARN, "before loop%lu\n\n", 
      results->itemcount);
	while (( res = getTokenFromStream(fd, &ap->combuf, &ap->comline, 
					"\n", "\r\n",NULL ))){
		/* get first word -> ip */
		strncpy(ipstr, (char *)ap->comline.buf, 56);
		if (res ==  -1) return -3;
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) ip: %s\n", ipstr);

		/* get second word -> port */
		if (getTokenFromBuffer(&ap->combuf, &ap->comline, " ", "\n",NULL ) == -1)
			return -3;
		strncpy(port, (char *)ap->comline.buf, 7);
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) port: %s\n", 
        port);

		if (parseIP(ipstr, (struct sockaddr *)&file.ip, port, 0) == -1)
			return -3;

		/* get third word -> filename */
		if (getTokenFromBuffer( &ap->combuf, &ap->comline, " ", "\n",NULL ) == -1)
			return -3;
		strcpy(file.filename, (char *)ap->comline.buf);
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) filename: %s\n",
			 	file.filename);

		/* get fourth word -> size */
		if (getTokenFromBuffer( &ap->combuf, &ap->comline, " ", "\n",NULL ) == -1)
			return -3;
    long size;
		if ((size = my_strtol((char *)ap->comline.buf)) < 0 || errno) return -3;
    file.size = size;
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) size: %d\n", 
        file.size);

		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "got this: %s\n%d\n%s\n%lu\n", 
        putIP((struct sockaddr *)&file.ip), 
					getPort((struct sockaddr *) &file.ip), file.filename, file.size);

		results2 = addArrayItem(results, &file);
		if (results2) results = results2;
		else {
			logmsg(ap->semid, ap->logfd, LOGLEVEL_FATAL, 
          "couldn't resize Resultsarray");
			return -3;
		}

		file = *((struct flEntry *)getArrayItem(results, counter));
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, 
				"Array Memory got this: %s\n%d\n%s\n%lu - entry no %d\n",
			 	putIP((struct sockaddr *)&file.ip), getPort((struct sockaddr *) &file.ip),
				file.filename, file.size, results->itemcount);
		counter++;
	}
	return counter;
}
Example #3
0
void *iterateArray(struct array *a, unsigned long *i) {
	/* if it's the last item then it doesn't matter if we inc i */
	return getArrayItem(a, (*i)++);
}