Exemple #1
0
int		Logger::log(int log_level,const char* format,...)
{
	KmScopedLock lock(log_mutex);
	if(!inited) return -1;

	if(log_level < this->log_level ||
		log_level > LOG_LEVEL::EMERG)
		return -2;

	try{
		if(!open_log_file()){
			return -3;
		}
	}catch(std::exception &e){
		op_error_of_what("Unhandle error of open log file,error msg:%s",e.what());
		return -4;
	}
	
	memset(buffer,0,MAX_BUFFER_SIZE);
	va_list ap;
	va_start(ap,format);
	vsnprintf(buffer,MAX_BUFFER_SIZE,format,ap);
	va_end(ap);
	
	get_header_line(log_level,header_line,MAX_PATH_LEN);
#ifndef WIN32
#ifdef PROC_LOG_LOCK
	log_file_lock->WriteLockW();
#endif
#endif
	fwrite(header_line,sizeof(char),strlen(header_line),log_file_ptr);
	fwrite(buffer,sizeof(char),strlen(buffer),log_file_ptr);
	fwrite("\n",1,1,log_file_ptr);
	if(flush)
		fflush(log_file_ptr);
#ifndef WIN32
#ifdef PROC_LOG_LOCK
	log_file_lock->Unlock();
#endif
#endif
	return 0;
}
Exemple #2
0
subuser *checkrecv(ape_socket *co, acetables *g_ape)
{
	unsigned int op;
	http_state *http = co->parser.data;
	subuser *user = NULL;
	clientget cget;
	
	if (http->host == NULL) {
		shutdown(co->fd, 2);
		return NULL;
	}
	
	if (gettransport(http->uri) == TRANSPORT_WEBSOCKET) {
		char *origin = get_header_line(http->hlines, "Origin");
		websocket_state *websocket;
		if (origin == NULL) {
			shutdown(co->fd, 2);
			return NULL;
		}
		
		PACK_TCP(co->fd);
		sendbin(co->fd, CONST_STR_LEN(WEBSOCKET_HARDCODED_HEADERS), 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN("WebSocket-Origin: "), 0, g_ape);
		sendbin(co->fd, origin, strlen(origin), 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN("\r\nWebSocket-Location: ws://"), 0, g_ape);
		sendbin(co->fd, http->host, strlen(http->host), 0, g_ape);
		sendbin(co->fd, http->uri, strlen(http->uri), 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN("\r\n\r\n"), 0, g_ape);
		FLUSH_TCP(co->fd);
		
		co->parser = parser_init_stream(co);
		websocket = co->parser.data;
		websocket->http = http; /* keep http data */
		
		return NULL;
	}

	if (http->data == NULL) {
		sendbin(co->fd, HEADER_DEFAULT, HEADER_DEFAULT_LEN, 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN(CONTENT_NOTFOUND), 0, g_ape);
		
		safe_shutdown(co->fd, g_ape);
		return NULL;
	}
	
	cget.client = co;
	cget.ip_get = co->ip_client;
	cget.get = http->data;
	cget.host = http->host;
	cget.hlines = http->hlines;
	
	op = checkcmd(&cget, gettransport(http->uri), &user, g_ape);

	switch (op) {
		case CONNECT_SHUTDOWN:
			safe_shutdown(co->fd, g_ape);			
			break;
		case CONNECT_KEEPALIVE:
			break;
	}
	
	return user;
}