示例#1
0
文件: onion.c 项目: KokaKiwi/onion
/**
 * @short Removes the allocated data
 * @memberof onion_t
 */
void onion_free(onion *onion){
	ONION_DEBUG("Onion free");
	onion_listen_stop(onion);
	
	if (onion->poller)
		onion_poller_free(onion->poller);
	
	if (onion->username)
		free(onion->username);
	
	if (onion->listen_points){
		onion_listen_point **p=onion->listen_points;
		while(*p!=NULL){
			ONION_DEBUG("Free %p listen_point", *p);
			onion_listen_point_free(*p++);
		}
		free(onion->listen_points);
	}
	if (onion->root_handler)
		onion_handler_free(onion->root_handler);
	if (onion->internal_error_handler)
		onion_handler_free(onion->internal_error_handler);
	onion_mime_set(NULL);
	if (onion->sessions)
		onion_sessions_free(onion->sessions);
	
#ifdef HAVE_PTHREADS
	if (onion->threads)
		free(onion->threads);
#endif
	free(onion);
}
示例#2
0
文件: server.c 项目: cemonds/onion
/**
 * @short Cleans all data used by this server
 * @memberof onion_server_t
 */
void onion_server_free(onion_server *server){
	if (server->root_handler)
		onion_handler_free(server->root_handler);
	if (server->internal_error_handler)
		onion_handler_free(server->internal_error_handler);
	onion_mime_set(NULL);
	onion_sessions_free(server->sessions);
	free(server);
}
示例#3
0
文件: onion.c 项目: Nov11/onion
/**
 * @short Removes the allocated data
 * @memberof onion_t
 */
void onion_free(onion *onion){
	ONION_DEBUG("Onion free");

	if (onion->flags&O_LISTENING)
		onion_listen_stop(onion);

	if (onion->poller)
		onion_poller_free(onion->poller);

	if (onion->username)
		onion_low_free(onion->username);

	if (onion->listen_points){
		onion_listen_point **p=onion->listen_points;
		while(*p!=NULL){
			ONION_DEBUG("Free %p listen_point", *p);
			onion_listen_point_free(*p++);
		}
		onion_low_free(onion->listen_points);
	}
	if (onion->root_handler)
		onion_handler_free(onion->root_handler);
	if (onion->internal_error_handler)
		onion_handler_free(onion->internal_error_handler);
	onion_mime_set(NULL);
	if (onion->sessions)
		onion_sessions_free(onion->sessions);

	{
#ifdef HAVE_PTHREADS
	  pthread_mutex_lock (&onion->mutex);
#endif
	  void* data = onion->client_data;
	  onion->client_data = NULL;
	  if (data && onion->client_data_free)
	     onion->client_data_free (data);
	  onion->client_data_free = NULL;
#ifdef HAVE_PTHREADS
	  pthread_mutex_unlock (&onion->mutex);
	  pthread_mutex_destroy (&onion->mutex);
#endif
	};
#ifdef HAVE_PTHREADS
	if (onion->threads)
		onion_low_free(onion->threads);
#endif
	if (!(onion->flags&O_NO_SIGTERM)){
		signal(SIGINT,SIG_DFL);
		signal(SIGTERM,SIG_DFL);
	}
	last_onion=NULL;
	onion_low_free(onion);
}
示例#4
0
void t01_test_mime(){
	INIT_LOCAL();
	
	FAIL_IF_NOT_EQUAL_STR("text/plain", onion_mime_get("txt"));
	FAIL_IF_NOT_EQUAL_STR("text/plain", onion_mime_get("fdsfds"));
	FAIL_IF_NOT_EQUAL_STR("text/html", onion_mime_get("html"));
	FAIL_IF_NOT_EQUAL_STR("image/png", onion_mime_get("file.png"));
	FAIL_IF_NOT_EQUAL_STR("application/javascript", onion_mime_get("js"));

	
	onion_mime_set(NULL);
	END_LOCAL();
}
示例#5
0
文件: mime.c 项目: Sts0mrg0/onion
/**
 * @short Reads the /etc/mime.types file
 * 
 * 
 */
static void onion_mime_fill(){
	onion_mime_set(NULL);
	onion_mime_dict=onion_dict_new();
	//ONION_DEBUG("Filling mime types");
	
	FILE *fd=fopen("/etc/mime.types", "rt");
	if (!fd){
		ONION_WARNING("Could not read MIME types (etc/mime.types), returned mime types may be incorrect. Adding minimal set.");
		onion_dict_add(onion_mime_dict, "html", "text/html",0);
		onion_dict_add(onion_mime_dict, "htm", "text/html",0);
		onion_dict_add(onion_mime_dict, "js", "application/javascript",0);
		onion_dict_add(onion_mime_dict, "css", "text/css",0);
		onion_dict_add(onion_mime_dict, "png", "image/png",0);
		onion_dict_add(onion_mime_dict, "jpg", "image/jpeg",0);
		return;
	}
	char mimetype[128];
	char extension[8];
	int mode=0; // 0 mimetype, 1 extension
	int i=0;
	int c;
	
	while ( (c=getc(fd)) >= 0){
		if (c=='#'){
			while ( (c=getc(fd)) >= 0 && c!='\n');
		}
		if (c=='\n'){
			if (mode==1 && i!=0){
				extension[i]=0;
				onion_dict_add(onion_mime_dict, extension, mimetype, OD_DUP_ALL);
				//ONION_DEBUG("Add mimetype '%s' (%s).", extension, mimetype);
			}
			mode=0;
			i=0;
		}
		else{
			if (is_space(c)){
				if (mode==0){
					mimetype[i]='\0';
					mode=1;
					i=0;
				}
				else if (i!=0){
					extension[i]='\0';
					i=0;
					onion_dict_add(onion_mime_dict, extension, mimetype, OD_DUP_ALL);
					//ONION_DEBUG("Add mimetype '%s' (%s)", extension, mimetype);
				}
			}
			else{
				if (mode==0){
					if (i>=sizeof(mimetype)-1){
						while ( (c=getc(fd)) >= 0 && c!='\n');
					}
					else
						mimetype[i++]=c;
				}
				else{
					if (i>=sizeof(extension)-1){
						while ( (c=getc(fd)) >= 0 && c!='\n');
						extension[i]='\0';
						i=0;
						mode=0;
						onion_dict_add(onion_mime_dict, extension, mimetype,  OD_DUP_ALL);
						//ONION_DEBUG("Add mimetype '%s' (%s)..", extension, mimetype);
					}
					else
						extension[i++]=c;
				}
			}
		}
	}
	fclose(fd);
	
	ONION_DEBUG("I know %d mime types", onion_dict_count(onion_mime_dict));
}