MenuItem *menuitem_create_ip(char *id, MenuEventFunc(*event_func),
	char *text, Client *client, bool v6, char *value)
{
	MenuItem *new_item;
	const IpSstringProperties *ipinfo;

	debug(RPT_DEBUG, "%s(id=\"%s\", event_func=%p, text=\"%s\", v6=%d, value=\"%s\")",
			__FUNCTION__, id, event_func, text, v6, value);

	new_item = menuitem_create(MENUITEM_IP, id, event_func, text, client);
	if (new_item == NULL)
		return NULL;

	new_item->data.ip.v6 = v6;
	ipinfo = (v6) ? &IPinfo[1] : &IPinfo[0];

	new_item->data.ip.maxlength = ipinfo->maxlen;;
	new_item->data.ip.value = malloc(new_item->data.ip.maxlength + 1);
	if (new_item->data.ip.value == NULL)
	{
		menuitem_destroy(new_item);
		return NULL;
	}

	strncpy(new_item->data.ip.value, value, new_item->data.ip.maxlength);
	new_item->data.ip.value[new_item->data.ip.maxlength] = '\0';

	if (ipinfo->verify != NULL) {
		char *start = new_item->data.ip.value;

		while (start != NULL) {
			char *skip = start;

			while ((*skip == ' ') || ((*skip == '0') && (skip[1] != ipinfo->sep) && (skip[1] != '\0')))
				skip++;
			memccpy(start, skip, '\0', new_item->data.ip.maxlength + 1);
			skip = strchr(start, ipinfo->sep);
			start = (skip != NULL) ? (skip + 1) : NULL;
		}

		if (!ipinfo->verify(new_item->data.ip.value)) {
			report(RPT_WARNING, "%s(id=\"%s\") ip address not verified: \"%s\"",
					    __FUNCTION__, id, value);
			strncpy(new_item->data.ip.value, ipinfo->dummy, new_item->data.ip.maxlength);
			new_item->data.ip.value[new_item->data.ip.maxlength] = '\0';
		}
	}

	new_item->data.ip.edit_str = malloc(new_item->data.ip.maxlength + 1);
	if (new_item->data.ip.edit_str == NULL) {
		menuitem_destroy(new_item);
		return NULL;
	}

	return new_item;
}
MenuItem *menuitem_create_slider(char *id, MenuEventFunc(*event_func),
	char *text, Client *client, char *mintext, char *maxtext,
	int minvalue, int maxvalue, int stepsize, int value)
{
	MenuItem *new_item;

	debug(RPT_DEBUG, "%s(id=[%s], event_func=%p, text=\"%s\", mintext=\"%s\", maxtext=\"%s\", minvalue=%d, maxvalue=%d, stepsize=%d, value=%d)",
			__FUNCTION__, id, event_func, text, mintext, maxtext, minvalue, maxvalue, stepsize, value);

	new_item = menuitem_create(MENUITEM_SLIDER, id, event_func, text, client);
	if (new_item != NULL) {
		new_item->data.slider.mintext = strdup(mintext);
		new_item->data.slider.maxtext = strdup(maxtext);
		if (new_item->data.slider.mintext == NULL ||
		    new_item->data.slider.maxtext == NULL) {
			menuitem_destroy(new_item);
			return NULL;
		}
		new_item->data.slider.minvalue = minvalue;
		new_item->data.slider.maxvalue = maxvalue;
		new_item->data.slider.stepsize = stepsize;
		new_item->data.slider.value = value;
	}

	return new_item;
}
示例#3
0
/*************************************************************************
 * menu_del_item_func
 *
 * Deletes an item from a menu
 *
 * Usage: menu_del_item <menuid> <itemid>
 * The given item in the given menu will be deleted. If you have deleted all
 * the items from your client menu, that menu will automatically be removed.
 */
int
menu_del_item_func (Client * c, int argc, char **argv)
{
	Menu * menu;
	MenuItem * item;
	char * menu_id;
	char * item_id;

	if (!c->ack)
		return 1;

	if (argc != 3 ) {
		sock_send_error(c->sock, "Usage: menu_del_item <menuid> <itemid>\n");
		return 0;
	}

	menu_id = argv[1];
	item_id = argv[2];

	/* Does the client have a menu already ? */
	if (!c->menu) {
		sock_send_error(c->sock, "Client has no menu\n");
		return 0;
	}

	if ( menu_id[0] == 0 ) {
		/* No menu specified = client's main menu */
		menu = c->menu;
	} else {
		/* A specified menu */
		menu = menu_find_item (c->menu, menu_id, true);
	}
	if (!menu) {
		sock_send_error(c->sock, "Cannot find menu id\n");
		return 0;
	}

	item = menu_find_item (c->menu, item_id, true);
	if (!item) {
		sock_send_error(c->sock, "Cannot find item\n");
		return 0;
	}
	menuscreen_inform_item_destruction (item);
	menu_remove_item (menu, item);
	menuscreen_inform_item_modified (item->parent);
	menuitem_destroy (item);

	/* Was it the last item in the client's menu ? */
	if (menu_getfirst_item(c->menu) == NULL) {
		menuscreen_inform_item_destruction (c->menu);
		menu_remove_item (main_menu, c->menu);
		menuscreen_inform_item_modified (main_menu);
		menu_destroy (c->menu);
		c->menu = NULL;
	}
	sock_send_string(c->sock, "success\n");
	return 0;
}
MenuItem *menuitem_create_alpha(char *id, MenuEventFunc(*event_func),
	char *text, Client *client, char password_char, short minlength, short maxlength,
	bool allow_caps, bool allow_noncaps, bool allow_numbers,
	char *allowed_extra, char *value)
{
	MenuItem *new_item;

	debug(RPT_DEBUG, "%s(id=\"%s\", event_func=%p, text=\"%s\", password_char=%d, maxlength=%d, value=\"%s\")",
			__FUNCTION__, id, event_func, text, password_char, maxlength, value);

	new_item = menuitem_create(MENUITEM_ALPHA, id, event_func, text, client);
	if (new_item != NULL) {
		new_item->data.alpha.password_char = password_char;
		new_item->data.alpha.minlength = minlength;
		new_item->data.alpha.maxlength = maxlength;

		new_item->data.alpha.allow_caps = allow_caps;
		new_item->data.alpha.allow_noncaps = allow_noncaps;
		new_item->data.alpha.allow_numbers = allow_numbers;
		new_item->data.alpha.allowed_extra = strdup(allowed_extra);
		if (new_item->data.alpha.allowed_extra == NULL) {
			menuitem_destroy(new_item);
			return NULL;
		}

		new_item->data.alpha.value = malloc(maxlength + 1);
		if (new_item->data.alpha.value == NULL) {
			menuitem_destroy(new_item);
			return NULL;
		}

		strncpy(new_item->data.alpha.value, value, maxlength);
		new_item->data.alpha.value[maxlength] = 0;

		new_item->data.alpha.edit_str = malloc(maxlength + 1);
		if (new_item->data.alpha.edit_str == NULL) {
			menuitem_destroy(new_item);
			return NULL;
		}
	}

	return new_item;
}
示例#5
0
void
menuscreen_remove_screen(Screen *s)
{
	debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__,
	      (s != NULL) ? s->id : "(NULL)");

	/* allow to remove the menuscreen itself */
	if ((s == NULL) || (s == menuscreen))
		return;

	if (screens_menu) {
		Menu *m = menu_find_item(screens_menu, s->id, false);

		menu_remove_item(screens_menu, m);
		menuitem_destroy(m);
	}
}
示例#6
0
int
menuscreens_shutdown(void)
{
	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	/* Program shutdown before completed startup */
	if (!menuscreen)
		return -1;

	/* Quit menu just to make sure */
	menuscreen_switch_item(NULL);

	/* Destroy the menuscreen */
	screenlist_remove(menuscreen);
	screen_destroy(menuscreen);
	menuscreen = NULL;

	/* Destroy all menus */
	menuitem_destroy(main_menu);
	main_menu = NULL;
	custom_main_menu = NULL;
	screens_menu = NULL;

	/* Forget menu's key reservations */
	input_release_client_keys(NULL);

	if (menu_key != NULL)
		free(menu_key);
	if (enter_key != NULL)
		free(enter_key);
	if (up_key != NULL)
		free(up_key);
	if (down_key != NULL)
		free(down_key);
	if (left_key != NULL)
		free(left_key);
	if (right_key != NULL)
		free(right_key);
	keymask = 0;

	return 0;
}
MenuItem *menuitem_create_numeric(char *id, MenuEventFunc(*event_func),
	char *text, Client *client, int minvalue, int maxvalue, int value)
{
	MenuItem *new_item;

	debug(RPT_DEBUG, "%s(id=[%s], event_func=%p, text=\"%s\", minvalue=%d, maxvalue=%d, value=%d)",
			__FUNCTION__, id, event_func, text, minvalue, minvalue, value);

	new_item = menuitem_create(MENUITEM_NUMERIC, id, event_func, text, client);
	if (new_item != NULL) {
		new_item->data.numeric.maxvalue = maxvalue;
		new_item->data.numeric.minvalue = minvalue;
		new_item->data.numeric.value = value;
		new_item->data.numeric.edit_str = malloc(MAX_NUMERIC_LEN);
		if (new_item->data.numeric.edit_str == NULL) {
			menuitem_destroy(new_item);
			return NULL;
		}
	}

	return new_item;
}