#include <string.h>
#include <stdio.h>
#include <unistd.h>
+#include <ctype.h>
#include <json-c/json.h>
const char *scope = NULL;
const char *prefix = NULL;
const char *postfix = NULL;
+char *capi = NULL;
int priv = -1;
-int conc = -1;
+int noconc = -1;
/**
* Search for a reference of type "#/a/b/c" int the
return path.object;
}
+char *cify(const char *str)
+{
+ char *r = strdup(str);
+ int i = 0;
+ while (r && r[i]) {
+ if (!isalnum(r[i]))
+ r[i] = '_';
+ i++;
+ }
+ return r;
+}
-char *make_desc(struct json_object *o)
+char *make_info(const char *text, int split)
{
const char *a, *b;
char *desc, c, buf[3];
size_t len;
int i, pos, e;
- a = b = json_object_to_json_string_ext(root, 0);
+ /* estimated length */
+ a = b = text;
len = 1;
while((c = *b++)) {
len += 1 + ('"' == c);
oom(desc);
len = pos = 0;
+ if (!split)
+ desc[len++] = '"';
b = a;
while((c = *b++)) {
if (c == '"') {
}
i = e = 0;
while (buf[i]) {
- if (pos >= 77 && !e) {
- desc[len++] = '"';
- desc[len++] = '\n';
- pos = 0;
- }
- if (pos == 0) {
- desc[len++] = ' ';
- desc[len++] = ' ';
- desc[len++] = ' ';
- desc[len++] = ' ';
- desc[len++] = '"';
- pos = 5;
+ if (split) {
+ if (pos >= 77 && !e) {
+ desc[len++] = '"';
+ desc[len++] = '\n';
+ pos = 0;
+ }
+ if (pos == 0) {
+ desc[len++] = ' ';
+ desc[len++] = ' ';
+ desc[len++] = ' ';
+ desc[len++] = ' ';
+ desc[len++] = '"';
+ pos = 5;
+ }
}
c = buf[i++];
desc[len++] = c;
}
}
desc[len++] = '"';
- desc[len++] = '\n';
+ if (split)
+ desc[len++] = '\n';
desc[len] = 0;
return desc;
}
+char *make_desc(struct json_object *o)
+{
+ return make_info(json_object_to_json_string_ext(root, 0), 1);
+}
+
struct json_object *permissions_of_verb(struct json_object *obj)
{
struct json_object *x, *y;
n = a_perms ? json_object_array_length(a_perms) : 0;
if (n) {
- printf("static const struct afb_auth _afb_auths_v2_%s[] = {\n" , api);
+ printf("static const struct afb_auth _afb_auths_v2_%s[] = {\n" , capi);
i = 0;
while (i < n) {
printf("\t{ %s }", json_object_get_string(json_object_array_get_idx(a_perms, i)));
a_perms = json_object_new_array();
}
- asprintf(&b, "&_afb_auths_v2_%s[%d]", api, json_object_array_length(a_perms));
+ asprintf(&b, "&_afb_auths_v2_%s[%d]", capi, json_object_array_length(a_perms));
x = json_object_new_string(desc);
y = json_object_new_string(b);
json_object_array_add(a_perms, x);
void print_struct_verb(const char *name, struct json_object *obj)
{
- struct json_object *p;
+ struct json_object *p, *i;
+ const char *info;
+
+ info = NULL;
+ if (json_object_object_get_ex(obj, "description", &i))
+ info = json_object_get_string(i);
p = permissions_of_verb(obj);
printf(
printf(
",\n"
" .auth = %s,\n"
+ " .info = %s,\n"
" .session = "
- , p ? json_object_get_string(decl_perm(p)) : "NULL"
+ , p && decl_perm(p) ? json_object_get_string(decl_perm(p)) : "NULL"
+ , info ? make_info(info, 0) : "NULL"
);
print_session(p);
printf(
void process(char *filename)
{
char *desc;
+ const char *info;
/* translate - */
if (!strcmp(filename, "-"))
getvar(&prefix, "#/info/x-binding-c-generator/prefix", "afb_verb_");
getvar(&postfix, "#/info/x-binding-c-generator/postfix", "_cb");
getvarbool(&priv, "#/info/x-binding-c-generator/private", 0);
- getvarbool(&conc, "#/info/x-binding-c-generator/concurrent", 0);
+ getvarbool(&noconc, "#/info/x-binding-c-generator/noconcurrency", 0);
getvar(&api, "#/info/title", "?");
+ info = NULL;
+ getvar(&info, "#/info/description", NULL);
+ capi = cify(api);
/* get the API name */
printf(
"%s"
";\n"
"\n"
- , api, desc
+ , capi, desc
);
enum_verbs(declare_permissions);
print_perms();
printf(
"\n"
"static const struct afb_verb_v2 _afb_verbs_v2_%s[] = {\n"
- , api
+ , capi
);
enum_verbs(print_struct_verb);
printf(
- " { .verb = NULL }\n"
+ " {\n"
+ " .verb = NULL,\n"
+ " .callback = NULL,\n"
+ " .auth = NULL,\n"
+ " .info = NULL,\n"
+ " .session = 0\n"
+ " }\n"
"};\n"
);
printf(
"%sconst struct afb_binding_v2 %s%s = {\n"
" .api = \"%s\",\n"
" .specification = _afb_description_v2_%s,\n"
+ " .info = %s,\n"
" .verbs = _afb_verbs_v2_%s,\n"
" .preinit = %s,\n"
" .init = %s,\n"
" .onevent = %s,\n"
- " .concurrent = %d\n"
+ " .noconcurrency = %d\n"
"};\n"
"\n"
, priv ? "static " : ""
, priv ? "_afb_binding_v2_" : "afbBindingV2"
- , priv ? api : ""
- , api
- , api
+ , priv ? capi : ""
, api
+ , capi
+ , info ? make_info(info, 0) : "NULL"
+ , capi
, preinit ?: "NULL"
, init ?: "NULL"
, onevent ?: "NULL"
- , !!conc
+ , !!noconc
);
/* clean up */