Beispiel #1
0
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    const char *msg;
    struct chatlog *log = self->chatwin->log;

    if (argc == 0) {
        if (log->log_on)
            msg = "Logging for this window is ON. Type \"/log off\" to disable.";
        else
            msg = "Logging for this window is OFF. Type \"/log on\" to enable.";

        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
        return;
    }

    const char *swch = argv[1];

    if (!strcmp(swch, "1") || !strcmp(swch, "on")) {
        char myid[TOX_FRIEND_ADDRESS_SIZE];
        tox_get_address(m, (uint8_t *) myid);

        if (self->is_chat) {
            Friends.list[self->num].logging_on = true;
            log_enable(self->name, myid, Friends.list[self->num].pub_key, log, LOG_CHAT);
        } else if (self->is_prompt) {
            log_enable(self->name, myid, NULL, log, LOG_PROMPT);
        } else if (self->is_groupchat) {
            log_enable(self->name, myid, NULL, log, LOG_GROUP);
        }

        msg = "Logging enabled";
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
        return;
    } else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
        if (self->is_chat)
            Friends.list[self->num].logging_on = false;

        log_disable(log);

        msg = "Logging disabled";
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
        return;
    }

    msg = "Invalid option. Use \"/log on\" and \"/log off\" to toggle logging.";
    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
Beispiel #2
0
/* renames chatlog file replacing src with dest.
   Returns 0 on success or if no log exists, -1 on failure. */
int rename_logfile(char *src, char *dest, const char *selfkey, const char *otherkey, int winnum)
{
    ToxWindow *toxwin = get_window_ptr(winnum);
    struct chatlog *log = NULL;
    bool log_on = false;

    /* disable log if necessary and save its state */
    if (toxwin != NULL) {
        log = toxwin->chatwin->log;
        log_on = log->log_on;
    }

    if (log_on)
        log_disable(log);

    char newpath[MAX_STR_SIZE];
    char oldpath[MAX_STR_SIZE];

    if (get_log_path(oldpath, sizeof(oldpath), src, selfkey, otherkey, LOG_CHAT) == -1)
        goto on_error;

    if (!file_exists(oldpath))
        return 0;

    if (get_log_path(newpath, sizeof(newpath), dest, selfkey, otherkey, LOG_CHAT) == -1)
        goto on_error;

    if (rename(oldpath, newpath) != 0)
        goto on_error;

    if (log_on)
        log_enable(dest, selfkey, otherkey, log, LOG_CHAT);

    return 0;

on_error:
    if (log_on)
        log_enable(src, selfkey, otherkey, log, LOG_CHAT);

    return -1;
}
Beispiel #3
0
// -----------------------------------------------------------------------
int ectl_log_state_set(int state)
{
	int res = -1;
	LOG(L_ECTL, "ECTL log state set: %i", state);
	if (state == ECTL_OFF) {
		log_disable();
		res = 0;
	} else if (state == ECTL_ON) {
		res = log_enable();
	}
	return res;
}
Beispiel #4
0
Datei: log.c Projekt: saper/em400
// -----------------------------------------------------------------------
int log_init(struct cfg_em400 *cfg)
{
	int res;
	int ret = E_ALLOC;

	log_file = strdup(cfg->log_file);
	if (!log_file) {
		ret = E_ALLOC;
		goto cleanup;
	}

	if (cfg->log_enabled) {
		ret = log_enable();
		if (ret != E_OK) {
			goto cleanup;
		}
	}

	// set up thresholds
	res = log_setup_levels(cfg->log_levels);
	if (res < 0) {
		ret = E_LEVELS;
		goto cleanup;
	}

	pthread_mutex_init(&log_mutex, NULL);

	// initialize deassembler
	emd = emdas_create(cfg->cpu_mod ? EMD_ISET_MX16 : EMD_ISET_MERA400, (emdas_getfun) mem_get);
	if (!emd) {
		ret = E_DASM;
		goto cleanup;
	}

	emdas_set_nl(emd, '\0');
	emdas_set_features(emd, EMD_FEAT_NONE);
	emdas_set_tabs(emd, 0, 0, 0, 0);
	dasm_buf = emdas_get_buf(emd);

	log_initialized = 1;

	return E_OK;

cleanup:
	if (log_f) fclose(log_f);
	free(log_file);
	emdas_destroy(emd);
	return ret;
}
Beispiel #5
0
static void chat_onInit(ToxWindow *self, Tox *m)
{
    curs_set(1);
    int x2, y2;
    getmaxyx(self->window, y2, x2);
    self->x = x2;

    /* Init statusbar info */
    StatusBar *statusbar = self->stb;

    statusbar->status = tox_get_user_status(m, self->num);
    statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;

    char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
    uint16_t s_len = tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
    statusmsg[s_len] = '\0';
    snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
    statusbar->statusmsg_len = s_len;

    char nick[TOX_MAX_NAME_LENGTH];
    int n_len = get_nick_truncate(m, nick, self->num);
    snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
    statusbar->nick_len = n_len;

    /* Init subwindows */
    ChatContext *ctx = self->chatwin;

    statusbar->topline = subwin(self->window, 2, x2, 0, 0);
    ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
    ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);

    ctx->hst = calloc(1, sizeof(struct history));
    ctx->log = calloc(1, sizeof(struct chatlog));

    if (ctx->log == NULL || ctx->hst == NULL)
        exit_toxic_err("failed in chat_onInit", FATALERR_MEMORY);

    line_info_init(ctx->hst);

    if (friends[self->num].logging_on)
        log_enable(nick, friends[self->num].pub_key, ctx->log);

    execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);

    scrollok(ctx->history, 0);
    wmove(self->window, y2 - CURS_Y_OFFSET, 0);
}
Beispiel #6
0
bool load_log_settings(const char *filename) {
    //this is a terrible algorithm, but im lazy today
    FILE *f = fopen(filename, "r");
    if(f == NULL)
        return false;
    char linebuf[512], type_name[256], value[256];
    while(!feof(f)) {
        if(fgets(linebuf, 512, f) == NULL)
            continue;
#ifdef WIN32
        if (sscanf(linebuf, "%[^=]=%[^\n]\n", type_name, value) != 2)
            continue;
#else
        if (sscanf(linebuf, "%[^=]=%[^\r\n]\n", type_name, value) != 2)
            continue;
#endif

        if(type_name[0] == '\0' || type_name[0] == '#')
            continue;

        //first make sure we understand the value
        bool enabled;
        if(!strcasecmp(value, "on") || !strcasecmp(value, "yes") || !strcasecmp(value, "enabled") || !strcmp(value, "1"))
            enabled = true;
        else if(!strcasecmp(value, "off") || !strcasecmp(value, "no") || !strcasecmp(value, "disabled") || !strcmp(value, "0"))
            enabled = false;
        else {
            printf("Unable to parse value '%s' from %s. Skipping line.", value, filename);
            continue;
        }

        int r;
        //first see if it is a category name
        for(r = 0; r < NUMBER_OF_LOG_CATEGORIES; r++) {
            if(!strcasecmp(log_category_names[r], type_name))
                break;
        }
        if(r != NUMBER_OF_LOG_CATEGORIES) {
            //matched a category.
            int k;
            for(k = 0; k < NUMBER_OF_LOG_TYPES; k++) {
                if(log_type_info[k].category != r)
                    continue;   //does not match this category.
                if(enabled)
                    log_enable(LogType(k));
                else
                    log_disable(LogType(k));
            }
            continue;
        }

        for(r = 0; r < NUMBER_OF_LOG_TYPES; r++) {
            if(!strcasecmp(log_type_info[r].name, type_name))
                break;
        }
        if(r == NUMBER_OF_LOG_TYPES) {
            printf("Unable to locate log type %s from file %s. Skipping line.", type_name, filename);
            continue;
        }

        //got it all figured out, do something now...
        if(enabled)
            log_enable(LogType(r));
        else
            log_disable(LogType(r));
    }
    fclose(f);
    return true;
}
Beispiel #7
0
int main(void) {

	if (!mm_sec_start()) {

		log_print("Secure memory pool did not start correctly.");
		return 1;
	}

	else if (sizeof(stringer_t) != 4) {

		log_print("The string options variable should be 4 bytes/32 bits.");
		return 1;
	}

	/*chr_t *data = "Hello world.";
	size_t len = ns_length_get(data);
	stringer_t *place =
		PLACER(data, len);

	log_print("%.*s\n%.*s\n", st_length_int(PLACER(data, len)), st_char_get(PLACER(data, len)),	st_length_int((stringer_t *)place), st_char_get((stringer_t *)place));
	if (st_cmp_cs_eq(PLACER(st_data_get(constant), st_length_get(constant)), constant) || memcmp("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", st_data_get(constant), st_length_get(constant)))
		exit(1);*/

	// Since were intentionally going to trigger errors, disable standard out while doing so.
	log_disable();
	// Check that we can't specify a length greater than the available buffer.
	if (!check_string_logic(MANAGED_T | CONTIGUOUS | HEAP) || !check_string_logic(MANAGED_T | JOINTED | HEAP)	|| !check_string_logic(MAPPED_T | JOINTED | HEAP)) {
		log_print("--------------------------------------- LOGIC -------------------------------------------\n");
		log_print("String logic checks failed.");
		return 1;
	}
	log_enable();

	log_print("--------------------------------------- CONSTANT ----------------------------------------\n%28.28s = %.*s",
			"constant[fixed+contiguous]", st_length_int(constant), st_char_get(constant));

	log_print("--------------------------------------- IMPORT ------------------------------------------");
	if (!check_string_import()) {
		log_print("Import check failed.");
		return 1;
	}

	// Begin allocation checks.
	log_print("--------------------------------------- ALLOCATION --------------------------------------");

	if (!check_string_alloc("nuller[heap+contiguous]", NULLER_T | CONTIGUOUS | HEAP) || !check_string_alloc("block[heap+contiguous]", BLOCK_T | CONTIGUOUS | HEAP)
			|| !check_string_alloc("managed[heap+contiguous]", MANAGED_T | CONTIGUOUS | HEAP)) {
		log_print("Standard allocation checks failed.");
		return 1;
	}

	if (!check_string_alloc("nuller[heap+jointed]", NULLER_T | JOINTED | HEAP) || !check_string_alloc("block[heap+jointed]", BLOCK_T | JOINTED | HEAP)
			|| !check_string_alloc("managed[heap+jointed]", MANAGED_T | JOINTED | HEAP) || !check_string_alloc("mapped[heap+jointed]", MAPPED_T | JOINTED | HEAP)) {
		log_print("Jointed allocation checks failed.");
		return 1;
	}

	if (!check_string_alloc("nuller[secure+contiguous]", NULLER_T | CONTIGUOUS | SECURE) || !check_string_alloc("block[secure+contiguous]", BLOCK_T | CONTIGUOUS | SECURE)
			|| !check_string_alloc("managed[secure+contiguous]", MANAGED_T | CONTIGUOUS | SECURE)) {
		log_print("Secure allocation of contiguous types failed.");
		return 1;
	}

	if (!check_string_alloc("nuller[secure+jointed]", NULLER_T | JOINTED | SECURE) || !check_string_alloc("block[secure+jointed]", BLOCK_T | JOINTED | SECURE)
			|| !check_string_alloc("managed[secure+jointed]", MANAGED_T | JOINTED | SECURE) || !check_string_alloc("mapped[secure+jointed]", MAPPED_T | JOINTED | SECURE)) {
		log_print("Secure allocation of jointed types failed.");
		return 1;
	}

	// Begin reallocation checks.
	log_print("-------------------------------------- REALLOCATION -------------------------------------");

	if (!check_string_realloc("nuller[heap+contiguous]", NULLER_T | CONTIGUOUS | HEAP) || !check_string_realloc("block[heap+contiguous]", BLOCK_T | CONTIGUOUS | HEAP)
			|| !check_string_realloc("managed[heap+contiguous]", MANAGED_T | CONTIGUOUS | HEAP)) {
		log_print("Standard reallocation checks failed.");
		return 1;
	}

	if (!check_string_realloc("nuller[heap+jointed]", NULLER_T | JOINTED | HEAP) || !check_string_realloc("block[heap+jointed]", BLOCK_T | JOINTED | HEAP)
			|| !check_string_realloc("managed[heap+jointed]", MANAGED_T | JOINTED | HEAP) || !check_string_realloc("mapped[heap+jointed]", MAPPED_T | JOINTED | HEAP)) {
		log_print("Jointed reallocation checks failed.");
		return 1;
	}

	if (!check_string_realloc("nuller[secure+contiguous]", NULLER_T | CONTIGUOUS | SECURE) || !check_string_realloc("block[secure+contiguous]", BLOCK_T | CONTIGUOUS
			| SECURE) || !check_string_realloc("managed[secure+contiguous]", MANAGED_T | CONTIGUOUS | SECURE)) {
		log_print("Secure reallocation of contiguous types failed.");
		return 1;
	}

	if (!check_string_realloc("nuller[secure+jointed]", NULLER_T | JOINTED | SECURE) || !check_string_realloc("block[secure+jointed]", BLOCK_T | JOINTED | SECURE)
			|| !check_string_realloc("managed[secure+jointed]", MANAGED_T | JOINTED | SECURE) || !check_string_realloc("mapped[secure+jointed]", MAPPED_T | JOINTED | SECURE)) {
		log_print("Secure reallocation of jointed types failed.");
		return 1;
	}

	// Begin duplication checks.
	log_print("-------------------------------------- DUPLICATION --------------------------------------");

	if (!check_string_dupe("nuller[heap+contiguous]", NULLER_T | CONTIGUOUS | HEAP) || !check_string_dupe("block[heap+contiguous]", BLOCK_T | CONTIGUOUS | HEAP)
			|| !check_string_dupe("managed[heap+contiguous]", MANAGED_T | CONTIGUOUS | HEAP)) {
		log_print("Standard duplication checks failed.");
		return 1;
	}

	if (!check_string_dupe("nuller[heap+jointed]", NULLER_T | JOINTED | HEAP) || !check_string_dupe("block[heap+jointed]", BLOCK_T | JOINTED | HEAP) || !check_string_dupe(
			"managed[heap+jointed]", MANAGED_T | JOINTED | HEAP) || !check_string_dupe("mapped[heap+jointed]", MAPPED_T | JOINTED | HEAP)) {
		log_print("Jointed duplication checks failed.");
		return 1;
	}

	if (!check_string_dupe("nuller[secure+contiguous]", NULLER_T | CONTIGUOUS | SECURE) || !check_string_dupe("block[secure+contiguous]", BLOCK_T | CONTIGUOUS | SECURE)
			|| !check_string_dupe("managed[secure+contiguous]", MANAGED_T | CONTIGUOUS | SECURE)) {
		log_print("Secure duplication of contiguous types failed.");
		return 1;
	}

	if (!check_string_dupe("nuller[secure+jointed]", NULLER_T | JOINTED | SECURE) || !check_string_dupe("block[secure+jointed]", BLOCK_T | JOINTED | SECURE)
			|| !check_string_dupe("managed[secure+jointed]", MANAGED_T | JOINTED | SECURE) || !check_string_dupe("mapped[secure+jointed]", MAPPED_T | JOINTED | SECURE)) {
		log_print("Secure duplication of jointed types failed.");
		return 1;
	}

	log_print("-------------------------------------- MERGE --------------------------------------------");
	if (!check_string_merge()) {
		log_print("The merge function failed.");
		return 1;
	}

	log_print("-------------------------------------- PRINT --------------------------------------------");
	if (!check_string_print()) {
		log_print("The print function failed.");
		return 1;
	}

	mm_sec_stop();
	log_print("---------------------------------------- FINISHED ---------------------------------------");
	return 0;
}