資源簡介
可以使用的ubus庫,只需要安裝標準cmake編譯方式進行編譯及安裝即可,編譯ubus之前首先確保系統(tǒng)已經(jīng)安裝了json-c,lua以及l(fā)ibubox.
代碼片段和文件信息
/*
?*?Copyright?(C)?2011?Felix?Fietkau?
?*
?*?This?program?is?free?software;?you?can?redistribute?it?and/or?modify
?*?it?under?the?terms?of?the?GNU?Lesser?General?Public?License?version?2.1
?*?as?published?by?the?Free?Software?Foundation
?*
?*?This?program?is?distributed?in?the?hope?that?it?will?be?useful
?*?but?WITHOUT?ANY?WARRANTY;?without?even?the?implied?warranty?of
?*?MERCHANTABILITY?or?FITNESS?FOR?A?PARTICULAR?PURPOSE.??See?the
?*?GNU?General?Public?License?for?more?details.
?*/
#include?
#include?
#include?“l(fā)ibubus.h“
static?struct?blob_buf?b;
static?int?timeout?=?30;
static?bool?simple_output?=?false;
static?int?verbose?=?0;
static?int?monitor_dir?=?-1;
static?uint32_t?monitor_mask;
static?const?char?*?const?monitor_types[]?=?{
[UBUS_MSG_HELLO]?=?“hello“
[UBUS_MSG_STATUS]?=?“status“
[UBUS_MSG_DATA]?=?“data“
[UBUS_MSG_PING]?=?“ping“
[UBUS_MSG_LOOKUP]?=?“l(fā)ookup“
[UBUS_MSG_INVOKE]?=?“invoke“
[UBUS_MSG_ADD_object]?=?“add_object“
[UBUS_MSG_REMOVE_object]?=?“remove_object“
[UBUS_MSG_SUBSCRIBE]?=?“subscribe“
[UBUS_MSG_UNSUBSCRIBE]?=?“unsubscribe“
[UBUS_MSG_NOTIFY]?=?“notify“
};
static?const?char?*format_type(void?*priv?struct?blob_attr?*attr)
{
static?const?char?*?const?attr_types[]?=?{
[BLOBMSG_TYPE_INT8]?=?“\“Boolean\““
[BLOBMSG_TYPE_INT32]?=?“\“Integer\““
[BLOBMSG_TYPE_STRING]?=?“\“String\““
[BLOBMSG_TYPE_ARRAY]?=?“\“Array\““
[BLOBMSG_TYPE_TABLE]?=?“\“Table\““
};
const?char?*type?=?NULL;
int?typeid;
if?(blob_id(attr)?!=?BLOBMSG_TYPE_INT32)
return?NULL;
typeid?=?blobmsg_get_u32(attr);
if?(typeid? type?=?attr_types[typeid];
if?(!type)
type?=?“\“(unknown)\““;
return?type;
}
static?void?receive_list_result(struct?ubus_context?*ctx?struct?ubus_object_data?*obj?void?*priv)
{
struct?blob_attr?*cur;
char?*s;
int?rem;
if?(simple_output?||?!verbose)?{
printf(“%s\n“?obj->path);
return;
}
printf(“‘%s‘?@%08x\n“?obj->path?obj->id);
if?(!obj->signature)
return;
blob_for_each_attr(cur?obj->signature?rem)?{
s?=?blobmsg_format_json_with_cb(cur?false?format_type?NULL?-1);
printf(“\t%s\n“?s);
free(s);
}
}
static?void?receive_call_result_data(struct?ubus_request?*req?int?type?struct?blob_attr?*msg)
{
char?*str;
if?(!msg)
return;
str?=?blobmsg_format_json_indent(msg?true?simple_output???-1?:?0);
printf(“%s\n“?str);
free(str);
}
static?void?receive_event(struct?ubus_context?*ctx?struct?ubus_event_handler?*ev
??const?char?*type?struct?blob_attr?*msg)
{
char?*str;
str?=?blobmsg_format_json(msg?true);
printf(“{?\“%s\“:?%s?}\n“?type?str);
fflush(stdout);
free(str);
}
static?int?ubus_cli_list(struct?ubus_context?*ctx?int?argc?char?**argv)
{
const?char?*path?=?NULL;
if?(argc?>?1)
return?-2;
if?(argc?==?1)
path?=?argv[0];
return?ubus_lookup(ctx?path?receive_list_result?NULL);
}
static?int?ubus_cli_call(struct?ubus_context?*ctx?int?argc?char?**argv)
{
- 上一篇:94授權(quán)軟件.rar
- 下一篇:Bullfight.rar
評論
共有 條評論