예제 #1
0
int main (int argc, char *argv[])
{
    int res = 1;

    if (argc != 3) {
        fprintf(stderr, "Usage: %s < unix:<socket_path> / tcp:<address>:<port> > <request_payload>\n", (argc > 0 ? argv[0] : ""));
        goto fail0;
    }

    char *connect_address = argv[1];
    char *request_payload_string = argv[2];

    BLog_InitStderr();

    BTime_Init();

    NCDValMem_Init(&request_mem);

    if (!NCDValParser_Parse(request_payload_string, strlen(request_payload_string), &request_mem, &request_value)) {
        BLog(BLOG_ERROR, "BReactor_Init failed");
        goto fail1;
    }

    if (!BNetwork_GlobalInit()) {
        BLog(BLOG_ERROR, "BNetwork_Init failed");
        goto fail1;
    }

    if (!BReactor_Init(&reactor)) {
        BLog(BLOG_ERROR, "BReactor_Init failed");
        goto fail1;
    }

    struct BConnection_addr addr;
    if (!make_connect_addr(connect_address, &addr)) {
        goto fail2;
    }

    if (!NCDRequestClient_Init(&client, addr, &reactor, NULL, client_handler_error, client_handler_connected)) {
        BLog(BLOG_ERROR, "NCDRequestClient_Init failed");
        goto fail2;
    }

    have_request = 0;

    res = BReactor_Exec(&reactor);

    if (have_request) {
        NCDRequestClientRequest_Free(&request);
    }
    NCDRequestClient_Free(&client);
fail2:
    BReactor_Free(&reactor);
fail1:
    NCDValMem_Free(&request_mem);
    BLog_Free();
fail0:
    DebugObjectGlobal_Finish();
    return res;
}
예제 #2
0
static void decode_value_eval (NCDCall call)
{
    if (NCDCall_ArgCount(&call) != 1) {
        return FunctionLog(&call, BLOG_ERROR, "decode_value: need one argument");
    }
    // Evaluate the string to a temporary mem, not ResMem.
    // Otherwise the ResMem could get resized while we're
    // parsing a string within it, and boom.
    NCDValMem temp_mem;
    NCDValMem_Init(&temp_mem, NCDCall_Iparams(&call)->string_index);
    NCDValRef arg = NCDCall_EvalArg(&call, 0, &temp_mem);
    if (NCDVal_IsInvalid(arg)) {
        goto fail1;
    }
    if (!NCDVal_IsString(arg)) {
        FunctionLog(&call, BLOG_ERROR, "decode_value: argument not a string");
        goto fail1;
    }
    NCDValRef value;
    int res = NCDValParser_Parse(NCDVal_StringMemRef(arg), NCDCall_ResMem(&call), &value);
    if (!res) {
        FunctionLog(&call, BLOG_ERROR, "decode_value: NCDValParser_Parse failed");
        goto fail1;
    }
    NCDCall_SetResult(&call, value);
fail1:
    NCDValMem_Free(&temp_mem);
}
예제 #3
0
static int parse_value (NCDModuleInst *i, MemRef str, NCDValMem *mem, NCDValRef *out)
{
    if (!NCDValParser_Parse(str, mem, out)) {
        ModuleLog(i, BLOG_ERROR, "failed to parse value");
        return 0;
    }
    
    return 1;
}