Ejemplo n.º 1
0
static eng_ctx_t* eng_context_init(void* p) {
    eng_ctx_t* eng_ctx = my_malloc(sizeof(eng_ctx_t));
    memset(eng_ctx, 0, sizeof(eng_ctx_t));

    eng_ctx->sql = malloc(SQL_BUFFER_LEN);

    engine_para_t* para = (engine_para_t *)(p);
    eng_ctx->tid = para->tid;

    // dispatch cluster to all thread
    size_t nserver;
    cq_server_t *server;
    char *ip;
    int port;

    cq_cluster_init(&(eng_ctx->thread_cluster));

    cq_server_t** write_servers 
        = cq_cluster_get_all_write_server(cluster_base, &nserver);

    for (int i = 0; i < nserver; i++) {
        ip = get_server_ip(write_servers[i]);
        port = get_server_port(write_servers[i]);

        server = server_init(ip, port, WRITE_SERVER);
        if (RET_FAILED == cq_cluster_add(eng_ctx->thread_cluster, server)) {
            log_error("Failed to add server into thread cluster");
            abort();
        }
    }

    cq_server_t** read_servers 
        = cq_cluster_get_all_read_server(cluster_base, &nserver);

    for (int i = 0; i < nserver; i++) {
        ip = get_server_ip(read_servers[i]);
        port = get_server_port(read_servers[i]);

        server = server_init(ip, port, READ_SERVER);
        if (RET_FAILED == cq_cluster_add(eng_ctx->thread_cluster, server)) {
            log_error("Failed to add server into thread cluster");
            abort();
        }
    }

    memset(&(eng_ctx->stats), 0, sizeof(struct eng_stats));

    my_free(write_servers);
    my_free(read_servers);

    return eng_ctx;
}
Ejemplo n.º 2
0
int handle_trans_message(void *args)
{
	struct packet *pkt = (struct packet*)args;
	DEBUG(INFO, "%s %d %d %u handle",pkt->ip, pkt->sockfd, pkt->ops_type, pkt->len);
	pkt->data += sizeof(struct common_header);
	pkt->len -= sizeof(struct common_header);
	char *buff = pkt->data;
	int len = pkt->len;
	int type = pkt->ops_type;

	if( buff == NULL || len == 0)
	{
		DEBUG( ERROR, "Trans message Empty");
		return ENORMERR;
	}
	char	*pms_addr;
	int	    pms_port = 0;
	int	    iret = 0;
	pms_addr = get_server_address();
	pms_port = get_server_port();
	if( pms_addr == NULL )
	{
		DEBUG( ERROR, "\n[%s][%d]pms_addr error\n", __FILE__, __LINE__ );
		return ENORMERR;
	}
	DEBUG( INFO, "\n[%s][%d]pms_addr=[%s] pms_port=[%d]\n", __FILE__, __LINE__, pms_addr, pms_port );

	iret = send_message_to_pms( pms_addr, pms_port, type, buff, len );
	if( iret != SUCCESS )
	{
		DEBUG( ERROR, "\n[%s][%d]send message to pms error\n", __FILE__, __LINE__ );
	}
	return SUCCESS;
}
Ejemplo n.º 3
0
// beos_stat_cache_opendir
DIR *
beos_stat_cache_opendir(const char *dirName)
{
	stat_cache_readdir_reply *reply;
	int32 replySize;
	status_t error;

	// fall back to standard, if there is no server
	if (get_server_port() < 0)
		return opendir(dirName);

	// send the request
	error = send_request(STAT_CACHE_COMMAND_READDIR, dirName);
	if (error != B_OK) {
		errno = error;
		return NULL;
	}

	// get the reply
	error = receive_reply((void**)&reply, &replySize, NULL, 0);
	if (error != B_OK)
		error = reply->error;
	if (error != B_OK) {
		free(reply);
		errno = error;
		return NULL;
	}

	reply->clientData = reply->buffer;

	// a bit ugly, but anyway... 
	return (DIR*)reply;
}
Ejemplo n.º 4
0
// beos_stat_cache_stat
int
beos_stat_cache_stat(const char *filename, struct stat *st)
{
	stat_cache_stat_reply reply;
	status_t error;

	// fall back to standard, if there is no server
	if (get_server_port() < 0)
		return stat(filename, st);

	// send the request
	error = send_request(STAT_CACHE_COMMAND_STAT, filename);
	if (error != B_OK)
		SET_ERRNO_AND_RETURN(error);

	// get the reply
	error = receive_reply(NULL, NULL, &reply, sizeof(reply));
	if (error != B_OK)
		error = reply.error;
	if (error != B_OK)
		SET_ERRNO_AND_RETURN(error);

	*st = reply.st;
	return 0;
}
Ejemplo n.º 5
0
/**
  * @brief AsyncServer框架要求实现的接口之一。 
  *
  */
extern "C" int  init_service(int isparent)
{
	if (!isparent) {
		setup_timer();
		init_all_timer_type();
		init_funcs();
        const char *udp_ip = get_server_ip();
        uint16_t udp_port = get_server_port();
        bind_udp_socket(udp_ip, udp_port);
		g_dirty_word = new Cdirty_word();
		if (!g_dirty_word->is_inited)
			return -1;
		regist_timers();
		if (load_xmlconf("../conf/GameSvr.xml", load_game_svr_config) == -1)
			return -1;

		max_msg_count = config_get_intval("max_msg_count", 1024);
		/*
		if(g_seg_mgr.init("../data/")) {
        	BOOT_LOG(-1,"online udp listen:%s:%d %u",udp_ip, udp_port, max_msg_count);
		}
		*/

        BOOT_LOG(0,"online udp listen:%s:%d %u",udp_ip, udp_port, max_msg_count);
	}

	return 0;
}
Ejemplo n.º 6
0
/**
  * @brief connect to switch and send an init package of online information when online is launched
  */
void connect_to_switch()
{
	DEBUG_LOG("do  connect_to_switch");
	switch_fd = connect_to_service(config_get_strval("service_switch"), 0, 65535, 1);
	if (switch_fd != -1) {
		//连上时
 		is_add_timer_to_connect_switch=false;
	   	static uint32_t seqno = 0;
		sw_report_online_info_in sw_in;
	 	sw_in.domain_id= config_get_intval("domain", 0);
		sw_in.online_id= get_server_id();
		memcpy(sw_in.online_name,get_server_name(),sizeof(sw_in.online_name)); 
		memcpy(sw_in.online_ip,get_server_ip(),sizeof(sw_in.online_ip)); 
		sw_in.online_port=get_server_port();
		sw_in.seqno=seqno;
		g_sprite_map->get_userid_list(sw_in.userid_list);

	 	sw_in.user_num=sw_in.userid_list.size() ;
	
	    ++seqno;
	    send_msg_to_switch(NULL,sw_report_online_info_cmd,0,&sw_in );

		KDEBUG_LOG(0, "BEGIN CONNECTING TO CENTRAL ONLINE AND SEND INIT PKG");
	}else{//
		if(! is_add_timer_to_connect_switch){//还没有加入定时器
			DEBUG_LOG("ADD TIMER connect_switch ");
			g_timer_map->add_timer( TimeVal(3),n_sw_report_online_info,0 );
			is_add_timer_to_connect_switch=true;
		}
	}
}
Ejemplo n.º 7
0
//LSDB_INFO
int handle_lsdb_snapshoot_dbm_to_pms(void *args)
{
	struct pkt * info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	char *buff = (char*)pkt->pkt;
	int len = pkt->pkt_len - sizeof(local_module_header);
	send_message_to_pms(get_server_address(), get_server_port(), OPS_PMA_LINKSTATE, buff, len); 
}
Ejemplo n.º 8
0
int handle_bgp_interface_ic_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	char* buff = (char*)pkt->pkt;
	int len = pkt->pkt_len - sizeof(local_module_header);
	return send_message_to_pms(get_server_address(), get_server_port(),
			OPS_PMA_BGP_INTERFACE_INFO, buff, len);
}
Ejemplo n.º 9
0
int handle_bgp_path_info_ic_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header* pkt = (local_module_header*)(info->data);
	char* buff = (char*)pkt->pkt;
	int len = pkt->pkt_len - sizeof(local_module_header);
	return send_message_to_pms(get_server_address(), get_server_port(),
			OPS_PMA_ROUTING_TABLE, buff, len);
}
Ejemplo n.º 10
0
Archivo: reg.c Proyecto: exeasy/pma2
int heart_beat_send()
{
	DEBUG(INFO,"Heart Beat Sended");
	int ret = send_message_to_pms( get_server_address(),  
			get_server_port(), OPS_PMA_HEARTBEAT,
			NULL, 0);
	pthread_detach(pthread_self());
	return ret;
}
Ejemplo n.º 11
0
int handle_trans_packet_to_pms(void *args)
{
	struct packet *pkt = (struct packet*)args;
	DEBUG(INFO, "%s %d %d %u handle",pkt->ip, pkt->sockfd, pkt->ops_type, pkt->len);
	memcpy(pkt->ip , get_server_address(), sizeof(pkt->ip)-1);
	pkt->port = get_server_port();
	int ret = send_message_to_pms( pkt->ip , pkt->port , pkt->ops_type, pkt->data, pkt->len);
	return ret;
}
Ejemplo n.º 12
0
//UP_INTERFACE_INFO
int handle_tc_message_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	char *buff = (char*)pkt->pkt;
	int info_type = pkt->pkt_type;
	int len = pkt->pkt_len - sizeof(local_module_header);
	return send_message_to_pms(get_server_address(), get_server_port(), 
			TC_TO_PMA_INTERFACE_INFO, buff, len);
}
Ejemplo n.º 13
0
Archivo: reg.c Proyecto: exeasy/pma2
int agent_register(u32 agent_id, const char *seq)
{

	//pack the login xml
	xmlDocPtr doc = create_xml_doc();
	xmlNodePtr devnode;
	xmlNodePtr childnode;

	xmlNodePtr rootnode = create_xml_root_node(doc,"AGENT_REGISTER");
	struct timeval now;
	gettimeofday(&now, NULL);
	char * time = PRINTTIME(now);
	add_xml_child(rootnode, "timestamp",time); free(time);

	devnode = add_xml_child(rootnode, "device", NULL);
	char aid[24];
	sprintf(aid,"%d", get_pma_id());
	add_xml_child_prop(devnode, "id",aid); 
	char dev_type[10];
	if( get_protocol_type() == OSPF_ROUTER )
		sprintf(dev_type, "ospf");
	else if( get_protocol_type() == BGP_ROUTER )
		sprintf(dev_type, "bgp");
	else {}
	add_xml_child(devnode, "type", dev_type);
	
	char* xmlbuff;
	int len = 0;
	xmlDocDumpFormatMemoryEnc( doc, &xmlbuff, &len, "UTF-8", 0);
	char* buff = (char*)malloc(len+1);
	memcpy(buff, xmlbuff, len);
	buff[len] = 0;
	xmlFree(xmlbuff);
	xmlFreeDoc(doc);

	struct req_args *login_args =
		(struct req_args *)malloc(sizeof(struct req_args)+len);

	memset(login_args->ip, 0, sizeof(login_args->ip));
	char *ip = get_server_address();
	memcpy(login_args->ip, ip, strlen(ip));
	login_args->port = get_server_port();
	login_args->ops_type = OPS_PMA_LOGIN;
	login_args->len = len;
	memcpy(login_args->data, buff, len);
	free(buff);
	if (login(login_args) == ((void *)-1)) {
		free(login_args);
		return -1;
	}
	free(login_args);
	agent_login_status = AGENT_LOGIN;
	return SUCCESS;
}
Ejemplo n.º 14
0
utility_retcode_t init_rtsp_server(struct rtsp_server *server)
{
	FUNC_ENTER;

	syscalls_memset(server, 0, sizeof(*server));
	get_server_name(server->name, sizeof(server->name));
	get_server_host(server->host, sizeof(server->host));
	get_server_port(&server->port);

	FUNC_RETURN;
	return UTILITY_SUCCESS;
}
Ejemplo n.º 15
0
void got_initial_version_28 (char **ArgList)
{
	char *server, *sversion, *user_modes, *channel_modes;

	server = ArgList[0];
	sversion = ArgList[1];
	user_modes = ArgList[2];
	channel_modes = ArgList[3];
		
	if (sversion)
	{
		if (!strncmp(sversion, "2.8", 3))
		{
			if (strstr(sversion, "mu") || strstr(sversion, "me"))
				set_server_version(from_server, Server_u2_8);
			else if (strstr(sversion, "hybrid-6"))
				set_server_version(from_server, Server2_8hybrid6);
			else if (strstr(sversion, "hybrid"))
				set_server_version(from_server, Server2_8hybrid);
			else if (strstr(sversion, "comstud"))
				set_server_version(from_server, Server2_8comstud);
			else if (strstr(channel_modes, "che"))
				set_server_version(from_server, Server2_8ts4); 
			else
				set_server_version(from_server, Server2_8);
		}
		else if (!strncmp(sversion, "2.9", 3))
		        set_server_version(from_server, Server2_9);
		else if (!strncmp(sversion, "2.10", 4))
	        	set_server_version(from_server, Server2_10);
		else if (!strncmp(sversion, "u2.9", 4))
			set_server_version(from_server, Server_u2_9);
		else if (!strncmp(sversion, "u2.10", 4))
			set_server_version(from_server, Server_u2_10);
		else if (!strncmp(sversion, "u3.0", 4))
			set_server_version(from_server, Server_u3_0);
		else
			set_server_version(from_server, Server2_8);
	} else
		set_server_version(from_server, Server2_8);

	set_server_version_string(from_server, sversion ? sversion : "2.8");
	set_server_itsname(from_server, server);
	reconnect_all_channels(from_server);

	reset_display_target();
	reinstate_user_modes();
	if (use_nat_address == 1)
		userhostbase(get_server_nickname(from_server), get_nat_address, 1, "%s", get_server_nickname(from_server));
	update_all_status(current_window, NULL, 0);
	do_hook(CONNECT_LIST, "%s %d %s", get_server_name(from_server), get_server_port(from_server), get_server_itsname(from_server));
}
Ejemplo n.º 16
0
// beos_stat_cache_closedir
int
beos_stat_cache_closedir(DIR *dir)
{
	stat_cache_readdir_reply *reply;

	// fall back to standard, if there is no server
	if (get_server_port() < 0)
		return closedir(dir);

	reply = (stat_cache_readdir_reply*)dir;
	free(reply);
	return 0;
}
Ejemplo n.º 17
0
//UP_ROUTE_INFO
int handle_route_table_ic_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	int pkt_len = pkt->pkt_len - sizeof(local_module_header);
	char * data = (char*)malloc(pkt_len+1);
	memcpy(data, pkt->pkt, pkt_len);
	data[pkt_len] = 0;
	char *buff = save_router_table_to_xml(data);
	int len = strlen(buff);
	free(data);
	int ret =  send_message_to_pms(get_server_address(), get_server_port(),
		OPS_PMA_ROUTING_TABLE, buff, len);
	free( buff );
	return ret;
	
}
Ejemplo n.º 18
0
/**
  * @brief AsyncServer框架要求实现的接口之一。 
  *
  */
extern "C" int  init_service(int isparent)
{
	if (!isparent) {
		setup_timer();
		init_all_timer_type();
		init_funcs();
        const char *udp_ip = get_server_ip();
        uint16_t udp_port = get_server_port();
        bind_udp_socket(udp_ip, udp_port);
		regist_timers();
		if (load_xmlconf("../conf/GameSvr.xml", load_game_svr_config) == -1)
			return -1;


		max_msg_count = config_get_intval("max_msg_count", 1024);

        BOOT_LOG(0,"online udp listen:%s:%d %u",udp_ip, udp_port, max_msg_count);
	}

	return 0;
}
Ejemplo n.º 19
0
// beos_stat_cache_readdir
struct dirent *
beos_stat_cache_readdir(DIR *dir)
{
	stat_cache_readdir_reply *reply;
	struct dirent *entry;

	// fall back to standard, if there is no server
	if (get_server_port() < 0)
		return readdir(dir);

	reply = (stat_cache_readdir_reply*)dir;
	if (reply->entryCount == 0)
		return NULL;

	entry = (struct dirent*)reply->clientData;

	// get the next entry
	if (--reply->entryCount > 0)
		reply->clientData = (uint8*)entry + entry->d_reclen;

	return entry;
}
Ejemplo n.º 20
0
static void p_kill(char *from, char **ArgList)
{
    char sc[20];
    int port;
    int local = 0;

    port = get_server_port(from_server);
    if (ArgList[1] && strstr(ArgList[1], get_server_name(from_server)))
	if (!strchr(from, '.'))
	    local = 1;
    snprintf(sc, 19, "+%i %d", from_server, port);

    close_server(from_server, empty_str);
    clean_whois_queue();
    window_check_servers();
    set_input_prompt(curr_scr_win, get_string_var(INPUT_PROMPT_VAR), 0);

    if (strchr(from, '.')) {
	say("Server [%s] has rejected you (probably due to a nick collision)", from);
	t_parse_command("SERVER", NULL);
    } else {
	if (local && get_int_var(NEXT_SERVER_ON_LOCAL_KILL_VAR)) {
	    int i = from_server + 1;

	    if (i >= number_of_servers)
		i = 0;
	    snprintf(sc, 19, "+%i", i);
	    from_server = -1;
	}
	if (do_hook(DISCONNECT_LIST, "Killed by %s (%s)", from, ArgList[1] ? ArgList[1] : "(No Reason Given)"))
	    put_it("%s",
		   convert_output_format(get_format(FORMAT_KILL_FSET), "%s %s", update_clock(GET_TIME),
					 ArgList[1] ? ArgList[1] : "You have been Killed"));
	if (get_int_var(AUTO_RECONNECT_VAR))
	    t_parse_command("SERVER", NULL);
    }
    update_all_status(curr_scr_win, NULL, 0);
}
Ejemplo n.º 21
0
// send_request
static
status_t
send_request(int32 command, const char *path)
{
	port_id requestPort = get_server_port();
	port_id replyPort = get_reply_port();
	stat_cache_request request;
	int requestSize;

	// get request port
	if (requestPort < 0)
		return requestPort;
	// get reply port
	if (replyPort < 0)
		return replyPort;
	// normalize the path
	if (!path || !normalize_path(path, request.path, sizeof(request.path)))
		return B_BAD_VALUE;
	requestSize = (request.path + strlen(request.path) + 1) - (char*)&request;
	// send request
	request.replyPort = replyPort;
	request.command = command;
	return write_port(requestPort, 0, &request, requestSize);
}
Ejemplo n.º 22
0
/*
 * got_initial_version_28: this is called when ircii gets the serial
 * number 004 reply.  We do this becuase the 004 numeric gives us the
 * server name and version in an easy to use fashion, and doesnt
 * rely on the syntax or construction of the 002 numeric.
 *
 * Hacked as neccesary by jfn, May 1995
 */
void 	got_initial_version_28 (const char *server, const char *version, const char *umodes)
{
	/* Worthless 004 reply.  Hope for the best! */
	if (!server || !version || !umodes)
	{
		set_server_version(from_server, Server2_8);
		set_server_version_string(from_server, "<none provided>");
		set_server_itsname(from_server, get_server_name(from_server));
	}
	else
	{
		if (!strncmp(version, "2.8", 3))
		{
			if (strstr(version, "mu") || strstr(version, "me"))
				set_server_version(from_server, Server_u2_8);
			else
				set_server_version(from_server, Server2_8);
		}
		else if (!strncmp(version, "2.9", 3))
			set_server_version(from_server, Server2_9);
		else if (!strncmp(version, "2.10", 4))
			set_server_version(from_server, Server2_10);
		else if (!strncmp(version, "u2.9", 4))
			set_server_version(from_server, Server_u2_9);
		else if (!strncmp(version, "u2.10", 4))
			set_server_version(from_server, Server_u2_10);
		else if (!strncmp(version, "u3.0", 4))
			set_server_version(from_server, Server_u3_0);
		else
			set_server_version(from_server, Server2_8);

		set_server_version_string(from_server, version);
		set_server_itsname(from_server, server);
		set_possible_umodes(from_server, umodes);
	}

	reconnect_all_channels();
	server_did_rejoin_channels(from_server);
	message_from(NULL, LOG_CRAP);
	reinstate_user_modes();

	if (never_connected)
	{
		never_connected = 0;
		permit_status_update(1);

		if (!ircrc_loaded)
			load_ircrc();

		if (default_channel)
		{
			e_channel("JOIN", default_channel, empty_string);
			new_free(&default_channel);
		}
	}
	else if (get_server_away(from_server))
		set_server_away(from_server, get_server_away(from_server));

	update_all_status();
	do_hook(CONNECT_LIST, "%s %d %s", get_server_name(from_server),
		get_server_port(from_server), get_server_itsname(from_server));
	window_check_channels();
}
Ejemplo n.º 23
0
Archivo: reg.c Proyecto: exeasy/pma2
int agent_init_request(char* routerid)
{
	//pack the login xml
	xmlDocPtr doc = create_xml_doc();
	xmlNodePtr devnode;
	xmlNodePtr childnode;

	xmlNodePtr rootnode = create_xml_root_node(doc,"AGENT_INIT");
	struct timeval now;
	gettimeofday(&now, NULL);
	char * time = PRINTTIME(now);
	add_xml_child(rootnode, "timestamp",time); free(time);

	devnode = add_xml_child(rootnode, "device", NULL);
	char aid[24];
	sprintf(aid,"%d", get_pma_id());
	add_xml_child_prop(devnode, "id",aid); 
	char dev_type[10];
	if( get_protocol_type() == OSPF_ROUTER )
	{
		sprintf(dev_type, "ospf");
		add_xml_child(devnode, "type", dev_type);
	}
	else if( get_protocol_type() == BGP_ROUTER )
	{
		sprintf(dev_type, "bgp");
		add_xml_child(devnode, "type", dev_type);
	}
	else {}

	char asid[24];
	inet_ntop(AF_INET, &pma_conf.as_num , asid, 24);
	add_xml_child(devnode, "as_id", asid);
	add_xml_child(devnode, "router_id", routerid);
	char ctlip[24];
	inet_ntop(AF_INET, &pma_conf.ic_config.hello_ip, ctlip,24);
	add_xml_child(devnode, "agent_control_ip", ctlip);
	
	char* xmlbuff;
	int len = 0;
	xmlDocDumpFormatMemoryEnc( doc, &xmlbuff, &len, "UTF-8", 0);
	char* buff = (char*)malloc(len+1);
	memcpy(buff, xmlbuff, len);
	buff[len] = 0;
	xmlFree(xmlbuff);
	xmlFreeDoc(doc);

	len = strlen(buff);
	char rid[24];
	strcpy(rid,routerid);
	struct req_args *req_arg =
		(struct req_args *)malloc(sizeof(struct req_args));

	memset(req_arg->ip, 0, sizeof(req_arg->ip));
	char *ip = get_server_address();
	memcpy(req_arg->ip, ip, strlen(ip));
	req_arg->port = get_server_port();
	req_arg->ops_type = OPS_PMA_INIT_REQUEST;
	req_arg->len = 0;
	int ret = send_message_to_pms(req_arg->ip,
			req_arg->port,
			req_arg->ops_type,
			buff,
			len);
	free(req_arg);
	free(buff);
	return ret;
	 
}