Skip to content
Snippets Groups Projects
Commit 8a345f43 authored by Roland's avatar Roland
Browse files
parents d33377e4 10def224
No related branches found
No related tags found
No related merge requests found
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-config-mode-plz
PKG_VERSION:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
PKG_BUILD_DEPENDS := respondd
include $(GLUONDIR)/include/package.mk
PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG)
define Package/gluon-config-mode-zip
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Set ZIP-Code location of a node
DEPENDS:=gluon-config-mode-core-virtual +gluon-node-info
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Configure
endef
define Build/Compile
$(call Build/Compile/Default)
$(call GluonBuildI18N,gluon-config-mode-zip,i18n)
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
endef
define Package/gluon-config-mode-zip/install
$(INSTALL_DIR) $(1)/lib/gluon/respondd
$(CP) $(PKG_BUILD_DIR)/respondd.so $(1)/lib/gluon/respondd/node-info-zip.so
$(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/
$(call GluonInstallI18N,gluon-config-mode-zip,$(1))
endef
$(eval $(call BuildPackage,gluon-config-mode-zip))
msgid ""
msgstr ""
"Project-Id-Version: gluon-config-mode-zip\n"
"PO-Revision-Date: 2016-12-19 02:18+0100\n"
"Last-Translator: Philippe Käufer <freifunk@philhil.de>\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
msgid "gluon-config-mode:zip-help"
"Some nice Text about the ZIP-Code "
"and how it help for subnetting."
msgstr ""
"Ein Netter Text warum die PLZ benötigt "
"wird."
msgid "ZIP-Code"
msgstr "PLZ"
msgid "e.g. %s"
msgstr "z.B. %s"
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
msgid "gluon-config-mode:zip-help"
"Some nice Text about the ZIP-Code "
"and how it help for subnetting."
msgstr ""
msgid "ZIP-Code"
msgstr ""
msgid "e.g. %s"
msgstr ""
local cbi = require "luci.cbi"
local i18n = require "luci.i18n"
local uci = luci.model.uci.cursor()
local M = {}
function M.section(form)
local text = i18n.translate("gluon-config-mode:zip-help")
local s = form:section(cbi.SimpleSection, nil, text)
local o = s:option(cbi.Value, "_zip", "ZIP-Code")
o.value = uci:get_first("gluon-node-info", "location", "zip")
o.rmempty = false
o.datatype = "float"
o.description = i18n.translatef("e.g. %s", "70499")
end
function M.handle(data)
local sname = uci:get_first("gluon-node-info", "location")
uci:set("gluon-node-info", sname, "zip", data._zip:trim())
uci:save("gluon-node-info")
uci:commit("gluon-node-info")
end
return M
all: respondd.so
CFLAGS += -Wall
respondd.so: respondd.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil -luci
/*
Copyright (c) 2016, Matthias Schiffer <mschiffer@universe-factory.net> and Philippe Käufer <freifunk@philhil.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <respondd.h>
#include <json-c/json.h>
#include <libgluonutil.h>
#include <uci.h>
#include <stdlib.h>
#include <string.h>
static struct uci_section * get_first_section(struct uci_package *p, const char *type) {
struct uci_element *e;
uci_foreach_element(&p->sections, e) {
struct uci_section *s = uci_to_section(e);
if (!strcmp(s->type, type))
return s;
}
return NULL;
}
static struct json_object * get_number(struct uci_context *ctx, struct uci_section *s, const char *name) {
const char *val = uci_lookup_option_string(ctx, s, name);
if (!val || !*val)
return NULL;
char *end;
double d = strtod(val, &end);
if (*end)
return NULL;
struct json_object *jso = json_object_new_double(d);
json_object_set_serializer(jso, json_object_double_to_json_string, "%.8f", NULL);
return jso;
}
static void maybe_add_number(struct uci_context *ctx, struct uci_section *s, const char *name, struct json_object *parent) {
struct json_object *jso = get_number(ctx, s, name);
if (jso)
json_object_object_add(parent, name, jso);
}
static struct json_object * get_location(struct uci_context *ctx, struct uci_package *p) {
struct uci_section *s = get_first_section(p, "location");
if (!s)
return NULL;
struct json_object *ret = json_object_new_object();
maybe_add_number(ctx, s, "zip", ret);
return ret;
}
static struct json_object * respondd_provider_nodeinfo_zip(void) {
struct json_object *ret = json_object_new_object();
struct uci_context *ctx = uci_alloc_context();
ctx->flags &= ~UCI_FLAG_STRICT;
struct uci_package *p;
if (!uci_load(ctx, "gluon-node-info", &p)) {
struct json_object *location = get_location(ctx, p);
if (location)
json_object_object_add(ret, "location", location);
}
uci_free_context(ctx);
return ret;
}
const struct respondd_provider_info respondd_providers[] = {
{"nodeinfo-zip", respondd_provider_nodeinfo_zip},
{}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment