Beispiel #1
0
static void init_global_config(global_conf_st *g_conf, char *file)
{
    if (NULL == file)
    {
	fprintf(stderr, "config file is wrong\n");
	exit(1);
    }
    int L_level = 0;
    xode pnode = xode_from_file(file);
    if (NULL == pnode)
    {
	fprintf(stderr, "config file is wrong\n");
	exit(1);
    }
    int max_thread = xode_get_integer(pnode, "maxThread");
    if (max_thread != -1)
    {
	g_conf->max_thread = max_thread;
    }
    int max_msg_queue_len = xode_get_integer(pnode, "maxMsgQueueLen");
    if (max_msg_queue_len != -1)
    {
	g_conf->max_msg_queue_len = max_msg_queue_len;
    }
    char *log_file = xode_get_string(pnode, "logDir");
    char *redis_conf = xode_get_string(pnode, "redisConf");
    char *reload_file = xode_get_string(pnode, "reloadFile");
    if (log_file == NULL || redis_conf == NULL || reload_file == NULL)
    {
	fprintf(stderr,
		"conf file format wrong ,can't file logDir or redisConf or reload_file\n");
	exit(1);
    }

    snprintf(g_conf->log_dir, sizeof(g_conf->log_dir), "%s", log_file);
    snprintf(g_conf->reload_file, sizeof(g_conf->reload_file), "%s",
	     reload_file);
    snprintf(g_conf->redis_config, sizeof(g_conf->redis_config), "%s",
	     redis_conf);
    char *log_level = xode_get_string(pnode, "logLevel");
    if (log_level != NULL)
    {
	L_level = get_log_level(log_level);
    }
    char program[128];
    memset(program, 0, sizeof(program));
    init_mq(g_conf, pnode);
    snprintf(program, sizeof(program), "%s-%s", PROGRAM,
	     g_conf->receive_mq->task_name);

    gozap_log_init(g_conf->log_dir, L_level, program);

    g_conf->redis_client = redis_client_init(g_conf->redis_config);
    return;
}
Beispiel #2
0
tt_user *users_read(const char *jid) {
	tt_user *user;
	xode cfg, x;
	char *file, *temp;

	if (jid == NULL)
		return NULL;

	if ((file = malloc(strlen(config_dir) + strlen(jid) + 2)) == NULL) {
		perror("malloc()");
		exit(1);
	}
	sprintf(file, "%s/%s", config_dir, jid);

	my_debug(0, "users: Wczytuje plik %s", file);

	if ((cfg = xode_from_file(file)) == NULL) {
		my_debug(0, "users: Nie moge wczytac usera");
		return NULL;
	}

	user = (tt_user*)malloc(sizeof(tt_user));
	memset(user, 0, sizeof(tt_user));

	x = xode_get_tag(cfg, "jid");
	temp = xode_get_data(x);
	my_strcpy(user->jid, temp);

	x = xode_get_tag(cfg, "tid");
	temp = xode_get_data(x);
	my_strcpy(user->tid_short, temp);

	user->tid = malloc(strlen(user->tid_short) + strlen("@tlen.pl") + 1);
	sprintf(user->tid, "*****@*****.**", user->tid_short);

	x = xode_get_tag(cfg, "password");
	temp = xode_get_data(x);
	my_strcpy(user->password, temp);

	user->tlen_sesja = NULL;
	user->tlen_loged = 0;
	user->last_ping_time = 0;

	user->roster = NULL;
	user->search = NULL;
	user->search_id = NULL;

	x = xode_get_tag(cfg, "notify");

	temp = xode_get_attrib(x, "mail");
	if (temp != NULL) {
		if (strcmp(temp, "1") == 0) {
			user->mailnotify = 1;
		} else if (strcmp(temp, "0") == 0) {
			user->mailnotify = 0;
		} else {
			user->mailnotify = 0;
			my_debug(0, "Blad w pliku");
		}
	} else {
		user->mailnotify = 0;
	}

	temp = xode_get_attrib(x, "typing");
	if (temp != NULL) {
		if (strcmp(temp, "1") == 0) {
			user->typingnotify = 1;
		} else if (strcmp(temp, "0") == 0) {
			user->typingnotify = 0;
		} else {
			user->typingnotify = 0;
			my_debug(0, "Blad w pliku");
		}
	} else {
		user->typingnotify = 0;
	}

	temp = xode_get_attrib(x, "alarm");
	if (temp != NULL) {
		if (strcmp(temp, "1") == 0) {
			user->alarmnotify = 1;
		} else if (strcmp(temp, "0") == 0) {
			user->alarmnotify = 0;
		} else {
			user->alarmnotify = 0;
			my_debug(0, "Blad w pliku");
		}
	} else {
		user->alarmnotify = 0;
	}

	user->status = NULL;
	user->status_type = 0;

	user->jabber_status = NULL;
	user->jabber_status_type = NULL;

	xode_free(cfg);
	t_free(file);

	return user;
}