コード例 #1
0
ファイル: dnssrv.c プロジェクト: VoxOx/VoxOx
GaimSrvQueryData *
gaim_srv_resolve(const char *protocol, const char *transport, const char *domain, GaimSrvCallback cb, gpointer extradata)
{
	char *query;
	GaimSrvQueryData *query_data;
#ifndef _WIN32
	int in[2], out[2];
	int pid;
#else
	GError* err = NULL;
	static gboolean initialized = FALSE;
#endif

	query = g_strdup_printf("_%s._%s.%s", protocol, transport, domain);
	gaim_debug_info("dnssrv","querying SRV record for %s\n", query);

#ifndef _WIN32
	if(pipe(in) || pipe(out)) {
		gaim_debug_error("dnssrv", "Could not create pipe\n");
		g_free(query);
		cb(NULL, 0, extradata);
		return NULL;
	}

	pid = fork();
	if (pid == -1) {
		gaim_debug_error("dnssrv", "Could not create process!\n");
		cb(NULL, 0, extradata);
		g_free(query);
		return NULL;
	}

	/* Child */
	if (pid == 0)
	{
		close(out[0]);
		close(in[1]);
		resolve(in[0], out[1]);
	}

	close(out[1]);
	close(in[0]);

	if (write(in[1], query, strlen(query)+1) < 0)
		gaim_debug_error("dnssrv", "Could not write to SRV resolver\n");

	query_data = g_new0(GaimSrvQueryData, 1);
	query_data->cb = cb;
	query_data->extradata = extradata;
	query_data->handle = gaim_input_add(out[0], GAIM_INPUT_READ, resolved, query_data);

	g_free(query);

	return query_data;
#else
	if (!initialized) {
		MyDnsQuery_UTF8 = (void*) wgaim_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");
		MyDnsRecordListFree = (void*) wgaim_find_and_loadproc(
			"dnsapi.dll", "DnsRecordListFree");
		initialized = TRUE;
	}

	query_data = g_new0(GaimSrvQueryData, 1);
	query_data->cb = cb;
	query_data->query = query;
	query_data->extradata = extradata;

	if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) {
		query_data->error_message = g_strdup_printf("System missing DNS API (Requires W2K+)\n");

		/* Asynchronously call the callback since stuff may not expect
		 * the callback to be called before this returns */
		query_data->handle = g_idle_add(res_main_thread_cb, query_data);

		return query_data;
	}

	query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err);
	if (query_data->resolver == NULL)
	{
		query_data->error_message = g_strdup_printf("SRV thread create failure: %s\n", err ? err->message : "");
		g_error_free(err);

		/* Asynchronously call the callback since stuff may not expect
		 * the callback to be called before this returns */
		query_data->handle = g_idle_add(res_main_thread_cb, query_data);

		return query_data;
	}

	return query_data;
#endif
}
コード例 #2
0
static void load_winver_specific_procs(void) {
	/* Used for Win98+ and WinNT5+ */
	MyFlashWindowEx = (LPFNFLASHWINDOWEX)wgaim_find_and_loadproc("user32.dll", "FlashWindowEx" );
}