static bool celix_logAdmin_executeCommand()

in bundles/logging/log_admin/src/celix_log_admin.c [592:643]


static bool celix_logAdmin_executeCommand(void *handle, const char *commandLine, FILE *outStream, FILE *errorStream) {
    celix_log_admin_t* admin = handle;

    char *cmd = celix_utils_strdup(commandLine); //note command_line_str should be treated as const.
    const char *subCmd = NULL;
    char *savePtr = NULL;

    strtok_r(cmd, " ", &savePtr);
    subCmd = strtok_r(NULL, " ", &savePtr);
    if (subCmd != NULL) {
        if (strncmp("log", subCmd, 64) == 0) {
            //expect 1 or 2 tokens
            const char* arg1 = strtok_r(NULL, " ", &savePtr);
            const char* arg2 = strtok_r(NULL, " ", &savePtr);
            if (arg1 != NULL && arg2 != NULL) {
                celix_logAdmin_setLogLevelCmd(admin, arg1, arg2, outStream, errorStream);
            } else if (arg1 != NULL) {
                celix_logAdmin_setLogLevelCmd(admin, NULL, arg1, outStream, errorStream);
            } else {
                fprintf(errorStream, "Invalid arguments. For log command expected 1 or 2 args. (<log_level> or <log_service_selection> <log_level>");
            }
        } else if (strncmp("sink", subCmd, 64) == 0) {
            const char* arg1 = strtok_r(NULL, " ", &savePtr);
            const char* arg2 = strtok_r(NULL, " ", &savePtr);
            if (arg1 != NULL && arg2 != NULL) {
                celix_logAdmin_setSinkEnabledCmd(admin, arg1, arg2, outStream, errorStream);
            } else if (arg1 != NULL) {
                celix_logAdmin_setSinkEnabledCmd(admin, NULL, arg1, outStream, errorStream);
            } else {
                fprintf(errorStream, "Invalid arguments. For log command expected 1 or 2 args. (<true|false> or <log_service_selection> <true|false>");
            }
        } else if (strncmp("detail", subCmd, 64) == 0) {
            const char* arg1 = strtok_r(NULL, " ", &savePtr);
            const char* arg2 = strtok_r(NULL, " ", &savePtr);
            if (arg1 != NULL && arg2 != NULL) {
                celix_logAdmin_setLogDetailedCmd(admin, arg1, arg2, outStream, errorStream);
            } else if (arg1 != NULL) {
                celix_logAdmin_setLogDetailedCmd(admin, NULL, arg1, outStream, errorStream);
            } else {
                fprintf(errorStream, "Invalid arguments. For log command expected 1 or 2 args. (<true|false> or <log_service_selection> <true|false>");
            }
        } else {
            fprintf(errorStream, "Unexpected sub command '%s'. Expected empty, log or sink command.'n", subCmd);
        }
    } else {
        celix_logAdmin_InfoCmd(admin, outStream, errorStream);
    }

    free(cmd);

    return true;
}