Esempio n. 1
0
Variant HHVM_FUNCTION(preg_split, const String& pattern, const String& subject,
                                  int limit /* = -1 */, int flags /* = 0 */) {
  return preg_split(pattern, subject, limit, flags);
}
Esempio n. 2
0
uint16_t handleGetRequest(char* req, cSocket* sock) {
	char* filename = NULL;
	
	char** matches = malloc(1*sizeof(char*));
	size_t reccount = preg_split(req,"(^GET[ ](.+)[ ])",matches);
	
	if(reccount > 1)
		return HTTP_ERROR_SERVER_ERROR;

	if(strlen(matches[0]) < MIN_CHAR_GET_REQ)
		return HTTP_ERROR_SERVER_ERROR;
	
	if(matches[0][4] != '/')
		return HTTP_ERROR_SERVER_ERROR;
	
	filename = (char*)malloc((strlen(chroot_path)+strlen(matches[0])-6+1)*sizeof(char));
	strcpy(filename,chroot_path);
	strncat(filename, &(matches[0])[5], strlen(matches[0])-6);
	strcat(filename,"\0");
	
	// free useless var from memory
	free(matches[0]);
	free(matches);
	
	FILE* file = fopen(filename,"r+");
	if(file == NULL) {
		forgeHeader(HTTP_ERROR_NOT_FOUND,sock,"");
		free(filename);
		return HTTP_ERROR_NOT_FOUND;
	}
	
	char rchar;
	uint64_t fileoffset = 0;
	
	// First pass to calculate filesize
	do {
		rchar = fgetc(file);
		fileoffset++;
	} while(rchar != EOF);
	
	// come back to the first offset
	rewind(file);
	
	// allocate the right memory size (optimize memory)
	char* content = malloc((fileoffset+1)*sizeof(char));
	fileoffset = 0;
	// copy file to content buffer
	do {
		rchar = fgetc(file);
		if(rchar != EOF) {
			content[fileoffset] = rchar;
			fileoffset++;
		}
	} while(rchar != EOF);
	
	content[fileoffset] = '\0';
	forgeHeader(HTTP_OK,sock,content);
	// proper close & memory free
	fclose(file);
	
	free(filename);
	//free(content); // memory bug for now :s
	return HTTP_OK;
}
Esempio n. 3
0
Variant f_preg_split(CVarRef pattern, CVarRef subject, int limit /* = -1 */,
                     int flags /* = 0 */) {
  return preg_split(pattern, subject, limit, flags);
}
Esempio n. 4
0
Variant HHVM_FUNCTION(preg_split, const String& pattern, const String& subject,
                                  const Variant& limit, int flags /* = 0 */) {
  //NOTE: .toInt64() returns 0 for null
  return preg_split(pattern, subject, limit.toInt64(), flags);
}