mirror of
				https://github.com/lxsang/ant-http
				synced 2025-10-31 02:15:45 +01:00 
			
		
		
		
	fix plugin exec
This commit is contained in:
		| @@ -243,7 +243,8 @@ void* resolve_request(void* data) | |||||||
| 	task->priority++; | 	task->priority++; | ||||||
| 	char* url = (char*)dvalue(rq->request, "RESOURCE_PATH"); | 	char* url = (char*)dvalue(rq->request, "RESOURCE_PATH"); | ||||||
| 	char* newurl = NULL; | 	char* newurl = NULL; | ||||||
| 	char* rqp = (char*)dvalue(rq->request, "REQUEST_PATH"); | 	char* rqp = NULL; | ||||||
|  | 	char* oldrqp = NULL; | ||||||
| 	strcpy(path, server_config.htdocs); | 	strcpy(path, server_config.htdocs); | ||||||
| 	strcat(path, url); | 	strcat(path, url); | ||||||
| 	LOG("Path is : %s \n", path); | 	LOG("Path is : %s \n", path); | ||||||
| @@ -251,7 +252,16 @@ void* resolve_request(void* data) | |||||||
| 	//	strcat(path, "index.html"); | 	//	strcat(path, "index.html"); | ||||||
| 	if (stat(path, &st) == -1) { | 	if (stat(path, &st) == -1) { | ||||||
| 		free(task); | 		free(task); | ||||||
| 		return execute_plugin(rq, rqp); | 		rqp = strdup((char*)dvalue(rq->request, "REQUEST_PATH")); | ||||||
|  | 		oldrqp = rqp; | ||||||
|  | 		trim(rqp, '/'); | ||||||
|  | 		newurl = strsep(&rqp, "/"); | ||||||
|  | 		if(!rqp) rqp = strdup("/"); | ||||||
|  | 		else	rqp = strdup(rqp); | ||||||
|  | 		dput(rq->request, "RESOURCE_PATH", rqp); | ||||||
|  | 		task = execute_plugin(rq, newurl); | ||||||
|  | 		free(oldrqp); | ||||||
|  | 		return task; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| @@ -301,12 +311,12 @@ void* resolve_request(void* data) | |||||||
| 			if(ex) free(ex); | 			if(ex) free(ex); | ||||||
| 			if(h) | 			if(h) | ||||||
| 			{ | 			{ | ||||||
| 				sprintf(path,"/%s%s",h,url); | 				//sprintf(path,"/%s%s",h,url); | ||||||
| 				LOG("WARNING::::Access octetstream via handler %s\n", path); | 				LOG("WARNING::::Access octetstream via handler %s\n", h); | ||||||
| 				//if(execute_plugin(client,buf,method,rq) < 0) | 				//if(execute_plugin(client,buf,method,rq) < 0) | ||||||
| 				//	cannot_execute(client); | 				//	cannot_execute(client); | ||||||
| 				free(task); | 				free(task); | ||||||
| 				return execute_plugin(rq, path); | 				return execute_plugin(rq, h); | ||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| 				unknow(rq->client); | 				unknow(rq->client); | ||||||
| @@ -521,6 +531,7 @@ void* decode_request_header(void* data) | |||||||
| 	// this for check if web socket is enabled | 	// this for check if web socket is enabled | ||||||
| 	// ip address | 	// ip address | ||||||
| 	dput(xheader,"REMOTE_ADDR", (void*)strdup(((antd_client_t*)rq->client)->ip )); | 	dput(xheader,"REMOTE_ADDR", (void*)strdup(((antd_client_t*)rq->client)->ip )); | ||||||
|  | 	dput(xheader, "SERVER_PORT", (void*)__s("%d",server_config.port )); | ||||||
| 	//while((line = read_line(client)) && strcmp("\r\n",line)) | 	//while((line = read_line(client)) && strcmp("\r\n",line)) | ||||||
| 	while((read_buf(rq->client,buf,sizeof(buf))) && strcmp("\r\n",buf)) | 	while((read_buf(rq->client,buf,sizeof(buf))) && strcmp("\r\n",buf)) | ||||||
| 	{ | 	{ | ||||||
| @@ -993,69 +1004,38 @@ char* post_data_decode(void* client,int len) | |||||||
|  * @return              -1 if failure |  * @return              -1 if failure | ||||||
|  *                      1 if sucess |  *                      1 if sucess | ||||||
|  */ |  */ | ||||||
| void* execute_plugin(void* data, const char *path) | void* execute_plugin(void* data, const char *pname) | ||||||
| { | { | ||||||
| 	char pname[255]; |  | ||||||
|  	char pfunc[255]; |  | ||||||
|  	void* (*fn)(void*); |  	void* (*fn)(void*); | ||||||
|  	struct plugin_entry *plugin ; |  	struct plugin_entry *plugin ; | ||||||
| 	int plen = strlen(path); |  | ||||||
| 	char * rpath = (char*) malloc((plen+1)*sizeof(char)); |  | ||||||
| 	char* orgs = rpath; |  | ||||||
| 	char *error; | 	char *error; | ||||||
| 	memcpy(rpath,path+1,plen); |  | ||||||
| 	rpath[plen] = '\0'; |  | ||||||
| 	trim(rpath,'/'); |  | ||||||
|  	char * delim = strchr(rpath,'/'); |  | ||||||
| 	antd_request_t* rq = (antd_request_t*) data; | 	antd_request_t* rq = (antd_request_t*) data; | ||||||
| 	antd_task_t* task = antd_create_task(NULL, (void*)rq, NULL);  | 	antd_task_t* task = antd_create_task(NULL, (void*)rq, NULL);  | ||||||
| 	task->priority++; | 	task->priority++; | ||||||
|  	if(delim == NULL) |  | ||||||
|  	{ |  | ||||||
|  		strcpy(pname,rpath); |  | ||||||
|  		strcpy(pfunc,"default"); |  | ||||||
| 	}  |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		int npos,fpos; |  | ||||||
| 		npos = delim - rpath; |  | ||||||
| 		fpos = strlen(rpath) - npos ; |  | ||||||
| 		memcpy(pname,rpath,npos); |  | ||||||
| 		pname[npos] = '\0'; |  | ||||||
| 		memcpy(pfunc,rpath+npos+1,fpos); |  | ||||||
| 		pfunc[fpos-1]='\0'; |  | ||||||
| 	} |  | ||||||
| 	LOG("Client %d\n",((antd_client_t*)rq->client)->sock ); |  | ||||||
| 	LOG("Path : '%s'\n", rpath); |  | ||||||
| 	LOG("Plugin name '%s'\n",pname); | 	LOG("Plugin name '%s'\n",pname); | ||||||
| 	LOG("Query path. '%s'\n", pfunc); |  | ||||||
| 	//LOG("query :%s\n", query_string); |  | ||||||
|  |  | ||||||
| 	//load the plugin | 	//load the plugin | ||||||
| 	if((plugin = plugin_lookup(pname)) == NULL) | 	if((plugin = plugin_lookup((char*)pname)) == NULL) | ||||||
| 	{ | 	{ | ||||||
| 		pthread_mutex_lock(&server_mux); | 		pthread_mutex_lock(&server_mux); | ||||||
| 		plugin= plugin_load(pname); | 		plugin= plugin_load((char*)pname); | ||||||
| 		pthread_mutex_unlock(&server_mux); | 		pthread_mutex_unlock(&server_mux); | ||||||
| 		if( plugin == NULL) | 		if( plugin == NULL) | ||||||
| 		{ | 		{ | ||||||
| 			if(orgs) free(orgs); |  | ||||||
| 			unknow(rq->client); | 			unknow(rq->client); | ||||||
| 			return task; | 			return task;  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	// load the function | 	// load the function | ||||||
|    fn = (void* (*)(void*))dlsym(plugin->handle, PLUGIN_HANDLER); |    fn = (void* (*)(void*))dlsym(plugin->handle, PLUGIN_HANDLER); | ||||||
| 	if ((error = dlerror()) != NULL)   | 	if ((error = dlerror()) != NULL)   | ||||||
| 	{ | 	{ | ||||||
| 		if(orgs) free(orgs); |  | ||||||
|     	LOG("Problem when finding %s method from %s : %s \n", PLUGIN_HANDLER, pname,error); |     	LOG("Problem when finding %s method from %s : %s \n", PLUGIN_HANDLER, pname,error); | ||||||
|     	unknow(rq->client); |     	unknow(rq->client); | ||||||
| 		return task; | 		return task; | ||||||
|    } |    } | ||||||
|    task->type = HEAVY; |    task->type = HEAVY; | ||||||
|    task->handle = fn; |    task->handle = fn; | ||||||
|    free(orgs); |  | ||||||
|    return task; |    return task; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user