/* start the connection when all the details are available */
void 
start_direct_connection()
{
	int server_pid=fork();
	if (server_pid==0)
	{
		/* child process: run the server */
		purple_debug_misc(PLUGIN_ID,"server_ip=\"%s\"\n",purple_value_get_string(server_ip));

		const char* cmd=purple_prefs_get_string(PREF_SERVER_COMMAND_LINE);

		/* replace the port in the command string */
		GRegex *port_regex=g_regex_new("[$]PORT",0,0,NULL);
		char* command=g_regex_replace(port_regex,cmd,-1,0,purple_value_get_string(port),0,NULL);

		purple_debug_misc(PLUGIN_ID,"server command=\"%s\"\n",command);
		gchar **splitted_command=g_strsplit(command," ",0);

		execvp(splitted_command[0],splitted_command);

		g_free(command);
		g_free(splitted_command);
		g_free(port_regex);
	}
	else 
	{
		/* original process: sent the connection request*/
		send_connect_request_message();

	}
}
void 
send_connect_request_message()
{
	PurpleAccount* account=purple_buddy_get_account(PURPLE_BUDDY(client_node));

	PurpleConversation *conv=purple_conversation_new (PURPLE_CONV_TYPE_IM, account, purple_buddy_get_name (PURPLE_BUDDY(client_node)));
	PurpleConvIm *im = purple_conversation_get_im_data(conv);

	const char* remote_message="sharedesk|request_connection|$SERVER_IP|$PORT|"
		"\nPlease start a vnc connection. Sample command line:"
		"\n$CLIENT_CMD"
		"\n|||";
	GRegex *port_regex1=g_regex_new("[$]CLIENT_CMD",0,0,NULL);
	char* msg1=g_regex_replace(port_regex1,remote_message,-1,0,purple_prefs_get_string(PREF_CLIENT_COMMAND_LINE),0,NULL);
	GRegex *port_regex2=g_regex_new("[$]PORT",0,0,NULL);
	char* msg2=g_regex_replace(port_regex2,msg1,-1,0,purple_value_get_string(port),0,NULL);
	GRegex *port_regex3=g_regex_new("[$]SERVER_IP",0,0,NULL);
	char* msg3=g_regex_replace(port_regex3,msg2,-1,0,purple_value_get_string(server_ip),0,NULL);

	purple_conv_im_send(im, msg3); 


	g_free(msg3);
	g_free(msg2);
	g_free(msg1);
	g_free(port_regex1);
	g_free(port_regex2);
	g_free(port_regex3);
}
static void no_upnp()
{
	char msg[100];
	snprintf(msg,100,"You must manually open the port %d on the router, if any",atoi(purple_value_get_string(port)));
	purple_notify_warning(the_plugin,"No upnp available","Port mapping",msg);
	const char* ip=purple_network_get_my_ip(-1);
	purple_debug_misc(PLUGIN_ID,"purple_network_get_my_ip(-1)=\"%s\"\n",ip);
	purple_value_set_string(server_ip,ip);
	start_direct_connection();
}
void upnp_discovery_cb(gboolean success, gpointer data)
{
	purple_notify_info(the_plugin,"Debug","Upnp discovery",success?"Ok!":"Failed!");
	if (!success)
		no_upnp();

	char *ip;
	if (!upnp_get_ip(&ip))
		no_upnp();
	purple_debug_misc(PLUGIN_ID,"upnp_get_ip()=\"%s\"\n",ip);
	
	purple_value_set_string(server_ip,ip);

	if (!upnp_add_port_mapping(atoi(purple_value_get_string(port))))
		no_upnp();

	start_direct_connection();
}
Beispiel #5
0
Data IMInvoker::purpleValueToData(PURPLE_VALUE* value) {
	Data data;

#if LIBPURPLE_VERSION_MAJOR >= 3
	if (false) {
	} else if (g_type_check_value_holds(value, G_TYPE_CHAR)) {
		data = Data(g_value_get_schar(value), Data::VERBATIM);

	} else if (g_type_check_value_holds(value, G_TYPE_UCHAR)) {
		data = Data(g_value_get_uchar(value), Data::VERBATIM);

	} else if (g_type_check_value_holds(value, G_TYPE_BOOLEAN)) {
		data = Data(g_value_get_boolean(value));

	} else if (g_type_check_value_holds(value, G_TYPE_INT)) {
		data = Data(g_value_get_int(value));

	} else if (g_type_check_value_holds(value, G_TYPE_UINT)) {
		data = Data(g_value_get_uint(value));

	} else if (g_type_check_value_holds(value, G_TYPE_LONG)) {
		data = Data(g_value_get_long(value));

	} else if (g_type_check_value_holds(value, G_TYPE_ULONG)) {
		data = Data(g_value_get_ulong(value));

	} else if (g_type_check_value_holds(value, G_TYPE_INT64)) {
		data = Data(g_value_get_int64(value));

	} else if (g_type_check_value_holds(value, G_TYPE_FLOAT)) {
		data = Data(g_value_get_float(value));

	} else if (g_type_check_value_holds(value, G_TYPE_DOUBLE)) {
		data = Data(g_value_get_double(value));

	} else if (g_type_check_value_holds(value, G_TYPE_STRING)) {
		const gchar* tmp = g_value_get_string(value);
		if (tmp == NULL) {
			data = Data("", Data::VERBATIM);
		} else {
			data = Data(g_value_get_string(value), Data::VERBATIM);
		}

	} else if (g_type_check_value_holds(value, G_TYPE_OBJECT) ||
	           g_type_check_value_holds(value, G_TYPE_PARAM) ||
	           g_type_check_value_holds(value, G_TYPE_POINTER) ||
	           g_type_check_value_holds(value, G_TYPE_FLAGS) ||
	           g_type_check_value_holds(value, G_TYPE_ENUM)) {
		LOG(ERROR) << "purple thingy not supported";
	} else {
		LOG(ERROR) << "purple thingy unknown";
	}
#else
	switch (purple_value_get_type(value)) {
	case PURPLE_TYPE_BOOLEAN:
		if (purple_value_get_boolean(value))
			data = Data("true");
		data = Data("false");
		break;
	case PURPLE_TYPE_STRING:
		if (purple_value_get_string(value)) {
			data = Data(purple_value_get_string(value), Data::VERBATIM);
		}
		break;
	case PURPLE_TYPE_CHAR:
		Data(purple_value_get_char(value));
		break;
	case PURPLE_TYPE_UCHAR:
		Data(purple_value_get_uchar(value));
		break;
	case PURPLE_TYPE_SHORT:
		Data(purple_value_get_short(value));
		break;
	case PURPLE_TYPE_USHORT:
		Data(purple_value_get_ushort(value));
		break;
	case PURPLE_TYPE_INT:
		Data(purple_value_get_int(value));
		break;
	case PURPLE_TYPE_UINT:
		Data(purple_value_get_uint(value));
		break;
	case PURPLE_TYPE_LONG:
		Data(purple_value_get_long(value));
		break;
	case PURPLE_TYPE_ULONG:
		Data(purple_value_get_ulong(value));
		break;
	case PURPLE_TYPE_INT64:
		Data(purple_value_get_int64(value));
		break;
	case PURPLE_TYPE_UINT64:
		Data(purple_value_get_uint64(value));
		break;
	case PURPLE_TYPE_OBJECT:
	case PURPLE_TYPE_POINTER:
	case PURPLE_TYPE_ENUM:
	case PURPLE_TYPE_BOXED:
	case PURPLE_TYPE_UNKNOWN:
	case PURPLE_TYPE_SUBTYPE:
		LOG(ERROR) << "purple thingy not supported";
		break;
	}
#endif
	return data;
}