예제 #1
0
파일: servlist.c 프로젝트: HextorIRC/hextor
static void
servlist_load_defaults (void)
{
    int i = 0, j = 0;
    ircnet *net = NULL;
    guint def_hash = g_str_hash ("freenode");

    while (1)
    {
        if (def[i].network)
        {
            net = servlist_net_add (def[i].network, def[i].host, FALSE);
            if (def[i].channel)
            {
                servlist_favchan_add (net, def[i].channel);
            }
            if (def[i].charset)
            {
                net->encoding = g_strdup (def[i].charset);
            }
            else
            {
                net->encoding = g_strdup (IRC_DEFAULT_CHARSET);
            }
            if (def[i].loginmode)
            {
                net->logintype = def[i].loginmode;
            }
            if (def[i].connectcmd)
            {
                servlist_command_add (net, def[i].connectcmd);
            }
            if (def[i].ssl)
            {
                net->flags |= FLAG_USE_SSL;
            }

            if (g_str_hash (def[i].network) == def_hash)
            {
                prefs.hex_gui_slist_select = j;
            }

            j++;
        }
        else
        {
            servlist_server_add (net, def[i].host);
            if (!def[i+1].host && !def[i+1].network)
            {
                break;
            }
        }
        i++;
    }
}
예제 #2
0
파일: servlist.c 프로젝트: HextorIRC/hextor
static int
servlist_load (void)
{
    FILE *fp;
    char buf[2048];
    int len;
    ircnet *net = NULL;

    /* simple migration we will keep for a short while */
    char *oldfile = g_build_filename (get_xdir (), "servlist_.conf", NULL);
    char *newfile = g_build_filename (get_xdir (), "servlist.conf", NULL);

    if (g_file_test (oldfile, G_FILE_TEST_EXISTS) && !g_file_test (newfile, G_FILE_TEST_EXISTS))
    {
        g_rename (oldfile, newfile);
    }

    g_free (oldfile);
    g_free (newfile);

    fp = hextor_fopen_file ("servlist.conf", "r", 0);
    if (!fp)
        return FALSE;

    while (fgets (buf, sizeof (buf) - 2, fp))
    {
        len = strlen (buf);
        buf[len] = 0;
        buf[len-1] = 0; /* remove the trailing \n */
        if (net)
        {
            switch (buf[0])
            {
            case 'I':
                net->nick = g_strdup (buf + 2);
                break;
            case 'i':
                net->nick2 = g_strdup (buf + 2);
                break;
            case 'U':
                net->user = g_strdup (buf + 2);
                break;
            case 'R':
                net->real = g_strdup (buf + 2);
                break;
            case 'P':
                net->pass = g_strdup (buf + 2);
                break;
            case 'L':
                net->logintype = atoi (buf + 2);
                break;
            case 'E':
                net->encoding = servlist_check_encoding (buf + 2) ? g_strdup (buf + 2) : g_strdup ("UTF-8");
                break;
            case 'F':
                net->flags = atoi (buf + 2);
                break;
            case 'S':       /* new server/hostname for this network */
                servlist_server_add (net, buf + 2);
                break;
            case 'C':
                servlist_command_add (net, buf + 2);
                break;
            case 'J':
                servlist_favchan_add (net, buf + 2);
                break;
            case 'D':
                net->selected = atoi (buf + 2);
                break;
                /* FIXME Migration code. In 2.9.5 the order was:
                 *
                 * P=serverpass, A=saslpass, B=nickservpass
                 *
                 * So if server password was unset, we can safely use SASL
                 * password for our new universal password, or if that's also
                 * unset, use NickServ password.
                 *
                 * Should be removed at some point.
                 */
            case 'A':
                if (!net->pass)
                {
                    net->pass = g_strdup (buf + 2);
                    if (!net->logintype)
                    {
                        net->logintype = LOGIN_SASL;
                    }
                }
            case 'B':
                if (!net->pass)
                {
                    net->pass = g_strdup (buf + 2);
                    if (!net->logintype)
                    {
                        net->logintype = LOGIN_NICKSERV;
                    }
                }
            }
        }
        if (buf[0] == 'N')
            net = servlist_net_add (buf + 2, /* comment */ NULL, FALSE);
    }
    fclose (fp);

    return TRUE;
}
예제 #3
0
파일: servlist.cpp 프로젝트: leeter/hexchat
static bool servlist_load (void)
{
	namespace bfs = boost::filesystem;
	namespace bs = boost::system;

	/* simple migration we will keep for a short while */
	auto oldfile = io::fs::make_config_path("servlist_.conf");
	auto newfile = io::fs::make_config_path("servlist.conf");
	
	bs::error_code ec;
	if (bfs::exists(oldfile, ec) && !bfs::exists(newfile, ec))
	{
		bfs::rename(oldfile, newfile, ec);
	}

	bfs::ifstream infile(io::fs::make_config_path("servlist.conf"), std::ios::in);
	if (!infile)
		return false;

	ircnet *net = nullptr;

	for(std::string buf; std::getline(infile, buf);)
	{
		if (net)
		{
			switch (buf[0])
			{
			case 'I':
				net->nick = buf.substr(2);
				break;
			case 'i':
				net->nick2 = buf.substr(2);
				break;
			case 'U':
				net->user = strdup (buf.c_str() + 2);
				break;
			case 'R':
				net->real = strdup (buf.c_str() + 2);
				break;
			case 'P':
				net->pass = strdup (buf.c_str() + 2);
				break;
			case 'L':
				net->logintype = std::atoi (buf.c_str() + 2);
				break;
			case 'E':
				net->encoding = strdup (buf.c_str() + 2);
				break;
			case 'F':
				net->flags = std::atoi (buf.c_str() + 2);
				break;
			case 'S':	/* new server/hostname for this network */
				servlist_server_add (net, buf.c_str() + 2);
				break;
			case 'C':
				servlist_command_add (net, buf.c_str() + 2);
				break;
			case 'J':
				servlist_favchan_add (net, buf.c_str() + 2);
				break;
			case 'D':
				net->selected = std::atoi (buf.c_str() + 2);
				break;
			/* FIXME Migration code. In 2.9.5 the order was:
			 *
			 * P=serverpass, A=saslpass, B=nickservpass
			 *
			 * So if server password was unset, we can safely use SASL
			 * password for our new universal password, or if that's also
			 * unset, use NickServ password.
			 *
			 * Should be removed at some point.
			 */
			case 'A':
				if (!net->pass)
				{
					net->pass = strdup (buf.c_str() + 2);
					if (!net->logintype)
					{
						net->logintype = LOGIN_SASL;
					}
				}
			case 'B':
				if (!net->pass)
				{
					net->pass = strdup (buf.c_str() + 2);
					if (!net->logintype)
					{
						net->logintype = LOGIN_NICKSERV;
					}
				}
			}
		}
		if (!buf.empty() && buf[0] == 'N')
			net = servlist_net_add (buf.c_str() + 2, /* comment */ nullptr, false);
	}

	return true;
}