Example #1
0
/*!

\brief Get first child config context stored in the config context.
\param[in] it ConfigIterator used to iterate over the child config contexts.
\param[out] data Config object used to store the first config context.
\return Returns dmz::True if the first child config context is stored in \a data.
Will return dmz::False if the config context contains no children.

*/
dmz::Boolean
dmz::Config::get_first_config (ConfigIterator &it, Config &data) const {

   Boolean result (False);

   if (_state.context) {

      ConfigContext::DataStruct *ds =
         _state.context->configOrderTable.get_first (it.state.it);

      if (ds) {

         if (ds->handle) { data.set_config_context (ds->context); result = True; }
         else { result = get_next_config (it, data); }
      }
   }

   return result;
}
Example #2
0
void test()
{
    bool result;
    const uint8_t* filename = (const uint8_t*)"/home/user/test.conf";
    uint8_t buffer[64];
    config_parser_t cfg;

    for(;;)
    {
        toggle_led(LED2);

        log_info(&log, "remove file %s", filename);

        // delete the file
        unlink((const char*)filename);

        // check the file is not present
        if(open_config_file(&cfg, buffer, sizeof(buffer), filename))
        {
            while(get_next_config(&cfg))
            	log_info(&log, "read %s=%s", get_config_key(&cfg), get_config_value(&cfg));
            close_config_file(&cfg);
        }
        else
            log_info(&log, "file %s removed successfully", filename);

        // add to a new file
        result = add_config_entry(buffer, sizeof(buffer),
        							filename,
									(const uint8_t*)"testkey",
									(const uint8_t*)"testvalue");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey", "testvalue", filename, result);

        result = add_config_entry(buffer, sizeof(buffer),
        							filename,
									(const uint8_t*)"testkey1",
									(const uint8_t*)"testvalue1");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey1", "testvalue1", filename, result);

        // check the file is now present with
        if(open_config_file(&cfg, buffer, sizeof(buffer), filename))
        {
            while(get_next_config(&cfg))
            	log_info(&log, "read %s=%s", get_config_key(&cfg), get_config_value(&cfg));
            close_config_file(&cfg);
        }

        // edit within file
        result = edit_config_entry(buffer, sizeof(buffer),
                                    filename,
                                    (const uint8_t*)"testkey",
                                    (const uint8_t*)"newtestvalue");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey", "testvalue", filename, result);

        result = edit_config_entry(buffer, sizeof(buffer),
                                    filename,
                                    (const uint8_t*)"testkey1",
                                    (const uint8_t*)"newtestvalue1");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey1", "testvalue1", filename, result);

        // check the file is now present with new values
        if(open_config_file(&cfg, buffer, sizeof(buffer), filename))
        {
            while(get_next_config(&cfg))
                log_info(&log, "read %s=%s", get_config_key(&cfg), get_config_value(&cfg));
            close_config_file(&cfg);
        }

        sleep(10);
    }

	pthread_exit(0);
}