Example #1
0
File: buf.c Project: SDAIA/kore
u_int8_t *
kore_buf_release(struct kore_buf *buf, size_t *len)
{
	u_int8_t	*p;

	p = buf->data;
	*len = buf->offset;

	buf->data = NULL;
	kore_buf_free(buf);

	return (p);
}
Example #2
0
int things_list(struct http_request *req) {
    int rc;
    char *zErrMsg = 0;
    char *query = "SELECT * FROM found ORDER BY last DESC";
    template_t tmpl;
	attrlist_t attributes;

    struct timespec when;

    buf = kore_buf_create(mb);

    if(!thing) thing = hashmap_new();

    // load template from assets
    template_load
        (asset_things_list_html, asset_len_things_list_html, &tmpl);

    // initialise attribute list
    attributes = attrinit();

    if( ! parse_datetime(&when, "now", NULL) )
        kore_log(LOG_ERR,"parse-datetime error");
    else {
        struct tm *tt;
        tt = localtime (&when.tv_sec);
        mktime(tt);
        strftime(line, ml, "Dowse :: %d %m %Y - %H:%M:%S", tt);
        attrcat(attributes, "title", line);
    }
    
    sqlquery(query, things_list_cb, attributes);

    template_apply(&tmpl, attributes, buf);

	http_response(req, 200, buf->data, buf->offset);

    template_free(&tmpl);
    attrfree(attributes);

    kore_buf_free(buf);


	return (KORE_RESULT_OK);
}
Example #3
0
int thing_show(struct http_request *req) {
    int rc;
    template_t tmpl;
	attrlist_t attributes;
    char *zErrMsg = 0;
    char *macaddr;

	http_populate_get(req);

    // we shouldn't free the result in macaddr
	if (http_argument_get_string(req, "macaddr", &macaddr))
		kore_log(LOG_DEBUG, "thing_show macaddr %s",macaddr);
    else
        kore_log(LOG_ERR,"thing_show get argument error");

    // prepare query
    snprintf(line,ml,"SELECT * FROM found WHERE macaddr = '%s'",macaddr);
    
    // allocate output buffer
    buf = kore_buf_create(mb);

    // load template
    template_load
        (asset_thing_show_html, asset_len_thing_show_html, &tmpl);
    attributes = attrinit();

    attrcat(attributes, "title", "Dowse information panel");

    // SQL query
    sqlquery(line, thing_show_cb, attributes);

    template_apply(&tmpl,attributes,buf);

	http_response(req, 200, buf->data, buf->offset);

    template_free(&tmpl);
    attrfree(attributes);

    kore_buf_free(buf);

	return (KORE_RESULT_OK);

}