Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
	int i;
	char url[102400]; // Should be plently long for most URLs
	char **proxies;

	/* Create the proxy factory object */
	pxProxyFactory *pf = px_proxy_factory_new();
	if (!pf)
	{
		fprintf(stderr, "An unknown error occurred!\n");
		return 1;
	}
	/* User entered some arguments on startup. skip interactive */
	if (argc > 1)
	{
		for (i=1; i < argc ; i++)
		{
			/*
			 * Get an array of proxies to use. These should be used
			 * in the order returned. Only move on to the next proxy
			 * if the first one fails (etc).
			 */
			proxies = px_proxy_factory_get_proxies(pf, argv[i]);
			print_proxies(proxies);
			px_proxy_factory_free_proxies(proxies);
		}
	}
	/* Interactive mode */
	else
	{
		/* For each URL we read on STDIN, get the proxies to use */
		for (url[0] = '\0' ; fgets(url, 102400, stdin) != NULL ; )
		{
			if (url[strlen(url)-1] == '\n') url[strlen(url)-1] = '\0';

			/*
			 * Get an array of proxies to use. These should be used
			 * in the order returned. Only move on to the next proxy
			 * if the first one fails (etc).
			 */
			proxies = px_proxy_factory_get_proxies(pf, url);
			print_proxies(proxies);
			px_proxy_factory_free_proxies(proxies);
		}
	}
	/* Destroy the proxy factory object */
	px_proxy_factory_free(pf);
	return 0;
}
static void
g_libproxy_resolver_finalize (GObject *object)
{
  GLibProxyResolver *resolver = G_LIBPROXY_RESOLVER (object);
  
  if (resolver->factory)
    {
      px_proxy_factory_free (resolver->factory);
      resolver->factory = NULL;
    }

  /* must chain up */
  G_OBJECT_CLASS (g_libproxy_resolver_parent_class)->finalize (object);
}
Ejemplo n.º 3
0
Archivo: xchat.c Proyecto: ArdaXi/XChat
int
main (int argc, char *argv[])
{
	int ret;
	
	srand (time (0));	/* CL: do this only once! */

#ifdef SOCKS
	SOCKSinit (argv[0]);
#endif

	ret = fe_args (argc, argv);
	if (ret != -1)
		return ret;
	
#ifdef USE_DBUS
	xchat_remote ();
#endif

	load_config ();

#ifdef USE_LIBPROXY
	libproxy_factory = px_proxy_factory_new();
#endif

	fe_init ();

	xchat_init ();

	fe_main ();

#ifdef USE_LIBPROXY
	px_proxy_factory_free(libproxy_factory);
#endif

#ifdef USE_OPENSSL
	if (ctx)
		_SSL_context_free (ctx);
#endif

#ifdef USE_DEBUG
	xchat_mem_list ();
#endif

#ifdef WIN32
	WSACleanup ();
#endif

	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	pxProxyFactory *pf;
	int i;

	if (argc < 2) {
		printf("Usage: %s <url> [url*]\n", argv[0]);
		return 1;
	}

	pf = px_proxy_factory_new();
	if (!pf) {
		fprintf(stderr, "Failed to create proxy factory\n");
		return 1;
	}

	for (i = 1; i < argc; i++) {
		char **result;
		int n;

		result = px_proxy_factory_get_proxies(pf, argv[i]);
		if (!result) {
			fprintf(stderr, "Failed to get proxy for %s\n",
								argv[i]);
			continue;
		}

		for (n = 0; result[n]; n++) {
			printf("%s%s", result[n], result[n + 1] ? " " : "\n");
			free(result[n]);
		}

		free(result);
	}

	px_proxy_factory_free(pf);

	return 0;
}
Ejemplo n.º 5
0
int
main (int argc, char *argv[])
{
	int i;
	int ret;

	srand (time (0));	/* CL: do this only once! */

	/* We must check for the config dir parameter, otherwise load_config() will behave incorrectly.
	 * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to
	 * know the language which is set in the config. The code below is copy-pasted from fe_args()
	 * for the most part. */
	if (argc >= 3)
	{
		for (i = 1; i < argc - 1; i++)
		{
			if (strcmp (argv[i], "-d") == 0)
			{
				if (xdir)
				{
					g_free (xdir);
				}

				xdir = strdup (argv[i + 1]);

				if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR)
				{
					xdir[strlen (xdir) - 1] = 0;
				}
			}
		}
	}

#if ! GLIB_CHECK_VERSION (2, 36, 0)
	g_type_init ();
#endif

	if (check_config_dir () == 0)
	{
		if (load_config () != 0)
			load_default_config ();
	} else
	{
		/* this is probably the first run */
		load_default_config ();
		make_config_dirs ();
		make_dcc_dirs ();
	}

	/* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */
	set_locale ();

#ifdef SOCKS
	SOCKSinit (argv[0]);
#endif

	ret = fe_args (argc, argv);
	if (ret != -1)
		return ret;
	
#ifdef USE_DBUS
	hexchat_remote ();
#endif

#ifdef USE_LIBPROXY
	libproxy_factory = px_proxy_factory_new();
#endif

	fe_init ();

	/* This is done here because cfgfiles.c is too early in
	* the startup process to use gtk functions. */
	if (g_access (get_xdir (), W_OK) != 0)
	{
		char buf[2048];

		g_snprintf (buf, sizeof(buf),
			_("You do not have write access to %s. Nothing from this session can be saved."),
			get_xdir ());
		fe_message (buf, FE_MSG_ERROR);
	}

#ifndef WIN32
#ifndef __EMX__
	/* OS/2 uses UID 0 all the time */
	if (getuid () == 0)
		fe_message (_("* Running IRC as root is stupid! You should\n"
			      "  create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT);
#endif
#endif /* !WIN32 */

	xchat_init ();

	fe_main ();

#ifdef USE_LIBPROXY
	px_proxy_factory_free(libproxy_factory);
#endif

#ifdef WIN32
	WSACleanup ();
#endif

	return 0;
}
Ejemplo n.º 6
0
int
main (int argc, char *argv[])
{
	int i;
	int ret;

	srand (time (0));	/* CL: do this only once! */

	/* We must check for the config dir parameter, otherwise load_config() will behave incorrectly.
	 * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to
	 * know the language which is set in the config. The code below is copy-pasted from fe_args()
	 * for the most part. */
	if (argc >= 3)
	{
		for (i = 1; i < argc - 1; i++)
		{
			if (strcmp (argv[i], "-d") == 0)
			{
				if (xdir)
				{
					g_free (xdir);
				}

				xdir = strdup (argv[i + 1]);

				if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR)
				{
					xdir[strlen (xdir) - 1] = 0;
				}
			}
		}
	}

#if ! GLIB_CHECK_VERSION (2, 36, 0)
	g_type_init ();
#endif

	if (check_config_dir () == 0)
	{
		if (load_config () != 0)
			load_default_config ();
	} else
	{
		/* this is probably the first run */
		load_default_config ();
		make_config_dirs (); /* FIXME: if this fail display an error (?) */
		make_dcc_dirs ();
	}

	/* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */
	set_locale ();

#ifdef SOCKS
	SOCKSinit (argv[0]);
#endif

	ret = fe_args (argc, argv);
	if (ret != -1)
		return ret;
	
#ifdef USE_DBUS
	hexchat_remote ();
#endif

#ifdef USE_LIBPROXY
	libproxy_factory = px_proxy_factory_new();
#endif

	fe_init ();

#ifndef WIN32
#ifndef __EMX__
	/* OS/2 uses UID 0 all the time */
	if (getuid () == 0)
		fe_message (_("* Running IRC as root is stupid! You should\n"
			      "  create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT);
#endif
#endif /* !WIN32 */

	xchat_init ();

	fe_main ();

#ifdef USE_LIBPROXY
	px_proxy_factory_free(libproxy_factory);
#endif

#ifdef USE_OPENSSL
	if (ctx)
		_SSL_context_free (ctx);
#endif

#ifdef USE_DEBUG
	hexchat_mem_list ();
#endif

#ifdef WIN32
	WSACleanup ();
#endif

	return 0;
}
Ejemplo n.º 7
0
int
main (int argc, char *argv[])
{
	int i;
	int ret;

        // BEGIN NEW CODE
        server *fake_serv;
        GIOChannel *channel;
        session *sess;
        // END NEW CODE

#ifdef WIN32
	HRESULT coinit_result;
#endif

	srand ((unsigned int) time (NULL)); /* CL: do this only once! */

	/* We must check for the config dir parameter, otherwise load_config() will behave incorrectly.
	 * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to
	 * know the language which is set in the config. The code below is copy-pasted from fe_args()
	 * for the most part. */
	if (argc >= 2)
	{
		for (i = 1; i < argc; i++)
		{
			if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0)
				&& i + 1 < argc)
			{
				xdir = g_strdup (argv[i + 1]);
			}
			else if (strncmp (argv[i], "--cfgdir=", 9) == 0)
			{
				xdir = g_strdup (argv[i] + 9);
			}

			if (xdir != NULL)
			{
				if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR)
				{
					xdir[strlen (xdir) - 1] = 0;
				}
				break;
			}
		}
	}

#if ! GLIB_CHECK_VERSION (2, 36, 0)
        // RFM: Don't think we hit this
	g_type_init ();
#endif

	if (check_config_dir () == 0)
	{
		if (load_config () != 0)
			load_default_config ();
	} else
	{
		/* this is probably the first run */
		load_default_config ();
		make_config_dirs ();
		make_dcc_dirs ();
	}

	/* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */
	// RFM: Does nothing on *NIX
        set_locale ();

        // RFM: Parses some command line crap. Not important
	ret = fe_args (argc, argv);
	if (ret != -1)
		return ret;
	
#ifdef USE_DBUS
	hexchat_remote ();
#endif

#ifdef USE_LIBPROXY
        // RFM: Not using
	libproxy_factory = px_proxy_factory_new();
#endif

#ifdef WIN32
	coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
	if (SUCCEEDED (coinit_result))
	{
		CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
	}
#endif

        // RFM: Inits some fe-text stuff
	fe_init ();

        // RFM: Pretty sure this just allows us to save chats...
	/* This is done here because cfgfiles.c is too early in
	* the startup process to use gtk functions. */
	if (g_access (get_xdir (), W_OK) != 0)
	{
		char buf[2048];

		g_snprintf (buf, sizeof(buf),
			_("You do not have write access to %s. Nothing from this session can be saved."),
			get_xdir ());
		fe_message (buf, FE_MSG_ERROR);
	}

        // RFM: Checks if root on *NIX 
#ifndef WIN32
#ifndef __EMX__
	/* OS/2 uses UID 0 all the time */
	if (getuid () == 0)
		fe_message (_("* Running IRC as root is stupid! You should\n"
			      "  create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT);
#endif
#endif /* !WIN32 */

        // RFM: Loads a bunch of configure options
	xchat_init ();

        // BEGIN NEW CODE
        fake_serv = server_new();
        fake_serv->sok = STDIN_FILENO;
        //        fake_serv->pos = 0; //??? 
        sess = session_new(fake_serv, "fake_sess", SESS_CHANNEL, 0);
        fake_serv->server_session = sess;
        fake_serv->front_session = sess;
        channel = g_io_channel_unix_new(STDIN_FILENO);
        g_io_add_watch(channel, G_IO_IN, (GIOFunc)server_read, fake_serv);
        //g_io_add_watch(channel, G_IO_IN, (GIOFunc)io_callback, fake_serv);
        g_io_channel_unref(channel);
        // END NEW CODE

	fe_main ();

#ifdef WIN32
	if (SUCCEEDED (coinit_result))
	{
		CoUninitialize ();
	}
#endif

#ifdef USE_LIBPROXY
	px_proxy_factory_free(libproxy_factory);
#endif

#ifdef WIN32
	WSACleanup ();
#endif

	return 0;
}
Ejemplo n.º 8
0
void ne_session_system_proxy(ne_session *sess, unsigned int flags)
{
#ifdef HAVE_LIBPROXY
    pxProxyFactory *pxf = px_proxy_factory_new();
    struct host_info *hi, **lasthi;
    char *url, **proxies;
    ne_uri uri;
    unsigned n;

    free_proxies(sess);

    /* Create URI for session to pass off to libproxy */
    memset(&uri, 0, sizeof uri);
    ne_fill_server_uri(sess, &uri);

    uri.path = "/"; /* make valid URI structure. */
    url = ne_uri_unparse(&uri);
    uri.path = NULL;

    /* Get list of pseudo-URIs from libproxy: */
    proxies = px_proxy_factory_get_proxies(pxf, url);
    
    for (n = 0, lasthi = &sess->proxies; proxies[n]; n++) {
        enum proxy_type ptype;

        ne_uri_free(&uri);

        NE_DEBUG(NE_DBG_HTTP, "sess: libproxy #%u=%s\n", 
                 n, proxies[n]);

        if (ne_uri_parse(proxies[n], &uri))
            continue;
        
        if (!uri.scheme) continue;

        if (ne_strcasecmp(uri.scheme, "http") == 0)
            ptype = PROXY_HTTP;
        else if (ne_strcasecmp(uri.scheme, "socks") == 0)
            ptype = PROXY_SOCKS;
        else if (ne_strcasecmp(uri.scheme, "direct") == 0)
            ptype = PROXY_NONE;
        else
            continue;

        /* Hostname/port required for http/socks schemes. */
        if (ptype != PROXY_NONE && !(uri.host && uri.port))
            continue;
        
        /* Do nothing if libproxy returned only a single "direct://"
         * entry -- a single "direct" (noop) proxy is equivalent to
         * having none. */
        if (n == 0 && proxies[1] == NULL && ptype == PROXY_NONE)
            break;

        NE_DEBUG(NE_DBG_HTTP, "sess: Got proxy %s://%s:%d\n",
                 uri.scheme, uri.host ? uri.host : "(none)",
                 uri.port);
        
        hi = *lasthi = ne_calloc(sizeof *hi);
        
        if (ptype == PROXY_NONE) {
            /* A "direct" URI requires an attempt to connect directly to
             * the origin server, so dup the server details. */
            set_hostinfo(hi, ptype, sess->server.hostname,
                         sess->server.port);
        }
        else {
            /* SOCKS/HTTP proxy. */
            set_hostinfo(hi, ptype, uri.host, uri.port);

            if (ptype == PROXY_HTTP)
                sess->any_proxy_http = 1;
            else if (ptype == PROXY_SOCKS)
                sess->socks_ver = NE_SOCK_SOCKSV5;
        }

        lasthi = &hi->next;
    }

    /* Free up the proxies array: */
    for (n = 0; proxies[n]; n++)
        free(proxies[n]);
    free(proxies[n]);

    ne_free(url);
    ne_uri_free(&uri);
    px_proxy_factory_free(pxf);
#endif
}
int trg_client_populate_with_settings(TrgClient * tc)
{
    TrgClientPrivate *priv = tc->priv;
    TrgPrefs *prefs = priv->prefs;

    gint port;
    gchar *host, *path;
#ifdef HAVE_LIBPROXY
    pxProxyFactory *pf = NULL;
#endif

    g_mutex_lock(&priv->configMutex);

    trg_prefs_set_connection(prefs, trg_prefs_get_profile(prefs));

    g_free(priv->url);
    priv->url = NULL;

    g_free(priv->username);
    priv->username = NULL;

    g_free(priv->password);
    priv->password = NULL;

    port =
        trg_prefs_get_int(prefs, TRG_PREFS_KEY_PORT, TRG_PREFS_CONNECTION);

    host = trg_prefs_get_string(prefs, TRG_PREFS_KEY_HOSTNAME,
                                TRG_PREFS_CONNECTION);
    path = trg_prefs_get_string(prefs, TRG_PREFS_KEY_RPC_URL_PATH, TRG_PREFS_CONNECTION);

    if (!host || strlen(host) < 1) {
        g_free(host);
        g_mutex_unlock(&priv->configMutex);
        return TRG_NO_HOSTNAME_SET;
    }
#ifndef CURL_NO_SSL
    priv->ssl = trg_prefs_get_bool(prefs, TRG_PREFS_KEY_SSL,
                                   TRG_PREFS_CONNECTION);
    priv->ssl_validate = trg_prefs_get_bool(prefs, TRG_PREFS_KEY_SSL_VALIDATE,
                                   TRG_PREFS_CONNECTION);

#else
    priv->ssl = FALSE;
#endif


    priv->url = g_strdup_printf("%s://%s:%d%s",
                                priv->ssl ? HTTPS_URI_PREFIX :
                                HTTP_URI_PREFIX, host, port, path);
    g_free(host);
    g_free(path);

    priv->username = trg_prefs_get_string(prefs, TRG_PREFS_KEY_USERNAME,
                                          TRG_PREFS_CONNECTION);

    priv->password = trg_prefs_get_string(prefs, TRG_PREFS_KEY_PASSWORD,
                                          TRG_PREFS_CONNECTION);

    g_free(priv->proxy);
    priv->proxy = NULL;

#ifdef HAVE_LIBPROXY
    if ((pf = px_proxy_factory_new())) {
        char **proxies = px_proxy_factory_get_proxies(pf, priv->url);
        int i;

        for (i = 0; proxies[i]; i++) {
            if (g_str_has_prefix(proxies[i], HTTP_URI_PREFIX)
                || g_str_has_prefix(proxies[i], HTTPS_URI_PREFIX)) {
                g_free(priv->proxy);
                priv->proxy = proxies[i];
            } else {
                g_free(proxies[i]);
            }
        }

        g_free(proxies);
        px_proxy_factory_free(pf);
    }
#endif

    priv->configSerial++;
    g_mutex_unlock(&priv->configMutex);
    return 0;
}
Ejemplo n.º 10
0
 ~nsUnixSystemProxySettings() {
   if (mProxyFactory) 
     px_proxy_factory_free(mProxyFactory); 
 }
Ejemplo n.º 11
0
int
main (int argc, char *argv[])
{
	int i;
	int ret;

#ifdef WIN32
	char hexchat_lang[13];	/* LC_ALL= plus 5 chars of hex_gui_lang and trailing \0 */
#endif

	srand (time (0));	/* CL: do this only once! */

	/* We must check for the config dir parameter, otherwise load_config() will behave incorrectly.
	 * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to
	 * know the language which is set in the config. The code below is copy-pasted from fe_args()
	 * for the most part. */
	if (argc >= 3)
	{
		for (i = 1; i < argc - 1; i++)
		{
			if (strcmp (argv[i], "-d") == 0)
			{
				if (xdir)
				{
					g_free (xdir);
				}

				xdir = strdup (argv[i + 1]);

				if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR)
				{
					xdir[strlen (xdir) - 1] = 0;
				}
			}
		}
	}

#if ! GLIB_CHECK_VERSION (2, 36, 0)
	g_type_init ();
#endif
	load_config ();

#ifdef WIN32
	/* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */
	strcpy (hexchat_lang, "LC_ALL=");

	/* this must be ordered EXACTLY as langsmenu[] */
	switch (prefs.hex_gui_lang)
	{
		case 0:
			strcat (hexchat_lang, "af");
			break;
		case 1:
			strcat (hexchat_lang, "sq");
			break;
		case 2:
			strcat (hexchat_lang, "am");
			break;
		case 3:
			strcat (hexchat_lang, "ast");
			break;
		case 4:
			strcat (hexchat_lang, "az");
			break;
		case 5:
			strcat (hexchat_lang, "eu");
			break;
		case 6:
			strcat (hexchat_lang, "be");
			break;
		case 7:
			strcat (hexchat_lang, "bg");
			break;
		case 8:
			strcat (hexchat_lang, "ca");
			break;
		case 9:
			strcat (hexchat_lang, "zh_CN");
			break;
		case 10:
			strcat (hexchat_lang, "zh_TW");
			break;
		case 11:
			strcat (hexchat_lang, "cs");
			break;
		case 12:
			strcat (hexchat_lang, "da");
			break;
		case 13:
			strcat (hexchat_lang, "nl");
			break;
		case 14:
			strcat (hexchat_lang, "en_GB");
			break;
		case 15:
			strcat (hexchat_lang, "en");
			break;
		case 16:
			strcat (hexchat_lang, "et");
			break;
		case 17:
			strcat (hexchat_lang, "fi");
			break;
		case 18:
			strcat (hexchat_lang, "fr");
			break;
		case 19:
			strcat (hexchat_lang, "gl");
			break;
		case 20:
			strcat (hexchat_lang, "de");
			break;
		case 21:
			strcat (hexchat_lang, "el");
			break;
		case 22:
			strcat (hexchat_lang, "gu");
			break;
		case 23:
			strcat (hexchat_lang, "hi");
			break;
		case 24:
			strcat (hexchat_lang, "hu");
			break;
		case 25:
			strcat (hexchat_lang, "id");
			break;
		case 26:
			strcat (hexchat_lang, "it");
			break;
		case 27:
			strcat (hexchat_lang, "ja");
			break;
		case 28:
			strcat (hexchat_lang, "kn");
			break;
		case 29:
			strcat (hexchat_lang, "rw");
			break;
		case 30:
			strcat (hexchat_lang, "ko");
			break;
		case 31:
			strcat (hexchat_lang, "lv");
			break;
		case 32:
			strcat (hexchat_lang, "lt");
			break;
		case 33:
			strcat (hexchat_lang, "mk");
			break;
		case 34:
			strcat (hexchat_lang, "ml");
			break;
		case 35:
			strcat (hexchat_lang, "ms");
			break;
		case 36:
			strcat (hexchat_lang, "nb");
			break;
		case 37:
			strcat (hexchat_lang, "no");
			break;
		case 38:
			strcat (hexchat_lang, "pl");
			break;
		case 39:
			strcat (hexchat_lang, "pt");
			break;
		case 40:
			strcat (hexchat_lang, "pt_BR");
			break;
		case 41:
			strcat (hexchat_lang, "pa");
			break;
		case 42:
			strcat (hexchat_lang, "ru");
			break;
		case 43:
			strcat (hexchat_lang, "sr");
			break;
		case 44:
			strcat (hexchat_lang, "sk");
			break;
		case 45:
			strcat (hexchat_lang, "sl");
			break;
		case 46:
			strcat (hexchat_lang, "es");
			break;
		case 47:
			strcat (hexchat_lang, "sv");
			break;
		case 48:
			strcat (hexchat_lang, "th");
			break;
		case 49:
			strcat (hexchat_lang, "uk");
			break;
		case 50:
			strcat (hexchat_lang, "vi");
			break;
		case 51:
			strcat (hexchat_lang, "wa");
			break;
		default:
			strcat (hexchat_lang, "en");
			break;
	}

	putenv (hexchat_lang);
#endif

#ifdef SOCKS
	SOCKSinit (argv[0]);
#endif

	ret = fe_args (argc, argv);
	if (ret != -1)
		return ret;
	
#ifdef USE_DBUS
	hexchat_remote ();
#endif

#ifdef USE_LIBPROXY
	libproxy_factory = px_proxy_factory_new();
#endif

	fe_init ();

	xchat_init ();

	fe_main ();

#ifdef USE_LIBPROXY
	px_proxy_factory_free(libproxy_factory);
#endif

#ifdef USE_OPENSSL
	if (ctx)
		_SSL_context_free (ctx);
#endif

#ifdef USE_DEBUG
	hexchat_mem_list ();
#endif

#ifdef WIN32
	WSACleanup ();
#endif

	return 0;
}
Ejemplo n.º 12
0
int
main (int argc, char *argv[])
{
	int i;
	int ret;

#ifdef WIN32
	HRESULT coinit_result;
#endif

	srand ((unsigned int) time (NULL)); /* CL: do this only once! */

	/* We must check for the config dir parameter, otherwise load_config() will behave incorrectly.
	 * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to
	 * know the language which is set in the config. The code below is copy-pasted from fe_args()
	 * for the most part. */
	if (argc >= 2)
	{
		for (i = 1; i < argc; i++)
		{
			if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0)
				&& i + 1 < argc)
			{
				xdir = g_strdup (argv[i + 1]);
			}
			else if (strncmp (argv[i], "--cfgdir=", 9) == 0)
			{
				xdir = g_strdup (argv[i] + 9);
			}

			if (xdir != NULL)
			{
				if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR)
				{
					xdir[strlen (xdir) - 1] = 0;
				}
				break;
			}
		}
	}

#if ! GLIB_CHECK_VERSION (2, 36, 0)
	g_type_init ();
#endif

	if (check_config_dir () == 0)
	{
		if (load_config () != 0)
			load_default_config ();
	} else
	{
		/* this is probably the first run */
		load_default_config ();
		make_config_dirs ();
		make_dcc_dirs ();
	}

	/* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */
	set_locale ();

	ret = fe_args (argc, argv);
	if (ret != -1)
		return ret;
	
#ifdef USE_DBUS
	hexchat_remote ();
#endif

#ifdef USE_LIBPROXY
	libproxy_factory = px_proxy_factory_new();
#endif

#ifdef WIN32
	coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
	if (SUCCEEDED (coinit_result))
	{
		CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
	}
#endif

	fe_init ();

	/* This is done here because cfgfiles.c is too early in
	* the startup process to use gtk functions. */
	if (g_access (get_xdir (), W_OK) != 0)
	{
		char buf[2048];

		g_snprintf (buf, sizeof(buf),
			_("You do not have write access to %s. Nothing from this session can be saved."),
			get_xdir ());
		fe_message (buf, FE_MSG_ERROR);
	}

#ifndef WIN32
#ifndef __EMX__
	/* OS/2 uses UID 0 all the time */
	if (getuid () == 0)
		fe_message (_("* Running IRC as root is stupid! You should\n"
			      "  create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT);
#endif
#endif /* !WIN32 */

	xchat_init ();

	fe_main ();

#ifdef WIN32
	if (SUCCEEDED (coinit_result))
	{
		CoUninitialize ();
	}
#endif

#ifdef USE_LIBPROXY
	px_proxy_factory_free(libproxy_factory);
#endif

#ifdef WIN32
	WSACleanup ();
#endif

	return 0;
}
Ejemplo n.º 13
0
int
main (int argc, char *argv[])
{
	int ret;

#ifdef WIN32
	char hexchat_lang[13];	/* LC_ALL= plus 5 chars of gui_lang and trailing \0 */
	HANDLE mutex;
#endif

	srand (time (0));	/* CL: do this only once! */

	load_config ();

#ifdef WIN32
	/* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */
	strcpy (hexchat_lang, "LC_ALL=");

	switch (prefs.gui_lang)
	{
		case 0:
			strcat (hexchat_lang, "sq");
			break;
		case 1:
			strcat (hexchat_lang, "am");
			break;
		case 2:
			strcat (hexchat_lang, "az");
			break;
		case 3:
			strcat (hexchat_lang, "eu");
			break;
		case 4:
			strcat (hexchat_lang, "be");
			break;
		case 5:
			strcat (hexchat_lang, "bg");
			break;
		case 6:
			strcat (hexchat_lang, "ca");
			break;
		case 7:
			strcat (hexchat_lang, "zh_CN");
			break;
		case 8:
			strcat (hexchat_lang, "zh_TW");
			break;
		case 9:
			strcat (hexchat_lang, "cs");
			break;
		case 10:
			strcat (hexchat_lang, "nl");
			break;
		case 11:
			strcat (hexchat_lang, "en_GB");
			break;
		case 12:
			strcat (hexchat_lang, "en_US");
			break;
		case 13:
			strcat (hexchat_lang, "et");
			break;
		case 14:
			strcat (hexchat_lang, "fi");
			break;
		case 15:
			strcat (hexchat_lang, "fr");
			break;
		case 16:
			strcat (hexchat_lang, "gl");
			break;
		case 17:
			strcat (hexchat_lang, "de");
			break;
		case 18:
			strcat (hexchat_lang, "el");
			break;
		case 19:
			strcat (hexchat_lang, "hi");
			break;
		case 20:
			strcat (hexchat_lang, "hu_HU");
			break;
		case 21:
			strcat (hexchat_lang, "it");
			break;
		case 22:
			strcat (hexchat_lang, "ja");
			break;
		case 23:
			strcat (hexchat_lang, "kn");
			break;
		case 24:
			strcat (hexchat_lang, "ko");
			break;
		case 25:
			strcat (hexchat_lang, "lv");
			break;
		case 26:
			strcat (hexchat_lang, "lt");
			break;
		case 27:
			strcat (hexchat_lang, "mk");
			break;
		case 28:
			strcat (hexchat_lang, "ms");
			break;
		case 29:
			strcat (hexchat_lang, "nb");
			break;
		case 30:
			strcat (hexchat_lang, "no");
			break;
		case 31:
			strcat (hexchat_lang, "pl");
			break;
		case 32:
			strcat (hexchat_lang, "pt");
			break;
		case 33:
			strcat (hexchat_lang, "pt_BR");
			break;
		case 34:
			strcat (hexchat_lang, "pa");
			break;
		case 35:
			strcat (hexchat_lang, "ru");
			break;
		case 36:
			strcat (hexchat_lang, "sr");
			break;
		case 37:
			strcat (hexchat_lang, "sk");
			break;
		case 38:
			strcat (hexchat_lang, "sl");
			break;
		case 39:
			strcat (hexchat_lang, "es");
			break;
		case 40:
			strcat (hexchat_lang, "sv");
			break;
		case 41:
			strcat (hexchat_lang, "th");
			break;
		case 42:
			strcat (hexchat_lang, "uk");
			break;
		case 43:
			strcat (hexchat_lang, "vi");
			break;
		case 44:
			strcat (hexchat_lang, "wa");
			break;
		default:
			strcat (hexchat_lang, "en_US");
			break;
	}

	putenv (hexchat_lang);

	if (prefs.gui_one_instance && !portable_mode ())
	{
		DWORD error;

		mutex = CreateMutex (NULL, TRUE, "Local\\hexchat");
		error = GetLastError ();

		if (error == ERROR_ALREADY_EXISTS || mutex == NULL)
		{
			/* restoring the XChat window from the tray via the taskbar icon
			 * only works correctly when X-Tray is used, but it's not a big deal
			 * since you can only minimize XChat to tray via the taskbar if you
			 * use X-Tray*/
			if (hextray_mode ())
			{
				/* FindWindow() doesn't support wildcards so we check all the open windows */
				EnumWindows (enum_windows_impl, NULL);
				return 0;
			}
			else
			{
				return 1;
			}
		}
	}
#endif

#ifdef SOCKS
	SOCKSinit (argv[0]);
#endif

	ret = fe_args (argc, argv);
	if (ret != -1)
		return ret;
	
#ifdef USE_DBUS
	xchat_remote ();
#endif

#ifdef USE_LIBPROXY
	libproxy_factory = px_proxy_factory_new();
#endif

	fe_init ();

	xchat_init ();

	fe_main ();

#ifdef USE_LIBPROXY
	px_proxy_factory_free(libproxy_factory);
#endif

#ifdef USE_OPENSSL
	if (ctx)
		_SSL_context_free (ctx);
#endif

#ifdef USE_DEBUG
	xchat_mem_list ();
#endif

#ifdef WIN32
	WSACleanup ();

	if (prefs.gui_one_instance && !portable_mode ())
	{
		ReleaseMutex (mutex);
		CloseHandle (mutex);
	}
#endif

	return 0;
}