コード例 #1
0
ファイル: iniparser.c プロジェクト: kionias/iniparser
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, const char * entry)
{
    char* lc_entry = xstrdup(entry);
    strlwc(lc_entry);
    dictionary_unset(ini, lc_entry);
    free(lc_entry);
}
コード例 #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);
}
コード例 #3
0
ファイル: dictionary.c プロジェクト: freeeyes/PSS
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 ;
}
コード例 #4
0
ファイル: dictionary.c プロジェクト: PlanetAPL/nars2000
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
コード例 #5
0
ファイル: iniparser.c プロジェクト: eledot/libnge2
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, char * entry)
{
    dictionary_unset(ini, strlwc(entry));
}
コード例 #6
0
ファイル: iniparser.c プロジェクト: ansi88/iniparser
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, const char * entry)
{
    char tmp_str[ASCIILINESZ+1];
    dictionary_unset(ini, strlwc(entry, tmp_str, sizeof(tmp_str)));
}
コード例 #7
0
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, char *section, char * key)
{
    dictionary_unset(ini, section, key);
}
コード例 #8
0
// quit fuid:0000001 
//int quit_cmd(int sockfd, char *pbuf, size_t pbuf_size)
int quit_cmd(struct clients *client_t, char *pbuf, size_t pbuf_size)
{
	int sockfd = client_t->fd;
	log_debug("pbuf:%s", pbuf);
	
	// pbuf[uid:0000001]
	char fuid[MAX_LINE] = {0};
	
	char tok[MAX_LINE] = {0};
	char *ptok = tok;
	
	int n = pbuf_size;
	while ((*pbuf != '\0') && (n > 0)) {
		char *psed = (char *)memchr(pbuf, ' ', strlen(pbuf));
		if (psed != NULL) {
			int m = (psed - pbuf);
			memcpy(ptok, pbuf, m);
			pbuf += (m + 1);
			n -= (m + 1);

		} else {
			ptok = pbuf;
			n -= strlen(pbuf);
		}
		
		log_debug("ptok:[%s]", ptok);
		if (strncasecmp(ptok, "fuid:", 5) == 0) {
			snprintf(fuid, sizeof(fuid), "%s", ptok+5);
		}

		memset(ptok, 0, strlen(ptok));
	}
	log_debug("get sockfd[%d] fuid[%s]", sockfd, fuid);
	
	// 设置离线
	// 查询fd
	int i = get_idx_with_sockfd(sockfd);
	if (i == -1) {
		log_error("get index failed: i[%d] = get_idx_with_sockfd(%d)", i, sockfd);
		return 1;
	}
	if (strcasecmp(client_st[i].uid, fuid) != 0) {
		log_error("logic error client_st[%d].uid=%s != fuid=%s", i, client_st[i].uid, fuid);
		return 1;
	}

	//client_st[i].used = 0;
	//client_st[i].fd = 0;
	//memset(client_st[i].uid, '0', strlen(client_st[i].uid));
	//memset(client_st[i].ios_token, '0', strlen(client_st[i].ios_token));
	
	// 注册为离线	(uid => ios_token)
	dictionary_unset(online_d, fuid);
	log_error("offline fuid[%s] sockfd[%d]", fuid, sockfd);

	// 关闭客户端fd
	close(sockfd);	

	// 回收与初始化当前item
	init_clientst_item_with_idx(i);
	
	
	return 0;
}
コード例 #9
0
ファイル: iniparser.c プロジェクト: kyosold/Carrots
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, char * entry)
{
	char l[ASCIILINESZ+1];
    dictionary_unset(ini, strlwc(l, entry));
}
コード例 #10
0
ファイル: iniparser.c プロジェクト: janl/couchdb-mac-app
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, char * entry)
{
    dictionary_unset(ini, entry);
}
コード例 #11
0
ファイル: startup.c プロジェクト: DomChey/ptpd
/**
 * 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->ip_mode != 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)
        goto end;

    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);
        goto end;
    }
    dictionary_merge(rtOpts->cliConfig, tmpConfig, 1, "from command line");
    /* Load default config to fill in the blanks in the config file */
    RunTimeOpts tmpOpts;
    loadDefaultSettings(&tmpOpts);

    /* Check the new configuration for errors, fill in the blanks from defaults */
    if( ( rtOpts->candidateConfig = parseConfig(tmpConfig,&tmpOpts)) == NULL ) {
        WARNING("Configuration file has errors, reload aborted\n");
        dictionary_del(tmpConfig);
        goto end;
    }

    /* Check for changes between old and new configuration */
    if(compareConfig(rtOpts->candidateConfig,rtOpts->currentConfig)) {
        INFO("Configuration unchanged\n");
        goto cleanup;
    }

    /*
     * Mark which subsystems have to be restarted. Most of this will be picked up by doState()
     * If there are errors past config correctness (such as non-existent NIC,
     * or lock file clashes if automatic lock files used - abort the mission
     */

    rtOpts->restartSubsystems =
        checkSubsystemRestart(rtOpts->candidateConfig, rtOpts->currentConfig);

    /* If we're told to re-check lock files, do it: tmpOpts already has what rtOpts should */
    if( (rtOpts->restartSubsystems & PTPD_CHECK_LOCKS) &&
            tmpOpts.autoLockFile && !checkOtherLocks(&tmpOpts)) {
        rtOpts->restartSubsystems = -1;
    }

    /* If the network configuration has changed, check if the interface is OK */
    if(rtOpts->restartSubsystems & PTPD_RESTART_NETWORK) {
        INFO("Network configuration changed - checking interface\n");
        if(!testInterface(tmpOpts.ifaceName, &tmpOpts)) {
            rtOpts->restartSubsystems = -1;
            ERROR("Error: Cannot use %s interface\n",tmpOpts.ifaceName);
        }

    }


#if defined(linux) && defined(HAVE_SCHED_H)
    /* Changing the CPU affinity mask */
    if(rtOpts->restartSubsystems & PTPD_CHANGE_CPUAFFINITY) {
        NOTIFY("Applying CPU binding configuration: changing selected CPU core\n");
        cpu_set_t mask;
        CPU_ZERO(&mask);
        if(tmpOpts.cpuNumber > -1) {
            CPU_SET(tmpOpts.cpuNumber,&mask);
        } else {
            int i;
            for(i = 0;  i < CPU_SETSIZE; i++) {
                CPU_SET(i, &mask);
            }
        }
        if(sched_setaffinity(0, sizeof(mask), &mask) < 0) {
            if(tmpOpts.cpuNumber == -1) {
                PERROR("Could not unbind from CPU core %d", rtOpts->cpuNumber);
            } else {
                PERROR("Could bind to CPU core %d", tmpOpts.cpuNumber);
            }
            rtOpts->restartSubsystems = -1;
        } else {
            if(tmpOpts.cpuNumber > -1)
                INFO("Successfully bound "PTPD_PROGNAME" to CPU core %d\n", tmpOpts.cpuNumber);
            else
                INFO("Successfully unbound "PTPD_PROGNAME" from cpu core CPU core %d\n", rtOpts->cpuNumber);
        }
    }
#endif /* linux && HAVE_SCHED_H */

#ifdef HAVE_SYS_CPUSET_H
    /* Changing the CPU affinity mask */
    if (rtOpts->restartSubsystems & PTPD_CHANGE_CPUAFFINITY) {
        NOTIFY("Applying CPU binding configuration:"
               "changing selected CPU core\n");
        cpuset_t mask;
        CPU_ZERO(&mask);
        if (tmpOpts.cpuNumber < 0) {
            if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_CPUSET, 1,
                                   sizeof(mask), &mask) < 0)
                PERROR("Could not get affinity.");
            if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
                                   -1, sizeof(mask), &mask) < 0)
                PERROR("Could not unbind from CPU core %d",
                       rtOpts->cpuNumber);
            else
                INFO("Successfully unbound "
                     PTPD_PROGNAME" from cpu core CPU core %d\n",
                     rtOpts->cpuNumber);
        } else {
            CPU_SET(tmpOpts.cpuNumber,&mask);
            if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
                                   -1, sizeof(mask), &mask) < 0)  {
                PERROR("Could not bind to CPU core %d",
                       tmpOpts.cpuNumber);
                rtOpts->restartSubsystems = -1;
            } else {
                INFO("Successfully bound "
                     PTPD_PROGNAME" to CPU core %d\n",
                     tmpOpts.cpuNumber);
            }
        }
    }
#endif

    if(rtOpts->restartSubsystems == -1) {
        ERROR("New configuration cannot be applied - aborting reload\n");
        rtOpts->restartSubsystems = 0;
        goto cleanup;
    }


    /* Tell parseConfig to shut up - it's had its chance already */
    dictionary_set(rtOpts->candidateConfig,"%quiet%:%quiet%","Y");

    /**
     * Commit changes to rtOpts and currentConfig
     * (this should never fail as the config has already been checked if we're here)
     * However if this DOES fail, some default has been specified out of range -
     * this is the only situation where parse will succeed but commit not:
     * disable quiet mode to show what went wrong, then die.
     */
    if (rtOpts->currentConfig) {
        dictionary_del(rtOpts->currentConfig);
    }
    if ( (rtOpts->currentConfig = parseConfig(rtOpts->candidateConfig,rtOpts)) == NULL) {
        CRITICAL("************ "PTPD_PROGNAME": parseConfig returned NULL during config commit"
                 "  - this is a BUG - report the following: \n");

        dictionary_unset(rtOpts->candidateConfig,"%quiet%:%quiet%");

        if ((rtOpts->currentConfig = parseConfig(rtOpts->candidateConfig,rtOpts)) == NULL)
            CRITICAL("*****************" PTPD_PROGNAME" shutting down **********************\n");
        /*
         * Could be assert(), but this should be done any time this happens regardless of
         * compile options. Anyhow, if we're here, the daemon will no doubt segfault soon anyway
         */
        abort();
    }

    /* clean up */
cleanup:

    dictionary_del(tmpConfig);
    dictionary_del(rtOpts->candidateConfig);

end:

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

    restartLogging(rtOpts);

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


}