Ejemplo n.º 1
0
void Test_iniparser_getsecname(CuTest *tc)
{
    unsigned i;
    char sec_name[32];
    dictionary *dic;
    /* NULL test */
    CuAssertTrue(tc, iniparser_getsecname(NULL, 0) == NULL);

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertPtrEquals(tc, NULL, iniparser_getsecname(dic, 0));
    dictionary_del(dic);

    /* Sections without entries dictionary */
    dic = generate_dictionary(100, 0);
    for (i = 0; i < 100; ++i) {
        sprintf(sec_name, "sec%d", i);
        CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i));
    }
    dictionary_del(dic);

    /* Generic dictionary */
    dic = generate_dictionary(10, 100);
    for (i = 0; i < 10; ++i) {
        sprintf(sec_name, "sec%d", i);
        CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i));
    }
    dictionary_del(dic);
}
Ejemplo n.º 2
0
void Test_iniparser_getnsec(CuTest *tc)
{
    int i;
    char sec_name[32];
    dictionary *dic;

    /* NULL test */
    CuAssertIntEquals(tc, -1, iniparser_getnsec(NULL));

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertIntEquals(tc, 0, iniparser_getnsec(dic));
    dictionary_del(dic);

    /* Regular dictionary */
    dic = generate_dictionary(512, 0);
    CuAssertIntEquals(tc, 512, iniparser_getnsec(dic));

    /* Check after removing sections */
    for (i = 1; i < 512; ++i) {
        sprintf(sec_name, "sec%d", i);
        dictionary_unset(dic, sec_name);
        CuAssertIntEquals(tc, 512 - i, iniparser_getnsec(dic));
    }
    dictionary_del(dic);

    /* Mix sections and regular keys */
    dic = generate_dictionary(10, 512);
    CuAssertIntEquals(tc, 10, iniparser_getnsec(dic));
    dictionary_del(dic);
}
Ejemplo n.º 3
0
void Test_iniparser_getseckeys(CuTest *tc)
{
    unsigned i;
    char key_name[64];
    dictionary *dic;
    int nkeys;
    const char * keys[10]; /* At most 10 elements per section */
    /* NULL test */
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, NULL, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", keys));

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys));
    dictionary_del(dic);

    /* Generic dictionary */

    dic = generate_dictionary(100, 10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec0", NULL));
    nkeys = iniparser_getsecnkeys(dic, "sec42");
    CuAssertIntEquals(tc, nkeys, 10);
    CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec42", keys));
    for (i = 0; i < 10; ++i) {
        sprintf(key_name, "sec42:key%d", i);
        CuAssertStrEquals(tc, key_name, keys[i]);
    }

    /* Remove some keys to make the dictionary more real */
    dictionary_unset(dic, "sec42");
    dictionary_unset(dic, "sec99:key9");
    dictionary_unset(dic, "sec0:key0");
    dictionary_unset(dic, "sec0:key1");
    dictionary_unset(dic, "sec0:key2");

    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec42", keys));
    nkeys = iniparser_getsecnkeys(dic, "sec99");
    CuAssertIntEquals(tc, nkeys, 9);
    CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec99", keys));
    for (i = 0; i < 9; ++i) {
        sprintf(key_name, "sec99:key%d", i);
        CuAssertStrEquals(tc, key_name, keys[i]);
    }

    nkeys = iniparser_getsecnkeys(dic, "sec0");
    CuAssertIntEquals(tc, nkeys, 7);
    CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec0", keys));
    for (i = 0; i < 7; ++i) {
        sprintf(key_name, "sec0:key%d", i + 3);
        CuAssertStrEquals(tc, key_name, keys[i]);
    }

    dictionary_del(dic);
}
Ejemplo n.º 4
0
void Test_iniparser_getseckeys(CuTest *tc)
{
    unsigned i;
    char key_name[64];
    dictionary *dic;
    const char ** sections;
    /* NULL test */
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy"));

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy"));
    dictionary_del(dic);

    /* Generic dictionary */
    dic = generate_dictionary(100, 10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy"));
    sections = iniparser_getseckeys(dic, "sec42");
    CuAssertPtrNotNull(tc, sections);
    for (i = 0; i < 10; ++i) {
        sprintf(key_name, "sec42:key%d", i);
        CuAssertStrEquals(tc, key_name, sections[i]);
    }
    free(sections);

    /* Remove some keys to make the dictionary more real */
    dictionary_unset(dic, "sec42");
    dictionary_unset(dic, "sec99:key9");
    dictionary_unset(dic, "sec0:key0");
    dictionary_unset(dic, "sec0:key1");
    dictionary_unset(dic, "sec0:key2");

    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec42"));
    sections = iniparser_getseckeys(dic, "sec99");
    CuAssertPtrNotNull(tc, sections);
    for (i = 0; i < 9; ++i) {
        sprintf(key_name, "sec99:key%d", i);
        CuAssertStrEquals(tc, key_name, sections[i]);
    }
    free(sections);
    sections = iniparser_getseckeys(dic, "sec0");
    CuAssertPtrNotNull(tc, sections);
    for (i = 0; i < 7; ++i) {
        sprintf(key_name, "sec0:key%d", i + 3);
        CuAssertStrEquals(tc, key_name, sections[i]);
    }
    free(sections);

    dictionary_del(dic);
}
Ejemplo n.º 5
0
/**
 * Signal handler for HUP which tells us to swap the log file
 * and reload configuration file if specified
 *
 * @param sig
 */
void
do_signal_sighup(RunTimeOpts * rtOpts, PtpClock * ptpClock)
{



	NOTIFY("SIGHUP received\n");

#ifdef RUNTIME_DEBUG
	if(rtOpts->transport == UDP_IPV4 && rtOpts->ipMode != IPMODE_UNICAST) {
		DBG("SIGHUP - running an ipv4 multicast based mode, re-sending IGMP joins\n");
		netRefreshIGMP(&ptpClock->netPath, rtOpts, ptpClock);
	}
#endif /* RUNTIME_DEBUG */


	/* if we don't have a config file specified, we're done - just reopen log files*/
	if(strlen(rtOpts->configFile) !=  0) {

	    dictionary* tmpConfig = dictionary_new(0);

	    /* Try reloading the config file */
	    NOTIFY("Reloading configuration file: %s\n",rtOpts->configFile);

            if(!loadConfigFile(&tmpConfig, rtOpts)) {

		    dictionary_del(&tmpConfig);

	    } else {
		    dictionary_merge(rtOpts->cliConfig, tmpConfig, 1, 1, "from command line");
		    applyConfig(tmpConfig, rtOpts, ptpClock);
		    dictionary_del(&tmpConfig);

	    }

	}

	/* tell the service it can perform any HUP-triggered actions */
	ptpClock->timingService.reloadRequested = TRUE;

	if(rtOpts->recordLog.logEnabled ||
	    rtOpts->eventLog.logEnabled ||
	    (rtOpts->statisticsLog.logEnabled))
		INFO("Reopening log files\n");

	restartLogging(rtOpts);

	if(rtOpts->statisticsLog.logEnabled)
		ptpClock->resetStatisticsLog = TRUE;


}
Ejemplo n.º 6
0
void registry_free(void) {
    if(!registry.enabled) return;

    // we need to destroy the dictionaries ourselves
    // since the dictionaries use memory we allocated

    while(registry.persons->values_index.root) {
        REGISTRY_PERSON *p = ((NAME_VALUE *)registry.persons->values_index.root)->value;
        registry_person_del(p);
    }

    while(registry.machines->values_index.root) {
        REGISTRY_MACHINE *m = ((NAME_VALUE *)registry.machines->values_index.root)->value;

        // fprintf(stderr, "\nMACHINE: '%s', first: %u, last: %u, usages: %u\n", m->guid, m->first_t, m->last_t, m->usages);

        while(m->machine_urls->values_index.root) {
            REGISTRY_MACHINE_URL *mu = ((NAME_VALUE *)m->machine_urls->values_index.root)->value;

            // fprintf(stderr, "\tURL: '%s', first: %u, last: %u, usages: %u, flags: 0x%02x\n", mu->url->url, mu->first_t, mu->last_t, mu->usages, mu->flags);

            //debug(D_REGISTRY, "Registry: destroying persons dictionary from url '%s'", mu->url->url);
            //dictionary_destroy(mu->persons);

            debug(D_REGISTRY, "Registry: deleting url '%s' from person '%s'", mu->url->url, m->guid);
            dictionary_del(m->machine_urls, mu->url->url);

            debug(D_REGISTRY, "Registry: unlinking url '%s' from machine", mu->url->url);
            registry_url_unlink(mu->url);

            debug(D_REGISTRY, "Registry: freeing machine url");
            freez(mu);
        }

        debug(D_REGISTRY, "Registry: deleting machine '%s' from machines registry", m->guid);
        dictionary_del(registry.machines, m->guid);

        debug(D_REGISTRY, "Registry: destroying URL dictionary of machine '%s'", m->guid);
        dictionary_destroy(m->machine_urls);

        debug(D_REGISTRY, "Registry: freeing machine '%s'", m->guid);
        freez(m);
    }

    // and free the memory of remaining dictionary structures

    debug(D_REGISTRY, "Registry: destroying persons dictionary");
    dictionary_destroy(registry.persons);

    debug(D_REGISTRY, "Registry: destroying machines dictionary");
    dictionary_destroy(registry.machines);
}
Ejemplo n.º 7
0
void close_config(dictionary *dict)
{
    if (dict != NULL) {
        dictionary_del(dict);
        dict = NULL;
    }
}
Ejemplo n.º 8
0
void Test_dictionary_growing(CuTest *tc)
{
    int i, j;
    char sec_name[32];
    char key_name[64];
    dictionary *dic;

    dic = dictionary_new(DICTMINSZ);
    CuAssertPtrNotNull(tc, dic);
    CuAssertIntEquals(tc, 0, dic->n);

    /* Makes the dictionary grow */
    for (i = 1 ; i < 101; ++i) {
        sprintf(sec_name, "sec%d", i);
        CuAssertIntEquals(tc, 0, dictionary_set(dic, sec_name, ""));
        for (j = 1 ; j < 11; ++j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            CuAssertIntEquals(tc, 0, dictionary_set(dic, key_name, "dummy_value"));
            CuAssertIntEquals(tc, i + (i - 1) * 10 + j, dic->n);
        }
    }

    /* Shrink the dictionary */
    for (i = 100 ; i > 0; --i) {
        sprintf(sec_name, "sec%d", i);
        for (j = 10 ; j > 0; --j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            dictionary_unset(dic, key_name);
        }
        dictionary_unset(dic, sec_name);
        CuAssertIntEquals(tc, (i - 1) * (11), dic->n);
    }

    dictionary_del(dic);
}
Ejemplo n.º 9
0
void camera_control_backup_system_settings(CameraControl* cc, const char* file) {
    int AutoAEC = 0;
    int AutoAGC = 0;
    int Gain = 0;
    int Exposure = 0;
    int Contrast = 0;
    int Brightness = 0;

    int fd = open_v4l2_device(cc->cameraID);

    if (fd != -1) {
        AutoAEC = v4l2_get_control(fd, V4L2_CID_EXPOSURE_AUTO);
        AutoAGC = v4l2_get_control(fd, V4L2_CID_AUTOGAIN);
        Gain = v4l2_get_control(fd, V4L2_CID_GAIN);
        Exposure = v4l2_get_control(fd, V4L2_CID_EXPOSURE);
        Contrast = v4l2_get_control(fd, V4L2_CID_CONTRAST);
        Brightness = v4l2_get_control(fd, V4L2_CID_BRIGHTNESS);
        v4l2_close(fd);

        dictionary* ini = dictionary_new(0);
        iniparser_set(ini, "PSEye", 0);
        iniparser_set_int(ini, "PSEye:AutoAEC", AutoAEC);
        iniparser_set_int(ini, "PSEye:AutoAGC", AutoAGC);
        iniparser_set_int(ini, "PSEye:Gain", Gain);
        iniparser_set_int(ini, "PSEye:Exposure", Exposure);
        iniparser_set_int(ini, "PSEye:Contrast", Contrast);
        iniparser_set_int(ini, "PSEye:Brightness", Brightness);
        iniparser_save_ini(ini, file);
        dictionary_del(ini);
    }
}
Ejemplo n.º 10
0
void registry_person_del(REGISTRY_PERSON *p) {
    debug(D_REGISTRY, "Registry: registry_person_del('%s'): creating dictionary of urls", p->guid);

    while(p->person_urls.root)
        registry_person_unlink_from_url(p, (REGISTRY_PERSON_URL *)p->person_urls.root);

    debug(D_REGISTRY, "Registry: deleting person '%s' from persons registry", p->guid);
    dictionary_del(registry.persons, p->guid);

    debug(D_REGISTRY, "Registry: freeing person '%s'", p->guid);
    freez(p);
}
Ejemplo n.º 11
0
void Test_iniparser_load(CuTest *tc)
{
    DIR *dir;
    struct dirent *curr;
    struct stat curr_stat;
    dictionary *dic;
    char ini_path[256];

    /* Dummy tests */
    dic = iniparser_load("/you/shall/not/path");
    CuAssertPtrEquals(tc, NULL, dic);

    /* Test all the good .ini files */
    dir = opendir(GOOD_INI_PATH);
    CuAssertPtrNotNullMsg(tc, "Cannot open good .ini conf directory", dir);
    for (curr = readdir(dir); curr != NULL; curr = readdir(dir)) {
        sprintf(ini_path, "%s/%s", GOOD_INI_PATH, curr->d_name);
        stat(ini_path, &curr_stat);
        if (S_ISREG(curr_stat.st_mode)) {
            dic = iniparser_load(ini_path);
            CuAssertPtrNotNullMsg(tc, ini_path, dic);
            dictionary_del(dic);
        }
    }
    closedir(dir);

    /* Test all the bad .ini files */
    dir = opendir(BAD_INI_PATH);
    CuAssertPtrNotNullMsg(tc, "Cannot open bad .ini conf directory", dir);
    for (curr = readdir(dir); curr != NULL; curr = readdir(dir)) {
        sprintf(ini_path, "%s/%s", BAD_INI_PATH, curr->d_name);
        stat(ini_path, &curr_stat);
        if (S_ISREG(curr_stat.st_mode)) {
            dic = iniparser_load(ini_path);
            CuAssertPtrEquals_Msg(tc, ini_path, NULL, dic);
            dictionary_del(dic);
        }
    }
    closedir(dir);
}
Ejemplo n.º 12
0
int main(int argc, char* argv[])
{
    dictionary*     d ;
    char*       val ;
    int         i ;
    char        cval[90] ;

    /* Allocate dictionary */
    printf("allocating...\n");
    d = dictionary_new(0);

    /* Set values in dictionary */
    printf("setting %d values...\n", NVALS);

    for (i=0 ; i<NVALS ; i++)
    {
        sprintf(cval, "%04d", i);
        dictionary_set(d, cval, "salut");
    }

    printf("getting %d values...\n", NVALS);

    for (i=0 ; i<NVALS ; i++)
    {
        sprintf(cval, "%04d", i);
        val = dictionary_get(d, cval, DICT_INVALID_KEY);

        if (val==DICT_INVALID_KEY)
        {
            printf("cannot get value for key [%s]\n", cval);
        }
    }

    printf("unsetting %d values...\n", NVALS);

    for (i=0 ; i<NVALS ; i++)
    {
        sprintf(cval, "%04d", i);
        dictionary_unset(d, cval);
    }

    if (d->n != 0)
    {
        printf("error deleting values\n");
    }

    printf("deallocating...\n");
    dictionary_del(d);
    return 0 ;
}
Ejemplo n.º 13
0
void Test_dictionary_dump(CuTest *tc)
{
    int i, j;
    char sec_name[32];
    char key_name[64];
    dictionary *dic;
    char *dump_buff;
    const char dump_real[] = "\
                sec1\t[]\n\
           sec1:key1\t[dummy_value]\n\
           sec1:key2\t[dummy_value]\n\
           sec1:key3\t[dummy_value]\n\
           sec1:key4\t[dummy_value]\n\
                sec2\t[]\n\
           sec2:key1\t[dummy_value]\n\
           sec2:key2\t[dummy_value]\n\
           sec2:key3\t[dummy_value]\n\
           sec2:key4\t[dummy_value]\n\
";

    dic = dictionary_new(DICTMINSZ);
    CuAssertPtrNotNull(tc, dic);

    /* Try dummy values */
    dictionary_dump(NULL, NULL);
    dictionary_dump(dic, NULL);

    /* Try with empty dictionary first */
    dump_buff = get_dump(dic);
    CuAssertStrEquals(tc, "empty dictionary\n", dump_buff);
    free(dump_buff);

    /* Populate the dictionary */
    for (i = 1 ; i < 3; ++i) {
        sprintf(sec_name, "sec%d", i);
        dictionary_set(dic, sec_name, "");
        for (j = 1 ; j < 5; ++j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            dictionary_set(dic, key_name, "dummy_value");
        }
    }

    /* Check the dump file */
    dump_buff = get_dump(dic);
    CuAssertStrEquals(tc, dump_real, dump_buff);
    free(dump_buff);

    dictionary_del(dic);
}
Ejemplo n.º 14
0
void Test_iniparser_getstring(CuTest *tc)
{
    dictionary *dic;
    /* NULL test */
    CuAssertPtrEquals(tc, NULL, iniparser_getstring(NULL, NULL, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getstring(NULL, "dummy", NULL));

    /* Check the def return element */
    dic = dictionary_new(10);
    CuAssertPtrEquals(tc, NULL, iniparser_getstring(dic, "dummy", NULL));
    CuAssertStrEquals(tc, "def", iniparser_getstring(dic, NULL, "def"));
    CuAssertStrEquals(tc, "def", iniparser_getstring(dic, "dummy", "def"));
    dictionary_del(dic);

    /* Generic dictionary */
    dic = generate_dictionary(100, 10);
    CuAssertStrEquals(tc, "value-0/0",
                      iniparser_getstring(dic, "sec0:key0", NULL));
    CuAssertStrEquals(tc, "value-42/5",
                      iniparser_getstring(dic, "sec42:key5", NULL));
    CuAssertStrEquals(tc, "value-99/9",
                      iniparser_getstring(dic, "sec99:key9", NULL));
    dictionary_del(dic);
}
Ejemplo n.º 15
0
int main
    (int  argc,
     char *argv[])

{
    LPDICTIONARY lpDict;        // Ptr to workspace dictionary
    LPWCHAR      lpwVal;
    int          i;
    WCHAR        cval[90];

    /* Allocate dictionary */
    printf ("allocating...\n");
    lpDict = dictionary_new (0);

    /* Set values in dictionary */
    printf ("setting %d values...\n", NVALS);
    for (i = 0; i < NVALS; i++)
    {
        wsprintfW (cval, L"%04d", i);
        dictionary_set (lpDict, cval, L"salut");
    } // End FOR

    printf ("getting %d values...\n", NVALS);
    for (i = 0; i < NVALS; i++)
    {
        wsprintfW (cval, L"%04d", i);
        lpwVal = dictionary_get (lpDict, cval, DICT_INVALID_KEY, NULL);
        if (lpwVal EQ DICT_INVALID_KEY)
            printf ("cannot get value for key [%s]\n", cval);
    } // End FOR

    printf ("unsetting %d values...\n", NVALS);
    for (i = 0; i < NVALS; i++)
    {
        wsprintfW (cval, L"%04d", i);
        dictionary_unset (lpDict, cval);
    } // End FOR

    if (lpDict->n NE 0)
        printf ("error deleting values\n");

    printf ("deallocating...\n");
    dictionary_del (lpDict); lpDict = NULL;

    return 0;
} // End main
Ejemplo n.º 16
0
int
config_load(void)
{
	int n;

	config = iniparser_load("spoold.conf");
	if(!config)
	{
		return -1;
	}
	for(n = 0; n < overrides->n; n++)
	{
		iniparser_set(config, overrides->key[n], overrides->val[n]);
	}
	dictionary_del(overrides);
	overrides = NULL;
	return 0;
}
Ejemplo n.º 17
0
void camera_control_backup_system_settings(CameraControl* cc, const char* file) {
#if !defined(CAMERA_CONTROL_USE_CL_DRIVER) && !defined(CAMERA_CONTROL_USE_PS3EYE_DRIVER) && defined(PSMOVE_USE_PSEYE)
	HKEY hKey;
	DWORD l = sizeof(DWORD);
	DWORD AutoAEC = 0;
	DWORD AutoAGC = 0;
	DWORD AutoAWB = 0;
	DWORD Exposure = 0;
	DWORD Gain = 0;
	DWORD wbB = 0;
	DWORD wbG = 0;
	DWORD wbR = 0;
	char* PATH = CL_DRIVER_REG_PATH;
	int err = RegOpenKeyEx(HKEY_CURRENT_USER, PATH, 0, KEY_ALL_ACCESS, &hKey);
	if (err != ERROR_SUCCESS) {
		printf("Error: %d Unable to open reg-key:  [HKCU]\\%s!", err, PATH);
		return;
	}
	RegQueryValueEx(hKey, "AutoAEC", NULL, NULL, (LPBYTE) &AutoAEC, &l);
	RegQueryValueEx(hKey, "AutoAGC", NULL, NULL, (LPBYTE) &AutoAGC, &l);
	RegQueryValueEx(hKey, "AutoAWB", NULL, NULL, (LPBYTE) &AutoAWB, &l);
	RegQueryValueEx(hKey, "Exposure", NULL, NULL, (LPBYTE) &Exposure, &l);
	RegQueryValueEx(hKey, "Gain", NULL, NULL, (LPBYTE) &Gain, &l);
	RegQueryValueEx(hKey, "WhiteBalanceB", NULL, NULL, (LPBYTE) &wbB, &l);
	RegQueryValueEx(hKey, "WhiteBalanceG", NULL, NULL, (LPBYTE) &wbG, &l);
	RegQueryValueEx(hKey, "WhiteBalanceR", NULL, NULL, (LPBYTE) &wbR, &l);

	dictionary* ini = dictionary_new(0);
	iniparser_set(ini, "PSEye", 0);
	iniparser_set_int(ini, "PSEye:AutoAEC", AutoAEC);
	iniparser_set_int(ini, "PSEye:AutoAGC", AutoAGC);
	iniparser_set_int(ini, "PSEye:AutoAWB", AutoAWB);
	iniparser_set_int(ini, "PSEye:Exposure", Exposure);
	iniparser_set_int(ini, "PSEye:Gain", Gain);
	iniparser_set_int(ini, "PSEye:WhiteBalanceB", wbB);
	iniparser_set_int(ini, "PSEye:WhiteBalanceG", wbG);
	iniparser_set_int(ini, "PSEye:WhiteBalanceR", wbG);
	iniparser_save_ini(ini, file);
	dictionary_del(ini);
#endif
}
Ejemplo n.º 18
0
void Test_iniparser_getdouble(CuTest *tc)
{
    dictionary *dic;

    /* NULL test */
    CuAssertDblEquals(tc, -42, iniparser_getdouble(NULL, NULL, -42), 0);
    CuAssertDblEquals(tc, 4.2, iniparser_getdouble(NULL, "dummy", 4.2), 0);

    /* Check the def return element */
    dic = dictionary_new(10);
    CuAssertDblEquals(tc, 3.1415, iniparser_getdouble(dic, "dummy", 3.1415), 0);
    CuAssertDblEquals(tc, 0xFFFFFFFF, iniparser_getdouble(dic, NULL, 0xFFFFFFFF), 0);
    CuAssertDblEquals(tc, -0xFFFFFFFF, iniparser_getdouble(dic, "dummy", -0xFFFFFFFF), 0);

    /* Insert some values */
    dictionary_set(dic, "double", "");
    dictionary_set(dic, "double:good0", "0");
    dictionary_set(dic, "double:good1", "-0");
    dictionary_set(dic, "double:good2", "1.0");
    dictionary_set(dic, "double:good3", "3.1415");
    dictionary_set(dic, "double:good4", "6.6655957");
    dictionary_set(dic, "double:good5", "-123456789.123456789");

    /* Add dummy stuff too */
    dictionary_set(dic, "double:bad0", "foo");

    /* Get back the values */
    CuAssertDblEquals(tc, 0, iniparser_getdouble(dic, "double:good0", 0xFF), 0);
    CuAssertDblEquals(tc, 0, iniparser_getdouble(dic, "double:good1", 0xFF), 0);
    CuAssertDblEquals(tc, 1.0, iniparser_getdouble(dic, "double:good2", 0xFF), 0);
    CuAssertDblEquals(tc, 3.1415, iniparser_getdouble(dic, "double:good3", 0xFF), 0);
    CuAssertDblEquals(tc, 6.6655957, iniparser_getdouble(dic, "double:good4", 0xFF), 0);
    CuAssertDblEquals(tc, -123456789.123456789,
                         iniparser_getdouble(dic, "double:good5", 0xFF), 0);

    CuAssertDblEquals(tc, 0, iniparser_getdouble(dic, "double:bad0", 42.42), 0);

    dictionary_del(dic);
}
Ejemplo n.º 19
0
void frame_factory_destroy(void)
{
    if (texture_cfg != NULL) {
        iniparser_freedict(texture_cfg);
        texture_cfg = NULL;
    }

    if (frame_cache != NULL) {
        int i;
        frame_t *frame;
        for (i = 0; i < frame_cache->size; ++ i) {
            if (frame_cache->key[i] != NULL) {
                frame = frame_factory_get(frame_cache->key[i]);
                frame_destroy(frame);
            }
        }
        dictionary_del(frame_cache);
        frame_cache = NULL;
    }

    return;
}
Ejemplo n.º 20
0
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame)
{
    FILE * in ;

    char line    [ASCIILINESZ+1] ;
    char section [ASCIILINESZ+1] ;
    char key     [ASCIILINESZ+1] ;
    char tmp     [ASCIILINESZ+1] ;
    char val     [ASCIILINESZ+1] ;

    int  last=0 ;
    int  len ;
    int  lineno=0 ;
    int  errs=0;

    dictionary * dict ;

    if ((in=fopen(ininame, "r"))==NULL) {
        fprintf(stderr, "iniparser: cannot open %s\n", ininame);
        return NULL ;
    }

    dict = dictionary_new(0) ;
    if (!dict) {
        fclose(in);
        return NULL ;
    }

    memset(line,    0, ASCIILINESZ);
    memset(section, 0, ASCIILINESZ);
    memset(key,     0, ASCIILINESZ);
    memset(val,     0, ASCIILINESZ);
    last=0 ;

    while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) {
        lineno++ ;
        len = (int)strlen(line)-1;
        /* Safety check against buffer overflows */
        if (line[len]!='\n') {
            fprintf(stderr,
                    "iniparser: input line too long in %s (%d)\n",
                    ininame,
                    lineno);
            dictionary_del(dict);
            fclose(in);
            return NULL ;
        }
        /* Get rid of \n and spaces at end of line */
        while ((len>=0) &&
                ((line[len]=='\n') || (isspace(line[len])))) {
            line[len]=0 ;
            len-- ;
        }
        /* Detect multi-line */
        if (line[len]=='\\') {
            /* Multi-line value */
            last=len ;
            continue ;
        } else {
            last=0 ;
        }
        switch (iniparser_line(line, section, key, val)) {
            case LINE_EMPTY:
            case LINE_COMMENT:
            break ;

            case LINE_SECTION:
            errs = dictionary_set(dict, section, NULL);
            break ;

            case LINE_VALUE:
            sprintf(tmp, "%s:%s", section, key);
            errs = dictionary_set(dict, tmp, val) ;
            break ;

            case LINE_ERROR:
            fprintf(stderr, "iniparser: syntax error in %s (%d):\n",
                    ininame,
                    lineno);
            fprintf(stderr, "-> %s\n", line);
            errs++ ;
            break;

            default:
            break ;
        }
        memset(line, 0, ASCIILINESZ);
        last=0;
        if (errs<0) {
            fprintf(stderr, "iniparser: memory allocation failure\n");
            break ;
        }
    }
    if (errs) {
        dictionary_del(dict);
        dict = NULL ;
    }
    fclose(in);
    return dict ;
}
Ejemplo n.º 21
0
void Test_iniparser_getboolean(CuTest *tc)
{
    unsigned i;
    char key_name[64];

    dictionary *dic;
    const char *token_true[] = {
        "1",
        "true",
        "t",
        "TRUE",
        "T",
        "yes",
        "y",
        "YES"
        "Y",
        NULL
    };
    const char *token_false[] = {
        "0",
        "false",
        "f",
        "FALSE",
        "F",
        "no",
        "n",
        "NO",
        "N",
        NULL
    };

    /* NULL test */
    CuAssertIntEquals(tc, 1, iniparser_getboolean(NULL, NULL, 1));
    CuAssertIntEquals(tc, 1, iniparser_getboolean(NULL, "dummy", 1));

    /* Check the def return element */
    dic = dictionary_new(10);
    CuAssertIntEquals(tc, 1, iniparser_getboolean(dic, "dummy", 1));
    CuAssertIntEquals(tc, 0, iniparser_getboolean(dic, NULL, 0));
    CuAssertIntEquals(tc, 1, iniparser_getboolean(dic, "dummy", 1));

    for (i = 0; token_true[i] != NULL; ++i) {
        sprintf(key_name, "bool:true%d", i);
        iniparser_set(dic, key_name, token_true[i]);
    }
    for (i = 0; token_false[i] != NULL; ++i) {
        sprintf(key_name, "bool:false%d", i);
        iniparser_set(dic, key_name, token_false[i]);
    }

    for (i = 0; token_true[i] != NULL; ++i) {
        sprintf(key_name, "bool:true%d", i);
        CuAssertIntEquals(tc, 1, iniparser_getboolean(dic, key_name, 0));
    }
    for (i = 0; token_false[i] != NULL; ++i) {
        sprintf(key_name, "bool:false%d", i);
        CuAssertIntEquals(tc, 0, iniparser_getboolean(dic, key_name, 1));
    }

    /* Test bad boolean */
    iniparser_set(dic, "bool:bad0", "");
    iniparser_set(dic, "bool:bad1", "m'kay");
    iniparser_set(dic, "bool:bad2", "42");
    iniparser_set(dic, "bool:bad3", "_true");
    CuAssertIntEquals(tc, 0xFF, iniparser_getboolean(dic, "bool:bad0", 0xFF));
    CuAssertIntEquals(tc, 0xFF, iniparser_getboolean(dic, "bool:bad1", 0xFF));
    CuAssertIntEquals(tc, 0xFF, iniparser_getboolean(dic, "bool:bad2", 0xFF));
    CuAssertIntEquals(tc, 0xFF, iniparser_getboolean(dic, "bool:bad3", 0xFF));

    dictionary_del(dic);
}
Ejemplo n.º 22
0
void Test_iniparser_getint(CuTest *tc)
{
    unsigned i;
    char key_name[64];
    dictionary *dic;
    const struct { int num; const char *value; } good_val[] = {
        { 0, "0" },
        { 1, "1" },
        { -1, "-1" },
        { 1000, "1000" },
        { 077, "077" },
        { -01000, "-01000" },
        { 0xFFFF, "0xFFFF" },
        { -0xFFFF, "-0xFFFF" },
        { 0x4242, "0x4242" },
        { 0, NULL} /* must be last */
    };
    const char *bad_val[] = {
        "",
        "notanumber",
        "0x",
        "k2000",
        " ",
        "0xG1"
    };
    /* NULL test */
    CuAssertIntEquals(tc, -42, iniparser_getint(NULL, NULL, -42));
    CuAssertIntEquals(tc, -42, iniparser_getint(NULL, "dummy", -42));

    /* Check the def return element */
    dic = dictionary_new(10);
    CuAssertIntEquals(tc, 42, iniparser_getint(dic, "dummy", 42));
    CuAssertIntEquals(tc, 0xFFFF, iniparser_getint(dic, NULL, 0xFFFF));
    CuAssertIntEquals(tc, -0xFFFF, iniparser_getint(dic, "dummy", -0xFFFF));
    dictionary_del(dic);

    /* Generic dictionary */
    dic = dictionary_new(10);
    for (i = 0; good_val[i].value != NULL; ++i) {
        sprintf(key_name, "int:value%d", i);
        dictionary_set(dic, key_name, good_val[i].value);
    }
    for (i = 0; good_val[i].value != NULL; ++i) {
        sprintf(key_name, "int:value%d", i);
        CuAssertIntEquals(tc, good_val[i].num,
                          iniparser_getint(dic, key_name, 0));
    }
    dictionary_del(dic);

    /* Test bad names */
    dic = dictionary_new(10);
    for (i = 0; i < sizeof (bad_val) / sizeof (char *); ++i) {
        sprintf(key_name, "int:bad%d", i);
        dictionary_set(dic, key_name, bad_val[i]);
    }
    for (i = 0; i < sizeof (bad_val) / sizeof (char *); ++i) {
        sprintf(key_name, "int:bad%d", i);
        CuAssertIntEquals(tc, 0,
                          iniparser_getint(dic, key_name, 0));
    }
    dictionary_del(dic);
}
Ejemplo n.º 23
0
int main(int argc, char **argv) {
	if(argc || argv) {;}

//	DICTIONARY *dict = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED|DICTIONARY_FLAG_WITH_STATISTICS);
	DICTIONARY *dict = dictionary_create(DICTIONARY_FLAG_WITH_STATISTICS);
	if(!dict) fatal("Cannot create dictionary.");

	struct rusage start, end;
	unsigned long long dt;
	char buf[100 + 1];
	struct myvalue value, *v;
	int i, max = 100000, max2;

	// ------------------------------------------------------------------------

	getrusage(RUSAGE_SELF, &start);
	dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
	fprintf(stderr, "Inserting %d entries in the dictionary\n", max);
	for(i = 0; i < max; i++) {
		value.i = i;
		snprintf(buf, 100, "%d", i);

		dictionary_set(dict, buf, &value, sizeof(struct myvalue));
	}
	getrusage(RUSAGE_SELF, &end);
	dt = (end.ru_utime.tv_sec * 1000000ULL + end.ru_utime.tv_usec) - (start.ru_utime.tv_sec * 1000000ULL + start.ru_utime.tv_usec);
	fprintf(stderr, "Added %d entries in %llu nanoseconds: %llu inserts per second\n", max, dt, max * 1000000ULL / dt);
	fprintf(stderr, " > Dictionary: %llu inserts, %llu deletes, %llu searches\n\n", dict->stats->inserts, dict->stats->deletes, dict->stats->searches);

	// ------------------------------------------------------------------------

	getrusage(RUSAGE_SELF, &start);
	dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
	fprintf(stderr, "Retrieving %d entries from the dictionary\n", max);
	for(i = 0; i < max; i++) {
		value.i = i;
		snprintf(buf, 100, "%d", i);

		v = dictionary_get(dict, buf);
		if(!v)
			fprintf(stderr, "ERROR: cannot get value %d from the dictionary\n", i);
		else if(v->i != i)
			fprintf(stderr, "ERROR: expected %d but got %d\n", i, v->i);
	}
	getrusage(RUSAGE_SELF, &end);
	dt = (end.ru_utime.tv_sec * 1000000ULL + end.ru_utime.tv_usec) - (start.ru_utime.tv_sec * 1000000ULL + start.ru_utime.tv_usec);
	fprintf(stderr, "Read %d entries in %llu nanoseconds: %llu searches per second\n", max, dt, max * 1000000ULL / dt);
	fprintf(stderr, " > Dictionary: %llu inserts, %llu deletes, %llu searches\n\n", dict->stats->inserts, dict->stats->deletes, dict->stats->searches);

	// ------------------------------------------------------------------------

	getrusage(RUSAGE_SELF, &start);
	dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
	fprintf(stderr, "Resetting %d entries in the dictionary\n", max);
	for(i = 0; i < max; i++) {
		value.i = i;
		snprintf(buf, 100, "%d", i);

		dictionary_set(dict, buf, &value, sizeof(struct myvalue));
	}
	getrusage(RUSAGE_SELF, &end);
	dt = (end.ru_utime.tv_sec * 1000000ULL + end.ru_utime.tv_usec) - (start.ru_utime.tv_sec * 1000000ULL + start.ru_utime.tv_usec);
	fprintf(stderr, "Reset %d entries in %llu nanoseconds: %llu resets per second\n", max, dt, max * 1000000ULL / dt);
	fprintf(stderr, " > Dictionary: %llu inserts, %llu deletes, %llu searches\n\n", dict->stats->inserts, dict->stats->deletes, dict->stats->searches);

	// ------------------------------------------------------------------------

	getrusage(RUSAGE_SELF, &start);
	dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
	fprintf(stderr, "Searching  %d non-existing entries in the dictionary\n", max);
	max2 = max * 2;
	for(i = max; i < max2; i++) {
		value.i = i;
		snprintf(buf, 100, "%d", i);

		v = dictionary_get(dict, buf);
		if(v)
			fprintf(stderr, "ERROR: cannot got non-existing value %d from the dictionary\n", i);
	}
	getrusage(RUSAGE_SELF, &end);
	dt = (end.ru_utime.tv_sec * 1000000ULL + end.ru_utime.tv_usec) - (start.ru_utime.tv_sec * 1000000ULL + start.ru_utime.tv_usec);
	fprintf(stderr, "Searched %d non-existing entries in %llu nanoseconds: %llu not found searches per second\n", max, dt, max * 1000000ULL / dt);
	fprintf(stderr, " > Dictionary: %llu inserts, %llu deletes, %llu searches\n\n", dict->stats->inserts, dict->stats->deletes, dict->stats->searches);

	// ------------------------------------------------------------------------

	getrusage(RUSAGE_SELF, &start);
	dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
	fprintf(stderr, "Deleting %d entries from the dictionary\n", max);
	for(i = 0; i < max; i++) {
		value.i = i;
		snprintf(buf, 100, "%d", i);

		dictionary_del(dict, buf);
	}
	getrusage(RUSAGE_SELF, &end);
	dt = (end.ru_utime.tv_sec * 1000000ULL + end.ru_utime.tv_usec) - (start.ru_utime.tv_sec * 1000000ULL + start.ru_utime.tv_usec);
	fprintf(stderr, "Deleted %d entries in %llu nanoseconds: %llu deletes per second\n", max, dt, max * 1000000ULL / dt);
	fprintf(stderr, " > Dictionary: %llu inserts, %llu deletes, %llu searches\n\n", dict->stats->inserts, dict->stats->deletes, dict->stats->searches);

	// ------------------------------------------------------------------------

	getrusage(RUSAGE_SELF, &start);
	dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
	fprintf(stderr, "Destroying dictionary\n");
	dictionary_destroy(dict);
	getrusage(RUSAGE_SELF, &end);
	dt = (end.ru_utime.tv_sec * 1000000ULL + end.ru_utime.tv_usec) - (start.ru_utime.tv_sec * 1000000ULL + start.ru_utime.tv_usec);
	fprintf(stderr, "Destroyed in %llu nanoseconds\n", dt);

	return 0;
}
Ejemplo n.º 24
0
dictionary * iniparser_new(char *ininame)
{
    dictionary  *   d ;
    char        lin[ASCIILINESZ+1];
    char        sec[ASCIILINESZ+1];
    char        key[ASCIILINESZ+1];
    char        val[ASCIILINESZ+1];
    char    *   where ;
    FILE    *   ini ;
    int         lineno ;

    if ((ini=fopen(ininame, "r"))==NULL) {
        return NULL ;
    }

    sec[0]=0;

    /*
     * Initialize a new dictionary entry
     */
    d = dictionary_new(0);
    if (d == NULL) {
      fclose(ini);
      return d;
    }
    lineno = 0 ;
    while (fgets(lin, ASCIILINESZ, ini)!=NULL) {
        lineno++ ;
        where = strskp(lin); /* Skip leading spaces */
        if (*where==';' || *where=='#' || *where==0)
            continue ; /* Comment lines */
        else {
            char lc_key[ASCIILINESZ+1];

            if (sscanf(where, "[%[^]]", sec)==1) {
                /* Valid section name */
                strcpy(sec, strlwc(sec, lc_key));
                if (iniparser_add_entry(d, sec, NULL, NULL) != 0) {
                  dictionary_del(d);
                  fclose(ini);
                  return NULL;
                }
            } else if (sscanf (where, "%[^=] = \"%[^\"]\"", key, val) == 2
                   ||  sscanf (where, "%[^=] = '%[^\']'",   key, val) == 2
                   ||  sscanf (where, "%[^=] = %[^;#]",     key, val) == 2) {
                char crop_key[ASCIILINESZ+1];

                strcpy(key, strlwc(strcrop(key, crop_key), lc_key));
                /*
                 * sscanf cannot handle "" or '' as empty value,
                 * this is done here
                 */
                if (!strcmp(val, "\"\"") || !strcmp(val, "''")) {
                    val[0] = (char)0;
                } else {
                    strcpy(val, strcrop(val, crop_key));
                }
                if (iniparser_add_entry(d, sec, key, val) != 0) {
                  dictionary_del(d);
                  fclose(ini);
                  return NULL;
                }
            }
        }
    }
    fclose(ini);
    return d ;
}
Ejemplo n.º 25
0
extern bool ini_conf_save(p_conf conf)
{
	dictionary *dict;
	FILE *fp;
	char buf[PATH_MAX];
	int i;

	if (conf == NULL) {
		return false;
	}

	conf->confver = XREADER_VERSION_NUM;
	dict = dictionary_new(0);

	if (dict == NULL)
		return false;

	fp = fopen(conf_filename, "w");

	if (fp == NULL) {
		return false;
	}

	if (iniparser_setstring(dict, "Global", NULL) != 0)
		goto error;
	if (iniparser_setstring(dict, "UI", NULL) != 0)
		goto error;
	if (iniparser_setstring(dict, "Text", NULL) != 0)
		goto error;
	if (iniparser_setstring(dict, "Image", NULL) != 0)
		goto error;
	if (iniparser_setstring(dict, "Music", NULL) != 0)
		goto error;

	iniparser_setstring(dict, "Global:path", conf->path);
	iniparser_setstring(dict, "UI:forecolor",
						hexToString(buf, sizeof(buf), conf->forecolor));
	iniparser_setstring(dict, "Image:giftranscolor",
						hexToString(buf, sizeof(buf), conf->giftranscolor));
	iniparser_setstring(dict, "UI:bgcolor",
						hexToString(buf, sizeof(buf), conf->bgcolor));
	iniparser_setstring(dict, "UI:have_bg",
						booleanToString(buf, sizeof(buf), conf->have_bg));
	iniparser_setstring(dict, "UI:titlecolor",
						hexToString(buf, sizeof(buf), conf->titlecolor));
	iniparser_setstring(dict, "UI:menutextcolor",
						hexToString(buf, sizeof(buf), conf->menutextcolor));
	iniparser_setstring(dict, "UI:menubcolor",
						hexToString(buf, sizeof(buf), conf->menubcolor));
	iniparser_setstring(dict, "UI:selicolor",
						hexToString(buf, sizeof(buf), conf->selicolor));
	iniparser_setstring(dict, "UI:selbcolor",
						hexToString(buf, sizeof(buf), conf->selbcolor));
	iniparser_setstring(dict, "UI:msgbcolor",
						hexToString(buf, sizeof(buf), conf->msgbcolor));
	iniparser_setstring(dict, "UI:usedyncolor",
						booleanToString(buf, sizeof(buf), conf->usedyncolor));
	iniparser_setstring(dict, "Text:rowspace",
						dwordToString(buf, sizeof(buf), conf->rowspace));
	iniparser_setstring(dict, "Text:infobar",
						infobarToString(buf, sizeof(buf), conf->infobar));
	iniparser_setstring(dict, "Text:infobar_style",
						intToString(buf, sizeof(buf), conf->infobar_style));
	iniparser_setstring(dict, "Text:rlastrow",
						booleanToString(buf, sizeof(buf), conf->rlastrow));
	iniparser_setstring(dict, "Text:autobm",
						booleanToString(buf, sizeof(buf), conf->autobm));
	iniparser_setstring(dict, "Text:vertread",
						vertreadToString(buf, sizeof(buf), conf->vertread));
	iniparser_setstring(dict, "Text:encode",
						encodeToString(buf, sizeof(buf), conf->encode));
	iniparser_setstring(dict, "Image:fit",
						fitToString(buf, sizeof(buf), conf->fit));
	iniparser_setstring(dict, "Image:imginfobar",
						booleanToString(buf, sizeof(buf), conf->imginfobar));
	iniparser_setstring(dict, "Text:scrollbar",
						booleanToString(buf, sizeof(buf), conf->scrollbar));
	iniparser_setstring(dict, "Image:scale",
						dwordToString(buf, sizeof(buf), conf->scale));
	iniparser_setstring(dict, "Image:rotate",
						rotateToString(buf, sizeof(buf), conf->rotate));

	for (i = 0; i < 20; ++i) {
		char key[20];

		SPRINTF_S(key, "Text:txtkey1_%02d", i);
		iniparser_setstring(dict, key,
							hexToString(buf, sizeof(buf), conf->txtkey[i]));
		SPRINTF_S(key, "Image:imgkey1_%02d", i);
		iniparser_setstring(dict, key,
							hexToString(buf, sizeof(buf), conf->imgkey[i]));
	}
	iniparser_setstring(dict, "Global:shortpath", conf->shortpath);
	iniparser_setstring(dict, "Global:confver",
						hexToString(buf, sizeof(buf), conf->confver));
	iniparser_setstring(dict, "Image:bicubic",
						booleanToString(buf, sizeof(buf), conf->bicubic));
	iniparser_setstring(dict, "Text:wordspace",
						dwordToString(buf, sizeof(buf), conf->wordspace));
	iniparser_setstring(dict, "Text:borderspace",
						dwordToString(buf, sizeof(buf), conf->borderspace));
	iniparser_setstring(dict, "Global:lastfile", conf->lastfile);
	iniparser_setstring(dict, "Music:mp3encode",
						encodeToString(buf, sizeof(buf), conf->mp3encode));
	iniparser_setstring(dict, "Music:lyricencode",
						encodeToString(buf, sizeof(buf), conf->lyricencode));
	iniparser_setstring(dict, "Music:mp3cycle",
						cycleToString(buf, sizeof(buf), conf->mp3cycle));
	iniparser_setstring(dict, "Global:isreading",
						booleanToString(buf, sizeof(buf), conf->isreading));
	iniparser_setstring(dict, "UI:bgarch", conf->bgarch);
	iniparser_setstring(dict, "UI:bgfile", conf->bgfile);
	iniparser_setstring(dict, "UI:bgwhere",
						intToString(buf, sizeof(buf), conf->bgwhere));
	iniparser_setstring(dict, "Image:slideinterval",
						dwordToString(buf, sizeof(buf), conf->slideinterval));
	iniparser_setstring(dict, "Music:hprmctrl",
						booleanToString(buf, sizeof(buf), conf->hprmctrl));
	iniparser_setstring(dict, "UI:grayscale",
						intToString(buf, sizeof(buf), conf->grayscale));
	iniparser_setstring(dict, "Global:showhidden",
						booleanToString(buf, sizeof(buf), conf->showhidden));
	iniparser_setstring(dict, "Global:showunknown",
						booleanToString(buf, sizeof(buf), conf->showunknown));
	iniparser_setstring(dict, "Global:showfinfo",
						booleanToString(buf, sizeof(buf), conf->showfinfo));
	iniparser_setstring(dict, "Global:allowdelete",
						booleanToString(buf, sizeof(buf), conf->allowdelete));
	iniparser_setstring(dict, "Global:arrange",
						arrangeToString(buf, sizeof(buf), conf->arrange));
	iniparser_setstring(dict, "Global:enableusb",
						booleanToString(buf, sizeof(buf), conf->enableusb));
	iniparser_setstring(dict, "Image:viewpos",
						viewposToString(buf, sizeof(buf), conf->viewpos));
	iniparser_setstring(dict, "Image:imgmvspd",
						dwordToString(buf, sizeof(buf), conf->imgmvspd));
	iniparser_setstring(dict, "Image:imgpaging",
						imgpagingToString(buf, sizeof(buf), conf->imgpaging));
	iniparser_setstring(dict, "Image:imgpaging_spd",
						dwordToString(buf, sizeof(buf), conf->imgpaging_spd));
	iniparser_setstring(dict, "Image:imgpaging_interval",
						dwordToString(buf, sizeof(buf),
									  conf->imgpaging_interval));
	iniparser_setstring(dict, "Image:imgpaging_duration",
						dwordToString(buf, sizeof(buf),
									  conf->imgpaging_duration));
	for (i = 0; i < 20; ++i) {
		char key[20];

		SPRINTF_S(key, "Global:flkey1_%02d", i);
		iniparser_setstring(dict, key,
							hexToString(buf, sizeof(buf), conf->flkey[i]));
	}
	iniparser_setstring(dict, "UI:fontsize",
						intToString(buf, sizeof(buf), conf->fontsize));
	iniparser_setstring(dict, "Text:reordertxt",
						booleanToString(buf, sizeof(buf), conf->reordertxt));
	iniparser_setstring(dict, "Text:pagetonext",
						booleanToString(buf, sizeof(buf), conf->pagetonext));
	iniparser_setstring(dict, "Text:autopage",
						intToString(buf, sizeof(buf), conf->autopage));
	iniparser_setstring(dict, "Text:prev_autopage",
						intToString(buf, sizeof(buf), conf->prev_autopage));
	iniparser_setstring(dict, "Text:autopagetype",
						intToString(buf, sizeof(buf), conf->autopagetype));
	iniparser_setstring(dict, "Text:autolinedelay",
						intToString(buf, sizeof(buf), conf->autolinedelay));
	iniparser_setstring(dict, "Image:thumb",
						thumbToString(buf, sizeof(buf), conf->thumb));
	iniparser_setstring(dict, "Text:bookfontsize",
						intToString(buf, sizeof(buf), conf->bookfontsize));
	iniparser_setstring(dict, "Text:enable_analog",
						booleanToString(buf, sizeof(buf), conf->enable_analog));
	iniparser_setstring(dict, "Image:img_enable_analog",
						booleanToString(buf, sizeof(buf),
										conf->img_enable_analog));
	for (i = 0; i < 20; ++i) {
		char key[20];

		SPRINTF_S(key, "Text:txtkey2_%02d", i);
		iniparser_setstring(dict, key,
							hexToString(buf, sizeof(buf), conf->txtkey2[i]));
		SPRINTF_S(key, "Image:imgkey2_%02d", i);
		iniparser_setstring(dict, key,
							hexToString(buf, sizeof(buf), conf->imgkey2[i]));
		SPRINTF_S(key, "Global:flkey2_%02d", i);
		iniparser_setstring(dict, key,
							hexToString(buf, sizeof(buf), conf->flkey2[i]));
	}
	iniparser_setstring(dict, "Image:imgpagereserve",
						dwordToString(buf, sizeof(buf), conf->imgpagereserve));
	iniparser_setstring(dict, "Music:lyricex",
						dwordToString(buf, sizeof(buf), conf->lyricex));
	iniparser_setstring(dict, "Music:autoplay",
						booleanToString(buf, sizeof(buf), conf->autoplay));
	iniparser_setstring(dict, "Text:usettf",
						booleanToString(buf, sizeof(buf), conf->usettf));
	iniparser_setstring(dict, "Text:cttfarch", conf->cttfarch);
	iniparser_setstring(dict, "Text:cttfpath", conf->cttfpath);
	iniparser_setstring(dict, "Text:ettfarch", conf->ettfarch);
	iniparser_setstring(dict, "Text:ettfpath", conf->ettfpath);
	for (i = 0; i < 3; ++i) {
		char key[20];

		SPRINTF_S(key, "Global:freqs_%d", i);
		iniparser_setstring(dict, key,
							intToString(buf, sizeof(buf), conf->freqs[i]));
	}
	iniparser_setstring(dict, "Image:imgbrightness",
						intToString(buf, sizeof(buf), conf->imgbrightness));
	iniparser_setstring(dict, "Global:dis_scrsave",
						booleanToString(buf, sizeof(buf), conf->dis_scrsave));
	iniparser_setstring(dict, "Global:autosleep",
						intToString(buf, sizeof(buf), conf->autosleep));
	iniparser_setstring(dict, "Image:load_exif",
						booleanToString(buf, sizeof(buf), conf->load_exif));
	iniparser_setstring(dict, "Global:launchtype",
						intToString(buf, sizeof(buf), conf->launchtype));
	iniparser_setstring(dict, "Text:infobar_use_ttf_mode",
						booleanToString(buf, sizeof(buf),
										conf->infobar_use_ttf_mode));
	iniparser_setstring(dict, "Text:infobar_fontsize",
						dwordToString(buf, sizeof(buf),
									  conf->infobar_fontsize));
	iniparser_setstring(dict, "Image:no_repeat",
						booleanToString(buf, sizeof(buf), conf->img_no_repeat));

	iniparser_setstring(dict, "Global:hide_flash",
						booleanToString(buf, sizeof(buf), conf->hide_flash));

	iniparser_setstring(dict, "Text:tabstop",
						dwordToString(buf, sizeof(buf), conf->tabstop));

	iniparser_setstring(dict, "Music:apetagorder",
						booleanToString(buf, sizeof(buf), conf->apetagorder));

	iniparser_setstring(dict, "UI:language", conf->language);

	iniparser_setstring(dict, "UI:filelistwidth",
						intToString(buf, sizeof(buf), conf->filelistwidth));

	iniparser_setstring(dict, "Text:ttf_load_to_memory",
						booleanToString(buf, sizeof(buf),
										conf->ttf_load_to_memory));

	iniparser_setstring(dict, "Global:save_password",
						booleanToString(buf, sizeof(buf), conf->save_password));

	iniparser_setstring(dict, "Text:scrollbar_width",
						intToString(buf, sizeof(buf), conf->scrollbar_width));

	iniparser_setstring(dict, "Text:hide_last_row",
						booleanToString(buf, sizeof(buf), conf->hide_last_row));

	iniparser_setstring(dict, "Text:infobar_show_timer",
						booleanToString(buf, sizeof(buf),
										conf->infobar_show_timer));

	iniparser_setstring(dict, "Text:englishtruncate",
						booleanToString(buf, sizeof(buf),
										conf->englishtruncate));

	iniparser_setstring(dict, "Image:image_scroll_chgn_speed",
						booleanToString(buf, sizeof(buf),
										conf->image_scroll_chgn_speed));

	iniparser_setstring(dict, "Text:ttf_haste_up",
						booleanToString(buf, sizeof(buf), conf->ttf_haste_up));

	iniparser_setstring(dict, "Text:linenum_style",
						booleanToString(buf, sizeof(buf), conf->linenum_style));

	iniparser_setstring(dict, "Text:infobar_align",
						alignToString(buf, sizeof(buf), conf->infobar_align));

	iniparser_setstring(dict, "Music:musicdrv_opts", conf->musicdrv_opts);

	iniparser_setstring(dict, "Image:magnetic_scrolling",
						booleanToString(buf, sizeof(buf),
										conf->magnetic_scrolling));

	iniparser_setstring(dict, "Image:use_image_queue",
						booleanToString(buf, sizeof(buf),
										conf->use_image_queue));

	iniparser_setstring(dict, "Image:max_cache_img",
						dwordToString(buf, sizeof(buf), conf->max_cache_img));

	iniparser_setstring(dict, "Music:show_encoder_msg",
						booleanToString(buf, sizeof(buf),
										conf->show_encoder_msg));
	
	iniparser_dump_ini(dict, fp);

	fclose(fp);

	dictionary_del(dict);

	return true;
  error:
	if (fp != NULL)
		fclose(fp);
	return false;
}
Ejemplo n.º 26
0
/*--------------------------------------------------------------------------*/
void iniparser_freedict(dictionary * d)
{
    dictionary_del(d);
}
Ejemplo n.º 27
0
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame)
{
    FILE * in = NULL ;

    char line    [ASCIILINESZ+1] ;
    char *section = xstrdup("");
    char *current_section = NULL;
    char *key = NULL;
    char *val = NULL;
    char* full_line = NULL;
    char* prev_line = NULL;

    int  len ;
    int  lineno=0 ;
    int  errs=0;
    int  seckey_size=0;

    dictionary * dict = NULL ;

    if ((in=fopen(ininame, "r"))==NULL) {
        fprintf(stderr, "iniparser: cannot open %s\n", ininame);
        goto out;
    }

    dict = dictionary_new(0) ;
    if (!dict) {
        goto out;
    }

    memset(line,    0, ASCIILINESZ);

    while (fgets(line, ASCIILINESZ, in)!=NULL) {
        int prev_line_len = 0;
        int multi_line = 0;
        int total_size = 0;

        if (key) {
            free(key);
            key = NULL;
        }
        if (val) {
            free(val);
            val = NULL;
        }

        lineno++ ;
        len = (int)strlen(line)-1;
        if (len==0)
            continue;
        /* Safety check against buffer overflows */
        if (line[len]!='\n' && !feof(in)) {
            fprintf(stderr,
                    "iniparser: input line too long in %s (%d)\n",
                    ininame,
                    lineno);
            errs++;
            goto out;
        }
        /* Get rid of \n and spaces at end of line */
        while ((len>=0) &&
                ((line[len]=='\n') || (isspace(line[len])))) {
            line[len]=0 ;
            len-- ;
        }

        if (len < 0) { /* Line was entirely \n and/or spaces */
            len = 0;
        }

        /* Detect multi-line */
        if (line[len]=='\\') {
            multi_line = 1;
        }
        if (multi_line) {
            /* Multi-line value */
            /* length without trailing '\' */
            /* remove multi-line indicator before appending*/
            line[len] = 0;
            len--;
        }

        /*
         * If processing a multi-line then append it the previous portion,
         * at this point 'full_line' has the previously read portion of a
         * multi-line line (or NULL)
         */
        prev_line = full_line;
        prev_line_len=0;
        if (prev_line) {
            prev_line_len = (int)strlen(prev_line);
        }

        /* len is not strlen(line) but strlen(line) -1 */
        total_size = (len+1) + prev_line_len + 1;

        full_line = malloc(total_size);
        if (!full_line) {
            fprintf(stderr,
                    "iniparser: out of mem\n");
            errs++;
            goto out;
        }

        memset(full_line, 0, total_size);

        if (prev_line) {
            strcpy(full_line, prev_line);
        }

        strcpy(full_line + prev_line_len, line);
        free(prev_line);
        prev_line = NULL;

        if (multi_line) {
            continue ;
        }

        switch (iniparser_line(total_size, full_line, &current_section, &key, &val)) {
            case LINE_EMPTY:
            case LINE_COMMENT:
            break ;

            case LINE_SECTION:
            if (section) {
                free(section);
                section=NULL;
            }
            errs = dictionary_set(dict, current_section, NULL);
            section = current_section;
            break ;

            case LINE_VALUE:
            {
                char *seckey;
                /* section + ':' + key + eos */
                seckey_size = (int)strlen(section) + (int)strlen(key) +2;
                seckey = malloc(seckey_size);
                if (!seckey) {
                    errs++;
                    fprintf(stderr,
                           "iniparser: out of mem\n");
                    goto out;
                }
                snprintf(seckey, seckey_size, "%s:%s", section, key);
                errs = dictionary_set(dict, seckey, val) ;
                free(seckey);
                seckey = NULL;
            }
            break ;

            case LINE_ERROR:
            fprintf(stderr, "iniparser: syntax error in %s (%d):\n",
                    ininame,
                    lineno);
            fprintf(stderr, "-> %s\n", full_line);
            errs++ ;
            break;

            default:
            break ;
        }
        memset(line, 0, ASCIILINESZ);
        if (full_line) {
            free(full_line);
            full_line = NULL;
        }
        if (errs<0) {
            fprintf(stderr, "iniparser: memory allocation failure\n");
            break ;
        }
    }
out:
    if (errs) {
        dictionary_del(dict);
        dict = NULL ;
    }
    if (val) {
        free(val);
        val = NULL;
    }
    if (key) {
        free(key);
        key = NULL;
    }
    if (section) {
        free(section);
        section = NULL;
    }
    if (full_line) {
        free(full_line);
        full_line = NULL;
    }
    if (prev_line) {
        free(prev_line);
        prev_line = NULL;
    }
    if (in) {
        fclose(in);
    }
    return dict ;
}
Ejemplo n.º 28
0
int validate_token(bstring token)
{
    int i;

    OpenSSL_add_all_algorithms();

    struct bstrList *parts = bsplit(token, '|');

    dictionary *dict = dictionary_new(10);

    bstring sig = bfromcstr("sig");
    bstring to_sign = bfromcstr("");
    
    for (i = 0; i < parts->qty; i++)
    {
	printf("%d: %s\n", i, parts->entry[i]->data);

	struct bstrList *x = bsplit(parts->entry[i], '=');
	if (x->qty == 2)
	{
	    if (bstrcmp(x->entry[0], sig) != 0)
	    {
		if (blength(to_sign) > 0)
		    bconchar(to_sign, '|');
		bconcat(to_sign, parts->entry[i]);
	    }
	    dictionary_set(dict, bdata(x->entry[0]), bdata(x->entry[1]));
	}
	bstrListDestroy(x);
    }
    bstrListDestroy(parts);
    parts = 0;
    bdestroy(sig);
    
    dictionary_dump(dict, stdout);
    printf("to sign: '%s'\n", bdata(to_sign));

    // Check signing subject (need to know the valid values)

    char *subj = dictionary_get(dict, "SigningSubject", 0);
    if (!subj)
    {
	fprintf(stderr, "could not get signing subject\n");
	return 0;
    }

    char *sigstr = dictionary_get(dict, "sig", 0);
    printf("sig to verify is %s\n", sigstr);

    bstring binsig = bfromcstralloc(strlen(sigstr) / 2, "");
    char *s, *e;
    for (s = sigstr, e = sigstr + strlen(sigstr); s < e; s += 2)
    {
	char n[3];
	n[0] = s[0];
	n[1] = s[1];
	n[2] = 0;
	long int v = strtol(n, 0, 16);
//	printf("n=%s v=%ld %lx\n", n, v, v);
	bconchar(binsig, (char) v);
    }

    unsigned char *sha = SHA1((const unsigned char *) to_sign->data, to_sign->slen, 0);

    bdestroy(to_sign);

    bstring bsubj = bfromcstr(subj);
    bstring pubkey = get_signer_pubkey(bsubj);

    BIO *bio = BIO_new(BIO_s_mem());
    BIO_puts(bio, bdata(pubkey));

    RSA *rsa = PEM_read_bio_RSAPublicKey(bio, 0, 0, 0);

    int rc = RSA_verify(NID_sha1, sha, SHA_DIGEST_LENGTH, binsig->data, binsig->slen, rsa);
    printf("rc=%d\n", rc);

    bdestroy(bsubj);
    bdestroy(binsig);
    bdestroy(pubkey);
    BIO_free(bio);
    RSA_free(rsa);
    dictionary_del(dict);
    EVP_cleanup();
    
    return rc;
}
Ejemplo n.º 29
0
extern bool ini_conf_load(const char *inifilename, p_conf conf)
{
	dictionary *dict;
	char buf[80];
	int i;
	extern void get_language(void);

	if (conf == NULL || inifilename == NULL) {
		return false;
	}

	dict = iniparser_load(inifilename);

	if (dict == NULL)
		return false;

	conf_default(conf);

	STRCPY_S(conf->path, iniparser_getstring(dict, "Global:path", conf->path));
	conf->forecolor =
		iniparser_getunsigned(dict, "UI:forecolor", conf->forecolor);
	conf->giftranscolor =
		iniparser_getunsigned(dict, "Image:giftranscolor", conf->giftranscolor);
	conf->bgcolor = iniparser_getunsigned(dict, "UI:bgcolor", conf->bgcolor);
	conf->have_bg = iniparser_getboolean(dict, "UI:have_bg", conf->have_bg);
	conf->titlecolor =
		iniparser_getunsigned(dict, "UI:titlecolor", conf->titlecolor);
	conf->menutextcolor =
		iniparser_getunsigned(dict, "UI:menutextcolor", conf->menutextcolor);
	conf->menubcolor =
		iniparser_getunsigned(dict, "UI:menubcolor", conf->menubcolor);
	conf->selicolor =
		iniparser_getunsigned(dict, "UI:selicolor", conf->selicolor);
	conf->selbcolor =
		iniparser_getunsigned(dict, "UI:selbcolor", conf->selbcolor);
	conf->msgbcolor =
		iniparser_getunsigned(dict, "UI:msgbcolor", conf->msgbcolor);
	conf->usedyncolor =
		iniparser_getboolean(dict, "UI:usedyncolor", conf->usedyncolor);
	conf->rowspace = iniparser_getint(dict, "Text:rowspace", conf->rowspace);
	conf->infobar =
		stringToInfobar(iniparser_getstring
						(dict, "Text:infobar",
						 infobarToString(buf, sizeof(buf), conf->infobar)));
	conf->infobar_style =
		iniparser_getint(dict, "Text:infobar_style", conf->infobar_style);
	conf->infobar_fontsize =
		iniparser_getunsigned(dict, "Text:infobar_fontsize",
							  conf->infobar_fontsize);
	conf->rlastrow =
		iniparser_getboolean(dict, "Text:rlastrow", conf->rlastrow);
	conf->autobm = iniparser_getboolean(dict, "Text:autobm", conf->autobm);
	conf->vertread =
		stringToVertread(iniparser_getstring
						 (dict, "Text:vertread",
						  vertreadToString(buf, sizeof(buf), conf->vertread)));
	conf->encode =
		stringToEncode(iniparser_getstring
					   (dict, "Text:encode",
						encodeToString(buf, sizeof(buf), conf->encode)));
	conf->fit =
		stringToFit(iniparser_getstring
					(dict, "Image:fit",
					 fitToString(buf, sizeof(buf), conf->fit)));
	conf->imginfobar =
		iniparser_getboolean(dict, "Image:imginfobar", conf->imginfobar);
	conf->scrollbar =
		iniparser_getboolean(dict, "Text:scrollbar", conf->scrollbar);
	conf->scale = iniparser_getint(dict, "Image:scale", conf->scale);
	conf->rotate =
		stringToRotate(iniparser_getstring
					   (dict, "Image:rotate",
						rotateToString(buf, sizeof(buf), conf->rotate)));

	for (i = 0; i < 20; ++i) {
		char key[20];

		SPRINTF_S(key, "Text:txtkey1_%02d", i);
		conf->txtkey[i] = iniparser_getint(dict, key, conf->txtkey[i]);
		SPRINTF_S(key, "Image:imgkey1_%02d", i);
		conf->imgkey[i] = iniparser_getint(dict, key, conf->imgkey[i]);
	}
	check_empty_imgkey(conf);
	STRCPY_S(conf->shortpath,
			 iniparser_getstring(dict, "Global:shortpath", conf->shortpath));
	conf->confver = iniparser_getint(dict, "Global:confver", conf->confver);
	conf->bicubic = iniparser_getboolean(dict, "Image:bicubic", conf->bicubic);
	conf->wordspace = iniparser_getint(dict, "Text:wordspace", conf->wordspace);
	conf->borderspace =
		iniparser_getunsigned(dict, "Text:borderspace", conf->borderspace);
	STRCPY_S(conf->lastfile,
			 iniparser_getstring(dict, "Global:lastfile", conf->lastfile));
	conf->mp3encode =
		stringToEncode(iniparser_getstring
					   (dict, "Music:mp3encode",
						encodeToString(buf, sizeof(buf), conf->mp3encode)));
	conf->lyricencode =
		stringToEncode(iniparser_getstring
					   (dict, "Music:lyricencode",
						encodeToString(buf, sizeof(buf), conf->lyricencode)));
	conf->mp3cycle =
		stringToCycle(iniparser_getstring
					  (dict, "Music:mp3cycle",
					   cycleToString(buf, sizeof(buf), conf->mp3cycle)));
	conf->isreading =
		iniparser_getboolean(dict, "Global:isreading", conf->isreading);
	STRCPY_S(conf->bgarch,
			 iniparser_getstring(dict, "UI:bgarch", conf->bgarch));
	STRCPY_S(conf->bgfile,
			 iniparser_getstring(dict, "UI:bgfile", conf->bgfile));
	conf->bgwhere = iniparser_getint(dict, "UI:bgwhere", conf->bgwhere);
	conf->slideinterval =
		iniparser_getint(dict, "Image:slideinterval", conf->slideinterval);
	conf->hprmctrl =
		iniparser_getboolean(dict, "Music:hprmctrl", conf->hprmctrl);
	conf->grayscale = iniparser_getint(dict, "UI:grayscale", conf->grayscale);
	conf->showhidden =
		iniparser_getboolean(dict, "Global:showhidden", conf->showhidden);
	conf->showunknown =
		iniparser_getboolean(dict, "Global:showunknown", conf->showunknown);
	conf->showfinfo =
		iniparser_getboolean(dict, "Global:showfinfo", conf->showfinfo);
	conf->allowdelete =
		iniparser_getboolean(dict, "Global:allowdelete", conf->allowdelete);
	conf->arrange =
		stringToArrange(iniparser_getstring
						(dict, "Global:arrange",
						 arrangeToString(buf, sizeof(buf), conf->arrange)));
	conf->enableusb =
		iniparser_getboolean(dict, "Global:enableusb", conf->enableusb);
	conf->viewpos =
		stringToViewpos(iniparser_getstring
						(dict, "Image:viewpos",
						 viewposToString(buf, sizeof(buf), conf->viewpos)));
	conf->imgmvspd = iniparser_getint(dict, "Image:imgmvspd", conf->imgmvspd);
	conf->imgpaging =
		stringToImgpaging(iniparser_getstring
						  (dict, "Image:imgpaging",
						   imgpagingToString(buf, sizeof(buf),
											 conf->imgpaging)));
	conf->imgpaging_spd =
		iniparser_getint(dict, "Image:imgpaging_spd", conf->imgpaging_spd);
	conf->imgpaging_interval =
		iniparser_getint(dict, "Image:imgpaging_interval",
						 conf->imgpaging_interval);
	conf->imgpaging_duration =
		iniparser_getint(dict, "Image:imgpaging_duration",
						 conf->imgpaging_duration);
	for (i = 0; i < 20; ++i) {
		char key[20];

		SPRINTF_S(key, "Global:flkey1_%02d", i);
		conf->flkey[i] = iniparser_getint(dict, key, conf->flkey[i]);
	}
	conf->fontsize = iniparser_getint(dict, "UI:fontsize", conf->fontsize);
	conf->reordertxt =
		iniparser_getboolean(dict, "Text:reordertxt", conf->reordertxt);
	conf->pagetonext =
		iniparser_getboolean(dict, "Text:pagetonext", conf->pagetonext);
	conf->autopage = iniparser_getint(dict, "Text:autopage", conf->autopage);
	conf->prev_autopage =
		iniparser_getint(dict, "Text:prev_autopage", conf->prev_autopage);
	conf->autopagetype =
		iniparser_getint(dict, "Text:autopagetype", conf->autopagetype);
	conf->autolinedelay =
		iniparser_getint(dict, "Text:autolinedelay", conf->autolinedelay);
	conf->thumb =
		stringToThumb(iniparser_getstring
					  (dict, "Image:thumb",
					   thumbToString(buf, sizeof(buf), conf->thumb)));
	conf->bookfontsize =
		iniparser_getint(dict, "Text:bookfontsize", conf->bookfontsize);
	conf->enable_analog =
		iniparser_getboolean(dict, "Text:enable_analog", conf->enable_analog);
	conf->img_enable_analog =
		iniparser_getboolean(dict, "Image:img_enable_analog",
							 conf->img_enable_analog);
	for (i = 0; i < 20; ++i) {
		char key[20];

		SPRINTF_S(key, "Text:txtkey2_%02d", i);
		conf->txtkey2[i] = iniparser_getint(dict, key, conf->txtkey2[i]);
		SPRINTF_S(key, "Image:imgkey2_%02d", i);
		conf->imgkey2[i] = iniparser_getint(dict, key, conf->imgkey2[i]);
		SPRINTF_S(key, "Global:flkey2_%02d", i);
		conf->flkey2[i] = iniparser_getint(dict, key, conf->flkey2[i]);
	}
	conf->imgpagereserve =
		iniparser_getint(dict, "Image:imgpagereserve", conf->imgpagereserve);
	conf->lyricex = iniparser_getint(dict, "Music:lyricex", conf->lyricex);
	conf->autoplay =
		iniparser_getboolean(dict, "Music:autoplay", conf->autoplay);
	conf->usettf = iniparser_getboolean(dict, "Text:usettf", conf->usettf);
	STRCPY_S(conf->cttfarch,
			 iniparser_getstring(dict, "Text:cttfarch", conf->cttfarch));
	STRCPY_S(conf->cttfpath,
			 iniparser_getstring(dict, "Text:cttfpath", conf->cttfpath));
	STRCPY_S(conf->ettfarch,
			 iniparser_getstring(dict, "Text:ettfarch", conf->ettfarch));
	STRCPY_S(conf->ettfpath,
			 iniparser_getstring(dict, "Text:ettfpath", conf->ettfpath));
	for (i = 0; i < 3; ++i) {
		char key[20];

		SPRINTF_S(key, "Global:freqs_%d", i);
		conf->freqs[i] = iniparser_getint(dict, key, conf->freqs[i]);
	}
	conf->imgbrightness =
		iniparser_getint(dict, "Image:imgbrightness", conf->imgbrightness);
	conf->dis_scrsave =
		iniparser_getboolean(dict, "Global:dis_scrsave", conf->dis_scrsave);
	conf->autosleep =
		iniparser_getint(dict, "Global:autosleep", conf->autosleep);
	conf->load_exif =
		iniparser_getboolean(dict, "Image:load_exif", conf->load_exif);
	conf->launchtype =
		iniparser_getint(dict, "Global:launchtype", conf->launchtype);
	conf->infobar_use_ttf_mode =
		iniparser_getboolean(dict, "Text:infobar_use_ttf_mode",
							 conf->infobar_use_ttf_mode);
	conf->img_no_repeat =
		iniparser_getboolean(dict, "Image:no_repeat", conf->img_no_repeat);

	conf->hide_flash =
		iniparser_getboolean(dict, "Global:hide_flash", conf->hide_flash);
	conf->tabstop = iniparser_getunsigned(dict, "Text:tabstop", conf->tabstop);

	conf->apetagorder =
		iniparser_getboolean(dict, "Music:apetagorder", conf->apetagorder);

	STRCPY_S(conf->language,
			 iniparser_getstring(dict, "UI:language", conf->language));

	get_language();

	conf->filelistwidth =
		iniparser_getint(dict, "UI:filelistwidth", conf->filelistwidth);

	if (conf->filelistwidth < 0 || conf->filelistwidth > 240)
		conf->filelistwidth = 160;

	conf->ttf_load_to_memory =
		iniparser_getboolean(dict, "Text:ttf_load_to_memory",
							 conf->ttf_load_to_memory);

	conf->save_password =
		iniparser_getboolean(dict, "Global:save_password", conf->save_password);

	conf->scrollbar_width =
		iniparser_getint(dict, "Text:scrollbar_width", conf->scrollbar_width);

	conf->hide_last_row =
		iniparser_getboolean(dict, "Text:hide_last_row", conf->hide_last_row);

	conf->infobar_show_timer =
		iniparser_getboolean(dict, "Text:infobar_show_timer",
							 conf->infobar_show_timer);

	conf->englishtruncate =
		iniparser_getboolean(dict, "Text:englishtruncate",
							 conf->englishtruncate);

	conf->image_scroll_chgn_speed =
		iniparser_getboolean(dict, "Image:image_scroll_chgn_speed",
							 conf->image_scroll_chgn_speed);

	conf->ttf_haste_up =
		iniparser_getboolean(dict, "Text:ttf_haste_up", conf->ttf_haste_up);

	conf->linenum_style =
		iniparser_getboolean(dict, "Text:linenum_style", conf->linenum_style);

	conf->infobar_align =
		stringToAlign(iniparser_getstring(dict, "Text:infobar_align", ""));

	STRCPY_S(conf->musicdrv_opts,
			 iniparser_getstring(dict, "Music:musicdrv_opts",
								 conf->musicdrv_opts));

	conf->magnetic_scrolling =
		iniparser_getboolean(dict, "Image:magnetic_scrolling",
							 conf->magnetic_scrolling);

	conf->use_image_queue =
		iniparser_getboolean(dict, "Image:use_image_queue",
							 conf->use_image_queue);

	conf->max_cache_img =
		iniparser_getunsigned(dict, "Image:max_cache_img", conf->max_cache_img);

	conf->show_encoder_msg = 
		iniparser_getboolean(dict, "Music:show_encoder_msg",
							 conf->show_encoder_msg);

	if (conf->max_cache_img == 0) {
		conf->use_image_queue = false;
	}

	dictionary_del(dict);

	return true;
}
Ejemplo n.º 30
0
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame)
{
    FILE *in, *include = NULL, *inifile;

    char line    [ASCIILINESZ+1] ;
    char section [ASCIILINESZ+1] ;
    char key     [ASCIILINESZ+1] ;
    char tmp     [ASCIILINESZ+1] ;
    char val     [ASCIILINESZ+1] ;

    int  last=0 ;
    int  len ;
    int  lineno=0 ;
    int  errs=0;

    dictionary * dict ;

    if ((inifile=fopen(ininame, "r"))==NULL) {
        LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", ininame);
        return NULL ;
    }

    dict = dictionary_new(0) ;
    if (!dict) {
        fclose(inifile);
        return NULL ;
    }

    memset(line,    0, ASCIILINESZ);
    memset(section, 0, ASCIILINESZ);
    memset(key,     0, ASCIILINESZ);
    memset(val,     0, ASCIILINESZ);
    last=0 ;

    in = inifile;
    while (1) {
        if (fgets(line+last, ASCIILINESZ-last, in) == NULL) {
            if (include) {
                fclose(include);
                include = NULL;
                in = inifile;
                continue;
            }
            break;
        }
        lineno++ ;
        len = (int)strlen(line)-1;
        if (len==0)
            continue;
        /* Safety check against buffer overflows */
        if (line[len]!='\n') {
            LOG(log_error, logtype_default, "iniparser: input line too long in \"%s\" (lineno: %d)",
                ininame, lineno);
            dictionary_del(dict);
            fclose(in);
            return NULL ;
        }
        /* Get rid of \n and spaces at end of line */
        while ((len>=0) &&
                ((line[len]=='\n') || (isspace(line[len])))) {
            line[len]=0 ;
            len-- ;
        }
        /* Detect multi-line */
        if (line[len]=='\\') {
            /* Multi-line value */
            last=len ;
            continue ;
        } else {
            last=0 ;
        }
        switch (iniparser_line(line, section, key, val)) {
        case LINE_EMPTY:
        case LINE_COMMENT:
            break ;
        case LINE_SECTION:
            if (strchr(section, ':') != NULL)
                LOG(log_error, logtype_default, "iniparser: syntax error \"%s\" section name must not contain \":\".", section);
            errs = dictionary_set(dict, section, NULL, NULL);
            break ;
        case LINE_VALUE:
            if (strcmp(key, "include") == 0) {
                if ((include = fopen(val, "r")) == NULL) {
                    LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", val);
                    continue;
                }
                in = include;
                continue;
            }
            errs = dictionary_set(dict, section, key, val) ;
            break ;
        case LINE_ERROR:
            LOG(log_error, logtype_default, "iniparser: syntax error in %s (lineno: %d): %s",
                ininame, lineno, line);
            errs++ ;
            break;
        default:
            break ;
        }
        memset(line, 0, ASCIILINESZ);
        last=0;
        if (errs<0) {
            LOG(log_error, logtype_default, "iniparser: memory allocation failure");
            break ;
        }
    }
    if (errs) {
        dictionary_del(dict);
        dict = NULL ;
    }
    fclose(in);
    return dict ;
}