Exemple #1
0
DbObject *dbObjectNew(size_t dataSize, void *data, bool sharedMemory) {
    DbObject *self;

    if ((self = malloc(sizeof_struct_member(DbObject, dataSize) + dataSize)) == NULL) {
        return NULL;
    }

    if (!dbObjectInit(self, dataSize, data, sharedMemory)) {
        dbObjectDestroy(&self);
        error("DbObject failed to initialize.");
        return NULL;
    }

    return self;
}
Exemple #2
0
void clax_dispatch_command(clax_ctx_t *clax_ctx, clax_http_request_t *req, clax_http_response_t *res)
{
    memset(&command_ctx, 0, sizeof(command_ctx_t));

    char *command = clax_kv_list_find(&req->body_params, "command");
    if (!command || !strlen(command)) {
        clax_dispatch_bad_request(clax_ctx, req, res);
        return;
    }

    strncpy(command_ctx.command, command, sizeof_struct_member(command_ctx_t, command));

    char *timeout = clax_kv_list_find(&req->body_params, "timeout");
    if (timeout && strlen(timeout)) {
        command_ctx.timeout = atoi(timeout);
    }

    pid_t pid = clax_command_start(&command_ctx);
    if (pid <= 0) {
        clax_dispatch_system_error(clax_ctx, req, res);
        return;
    }

    res->status_code = 200;

    clax_kv_list_push(&res->headers, "Transfer-Encoding", "chunked");

    char buf_pid[15];
    snprintf(buf_pid, sizeof(buf_pid), "%d", pid);

    clax_kv_list_push(&res->headers, "Trailer", "X-Clax-Exit");
    clax_kv_list_push(&res->headers, "X-Clax-PID", buf_pid);

    res->body_cb_ctx = &command_ctx;
    res->body_cb = clax_command_read_cb;
}