예제 #1
0
파일: tracker.c 프로젝트: tarcieri/hotwired
void tracker_init()
{
	int i, v;
	char *t;

	pthread_mutex_lock(&tlock);
	tlist_clear();
	
	for(i = 0; (t = config_vlist_value("trackers", "host_list", i)) != NULL; i++) {
		tlist_add(t);
		xfree(t);
	}

	if(i == 0) 
		goto done;
	
	t = config_value("global", "server_name");

	if(server_name == NULL && t == NULL) {
		log("*** Set global::server_name if you wish to broadcast to trackers");
		log("*** No broadcasting to trackers will be done with the current configuration");
		goto done;
	}

	if(t != NULL) {
		if(server_name != NULL)
			xfree(server_name);

		server_name = t;
		server_name_l = strlen(server_name);
	}

	t = config_value("global", "server_description");

	if(server_desc != NULL) {
		if(t != NULL) { 
			xfree(server_desc); 
			server_desc = NULL;
		}
	} else if(t == NULL)
		t = xstrdup("");

	if(server_name == NULL) {
		server_desc = t;
		server_desc_l = strlen(server_desc);
	}

	if((v = config_int_value("trackers", "update_interval")) < 0) {
		log("*** trackers::update_interval invalid/unspecified");
	} else
		update_interval = v;

	if((server_port = config_int_value("global", "port")) < 0)
		server_port = DEFAULT_HOTLINE_PORT;

	tracker_thread_spawn();
done:
	pthread_mutex_unlock(&tlock);
}
예제 #2
0
파일: config.c 프로젝트: GlenWalker/rrdbot
int
cfg_value(const char* filename, const char* header, const char* name,
          char* value, void* data)
{
    config_ctx* ctx = (config_ctx*)data;

    ASSERT(filename);
    ASSERT(ctx);

    /* A little setup where necessary */
    if(!ctx->confname)
        ctx->confname = filename;

    /* Called like this after each file */
    if(!header)
    {
        config_done(ctx);
        ctx->confname = NULL;
        return 0;
    }

    ASSERT(ctx->confname);
    ASSERT(name && value && header);

    log_debug("config: %s: [%s] %s = %s", ctx->confname, header, name, value);

    config_value(header, name, value, ctx);

    return 0;
}
예제 #3
0
void eeprom_config_init(bool restore_default)
{
	
	uint16_t i;
	uint8_t *config_ptr = config_raw;

	for (i=0;i<CONFIG_RAW_SIZE;i++)
	{
	    if (restore_default)
		{
   		   *config_ptr = config_default(i); // default value
   	    }
		else
		{
   		   *config_ptr =  config_value(i);
    		if ((*config_ptr < config_min(i))	//min
    		 || (*config_ptr > config_max(i)))	//max
			{
    			*config_ptr = config_default(i); // default value
    		}
		}
		eeprom_config_save(i); // update if default value is restored
		config_ptr++;
	}
}
/*
 * This function is called to fill in config values read from the config for non-enabled (yet) backends.
 *
 * If config template provides API for serializing parsed config values to json
 * it fills 'backend::config' section otherwise it uses unparsed values from original config
 * and fills 'backend::config_template'.
 *
 * After backend has been enabled, @fill_backend_backend() is called instead.
 */
static void fill_disabled_backend_config(rapidjson::Value &stat_value,
                                         rapidjson::Document::AllocatorType &allocator,
                                         const dnet_backend_info *config_backend) {
	rapidjson::Value backend_value(rapidjson::kObjectType);

	/* If config template provides API for serializing parsed config values to json - use it */
	if (config_backend->config_template.to_json) {
		char *json_stat = NULL;
		size_t size = 0;

		dnet_config_backend config = config_backend->config_template;
		std::vector<char> data(config.size, '\0');
		config.data = data.data();
		config.log = config_backend->log.get();

		for (auto it = config_backend->options.begin(); it != config_backend->options.end(); ++it) {
			const dnet_backend_config_entry &entry = *it;
			entry.entry->callback(&config, entry.entry->key, entry.value_template.data());
		}

		config.to_json(&config, &json_stat, &size);
		if (json_stat && size) {
			rapidjson::Document config_value(&allocator);
			config_value.Parse<0>(json_stat);
			config_value.AddMember("group", config_backend->group, allocator);
			backend_value.AddMember("config",
			                        static_cast<rapidjson::Value&>(config_value),
			                        allocator);
		}
		free(json_stat);
		config.cleanup(&config);
	} else {
		rapidjson::Value config_value(rapidjson::kObjectType);
		for (auto it = config_backend->options.begin(); it != config_backend->options.end(); ++it) {
			const dnet_backend_config_entry &entry = *it;

			rapidjson::Value tmp_val(entry.value_template.data(), allocator);
			config_value.AddMember(entry.entry->key, tmp_val, allocator);
		}
		config_value.AddMember("group", config_backend->group, allocator);
		backend_value.AddMember("config_template", config_value, allocator);
	}

	stat_value.AddMember("backend", backend_value, allocator);
}
예제 #5
0
void ConfigOptionsGroup::reload_config(){
	for (std::map< std::string, std::pair<std::string, int> >::iterator it = m_opt_map.begin(); it != m_opt_map.end(); ++it) {
		auto opt_id = it->first;
		std::string opt_key = m_opt_map.at(opt_id).first;
		int opt_index = m_opt_map.at(opt_id).second;
		auto option = m_options.at(opt_id).opt;
		set_value(opt_id, config_value(opt_key, opt_index, option.gui_flags.compare("serialized") == 0 ));
	}

}
예제 #6
0
/*!
 *******************************************************************************
 *  Update configuration storage
 *
 *  \note
 ******************************************************************************/
void eeprom_config_save(uint8_t idx) {
	if (idx<CONFIG_RAW_SIZE) {
		if (config_raw[idx] != config_value(idx)) {
			if ((config_raw[idx] < config_min(idx)) //min
		 	|| (config_raw[idx] > config_max(idx))) { //max
				config_raw[idx] = config_default(idx); // default value
			}
			config_write(idx, config_raw[idx]);
		}
	}
}
예제 #7
0
파일: eeprom.c 프로젝트: krmnn/openhr20
/*!
 *******************************************************************************
 *  Update configuration data as stored in EEPROM
 *
 *  \note
 *	@param uint8_t integer - address (offset) within first 256 bytes of EEPROM
 ******************************************************************************/
void eeprom_config_save(uint8_t idx) 
{
	if (idx<CONFIG_RAW_SIZE) 
	{
		if (config_raw[idx] != config_value(idx)) 
		{	// Data in EEPROM different here
			if ((config_raw[idx] < config_min(idx)) //min
			 	|| (config_raw[idx] > config_max(idx))) 
			 { //max
				config_raw[idx] = config_default(idx);	// default value - set if value to be written is out of range
			}
			config_write(idx, config_raw[idx]);
		}
	}
}
/*
 * Fills config with common backend info like config, group id
 */
static void fill_disabled_backend_config(rapidjson::Value &stat_value,
                                         rapidjson::Document::AllocatorType &allocator,
					 const dnet_backend_info &config_backend) {
	rapidjson::Value backend_value(rapidjson::kObjectType);
	rapidjson::Value config_value(rapidjson::kObjectType);

	for (auto it = config_backend.options.begin(); it != config_backend.options.end(); ++it) {
		const dnet_backend_config_entry &entry = *it;

		rapidjson::Value tmp_val(entry.value_template.data(), allocator);
		config_value.AddMember(entry.entry->key, tmp_val, allocator);
	}

	backend_value.AddMember("config", config_value, allocator);
	stat_value.AddMember("backend", backend_value, allocator);
}
예제 #9
0
int main( int argc, char *argv[] )
{
    int		i;

    for (i=1; i<argc; i++)
	{
	    if (read_config(argv[i]) == -1)
		{
		    printf("Error opening \"%s\".\n", argv[i]);
		    return -1;
		}
	}

    printf("%10s == '%s'\n", "sju", config_value("sju") );
    printf("%10s == %i\n", "sju", config_value_int("sju") );
}
void main(){
	config_init();
	config_value();
	uart_init();
	IE2 |= UCA0RXIE;
	__enable_interrupt();
    _BIS_SR(GIE);

	while (1)
	{
		if (Sample_count >=10)
		{
			Rspeed=Rspeed/10;
			uart_put_num(Rspeed,0,0);
			b[9]=10;
			uart_putc(b[9]);
			Sample_count=0;
		}
	}
}
예제 #11
0
void eeprom_config_init(bool restore_default) {
	
	uint16_t i;
	uint8_t *config_ptr = config_raw;
#if (NANODE == 1 || JEENODE == 1)
        // set to allow erase and write in one operation
        EECR |= (EEPM1 | EEPM0);
#endif
	for (i=0;i<CONFIG_RAW_SIZE;i++) {
	    if (restore_default) {
   		   *config_ptr = config_default(i); // default value
   	    } else {
   		   *config_ptr =  config_value(i);
    		if ((*config_ptr < config_min(i)) //min
    		 || (*config_ptr > config_max(i))) { //max
    			*config_ptr = config_default(i); // default value
    		}
        }
		eeprom_config_save(i); // update if default value is restored
		config_ptr++;
	}
}
예제 #12
0
파일: menu.c 프로젝트: robots/openhr20
/*!
 *******************************************************************************
 * \brief menu Controller
 * 
 * \returns true for controler restart  
 ******************************************************************************/
bool menu_controller(bool new_state) {
    int8_t wheel = wheel_proccess(); //signed number
	bool ret = false;
    switch (menu_state) {
    case menu_startup:
        if (new_state) {
            menu_auto_update_timeout=2;
        }
        if (menu_auto_update_timeout==0) {
            menu_state = menu_version;
            ret=true;
        }
        break;
    case menu_version:
        if (new_state) {
            menu_auto_update_timeout=2;
        }
        if (menu_auto_update_timeout==0) {
            #if (DEBUG_SKIP_DATETIME_SETTING_AFTER_RESET) || (REMOTE_SETTING_ONLY)
                menu_state = menu_home;
            #else
                menu_state = menu_set_year;
            #endif
            ret=true;
        }
        break;
#if (! REMOTE_SETTING_ONLY)
    case menu_set_year:
        if (wheel != 0) RTC_SetYear(RTC_GetYearYY()+wheel);
        if ( kb_events & KB_EVENT_PROG) {
            menu_state = menu_set_month;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_month:
        if (wheel != 0) RTC_SetMonth(RTC_GetMonth()+wheel);
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_set_day;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_day:
        if (wheel != 0) RTC_SetDay(RTC_GetDay()+wheel);
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_set_hour;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_hour:
        if (wheel != 0) RTC_SetHour(RTC_GetHour()+wheel);
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_set_minute;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_minute:
        if (wheel != 0) {
            RTC_SetMinute(RTC_GetMinute()+wheel);
            RTC_SetSecond(0);
        }
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_home;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
#endif
    case menu_home_no_alter: // same as home screen, but without alternate contend
    case menu_home:         // home screen
    case menu_home2:        // alternate version, real temperature
    case menu_home3:        // alternate version, valve pos
    case menu_home4:        // alternate version, time    
#if MENU_SHOW_BATTERY
    case menu_home5:        // alternate version, battery    
#endif
        if ( kb_events & KB_EVENT_C ) {
            menu_state++;       // go to next alternate home screen
#if MENU_SHOW_BATTERY
            if (menu_state > menu_home5) menu_state=menu_home;
#else
            if (menu_state > menu_home4) menu_state=menu_home;
#endif
            ret=true; 
        } else {
            if (menu_locked) {
                if ( kb_events & (
                        KB_EVENT_WHEEL_PLUS  | KB_EVENT_WHEEL_MINUS | KB_EVENT_PROG
                        | KB_EVENT_AUTO | KB_EVENT_PROG_REWOKE | KB_EVENT_C_REWOKE | KB_EVENT_AUTO_REWOKE
                        | KB_EVENT_PROG_LONG | KB_EVENT_C_LONG | KB_EVENT_AUTO_LONG )) {
                    menu_auto_update_timeout=LONG_PRESS_THLD+1;
                    menu_state=menu_lock;
                    ret=true;
                    }
            } else { // not locked
                if ((menu_state == menu_home) || (menu_state == menu_home_no_alter)) {
                    if (wheel != 0) {
                        CTL_temp_change_inc(wheel);
                        menu_state = menu_home_no_alter;
						ret=true; 
                    } 			 
                    if ( kb_events & KB_EVENT_AUTO ) {
                        CTL_change_mode(CTL_CHANGE_MODE); // change mode
                        menu_state=menu_home_no_alter;
						ret=true; 
                    } else if ( kb_events & KB_EVENT_AUTO_REWOKE ) {
                        CTL_change_mode(CTL_CHANGE_MODE_REWOKE); // change mode
                        menu_state=menu_home_no_alter;
						ret=true; 
                    }
                } else {
                    if ( kb_events & (
                        KB_EVENT_WHEEL_PLUS  | KB_EVENT_WHEEL_MINUS | KB_EVENT_PROG
                        | KB_EVENT_AUTO | KB_EVENT_PROG_REWOKE | KB_EVENT_C_REWOKE | KB_EVENT_AUTO_REWOKE
                        | KB_EVENT_PROG_LONG | KB_EVENT_C_LONG | KB_EVENT_AUTO_LONG )) {
                            menu_state = menu_home;
							ret = true;
                    }
                }
                // TODO ....  
            }
        } 
        break;
#if (! REMOTE_SETTING_ONLY)
    case menu_set_timmer_dow_start:
        if (new_state) menu_set_dow=((config.timer_mode==1)?RTC_GetDayOfWeek():0);
        menu_state = menu_set_timmer_dow;
        // do not use break here
    case menu_set_timmer_dow:
        if (wheel != 0) menu_set_dow=(menu_set_dow+wheel+8)%8;
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state=menu_set_timmer;
            menu_set_slot=0;
            config.timer_mode = (menu_set_dow>0);
            eeprom_config_save((uint16_t)(&config.timer_mode)-(uint16_t)(&config)); // save value to eeprom
                // update hourbar
            menu_update_hourbar((config.timer_mode==1)?RTC_GetDayOfWeek():0);
            ret=true; 
        } else if ( kb_events & KB_EVENT_AUTO ) { // exit without save
            menu_state=menu_home;
            ret=true; 
        }
        break;        
    case menu_set_timmer:
        if (new_state) {
            menu_set_time= RTC_DowTimerGet(menu_set_dow, menu_set_slot, &menu_set_mode);
            if (menu_set_time>24*60) menu_set_time=24*60;
        }
        if (wheel != 0) {
            menu_set_time=((menu_set_time/10+(24*6+1)+wheel)%(24*6+1))*10;
        }
        if ( kb_events & KB_EVENT_C ) {
            menu_set_mode=(menu_set_mode+5)%4;
        } else if ( kb_events & KB_EVENT_PROG ) {
            RTC_DowTimerSet(menu_set_dow, menu_set_slot, menu_set_time, menu_set_mode);
            if (++menu_set_slot>=RTC_TIMERS_PER_DOW) {
                if (menu_set_dow!=0) menu_set_dow=menu_set_dow%7+1; 
                menu_state=menu_set_timmer_dow;
            }
            CTL_update_temp_auto();
            menu_update_hourbar((config.timer_mode==1)?RTC_GetDayOfWeek():0);
            ret=true; 
        } else if ( kb_events & KB_EVENT_AUTO ) { // exit without save
            menu_state=menu_home;
            ret=true; 
        }
        break;
#endif
#if (! REMOTE_SETTING_ONLY)
    case menu_preset_temp0:
    case menu_preset_temp1:
    case menu_preset_temp2:
    case menu_preset_temp3:
        if (new_state) menu_set_temp=temperature_table[menu_state-menu_preset_temp0];
        if (wheel != 0) {
            menu_set_temp+=wheel;
            if (menu_set_temp > TEMP_MAX+1) menu_set_temp = TEMP_MAX+1;
            if (menu_set_temp < TEMP_MIN-1) menu_set_temp = TEMP_MIN-1;
        }
        if ( kb_events & KB_EVENT_PROG ) {
            temperature_table[menu_state-menu_preset_temp0]=menu_set_temp;
            eeprom_config_save(menu_state+((temperature_table-config_raw)-menu_preset_temp0));
            menu_state++; // menu_preset_temp3+1 == menu_home
            CTL_update_temp_auto();
            ret=true; 
        } else if ( kb_events & KB_EVENT_AUTO ) { // exit without save
            menu_state=menu_home;
            ret=true; 
        }
        break;
#endif
    default:
    case menu_lock:        // "bloc" message
        if (menu_auto_update_timeout==0) { menu_state=menu_home; ret=true; } 
        break;        
    case menu_service1:     // service menu        
    case menu_service2:        
        if (kb_events & KB_EVENT_AUTO) { 
            menu_state=menu_home; 
            ret=true;
        } else if (kb_events & KB_EVENT_C) { 
            menu_state=menu_service_watch; 
            ret=true;
        } else if (kb_events & KB_EVENT_PROG) {
            if (menu_state == menu_service2) {
                eeprom_config_save(service_idx); // save current value
                menu_state = menu_service1;
            } else {
                menu_state = menu_service2;
            }
        } else {
            if (menu_state == menu_service1) {
                // change index
                service_idx = (service_idx+wheel+CONFIG_RAW_SIZE)%CONFIG_RAW_SIZE;
            } else {
                // change value in RAM, to save press PROG
                int16_t min = (int16_t)config_min(service_idx);
                int16_t max_min_1 = (int16_t)(config_max(service_idx))-min+1;
                config_raw[service_idx] = (uint8_t) (
                        ((int16_t)(config_raw[service_idx])+(int16_t)wheel-min+max_min_1)%max_min_1+min);
                if (service_idx==0) LCD_Init();
            }
        }
        break;        
    case menu_service_watch:
        if (kb_events & KB_EVENT_AUTO) { 
            menu_state=menu_home; 
            ret=true;
        } else if (kb_events & KB_EVENT_C) { 
            menu_state=menu_service1; 
            ret=true;
        } else {
            service_watch_n=(service_watch_n+wheel+WATCH_N)%WATCH_N;
            if (wheel != 0) ret=true;
        }
        break;
    }
    if (events_common()) ret=true;
    if (ret && (service_idx<CONFIG_RAW_SIZE)) {
        // back config to default value
        config_raw[service_idx] = config_value(service_idx);
        service_idx = CONFIG_RAW_SIZE;
    }
    kb_events = 0; // clear unused keys
    return ret;
} 
예제 #13
0
파일: pdb_pgsql.c 프로젝트: hajuuk/R7000
static NTSTATUS pgsqlsam_init ( struct pdb_context *pdb_context, struct pdb_methods **pdb_method, const char *location )
{
  NTSTATUS nt_status ;
  struct pdb_pgsql_data *data ;
  
  if ( !pdb_context )
  {
    DEBUG( 0, ("invalid pdb_methods specified\n") ) ;
    return NT_STATUS_UNSUCCESSFUL;
  }
  
  if (!NT_STATUS_IS_OK
    (nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) {
    return nt_status;
  }
  
  (*pdb_method)->name               = "pgsqlsam" ;
  
  (*pdb_method)->setsampwent        = pgsqlsam_setsampwent ;
  (*pdb_method)->endsampwent        = pgsqlsam_endsampwent ;
  (*pdb_method)->getsampwent        = pgsqlsam_getsampwent ;
  (*pdb_method)->getsampwnam        = pgsqlsam_getsampwnam ;
  (*pdb_method)->getsampwsid        = pgsqlsam_getsampwsid ;
  (*pdb_method)->add_sam_account    = pgsqlsam_add_sam_account ;
  (*pdb_method)->update_sam_account = pgsqlsam_update_sam_account ;
  (*pdb_method)->delete_sam_account = pgsqlsam_delete_sam_account ;
  
  data = talloc( pdb_context->mem_ctx, sizeof( struct pdb_pgsql_data ) ) ;
  (*pdb_method)->private_data = data ;
  data->handle = NULL ;
  data->pwent  = NULL ;

  if ( !location )
  {
    DEBUG( 0, ("No identifier specified. Check the Samba HOWTO Collection for details\n") ) ;
    return NT_STATUS_INVALID_PARAMETER;
  }
  
  data->location = smb_xstrdup( location ) ;

  if(!sql_account_config_valid(data->location)) {
	  return NT_STATUS_INVALID_PARAMETER;
  }
  
  DEBUG
  (
    1, 
    (
      "Connecting to database server, host: %s, user: %s, password: XXXXXX, database: %s, port: %s\n",
      config_value( data, "pgsql host"    , CONFIG_HOST_DEFAULT ),
      config_value( data, "pgsql user"    , CONFIG_USER_DEFAULT ),
      config_value( data, "pgsql database", CONFIG_DB_DEFAULT   ),
      config_value( data, "pgsql port"    , CONFIG_PORT_DEFAULT )
    )
  ) ;
  
  /* Do the pgsql initialization */
  data->handle = PQsetdbLogin( 
                                config_value( data, "pgsql host"    , CONFIG_HOST_DEFAULT ),
                                config_value( data, "pgsql port"    , CONFIG_PORT_DEFAULT ),
                                NULL,
                                NULL,
                                config_value( data, "pgsql database", CONFIG_DB_DEFAULT   ),
                                config_value( data, "pgsql user"    , CONFIG_USER_DEFAULT ),
                                config_value( data, "pgsql password", CONFIG_PASS_DEFAULT )
                             ) ;
  
  if ( PQstatus( data->handle ) != CONNECTION_OK )
  {
    DEBUG( 0, ("Failed to connect to pgsql database: error: %s\n", PQerrorMessage( data->handle )) ) ;
    return NT_STATUS_UNSUCCESSFUL;
  }
  
  DEBUG( 5, ("Connected to pgsql database\n") ) ;
  return NT_STATUS_OK;
}