예제 #1
0
파일: config.c 프로젝트: chenyukang/hybrid
HybridConfig*
hybrid_config_create()
{
	HybridConfig *config;

	config = g_new0(HybridConfig, 1);

	config->config_path = hybrid_config_get_path();

	return config;
}
예제 #2
0
파일: logs.c 프로젝트: bigbo/hybrid
gchar*
hybrid_logs_get_path(HybridAccount *account, const gchar *id)
{
    gchar *path;
	const gchar *config_path;

    config_path = hybrid_config_get_path();
    path = g_strdup_printf("%s/logs/%s/%s/%s",
            config_path, account->proto->info->name,
            account->username, id);

    return path;
}
예제 #3
0
파일: config.c 프로젝트: celiachen/hybrid
gchar*
hybrid_config_get_cert_path(void)
{
    gchar *config_path;
    gchar *cert_path;
    gint   e;

    config_path = hybrid_config_get_path();
    cert_path   = g_strdup_printf("%s/certificates", config_path);

    e = mkdir(cert_path, S_IRWXU|S_IRWXO|S_IRWXG);

    if (e && access(cert_path, R_OK|W_OK)) {
        hybrid_debug_error("config", "%s,cannot create, read or write",
                           cert_path);
        g_free(cert_path);
        return NULL;
    }

    return cert_path;
}
예제 #4
0
파일: logs.c 프로젝트: bigbo/hybrid
HybridLogs*
hybrid_logs_create(HybridAccount *account, const gchar *id)
{
    HybridLogs *log;
    const gchar *config_path;
    gchar *log_path;
    gchar *account_path;
    gchar *final_path;
    gchar *proto_path;
    struct tm *local_time;
    time_t now;
    gint e;

    g_return_val_if_fail(account != NULL, NULL);
    g_return_val_if_fail(id != NULL, NULL);

    now = time(NULL);

    log = g_new0(HybridLogs, 1);

    log->id = g_strdup(id);
    log->time = now;

    config_path = hybrid_config_get_path();
    log_path = g_strdup_printf("%s/logs", config_path);

    proto_path = g_strdup_printf("%s/%s", log_path,
                    account->proto->info->name);
    g_free(log_path);

    e = mkdir(proto_path, S_IRWXU|S_IRWXO|S_IRWXG);

    if (e && access(proto_path, R_OK|W_OK)) {
        hybrid_debug_error("logs", "%s,cannot create, read or write",
                            proto_path);
        g_free(proto_path);

        return NULL;
    }

    /* create log directory for a specified account. */
    account_path = g_strdup_printf("%s/%s", proto_path, account->username);
    g_free(proto_path);

    e = mkdir(account_path, S_IRWXU|S_IRWXO|S_IRWXG);

    if (e && access(account_path, R_OK|W_OK)) {
        hybrid_debug_error("logs", "%s,cannot create, read or write",
                            account_path);
        g_free(account_path);

        return NULL;
    }


    /* create log directory for a specified account. */
    final_path = g_strdup_printf("%s/%s", account_path, id);
    g_free(account_path);

    e = mkdir(final_path, S_IRWXU|S_IRWXO|S_IRWXG);

    if (e && access(final_path, R_OK|W_OK)) {

        hybrid_debug_error("logs", "%s,cannot create, read or write",
                            final_path);
        g_free(final_path);

        return NULL;
    }

    /* create/get the log file for a specified chat id, with the name
     * in form of id_date.xml */
    local_time = localtime(&now);

    log->log_path = g_strdup_printf("%s/%d_%d_%d.xml",
                    final_path, local_time->tm_year + 1900,
                    local_time->tm_mon + 1, local_time->tm_mday);

    g_free(final_path);

    log->root = xmlnode_root_from_file(log->log_path);

    return log;
}