/** * Query for a certain plugin name * @param libname name of plugin * @return pointer to plugin db entry, NULL if not found */ struct olsr_plugin * olsr_get_plugin(const char *libname) { struct olsr_plugin *plugin; /* SOT: Hacked away the funny plugin check which fails if pathname is included */ if (strrchr(libname, '/')) libname = strrchr(libname, '/') + 1; plugin = avl_find_element(&plugin_tree, libname, plugin, p_node); return plugin; }
struct device * device_alias_get(const char *name) { struct alias_device *alias; alias = avl_find_element(&aliases, name, alias, avl); if (alias) return &alias->dev; return alias_device_create(name, NULL); }
void alias_notify_device(const char *name, struct device *dev) { struct alias_device *alias; device_lock(); alias = avl_find_element(&aliases, name, alias, avl); if (alias) alias_set_device(alias, dev); device_unlock(); }
static void ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr, struct ubus_object *obj, struct blob_attr **attrbuf) { printf("-> [obj] ubus_process_invoke\n"); struct ubus_request_data req = { .fd = -1, }; int method; int ret; bool no_reply = false; if (!obj) { ret = UBUS_STATUS_NOT_FOUND; goto send; } if (!attrbuf[UBUS_ATTR_METHOD]) { ret = UBUS_STATUS_INVALID_ARGUMENT; goto send; } if (attrbuf[UBUS_ATTR_NO_REPLY]) no_reply = blob_get_int8(attrbuf[UBUS_ATTR_NO_REPLY]); req.peer = hdr->peer; req.seq = hdr->seq; req.object = obj->id; if (attrbuf[UBUS_ATTR_USER] && attrbuf[UBUS_ATTR_GROUP]) { req.acl.user = blobmsg_get_string(attrbuf[UBUS_ATTR_USER]); req.acl.group = blobmsg_get_string(attrbuf[UBUS_ATTR_GROUP]); req.acl.object = obj->name; } for (method = 0; method < obj->n_methods; method++) if (!obj->methods[method].name || !strcmp(obj->methods[method].name, blob_data(attrbuf[UBUS_ATTR_METHOD]))) goto found; /* not found */ ret = UBUS_STATUS_METHOD_NOT_FOUND; goto send; found: ret = obj->methods[method].handler(ctx, obj, &req, blob_data(attrbuf[UBUS_ATTR_METHOD]), attrbuf[UBUS_ATTR_DATA]); if (req.deferred || no_reply) return; send: ubus_complete_deferred_request(ctx, &req, ret); } void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf) { void (*cb)(struct ubus_context *, struct ubus_msghdr *, struct ubus_object *, struct blob_attr **); struct ubus_msghdr *hdr = &buf->hdr; struct blob_attr **attrbuf; struct ubus_object *obj; uint32_t objid; void *prev_data = NULL; attrbuf = ubus_parse_msg(buf->data); if (!attrbuf[UBUS_ATTR_OBJID]) return; objid = blob_get_u32(attrbuf[UBUS_ATTR_OBJID]); obj = avl_find_element(&ctx->objects, &objid, obj, avl); switch (hdr->type) { case UBUS_MSG_INVOKE: cb = ubus_process_invoke; break; case UBUS_MSG_UNSUBSCRIBE: cb = ubus_process_unsubscribe; break; case UBUS_MSG_NOTIFY: cb = ubus_process_notify; break; default: return; } if (buf == &ctx->msgbuf) { prev_data = buf->data; buf->data = NULL; } cb(ctx, hdr, obj, attrbuf); if (prev_data) { if (buf->data) free(prev_data); else buf->data = prev_data; } }
static int rrdns_parse_response(struct rrdns_context *rctx) { int n, len; struct rrdns_request *req; unsigned char *p, *eom, res[512]; char aname[128], buf[INET6_ADDRSTRLEN]; uint16_t qdcount, ancount, type, cls, dlen, id; uint32_t ttl; HEADER *hdr; len = recv(rctx->socket.fd, res, sizeof(res), 0); if (len < sizeof(*hdr)) return -ENODATA; hdr = (HEADER *)res; id = hdr->id; req = avl_find_element(&rctx->request_ids, &id, req, by_id); if (!req) return -ENOENT; avl_delete(&rctx->request_ids, &req->by_id); qdcount = ntohs(hdr->qdcount); ancount = ntohs(hdr->ancount); eom = res + len; p = res + sizeof(*hdr); while (qdcount-- > 0 && p < eom) { memset(aname, 0, sizeof(aname)); n = dn_expand(res, eom, p, aname, sizeof(aname) - 1); if (n < 0) return -EINVAL; p += n + QFIXEDSZ; } while (ancount-- > 0 && p < eom) { memset(aname, 0, sizeof(aname)); n = dn_expand(res, eom, p, aname, sizeof(aname) - 1); if (n < 0) return -EINVAL; p += n; get16(p, type); get16(p, cls); get32(p, ttl); get16(p, dlen); if (p + dlen > eom) return -EINVAL; if (type == T_PTR) { memset(aname, 0, sizeof(aname)); n = dn_expand(res, eom, p, aname, sizeof(aname) - 1); if (n > 0) { inet_ntop(req->family, &req->addr, buf, sizeof(buf)); blobmsg_add_string(&rctx->blob, buf, aname); } break; } p += dlen; } return 0; }