Пример #1
0
G_MODULE_EXPORT gboolean algorithm_combo_callback(GtkComboBox *combo_box, gtk_widgets_t *data)
{
	int cipher = gtk_combo_box_get_active((GtkComboBox *)data->crypto_combo);
	int hash = gtk_combo_box_get_active((GtkComboBox *)data->hash_combo);
	int mode = gtk_combo_box_get_active((GtkComboBox *)data->mode_combo);

	gboolean en = _files;

	if (cipher && hash && mode)
	{
		const char **ciphers = list_of_ciphers();
		const char **hashes = list_of_hashes();
		const char **modes = list_of_modes();

		if (cipher > 0)
			update_config(CONF_CIPHER, ciphers[cipher - 1]);
		if (hash > 0)
			update_config(CONF_HASH, hashes[hash - 1]);
		if (mode > 0)
			update_config(CONF_MODE, modes[mode - 1]);

	}
	else
		en = FALSE;

	gtk_widget_set_sensitive(data->password_entry, en);
	gtk_widget_set_sensitive(data->key_button, en);

	return (void)combo_box, TRUE;
}
Пример #2
0
G_MODULE_EXPORT gboolean on_follow_toggle(GtkWidget *widget, gtk_widgets_t *data)
{
	_follow = gtk_check_menu_item_get_active((GtkCheckMenuItem *)widget);
	update_config(CONF_FOLLOW, _follow ? CONF_TRUE : CONF_FALSE);

	return (void)data, TRUE;
}
Пример #3
0
G_MODULE_EXPORT gboolean on_compress_toggle(GtkWidget *widget, gtk_widgets_t *data)
{
	_compress = gtk_check_menu_item_get_active((GtkCheckMenuItem *)widget);
	update_config(CONF_COMPRESS, _compress ? CONF_TRUE : CONF_FALSE);

	return (void)data, TRUE;
}
Пример #4
0
G_MODULE_EXPORT gboolean on_compatibility_change(GtkWidget *widget, gtk_widgets_t *data)
{
	_version = parse_version(gtk_menu_item_get_label((GtkMenuItem *)widget));
	const char *v = get_version_string(_version);
	update_config(CONF_VERSION, v);

	return (void)data, TRUE;
}
Пример #5
0
G_MODULE_EXPORT gboolean on_raw_toggle(GtkWidget *widget, gtk_widgets_t *data)
{
	_raw = gtk_check_menu_item_get_active((GtkCheckMenuItem *)widget);
	update_config(CONF_SKIP_HEADER, _raw ? CONF_TRUE : CONF_FALSE);

	set_raw_buttons(data, _raw);

	return (void)data, TRUE;
}
Пример #6
0
 void CapacitiveSensor::receive_data(ConnectionPtr the_device, const std::vector<uint8_t> &the_data)
 {
     if(m_impl->m_dirty_params && is_initialized())
     {
         if(!update_config()){ LOG_WARNING << "could not update config"; }
         m_impl->m_dirty_params = false;
     }
     
     // init with unchanged status
     uint16_t current_touches = m_impl->m_touch_status;
     
     for(uint8_t byte : the_data)
     {
         switch(byte)
         {
             case SERIAL_END_CODE:
             {
                 auto tmp = split(string(m_impl->m_sensor_accumulator.begin(),
                                         m_impl->m_sensor_accumulator.end()));
                 std::vector<std::string> tokens(tmp.begin(), tmp.end());
                 m_impl->m_sensor_accumulator.clear();
                 
                 if(!tokens.empty())
                 {
                     current_touches = string_to<uint16_t>(tokens.front());
                     
                     for(uint32_t j = 1; j < tokens.size(); ++j)
                     {
                         m_impl->m_proximity_values[j - 1] = string_to<float>(tokens[j]);
                     }
                 }
                 break;
             }
             default:
                 m_impl->m_sensor_accumulator.push_back(byte);
                 break;
         }
     }
     
     auto old_state = m_impl->m_touch_status;
     m_impl->m_touch_status = current_touches;
     
     for (int i = 0; i < NUM_SENSOR_PADS; i++)
     {
         uint16_t mask = 1 << i;
         
         // pad is currently being touched
         if(mask & current_touches && !(mask & old_state))
         {
             if(m_impl->m_touch_callback){ m_impl->m_touch_callback(i); }
         }
         else if(mask & old_state && !(mask & current_touches))
         {
             if(m_impl->m_release_callback){ m_impl->m_release_callback(i); }
         }
     }
 }
Пример #7
0
static void sys_cfg_set_agent()
{
    CLEAR_SCREEN;
    const uint32 input_length = 190;
    input_dst* agent_input, *agent_port_input;
    agent_input = input_init(FREE_MOD);
    agent_port_input = input_init(FREE_MOD);

    input_props_set(agent_input, input_one_property);
    input_property_set(agent_input, INPUT_HIND, "前置IP");
    input_property_set(agent_input, INPUT_MAX_LEN, 15);
    input_property_set(agent_input, INPUT_RET_STA, 176, INPUT_Y_COOR);
    input_property_set(agent_input, INPUT_RET_SIZ, INPUT_HEIGHT, input_length);

    input_props_set(agent_port_input, input_two_property);
    input_property_set(agent_port_input, INPUT_HIND, "前置端口");
    input_property_set(agent_port_input, INPUT_MAX_LEN, 5);
    input_dis(MAIN_DISP, agent_input);
    input_dis(MAIN_DISP, agent_port_input);

    printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入前置地址", 1);

    lcd_160_upd();

    input_key_manege(MAIN_DISP, agent_input , lcd_160_upd);
    input_key_manege(MAIN_DISP, agent_port_input , lcd_160_upd);

    char agent_ip[24] = {0};

    input_str_get(agent_input, agent_ip);
    uint32 agent_port = input_val_get(agent_port_input) / 100;

    input_destory(agent_input);
    input_destory(agent_port_input);

    if (check_ip_valid(agent_ip)
            || agent_port < 80 || agent_port > 65535)
    {
        LOG((LOG_DEBUG, "前置机IP: %s:%d", agent_ip, agent_port));
        disp_msg("地址格式错误", 10);
        return;
    }

    if (update_config("svc.remotename", agent_ip)
            || update_config_int("svc.remoteport", agent_port))
    {
        disp_msg("更新前置信息失败", 10);
        return;
    }
    SAFE_STR_CPY(p16pos.remote[REMOTE_WIRE].u.host.host_name, agent_ip);
    p16pos.remote[REMOTE_WIRE].u.host.host_port = agent_port;
    setup_svc_url();

    disp_msg("修改前置信息成功", 5);
}
Пример #8
0
/**
 * Save a settings section to configuration file
 */
static int Configuration_SaveSection(const char *pFilename, const struct Config_Tag configs[], const char *pSection)
{
	int ret;

	ret = update_config(pFilename, configs, pSection);

	if (ret < 0)
		fprintf(stderr, "Error while updating section %s in %s\n", pSection, pFilename);

	return ret;
}
Пример #9
0
static void sys_cfg_set_admin()
{
    CLEAR_SCREEN;
    input_dst* pswd1, *pswd2;
    pswd1 = input_init(PASSWORD_MOD);
    pswd2 = input_init(PASSWORD_MOD);

    input_props_set(pswd1, input_one_property);
    input_property_set(pswd1, INPUT_HIND, "密码");
    input_property_set(pswd1, INPUT_MAX_LEN, 8);
    input_props_set(pswd2, input_two_property);
    input_property_set(pswd2, INPUT_HIND, "确认");
    input_property_set(pswd2, INPUT_MAX_LEN, 8);

    input_dis(MAIN_DISP, pswd1);
    input_dis(MAIN_DISP, pswd2);

    lcd_160_upd();

    int ret;
    ret = input_key_manege(MAIN_DISP, pswd1 , lcd_160_upd);
    if (ret < 0)
        goto L_END;

    ret = input_key_manege(MAIN_DISP, pswd2 , lcd_160_upd);
    if (ret < 0)
        goto L_END;

    char pswd1_str[9] = {0};
    char pswd2_str[9] = {0};
    input_str_get(pswd1, pswd1_str);
    input_str_get(pswd2, pswd2_str);


    if (strcmp(pswd1_str, pswd2_str) != 0)
    {
        disp_msg("输入密码不符", 10);
    }
    else if (strlen(pswd1_str) < 6 || strlen(pswd1_str) > 8)
    {
        disp_msg("密码长度不符", 10);
    }
    else if (update_config("sys.password", pswd1_str))
    {
        disp_msg("修改参数失败", 10);
    }
    else
    {
        disp_msg("修改密码成功", 5);
    }
L_END:
    input_destory(pswd1);
    input_destory(pswd2);
}
Пример #10
0
static void
response (GtkWidget *widget, gint id, gpointer data)
{
	if (id == GTK_RESPONSE_OK)
	{
		update_config();
		config_save(config);
		minbar_apply_config();
	}

	gtk_widget_destroy(widget);
}
Пример #11
0
G_MODULE_EXPORT gboolean on_key_source_change(GtkWidget *widget, gtk_widgets_t *data)
{
	if (widget == data->key_file_menu_item)
		_key_source = KEY_SOURCE_FILE;
	else if (widget == data->key_password_menu_item)
		_key_source = KEY_SOURCE_PASSWORD;
	update_config(CONF_KEY, KEY_SOURCE[_key_source]);

	gtk_widget_hide(_key_source == KEY_SOURCE_PASSWORD ? data->key_button : data->password_entry);
	gtk_widget_show(_key_source == KEY_SOURCE_PASSWORD ? data->password_entry : data->key_button);

	return (void)data, TRUE;
}
Пример #12
0
static int clk_rcg2_set_parent(struct clk_hw *hw, u8 index)
{
	struct clk_rcg2 *rcg = to_clk_rcg2(hw);
	int ret;

	ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
				 CFG_SRC_SEL_MASK,
				 rcg->parent_map[index] << CFG_SRC_SEL_SHIFT);
	if (ret)
		return ret;

	return update_config(rcg);
}
Пример #13
0
void btd_config_populate(struct btd_config *config, int argc, char **argv)
{
	FILE *fp;
	char *key, *line = NULL;
	size_t len, sep;

	config->configpath = NULL;

	config->socket = NULL;

	config->filefmt = safe_strdup(".pdf");
	config->check_fields = true;
	config->multithread = true;
	config->pidfile = safe_strdup("");

	argp_parse(&argp, argc, argv, 0, 0, config);
	btd_log(2, "Arguments parsed. Loglevel set to %d\n",
		get_btd_log_level());

	if (config->configpath == NULL)
		config->configpath = btd_get_config_path();

	config->datadir = btd_get_data_path();
	key = safe_strcat(2, config->datadir, "/btd.socket");
	printf("config.socket: %p\n", (void *)config->socket);
	config->socket = btd_get_addrinfo(key);
	printf("config.socket: %p\n", (void *)config->socket);
	free(key);

	btd_log(2, "Opening config at '%s'\n", config->configpath);
	fp = safe_fopen(config->configpath, "r");

	while (getline(&line, &len, fp) != -1) {
		sep = strcspn(line, "=");
		key = strndup(line, sep);
		if (key == NULL){
			die("strndup() failed\n");
		}
		update_config(config, key, line+sep+1);
		free(line);
		free(key);
		line = NULL;
	}
	free(line);
	btd_log(2, "Done parsing\n");
	config->db = safe_strcat(2, config->datadir, "/db.sqlite");
	config->filesdir = safe_strcat(2, config->datadir, "/files/");

	safe_fclose(fp);
}
Пример #14
0
void App::save_config(){
    log("Zapisywanie ustawieñ...");
    //wczytanie starego pliku
    vector<string> *lines = get_all_lines("config.txt");
    if(lines==NULL){ //jeœli nie by³o pliku
        lines = new vector<string>;
    }
    //aktualizacja danych
    update_config(lines, "instrument=", config->midi_instrument);
    update_config(lines, "volume=", config->midi_volume);
    update_config(lines, "basetone=", config->midi_basetone);
    update_config(lines, "pause=", config->midi_pause);
    update_config(lines, "interval_type=", config->ustawienia_type);
    //ci¹g w³¹czonych interwa³ów
    string interwaly = "";
    for(int i=0; i<12; i++){
        if(config->ustawienia_interwaly[i]){
            interwaly += "1";
        }else{
            interwaly += "0";
        }
    }
    update_config(lines, "interwaly=", interwaly);
    //ci¹g w³¹czonych oktaw
    string oktawy = "";
    for(int i=0; i<7; i++){
        if(config->ustawienia_oktawy[i]){
            oktawy += "1";
        }else{
            oktawy += "0";
        }
    }
    update_config(lines, "oktawy=", oktawy);
    //zapisanie do pliku
    fstream plik;
    plik.open("config.txt",fstream::out|fstream::trunc|fstream::binary);
    if(!plik.good()){
        plik.close();
        return;
    }
    for(unsigned int i=0; i<lines->size(); i++){
        if(i<lines->size()-1 || lines->at(i).length()>0){
            plik<<lines->at(i)<<endl;
        }
    }
    plik.close();
    lines->clear();
    delete lines;
}
Пример #15
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(mqtt_demo_process, ev, data)
{

  PROCESS_BEGIN();

  printf("MQTT Demo Process\n");

  if(init_config() != 1) {
    PROCESS_EXIT();
  }

  update_config();

  def_rt_rssi = 0x8000000;
  uip_icmp6_echo_reply_callback_add(&echo_reply_notification,
                                    echo_reply_handler);
  etimer_set(&echo_request_timer, conf.def_rt_ping_interval);

	PUBLISH_TRIGGER->configure(SENSORS_ACTIVE, 1);

  /* Main loop */
  while(1) {

    PROCESS_YIELD();

    if(ev == sensors_event && data == PUBLISH_TRIGGER) {
      if(state == STATE_ERROR) {
        connect_attempt = 1;
        state = STATE_REGISTERED;
      }
    }

    if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) ||
       ev == PROCESS_EVENT_POLL ||
       (ev == sensors_event && data == PUBLISH_TRIGGER && PUBLISH_TRIGGER->value(BUTTON_SENSOR_VALUE_STATE) == 0)) {
      state_machine();
    }

    if(ev == PROCESS_EVENT_TIMER && data == &echo_request_timer) {
      ping_parent();
      etimer_set(&echo_request_timer, conf.def_rt_ping_interval);
    }
  }

  PROCESS_END();
}
Пример #16
0
static httpd_cgi_call_t *
webserver_config_set(struct httpd_state *s)
{
  uint8_t reboot_needed = 0;
  webserver_result_title = "Configuration";
  if(!s->query || update_config(s->query, &reboot_needed)) {
    if(!reboot_needed) {
      webserver_result_text = "Configuration updated";
    } else {
      cetic_6lbr_restart_type = CETIC_6LBR_RESTART;
      webserver_result_text = "Configuration updated, restarting BR...";
      webserver_result_refresh = 15;
      process_post(&cetic_6lbr_process, cetic_6lbr_restart_event, NULL);
    }
  } else {
    webserver_result_text = "Configuration invalid";
  }
  return &webserver_result_page;
}
Пример #17
0
int
update_hook(int action,
            u_char * var_val,
            u_char var_val_type,
            size_t var_val_len,
            u_char * statP, oid * name, size_t name_len)
{
    long            tmp = 0;

    if (var_val_type != ASN_INTEGER) {
        snmp_log(LOG_ERR, "Wrong type != int\n");
        return SNMP_ERR_WRONGTYPE;
    }
    tmp = *((long *) var_val);
    if (tmp == 1 && action == COMMIT) {
        update_config();
    }
    return SNMP_ERR_NOERROR;
}
Пример #18
0
static void sys_cfg_set_devphyid()
{
    CLEAR_SCREEN;
    input_dst* devphyid_input;
    devphyid_input = input_init(FREE_MOD);

    input_props_set(devphyid_input, input_one_property);
    input_property_set(devphyid_input, INPUT_HIND, "终端编号");
    input_property_set(devphyid_input, INPUT_MAX_LEN, 8);
    input_dis(MAIN_DISP, devphyid_input);

    printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入8位终端编号", 1);

    lcd_160_upd();

    input_key_manege(MAIN_DISP, devphyid_input , lcd_160_upd);

    char devphyid_buf[24] = {0};

    input_str_get(devphyid_input, devphyid_buf);

    input_destory(devphyid_input);

    if (strlen(devphyid_buf) != 8)
    {
        disp_msg("终端号格式错误", 10);
        return;
    }

    if (update_config("dev.devphyid", devphyid_buf))
    {
        disp_msg("更新终端号失败", 10);
        return;
    }
    strcpy(p16pos.devphyid, devphyid_buf);
    LOG((LOG_DEBUG, "终端号%s", p16pos.devphyid));

    disp_msg("修改终端号成功", 5);
}
void new_virtualhost(MultiWatch* watch, struct inotify_event* event) {

    // add host to /etc/hosts file
    FILE* etc_hosts = fopen("/etc/hosts", "a");
    if (etc_hosts) {
        fputs("127.0.0.1\t", etc_hosts);
        fputs(event->name, etc_hosts);
        fputs(".local\n", etc_hosts);
        fclose(etc_hosts);
    }

    // add .nginx file and add this file to our watch
    add_nginx_config(watch, event->name);

    char* message = malloc(21 + strlen(event->name) + 1);
    strcpy(message, "Neuer Host angelegt: ");
    strcat(message, event->name);

    notify_all_users("nginx", message, NOTIFY_ICON_INFORMATION);

    free(message);

    update_config(watch, event);
}
Пример #20
0
static void show_project_properties(gboolean show_build)
{
	GeanyProject *p = app->project;
	GtkWidget *widget = NULL;
	GtkWidget *radio_long_line_custom;
	static PropertyDialogElements e;
	GSList *node;

	g_return_if_fail(app->project != NULL);

	entries_modified = FALSE;

	if (e.dialog == NULL)
		create_properties_dialog(&e);

	insert_build_page(&e);

	foreach_slist(node, stash_groups)
		stash_group_display(node->data, e.dialog);

	/* fill the elements with the appropriate data */
	gtk_entry_set_text(GTK_ENTRY(e.name), p->name);
	gtk_label_set_text(GTK_LABEL(e.file_name), p->file_name);
	gtk_entry_set_text(GTK_ENTRY(e.base_path), p->base_path);

	radio_long_line_custom = ui_lookup_widget(e.dialog, "radio_long_line_custom_project");
	switch (p->long_line_behaviour)
	{
		case 0: widget = ui_lookup_widget(e.dialog, "radio_long_line_disabled_project"); break;
		case 1: widget = ui_lookup_widget(e.dialog, "radio_long_line_default_project"); break;
		case 2: widget = radio_long_line_custom; break;
	}
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);

	widget = ui_lookup_widget(e.dialog, "spin_long_line_project");
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), (gdouble)p->long_line_column);
	on_radio_long_line_custom_toggled(GTK_TOGGLE_BUTTON(radio_long_line_custom), widget);

	if (p->description != NULL)
	{	/* set text */
		GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e.description));
		gtk_text_buffer_set_text(buffer, p->description, -1);
	}

	if (p->file_patterns != NULL)
	{	/* set the file patterns */
		gchar *str;

		str = g_strjoinv(" ", p->file_patterns);
		gtk_entry_set_text(GTK_ENTRY(e.patterns), str);
		g_free(str);
	}

	g_signal_emit_by_name(geany_object, "project-dialog-open", e.notebook);
	gtk_widget_show_all(e.dialog);

	/* note: notebook page must be shown before setting current page */
	if (show_build)
		gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
	else
		gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), 0);

	while (gtk_dialog_run(GTK_DIALOG(e.dialog)) == GTK_RESPONSE_OK)
	{
		if (update_config(&e, FALSE))
		{
			g_signal_emit_by_name(geany_object, "project-dialog-confirmed", e.notebook);
			if (!write_config(TRUE))
				SHOW_ERR(_("Project file could not be written"));
			else
			{
				ui_set_statusbar(TRUE, _("Project \"%s\" saved."), app->project->name);
				break;
			}
		}
	}

	build_free_fields(e.build_properties);
	g_signal_emit_by_name(geany_object, "project-dialog-close", e.notebook);
	gtk_notebook_remove_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
	gtk_widget_hide(e.dialog);
}
Пример #21
0
/* TODO: this should be ported to Glade like the project preferences dialog,
 * then we can get rid of the PropertyDialogElements struct altogether as
 * widgets pointers can be accessed through ui_lookup_widget(). */
void project_new(void)
{
	GtkWidget *vbox;
	GtkWidget *table;
	GtkWidget *image;
	GtkWidget *button;
	GtkWidget *bbox;
	GtkWidget *label;
	PropertyDialogElements *e;

	if (! project_ask_close())
		return;

	g_return_if_fail(app->project == NULL);

	e = g_new0(PropertyDialogElements, 1);
	e->dialog = gtk_dialog_new_with_buttons(_("New Project"), GTK_WINDOW(main_widgets.window),
										 GTK_DIALOG_DESTROY_WITH_PARENT,
										 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);

	gtk_widget_set_name(e->dialog, "GeanyDialogProject");
	bbox = gtk_hbox_new(FALSE, 0);
	button = gtk_button_new();
	image = gtk_image_new_from_stock(GTK_STOCK_NEW, GTK_ICON_SIZE_BUTTON);
	label = gtk_label_new_with_mnemonic(_("C_reate"));
	gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 3);
	gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 3);
	gtk_container_add(GTK_CONTAINER(button), bbox);
	gtk_dialog_add_action_widget(GTK_DIALOG(e->dialog), button, GTK_RESPONSE_OK);

	vbox = ui_dialog_vbox_new(GTK_DIALOG(e->dialog));

	entries_modified = FALSE;

	table = gtk_table_new(3, 2, FALSE);
	gtk_table_set_row_spacings(GTK_TABLE(table), 5);
	gtk_table_set_col_spacings(GTK_TABLE(table), 10);

	label = gtk_label_new(_("Name:"));
	gtk_misc_set_alignment(GTK_MISC(label), 1, 0);

	e->name = gtk_entry_new();
	ui_entry_add_clear_icon(GTK_ENTRY(e->name));
	gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);

	ui_table_add_row(GTK_TABLE(table), 0, label, e->name, NULL);

	label = gtk_label_new(_("Filename:"));
	gtk_misc_set_alignment(GTK_MISC(label), 1, 0);

	e->file_name = gtk_entry_new();
	ui_entry_add_clear_icon(GTK_ENTRY(e->file_name));
	gtk_entry_set_width_chars(GTK_ENTRY(e->file_name), 30);
	button = gtk_button_new();
	g_signal_connect(button, "clicked", G_CALLBACK(on_file_save_button_clicked), e);
	image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
	gtk_container_add(GTK_CONTAINER(button), image);
	bbox = gtk_hbox_new(FALSE, 6);
	gtk_box_pack_start_defaults(GTK_BOX(bbox), e->file_name);
	gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);

	ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL);

	label = gtk_label_new(_("Base path:"));
	gtk_misc_set_alignment(GTK_MISC(label), 1, 0);

	e->base_path = gtk_entry_new();
	ui_entry_add_clear_icon(GTK_ENTRY(e->base_path));
	gtk_widget_set_tooltip_text(e->base_path,
		_("Base directory of all files that make up the project. "
		"This can be a new path, or an existing directory tree. "
		"You can use paths relative to the project filename."));
	bbox = ui_path_box_new(_("Choose Project Base Path"),
		GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));

	ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL);

	gtk_container_add(GTK_CONTAINER(vbox), table);

	/* signals */
	g_signal_connect(e->name, "changed", G_CALLBACK(on_name_entry_changed), e);
	/* run the callback manually to initialise the base_path and file_name fields */
	on_name_entry_changed(GTK_EDITABLE(e->name), e);

	g_signal_connect(e->file_name, "changed", G_CALLBACK(on_entries_changed), e);
	g_signal_connect(e->base_path, "changed", G_CALLBACK(on_entries_changed), e);

	gtk_widget_show_all(e->dialog);

	while (gtk_dialog_run(GTK_DIALOG(e->dialog)) == GTK_RESPONSE_OK)
	{
		if (update_config(e, TRUE))
		{
			if (!write_config(TRUE))
				SHOW_ERR(_("Project file could not be written"));
			else
			{
				ui_set_statusbar(TRUE, _("Project \"%s\" created."), app->project->name);

				ui_add_recent_project_file(app->project->file_name);
				break;
			}
		}
	}
	gtk_widget_destroy(e->dialog);
	g_free(e);
}
Пример #22
0
static int check_send_transdtl()
{
	const int TRANSDTL_SLEEP_TM = 10;
	const int HEART_SLEEP_TM = 30;
	char recv_buf[1024] = {0};
	int recv_len = 0;
	int ret =0;
	LOG((LOG_DEBUG,"进入check_send_transdtl"));
	while (p16pos.app_running)
	{
		memset(recv_buf,0,1024);
		recv_len = 0;
		ret = send_rt_transdtl_data(recv_buf,&recv_len);
		if(ret == 0)//发送实时流水成功的情况
		{
			if(recv_len>0)
			{
				p16_recv_rt_transdtl_package recv_package;
				memset(&recv_package,0,sizeof(recv_package));
				parse_recv_data(recv_buf,3,&recv_package);
				if(recv_package.data.ret_code == 0)
				{
					LOG((LOG_DEBUG,"上传实时流水成功"));
				}
				else
				{
					LOG((LOG_DEBUG,"上传实时流水失败,pos机不再上传流水"));
				}
			}
			LOG((LOG_DEBUG,"=========================sleep %d========================",TRANSDTL_SLEEP_TM));
			sleep(TRANSDTL_SLEEP_TM);
		}
		else//没有交易流水需要发送
		{
			//发送心跳
			send_heart_data(recv_buf,&recv_len);
			if(recv_len>0)
			{
				//分析接收的数据
				p16_recv_heart_package recv_heart;
				parse_recv_data(recv_buf,0,&recv_heart);

				LOG((LOG_DEBUG,"心跳收到的系统版本号:"));
				p16dump_hex(LOG_DEBUG,recv_heart.data.cfgverno,4);
				LOG((LOG_DEBUG,"心跳收到的服务器时间:"));
				p16dump_hex(LOG_DEBUG,recv_heart.data.server_datetime,6);
				LOG((LOG_DEBUG,"心跳收到的服务器黑名单版本号:"));
				p16dump_hex(LOG_DEBUG,recv_heart.data.current_blacklist_version,6);
				LOG((LOG_DEBUG,"当前系统的黑名单版本号:"));
				p16dump_hex(LOG_DEBUG,p16pos.pos_blacklist_version, 6);
				if(memcmp(recv_heart.data.current_blacklist_version,p16pos.pos_blacklist_version, 6)>0)
				{
					LOG((LOG_DEBUG,"心跳收到的黑名单版本号大于当前系统的黑名单版本号,执行下载黑名单函数!!"));
					//下载黑名单
					memset(recv_buf,0,1024);
					recv_len = 0;
					send_download_blacklist_data(recv_buf,&recv_len);
					if(recv_len>0)
					{
						p16_recv_blacklist_package recv_package;
						parse_recv_data(recv_buf, 2, &recv_package);
						if(recv_package.data.list_cnt>0)
						{
							//有黑名单
							LOG((LOG_DEBUG,"有黑名单%d条",recv_package.data.list_cnt));
							ret = save_blackcard_record(recv_package.data.list_cnt, recv_package.data.blacklist_list);
							if(ret)
							{
								//致命错误,联系管理员
								disp_msg("操作数据库失败,请联系管理员",10);
								return -1;
							}
							//更新系统黑名单版本号
							char pos_blacklist_version[13] = {0};
							encode_hex(recv_package.data.sys_list_version, 6, pos_blacklist_version);
							//更新系统版本号
							ret = update_config("dev.pos_blacklist_version",pos_blacklist_version);
							if(ret)
							{
								//致命错误
								return -2;
							}
							memcpy(p16pos.pos_blacklist_version, recv_package.data.sys_list_version, 6);
							LOG((LOG_DEBUG,"更新版本号为:%s",pos_blacklist_version));
							LOG((LOG_DEBUG,"======================================================="));
						}
					}

				}
			}
			LOG((LOG_DEBUG,"=========================sleep %d========================",HEART_SLEEP_TM));
			sleep(HEART_SLEEP_TM);
		}
		
	}
    return 0;
}
Пример #23
0
int
main(int argc, char *argv[])
{
    int	arg,i;
    int ret;
    u_short dest_port = 161;
    int dont_fork = 0, dont_zero_log = 0;
    char logfile[300];
    char *cptr, **argvptr;

    logfile[0] = 0;
    optconfigfile = NULL;
    dontReadConfigFiles = 0;
    
#ifdef LOGFILE
    strcpy(logfile,LOGFILE);
#endif

    /*
     * usage: snmpd
     */
    for(arg = 1; arg < argc; arg++){
	if (argv[arg][0] == '-'){
	    switch(argv[arg][1]){
                case 'c':
		    if (++arg == argc) usage(argv[0]);
                    optconfigfile = strdup(argv[arg]);
                    break;
                case 'C':
                    dontReadConfigFiles = 1;
                    break;
		case 'd':
		    snmp_dump_packet++;
		    verbose = 1;
		    break;
		case 'q':
		    snmp_set_quick_print(1);
		    break;
		case 'D':
                    debug_register_tokens(&argv[arg][2]);
		    snmp_set_do_debugging(1);
		    break;
                case 'p':
		    if (++arg == argc) usage(argv[0]);
                    dest_port = atoi(argv[arg]);
		    if (dest_port <= 0) usage(argv[0]);
                    break;
		case 'a':
		    log_addresses++;
		    break;
		case 'V':
		    verbose = 1;
		    break;
		case 'f':
		    dont_fork = 1;
		    break;
                case 'l':
		    if (++arg == argc) usage(argv[0]);
                    strcpy(logfile,argv[arg]);
                    break;
                case 'L':
                    logfile[0] = 0;
                    break;
                case 'A':
                    dont_zero_log = 1;
                    break;
                case 'h':
                    usage(argv[0]);
                    break;
                case 'H':
                    init_agent();            /* register our .conf handlers */
#ifdef HAVE_MIB
                    register_mib_handlers(); /* snmplib .conf handlers */
#endif
                    fprintf(stderr, "Configuration directives understood:\n");
                    read_config_print_usage("  ");
                    break;
                case 'v':
                    printf("\nUCD-snmp version:  %s\n",VersionInfo);
                    printf("Author:            Wes Hardaker\n");
                    printf("Email:             [email protected]\n\n");
                    exit (0);
                case '-':
                  switch(argv[arg][2]){
                    case 'v': 
                      printf("\nUCD-snmp version:  %s\n",VersionInfo);
                      printf("Author:            Wes Hardaker\n");
                      printf("Email:             [email protected]\n\n");
                      exit (0);
                    case 'h':
                      usage(argv[0]);
                      exit(0);
                  }
		default:
		    printf("invalid option: %s\n", argv[arg]);
                    usage(argv[0]);
		    break;
	    }
	    continue;
	}
    }
    /* initialize a argv set to the current for restarting the agent */
    argvrestartp = (char **) malloc((argc+2) * sizeof (char *));
    argvptr = argvrestartp;
    for(i=0, ret = 1; i < argc; i++) {
      ret += strlen(argv[i])+1;
    }
    argvrestart = (char *) malloc((ret));
    argvrestartname = (char *) malloc(strlen(argv[0])+1);
    strcpy(argvrestartname,argv[0]);
    for(cptr = argvrestart,i = 0; i < argc; i++) {
      strcpy(cptr,argv[i]);
      *(argvptr++) = cptr;
      cptr += strlen(argv[i]) + 1;
    }
    *cptr = 0;
    *argvptr = NULL;

    /* open the logfile if necessary */
    if (logfile[0]) {
      close(1);
      open(logfile,O_WRONLY|O_CREAT| ((dont_zero_log) ? O_APPEND : O_TRUNC),
           0644);
      close(2);
      dup(1);
      close(0);
    }
#ifdef USE_LIBWRAP
    openlog("snmpd", LOG_CONS, LOG_AUTH|LOG_INFO);
#endif
    setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
    printf ("%s UCD-SNMP version %s\n", sprintf_stamp (NULL), VersionInfo);
    if (!dont_fork && fork() != 0)   /* detach from shell */
      exit(0);
    init_agent();            /* register our .conf handlers */
#ifdef HAVE_MIB
    register_mib_handlers(); /* snmplib .conf handlers */
    read_premib_configs();   /* read pre-mib-reading .conf handlers */
    init_mib();              /* initialize the mib structures */
#endif
    update_config(0);        /* read in config files and register HUP */
#ifdef PERSISTENTFILE
    /* read in the persistent information cache */
    read_config_with_type(PERSISTENTFILE, "snmpd");
    unlink(PERSISTENTFILE);  /* nuke it now that we've read it */
#endif
#ifdef HAVE_SNMP2P
    init_snmp2p( dest_port );
#endif
    
    printf("Opening port(s): "); 
    fflush(stdout);
    if (( ret = open_port( dest_port )) > 0 )
        sd_handlers[ret-1] = snmp_read_packet;   /* Save pointer to function */
#ifdef HAVE_SNMP2P
    open_ports_snmp2p( );
#endif
    printf("\n");
    fflush(stdout);

    /* get current time (ie, the time the agent started) */
    gettimeofday(&starttime, NULL);
    starttime.tv_sec--;
    starttime.tv_usec += 1000000L;

    /* send coldstart trap via snmptrap(1) if possible */
    send_easy_trap (0, 0);
    signal(SIGTERM, SnmpdShutDown);
    signal(SIGINT, SnmpdShutDown);

    memset(addrCache, 0, sizeof(addrCache));
    receive(sdlist);
#include "mib_module_shutdown.h"
    DEBUGMSGTL(("snmpd", "sending shutdown trap\n"));
    SnmpTrapNodeDown();
    DEBUGMSGTL(("snmpd", "Bye...\n"));
    return 0;
}
Пример #24
0
/*---------------------------------------------------------------------------*/
httpd_simple_script_t
httpd_simple_get_script(const char *name)
{
  static uip_ds6_route_t *r;
  static char filename[HTTPD_PATHLEN];
  static int i;

  strcpy(filename, slip_config_www_root);
  strcat(filename, "/");
  strcat(filename, name);

  redirect = 0;

  if(strcmp(name, "index.html") == 0 || strcmp(name, "") == 0) {
    return generate_index;
#if CONTIKI_TARGET_NATIVE
  } else if (access(filename, R_OK) == 0) {
      return send_file;
#endif
#if CETIC_NODE_INFO
  } else if(strcmp(name, "sensors.html") == 0) {
    return generate_sensors;
#endif
  } else if(strcmp(name, "rpl.html") == 0) {
    return generate_rpl;
  } else if(strcmp(name, "network.html") == 0) {
    return generate_network;
  } else if(strcmp(name, "config.html") == 0) {
    return generate_config;
  } else if(strcmp(name, "statistics.html") == 0) {
    return generate_statistics;
  } else if ((nvm_data.global_flags & CETIC_GLOBAL_DISABLE_CONFIG) == 0) {
    if(strcmp(name, "rpl-gr") == 0) {
#if UIP_CONF_IPV6_RPL
      rpl_repair_root(RPL_DEFAULT_INSTANCE);
#endif
      return generate_rpl;
    } else if(memcmp(name, "route_rm?", 9) == 0) {
      redirect = 1;
      i = atoi(name + 9);
      for(r = uip_ds6_route_list_head(); r != NULL; r = list_item_next(r), --i) {
        if(i == 0) {
          uip_ds6_route_rm(r);
          break;
        }
      }
      return generate_network;
    } else if(memcmp(name, "nbr_rm?", 7) == 0) {
      redirect = 1;
      uip_ds6_nbr_rm(&uip_ds6_nbr_cache[atoi(name + 7)]);
      return generate_network;
    } else if(memcmp(name, "config?", 7) == 0) {
      if(update_config(name + 7)) {
        return generate_config;
      } else {
        return generate_reboot;
      }
    } else {
      return generate_404;
    }
  } else {
    return generate_404;
  }
}
Пример #25
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(mqtt_client_process, ev, data)
{

    PROCESS_BEGIN();

    printf("CC26XX MQTT Client Process\n");

    conf = &cc26xx_web_demo_config.mqtt_config;
    if(init_config() != 1) {
        PROCESS_EXIT();
    }

    register_http_post_handlers();

    def_rt_rssi = 0x8000000;
    uip_icmp6_echo_reply_callback_add(&echo_reply_notification,
                                      echo_reply_handler);
    etimer_set(&echo_request_timer, conf->def_rt_ping_interval);

    /* Main loop */
    while(1) {

        PROCESS_YIELD();

        if(ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER) {
            if(state == MQTT_CLIENT_STATE_ERROR) {
                connect_attempt = 1;
                state = MQTT_CLIENT_STATE_REGISTERED;
            }
        }

        if(ev == httpd_simple_event_new_config) {
            /*
             * Schedule next pass in a while. When HTTPD sends us this event, it is
             * also in the process of sending the config page. Wait a little before
             * reconnecting, so as to not cause congestion.
             */
            etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL);
        }

        if(ev == cc26xx_web_demo_config_loaded_event) {
            update_config();
        }

        if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) ||
                ev == PROCESS_EVENT_POLL ||
                ev == cc26xx_web_demo_publish_event ||
                (ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER)) {
            state_machine();
        }

        if(ev == PROCESS_EVENT_TIMER && data == &echo_request_timer) {
            ping_parent();
            etimer_set(&echo_request_timer, conf->def_rt_ping_interval);
        }

        if(ev == cc26xx_web_demo_load_config_defaults) {
            init_config();
            etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL);
        }
    }

    PROCESS_END();
}
Пример #26
0
/*---------------------------------------------------------------------------*/
static void
state_machine(void)
{
    switch(state) {
    case MQTT_CLIENT_STATE_INIT:
        /* If we have just been configured register MQTT connection */
        mqtt_register(&conn, &mqtt_client_process, client_id, mqtt_event,
                      MQTT_CLIENT_MAX_SEGMENT_SIZE);

        /*
         * Authentication: provide user name and password
         */
        if(strlen(conf->auth_token) > 0) {
            mqtt_set_username_password(&conn, "use-token-auth",
                                       conf->auth_token);
        }

        /* _register() will set auto_reconnect. We don't want that. */
        conn.auto_reconnect = 0;
        connect_attempt = 1;

        /*
         * Wipe out the default route so we'll republish it every time we switch to
         * a new broker
         */
        memset(&def_route, 0, sizeof(def_route));

        state = MQTT_CLIENT_STATE_REGISTERED;
        DBG("Init\n");
    /* Continue */
    case MQTT_CLIENT_STATE_REGISTERED:
        if(uip_ds6_get_global(ADDR_PREFERRED) != NULL) {
            /* Registered and with a public IP. Connect */
            DBG("Registered. Connect attempt %u\n", connect_attempt);
            ping_parent();
            connect_to_broker();
        }
        etimer_set(&publish_periodic_timer, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC);
        return;
        break;
    case MQTT_CLIENT_STATE_CONNECTING:
        leds_on(CC26XX_WEB_DEMO_STATUS_LED);
        ctimer_set(&ct, CONNECTING_LED_DURATION, publish_led_off, NULL);
        /* Not connected yet. Wait */
        DBG("Connecting (%u)\n", connect_attempt);
        break;
    case MQTT_CLIENT_STATE_CONNECTED:
    /* Don't subscribe unless we are a registered device
    if(strncasecmp(conf->org_id, QUICKSTART, strlen(conf->org_id)) == 0) {
      DBG("Using 'quickstart': Skipping subscribe\n");
      state = MQTT_CLIENT_STATE_PUBLISHING;
    }*/
    /* Continue */
    case MQTT_CLIENT_STATE_PUBLISHING:
        /* If the timer expired, the connection is stable. */
        if(timer_expired(&connection_life)) {
            /*
             * Intentionally using 0 here instead of 1: We want RECONNECT_ATTEMPTS
             * attempts if we disconnect after a successful connect
             */
            connect_attempt = 0;
        }

        if(mqtt_ready(&conn) && conn.out_buffer_sent) {
            /* Connected. Publish */
            if(state == MQTT_CLIENT_STATE_CONNECTED) {
                subscribe();
                state = MQTT_CLIENT_STATE_PUBLISHING;
            } else {
                leds_on(CC26XX_WEB_DEMO_STATUS_LED);
                ctimer_set(&ct, PUBLISH_LED_ON_DURATION, publish_led_off, NULL);
                publish();
            }
            etimer_set(&publish_periodic_timer, conf->pub_interval);

            DBG("Publishing\n");
            /* Return here so we don't end up rescheduling the timer */
            return;
        } else {
            /*
             * Our publish timer fired, but some MQTT packet is already in flight
             * (either not sent at all, or sent but not fully ACKd).
             *
             * This can mean that we have lost connectivity to our broker or that
             * simply there is some network delay. In both cases, we refuse to
             * trigger a new message and we wait for TCP to either ACK the entire
             * packet after retries, or to timeout and notify us.
             */
            DBG("Publishing... (MQTT state=%d, q=%u)\n", conn.state,
                conn.out_queue_full);
        }
        break;
    case MQTT_CLIENT_STATE_DISCONNECTED:
        DBG("Disconnected\n");
        if(connect_attempt < RECONNECT_ATTEMPTS ||
                RECONNECT_ATTEMPTS == RETRY_FOREVER) {
            /* Disconnect and backoff */
            clock_time_t interval;
            mqtt_disconnect(&conn);
            connect_attempt++;

            interval = connect_attempt < 3 ? RECONNECT_INTERVAL << connect_attempt :
                       RECONNECT_INTERVAL << 3;

            DBG("Disconnected. Attempt %u in %lu ticks\n", connect_attempt, interval);

            etimer_set(&publish_periodic_timer, interval);

            state = MQTT_CLIENT_STATE_REGISTERED;
            return;
        } else {
            /* Max reconnect attempts reached. Enter error state */
            state = MQTT_CLIENT_STATE_ERROR;
            DBG("Aborting connection after %u attempts\n", connect_attempt - 1);
        }
        break;
    case MQTT_CLIENT_STATE_NEWCONFIG:
        /* Only update config after we have disconnected */
        if(conn.state == MQTT_CONN_STATE_NOT_CONNECTED) {
            update_config();
            DBG("New config\n");

            /* update_config() scheduled next pass. Return */
            return;
        }
        break;
    case MQTT_CLIENT_STATE_CONFIG_ERROR:
        /* Idle away. The only way out is a new config */
        printf("Bad configuration.\n");
        return;
    case MQTT_CLIENT_STATE_ERROR:
    default:
        leds_on(CC26XX_WEB_DEMO_STATUS_LED);
        /*
         * 'default' should never happen.
         *
         * If we enter here it's because of some error. Stop timers. The only thing
         * that can bring us out is a new config event
         */
        printf("Default case: State=0x%02x\n", state);
        return;
    }

    /* If we didn't return so far, reschedule ourselves */
    etimer_set(&publish_periodic_timer, STATE_MACHINE_PERIODIC);
}
Пример #27
0
/*******************************************************************-o-******
 * receive
 *
 * Parameters:
 *      
 * Returns:
 *	0	On success.
 *	-1	System error.
 *
 * Infinite while-loop which monitors incoming messges for the agent.
 * Invoke the established message handlers for incoming messages on a per
 * port basis.  Handle timeouts.
 */
static int
receive(void)
{
    int             numfds;
    fd_set          readfds, writefds, exceptfds;
    struct timeval  timeout, *tvp = &timeout;
    struct timeval  sched, *svp = &sched, now, *nvp = &now;
    int             count, block, i;
#ifdef	USING_SMUX_MODULE
    int             sd;
#endif                          /* USING_SMUX_MODULE */


    /*
     * Set the 'sched'uled timeout to the current time + one TIMETICK.
     */
    gettimeofday(nvp, (struct timezone *) NULL);
    svp->tv_usec = nvp->tv_usec + TIMETICK;
    svp->tv_sec = nvp->tv_sec;

    while (svp->tv_usec >= ONE_SEC) {
        svp->tv_usec -= ONE_SEC;
        svp->tv_sec++;
    }

    /*
     * ignore early sighup during startup
     */
    reconfig = 0;

    /*
     * Loop-forever: execute message handlers for sockets with data,
     * reset the 'sched'uler.
     */
    while (netsnmp_running) {
        if (reconfig) {
            reconfig = 0;
            snmp_log(LOG_INFO, "Reconfiguring daemon\n");
	    /*  Stop and restart logging.  This allows logfiles to be
		rotated etc.  */
	    snmp_disable_log();
	    setup_log(1, 0, 0, 0, NULL);
	    snmp_log(LOG_INFO, "NET-SNMP version %s restarted\n",
		     netsnmp_get_version());
            update_config();
            send_easy_trap(SNMP_TRAP_ENTERPRISESPECIFIC, 3);
        }

        for (i = 0; i < NUM_EXTERNAL_SIGS; i++) {
            if (external_signal_scheduled[i]) {
                external_signal_scheduled[i]--;
                external_signal_handler[i](i);
            }
        }

        tvp = &timeout;
        tvp->tv_sec = 0;
        tvp->tv_usec = TIMETICK;

        numfds = 0;
        FD_ZERO(&readfds);
        FD_ZERO(&writefds);
        FD_ZERO(&exceptfds);
        block = 0;
        snmp_select_info(&numfds, &readfds, tvp, &block);
        if (block == 1) {
            tvp = NULL;         /* block without timeout */
	}

#ifdef	USING_SMUX_MODULE
        if (smux_listen_sd >= 0) {
            FD_SET(smux_listen_sd, &readfds);
            numfds =
                smux_listen_sd >= numfds ? smux_listen_sd + 1 : numfds;
            for (i = 0; i < sdlen; i++) {
                FD_SET(sdlist[i], &readfds);
                numfds = sdlist[i] >= numfds ? sdlist[i] + 1 : numfds;
            }
        }
#endif                          /* USING_SMUX_MODULE */

        for (i = 0; i < external_readfdlen; i++) {
            FD_SET(external_readfd[i], &readfds);
            if (external_readfd[i] >= numfds)
                numfds = external_readfd[i] + 1;
        }
        for (i = 0; i < external_writefdlen; i++) {
            FD_SET(external_writefd[i], &writefds);
            if (external_writefd[i] >= numfds)
                numfds = external_writefd[i] + 1;
        }
        for (i = 0; i < external_exceptfdlen; i++) {
            FD_SET(external_exceptfd[i], &exceptfds);
            if (external_exceptfd[i] >= numfds)
                numfds = external_exceptfd[i] + 1;
        }

    reselect:
        DEBUGMSGTL(("snmpd/select", "select( numfds=%d, ..., tvp=%p)\n",
                    numfds, tvp));
        count = select(numfds, &readfds, &writefds, &exceptfds, tvp);
        DEBUGMSGTL(("snmpd/select", "returned, count = %d\n", count));

        if (count > 0) {

#ifdef USING_SMUX_MODULE
            /*
             * handle the SMUX sd's 
             */
            if (smux_listen_sd >= 0) {
                for (i = 0; i < sdlen; i++) {
                    if (FD_ISSET(sdlist[i], &readfds)) {
                        if (smux_process(sdlist[i]) < 0) {
                            for (; i < (sdlen - 1); i++) {
                                sdlist[i] = sdlist[i + 1];
                            }
                            sdlen--;
                        }
                    }
                }
                /*
                 * new connection 
                 */
                if (FD_ISSET(smux_listen_sd, &readfds)) {
                    if ((sd = smux_accept(smux_listen_sd)) >= 0) {
                        sdlist[sdlen++] = sd;
                    }
                }
            }
#endif                          /* USING_SMUX_MODULE */

            snmp_read(&readfds);

            for (i = 0; count && (i < external_readfdlen); i++) {
                if (FD_ISSET(external_readfd[i], &readfds)) {
                    DEBUGMSGTL(("snmpd/select", "readfd[%d] = %d\n",
                                i, external_readfd[i]));
                    external_readfdfunc[i] (external_readfd[i],
                                            external_readfd_data[i]);
                    FD_CLR(external_readfd[i], &readfds);
                    count--;
                }
            }
            for (i = 0; count && (i < external_writefdlen); i++) {
                if (FD_ISSET(external_writefd[i], &writefds)) {
                    DEBUGMSGTL(("snmpd/select", "writefd[%d] = %d\n",
                                i, external_writefd[i]));
                    external_writefdfunc[i] (external_writefd[i],
                                             external_writefd_data[i]);
                    FD_CLR(external_writefd[i], &writefds);
                    count--;
                }
            }
            for (i = 0; count && (i < external_exceptfdlen); i++) {
                if (FD_ISSET(external_exceptfd[i], &exceptfds)) {
                    DEBUGMSGTL(("snmpd/select", "exceptfd[%d] = %d\n",
                                i, external_exceptfd[i]));
                    external_exceptfdfunc[i] (external_exceptfd[i],
                                              external_exceptfd_data[i]);
                    FD_CLR(external_exceptfd[i], &exceptfds);
                    count--;
                }
            }

        } else
            switch (count) {
            case 0:
                snmp_timeout();
                break;
            case -1:
                if (errno == EINTR) {
                    /*
                     * likely that we got a signal. Check our special signal
                     * flags before retrying select.
                     */
		    if (netsnmp_running && !reconfig) {
                        goto reselect;
		    }
                    continue;
                } else {
                    snmp_log_perror("select");
                }
                return -1;
            default:
                snmp_log(LOG_ERR, "select returned %d\n", count);
                return -1;
            }                   /* endif -- count>0 */




        /*
         * If the time 'now' is greater than the 'sched'uled time, then:
         *
         *    Check alarm and event timers.
         *    Reset the 'sched'uled time to current time + one TIMETICK.
         *    Age the cache network addresses (from whom messges have
         *        been received).
         */
        gettimeofday(nvp, (struct timezone *)NULL);

        if (nvp->tv_sec > svp->tv_sec || (nvp->tv_sec == svp->tv_sec &&
					  nvp->tv_usec > svp->tv_usec)) {
            svp->tv_usec = nvp->tv_usec + TIMETICK;
            svp->tv_sec = nvp->tv_sec;

            while (svp->tv_usec >= ONE_SEC) {
                svp->tv_usec -= ONE_SEC;
                svp->tv_sec++;
            }
        }

        /*
         * endif -- now>sched 
         */
        /*
         * run requested alarms 
         */
        run_alarms();

        netsnmp_check_outstanding_agent_requests();

    }                           /* endwhile */

    snmp_log(LOG_INFO, "Received TERM or STOP signal...  shutting down...\n");
    return 0;

}                               /* end receive() */
Пример #28
0
/*******************************************************************-o-******
 * receive
 *
 * Parameters:
 *
 * Returns:
 *	0	On success.
 *	-1	System error.
 *
 * Infinite while-loop which monitors incoming messges for the agent.
 * Invoke the established message handlers for incoming messages on a per
 * port basis.  Handle timeouts.
 */
static int
receive(void)
{
    int numfds;
    fd_set fdset;
    struct timeval	timeout, *tvp = &timeout;
    struct timeval	sched,   *svp = &sched,
                                  now,     *nvp = &now;
    int count, block;
#ifdef	USING_SMUX_MODULE
    int i, sd;
#endif	/* USING_SMUX_MODULE */


    /*
     * Set the 'sched'uled timeout to the current time + one TIMETICK.
     */
    gettimeofday(nvp, (struct timezone *) NULL);
    svp->tv_usec = nvp->tv_usec + TIMETICK;
    svp->tv_sec = nvp->tv_sec;

    while (svp->tv_usec >= ONE_SEC) {
        svp->tv_usec -= ONE_SEC;
        svp->tv_sec++;
    }

    /*
     * Loop-forever: execute message handlers for sockets with data,
     * reset the 'sched'uler.
     */
    while (running) {
        if (reconfig) {
            reconfig = 0;
            snmp_log(LOG_INFO, "Reconfiguring daemon\n");
            update_config();
        }
        tvp =  &timeout;
        tvp->tv_sec = 0;
        tvp->tv_usec = TIMETICK;

        numfds = 0;
        FD_ZERO(&fdset);
        block = 0;
        snmp_select_info(&numfds, &fdset, tvp, &block);
        if (block == 1)
            tvp = NULL; /* block without timeout */

#ifdef	USING_SMUX_MODULE
        if (smux_listen_sd >= 0) {
            FD_SET(smux_listen_sd, &fdset);
            numfds = smux_listen_sd >= numfds ? smux_listen_sd + 1 : numfds;
            for (i = 0; i < sdlen; i++) {
                FD_SET(sdlist[i], &fdset);
                numfds = sdlist[i] >= numfds ? sdlist[i] + 1 : numfds;
            }
        }
#endif	/* USING_SMUX_MODULE */

        count = select(numfds, &fdset, 0, 0, tvp);

        if (count > 0) {
            snmp_read(&fdset);
        } else switch(count) {
            case 0:
                snmp_timeout();
                break;
            case -1:
                if (errno == EINTR) {
                    continue;
                } else {
                    snmp_log_perror("select");
                }
                return -1;
            default:
                snmp_log(LOG_ERR, "select returned %d\n", count);
                return -1;
            }  /* endif -- count>0 */

#ifdef	USING_SMUX_MODULE
        /* handle the SMUX sd's */
        if (smux_listen_sd >= 0) {
            for (i = 0; i < sdlen; i++) {
                if (FD_ISSET(sdlist[i], &fdset)) {
                    if (smux_process(sdlist[i]) < 0) {
                        for (; i < (sdlen - 1); i++) {
                            sdlist[i] = sdlist[i+1];
                        }
                        sdlen--;
                    }
                }
            }
            /* new connection */
            if (FD_ISSET(smux_listen_sd, &fdset)) {
                if ((sd = smux_accept(smux_listen_sd)) >= 0) {
                    sdlist[sdlen++] = sd;
                }
            }
        }
#endif	/* USING_SMUX_MODULE */



        /*
         * If the time 'now' is greater than the 'sched'uled time, then:
         *
         *    Check alarm and event timers.
         *    Reset the 'sched'uled time to current time + one TIMETICK.
         *    Age the cache network addresses (from whom messges have
         *        been received).
         */
        gettimeofday(nvp, (struct timezone *) NULL);

        if (nvp->tv_sec > svp->tv_sec
                || (nvp->tv_sec == svp->tv_sec && nvp->tv_usec > svp->tv_usec)) {
            svp->tv_usec = nvp->tv_usec + TIMETICK;
            svp->tv_sec = nvp->tv_sec;

            while (svp->tv_usec >= ONE_SEC) {
                svp->tv_usec -= ONE_SEC;
                svp->tv_sec++;
            }
            if (log_addresses && lastAddrAge++ > 600) {

                lastAddrAge = 0;
                for(count = 0; count < ADDRCACHE; count++) {
                    if (addrCache[count].status == OLD)
                        addrCache[count].status = UNUSED;
                    if (addrCache[count].status == USED)
                        addrCache[count].status = OLD;
                }
            }
        }  /* endif -- now>sched */

        /* run requested alarms */
        run_alarms();

    }  /* endwhile */

    snmp_log(LOG_INFO, "Received TERM or STOP signal...  shutting down...\n");
    return 0;

}  /* end receive() */
Пример #29
0
/*******************************************************************-o-******
 * receive
 *
 * Parameters:
 *      
 * Returns:
 *	0	On success.
 *	-1	System error.
 *
 * Infinite while-loop which monitors incoming messages for the agent.
 * Invoke the established message handlers for incoming messages on a per
 * port basis.  Handle timeouts.
 */
static int
receive(void)
{
    int             numfds;
    netsnmp_large_fd_set readfds, writefds, exceptfds;
    struct timeval  timeout, *tvp = &timeout;
    int             count, block, i;
#ifdef	USING_SMUX_MODULE
    int             sd;
#endif                          /* USING_SMUX_MODULE */

    netsnmp_large_fd_set_init(&readfds, FD_SETSIZE);
    netsnmp_large_fd_set_init(&writefds, FD_SETSIZE);
    netsnmp_large_fd_set_init(&exceptfds, FD_SETSIZE);

    /*
     * ignore early sighup during startup
     */
    reconfig = 0;

#if defined(WIN32)
    create_stdin_waiter_thread();
#endif

    /*
     * Loop-forever: execute message handlers for sockets with data
     */
    while (netsnmp_running) {
        if (reconfig) {
#if HAVE_SIGHOLD
            sighold(SIGHUP);
#endif
            reconfig = 0;
            snmp_log(LOG_INFO, "Reconfiguring daemon\n");
	    /*  Stop and restart logging.  This allows logfiles to be
		rotated etc.  */
	    netsnmp_logging_restart();
	    snmp_log(LOG_INFO, "NET-SNMP version %s restarted\n",
		     netsnmp_get_version());
            update_config();
            send_easy_trap(SNMP_TRAP_ENTERPRISESPECIFIC, 3);
#if HAVE_SIGHOLD
            sigrelse(SIGHUP);
#endif
        }

        /*
         * default to sleeping for a really long time. INT_MAX
         * should be sufficient (eg we don't care if time_t is
         * a long that's bigger than an int).
         */
        tvp = &timeout;
        tvp->tv_sec = INT_MAX;
        tvp->tv_usec = 0;

        numfds = 0;
        NETSNMP_LARGE_FD_ZERO(&readfds);
        NETSNMP_LARGE_FD_ZERO(&writefds);
        NETSNMP_LARGE_FD_ZERO(&exceptfds);
        block = 0;
        snmp_select_info2(&numfds, &readfds, tvp, &block);
        if (block == 1) {
            tvp = NULL;         /* block without timeout */
	}

#ifdef	USING_SMUX_MODULE
        if (smux_listen_sd >= 0) {
            NETSNMP_LARGE_FD_SET(smux_listen_sd, &readfds);
            numfds =
                smux_listen_sd >= numfds ? smux_listen_sd + 1 : numfds;

            for (i = 0; i < smux_snmp_select_list_get_length(); i++) {
                sd = smux_snmp_select_list_get_SD_from_List(i);
                if (sd != 0)
                {
                   NETSNMP_LARGE_FD_SET(sd, &readfds);
                   numfds = sd >= numfds ? sd + 1 : numfds;
                }
            }
        }
#endif                          /* USING_SMUX_MODULE */

#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
        netsnmp_external_event_info2(&numfds, &readfds, &writefds, &exceptfds);
#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */

    reselect:
        for (i = 0; i < NUM_EXTERNAL_SIGS; i++) {
            if (external_signal_scheduled[i]) {
                external_signal_scheduled[i]--;
                external_signal_handler[i](i);
            }
        }

        DEBUGMSGTL(("snmpd/select", "select( numfds=%d, ..., tvp=%p)\n",
                    numfds, tvp));
        if (tvp)
            DEBUGMSGTL(("timer", "tvp %ld.%ld\n", (long) tvp->tv_sec,
                        (long) tvp->tv_usec));
        count = netsnmp_large_fd_set_select(numfds, &readfds, &writefds, &exceptfds,
				     tvp);
        DEBUGMSGTL(("snmpd/select", "returned, count = %d\n", count));

        if (count > 0) {

#ifdef USING_SMUX_MODULE
            /*
             * handle the SMUX sd's 
             */
            if (smux_listen_sd >= 0) {
                for (i = 0; i < smux_snmp_select_list_get_length(); i++) {
                    sd = smux_snmp_select_list_get_SD_from_List(i);
                    if (NETSNMP_LARGE_FD_ISSET(sd, &readfds)) {
                        if (smux_process(sd) < 0) {
                            smux_snmp_select_list_del(sd);
                        }
                    }
                }
                /*
                 * new connection 
                 */
                if (NETSNMP_LARGE_FD_ISSET(smux_listen_sd, &readfds)) {
                    if ((sd = smux_accept(smux_listen_sd)) >= 0) {
                        smux_snmp_select_list_add(sd);
                    }
                }
            }

#endif                          /* USING_SMUX_MODULE */

#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
            netsnmp_dispatch_external_events2(&count, &readfds,
                                              &writefds, &exceptfds);
#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */

            /* If there are still events leftover, process them */
            if (count > 0) {
              snmp_read2(&readfds);
            }
        } else
            switch (count) {
            case 0:
                snmp_timeout();
                break;
            case -1:
                DEBUGMSGTL(("snmpd/select", "  errno = %d\n", errno));
                if (errno == EINTR) {
                    /*
                     * likely that we got a signal. Check our special signal
                     * flags before retrying select.
                     */
		    if (netsnmp_running && !reconfig) {
                        goto reselect;
		    }
                    continue;
                } else {
                    snmp_log_perror("select");
                }
                return -1;
            default:
                snmp_log(LOG_ERR, "select returned %d\n", count);
                return -1;
            }                   /* endif -- count>0 */

        /*
         * see if persistent store needs to be saved
         */
        snmp_store_if_needed();

        /*
         * run requested alarms 
         */
        run_alarms();

        netsnmp_check_outstanding_agent_requests();

    }                           /* endwhile */

    netsnmp_large_fd_set_cleanup(&readfds);
    netsnmp_large_fd_set_cleanup(&writefds);
    netsnmp_large_fd_set_cleanup(&exceptfds);

#if defined(WIN32)
    join_stdin_waiter_thread();
#endif

    snmp_log(LOG_INFO, "Received TERM or STOP signal...  shutting down...\n");
    return 0;

}                               /* end receive() */
Пример #30
0
void update_config(vector<string> *&lines, string var_name, int var_value){
    stringstream ss2;
    ss2<<var_value;
    update_config(lines, var_name, ss2.str());
}