Exemplo n.º 1
0
static gint
hybrid_blist_cache_init(HybridConfig *config)
{
	gchar *cache_file_name;
	HybridBlistCache *cache;
	xmlnode *root;
	gint err;

	g_return_val_if_fail(config != NULL, HYBRID_ERROR);

	cache_file_name = g_strdup_printf("%s/blist.xml", config->config_path);

	hybrid_debug_info("config", "init the blist cache from %s",
			cache_file_name);

	cache = g_new0(HybridBlistCache, 1);
	cache->cache_file_name = cache_file_name;

	config->blist_cache = cache;

	if (!(root = xmlnode_root_from_file(cache_file_name))) {
		const gchar *root_string = "<blist></blist>";
		root = xmlnode_root(root_string, strlen(root_string));
		cache->root = root;

		goto blist_cache_init_null;
	}

	if (!root) {
		hybrid_debug_error("config", "FATAL, init blist cache");
		return HYBRID_ERROR;
	}

	cache->root = root;

	/* Load the cached buddy list */
	goto blist_cache_init_fin;

blist_cache_init_null:
	/* initialize the xml context since we don't have local cache */
	xmlnode_new_child(root, "accounts");

	xmlnode_save_file(root, cache->cache_file_name);

blist_cache_init_fin:
	/* initialize the icon path. */
	config->icon_path = g_strdup_printf("%s/icons", config->config_path);

	err = mkdir(config->icon_path, S_IRWXU|S_IRWXO|S_IRWXG);

	if (err && access(config->icon_path, R_OK|W_OK)) {
		hybrid_debug_error("config", "%s,cannot create, read or write",
				config->icon_path);
		g_free(config->icon_path);

		return HYBRID_ERROR;
	}

	return HYBRID_OK;
}
Exemplo n.º 2
0
void
hybrid_pref_save(void)
{
    g_return_if_fail(hybrid_pref != NULL);
    g_return_if_fail(hybrid_pref->root != NULL);

    xmlnode_save_file(hybrid_pref->root, hybrid_pref->filename);
}
Exemplo n.º 3
0
void
hybrid_blist_cache_flush()
{
    HybridBlistCache *cache;

    cache = global_config->blist_cache;

    xmlnode_save_file(cache->root, cache->cache_file_name);
}
Exemplo n.º 4
0
Arquivo: logs.c Projeto: bigbo/hybrid
gint
hybrid_logs_write(HybridLogs *log, const gchar *name, const gchar *msg,
                    gboolean sendout)
{
    xmlnode *time_node;
    xmlnode *name_node;
    xmlnode *cont_node;
    xmlnode *node;
    time_t now;
    const gchar *body;
    struct tm *local_time;
    gchar time_str[128];

    g_return_val_if_fail(log != NULL, HYBRID_ERROR);
    g_return_val_if_fail(name != NULL, HYBRID_ERROR);

    now = time(NULL);

    local_time = localtime(&now);

    /* log file doesn't exist, we create one. */
    if (!log->root) {
        body = "<root></root>";
        log->root = xmlnode_root(body, strlen(body));
    }

    node = xmlnode_new_child(log->root, "m");
    if (sendout) {
        xmlnode_new_prop(node, "type", "o");

    } else {
        xmlnode_new_prop(node, "type", "i");
    }

    time_node = xmlnode_new_child(node, "t");

    memset(time_str, 0, sizeof(time_str));
    strftime(time_str, sizeof(time_str) - 1, "%H:%M:%S", local_time);

    xmlnode_set_content(time_node, time_str);

    name_node = xmlnode_new_child(node, "n");
    xmlnode_set_content(name_node, name);

    cont_node = xmlnode_new_child(node, "c");
    xmlnode_set_content(cont_node, msg);

    xmlnode_save_file(log->root, log->log_path);

    return HYBRID_OK;
}
Exemplo n.º 5
0
gint
hybrid_logs_write(HybridLogs *log, const gchar *name, const gchar *msg,
					gboolean sendout)
{
	xmlnode *head_node;
	xmlnode *body_node;
	xmlnode *time_node;
	xmlnode *font_node;
	xmlnode *name_node;
	xmlnode *cont_node;
	xmlnode *node;
	time_t now;
	const gchar *body;
	gchar *title;
	gchar *content;
	struct tm *local_time;
	gchar time_str[128];

	g_return_val_if_fail(log != NULL, HYBRID_ERROR);
	g_return_val_if_fail(name != NULL, HYBRID_ERROR);

	now = time(NULL);

	local_time = localtime(&now);


	/* log file doesn't exist, we create one. */
	if (!log->root) {
		body = "<html></html>";

		title = g_strdup_printf(_("Conversation with %s (%s) at %d-%d-%d"),
				name, log->id, local_time->tm_year + 1900,
				local_time->tm_mon, local_time->tm_mday);

		log->root = xmlnode_root(body, strlen(body));

		head_node = xmlnode_new_child(log->root, "head");

		node = xmlnode_new_child(head_node, "meta");
		xmlnode_new_prop(node, "http-equiv", "content-type");
		xmlnode_new_prop(node, "content", "text/html; charset=UTF-8");

		node = xmlnode_new_child(head_node, "title");

		xmlnode_set_content(node, title);

		node = xmlnode_new_child(log->root, "body");

		node = xmlnode_new_child(node, "h3");

		xmlnode_set_content(node, title);

		g_free(title);
	}

	if (!(body_node = xmlnode_find(log->root, "body"))) {

		hybrid_debug_error("logs", "invalid log file.");

		g_free(title);

		return HYBRID_ERROR;
	}

	node = xmlnode_new_child(body_node, "span");

	font_node = xmlnode_new_child(node, "font");
	if (sendout) {
		xmlnode_new_prop(font_node, "color", "#16569E");

	} else {
		xmlnode_new_prop(font_node, "color", "#A82F2F");
	}

	time_node = xmlnode_new_child(font_node, "font");
	xmlnode_new_prop(time_node, "size", "2");

	memset(time_str, 0, sizeof(time_str));
	strftime(time_str, sizeof(time_str) - 1, "(%H:%M:%S) ", local_time);

	xmlnode_set_content(time_node, time_str);

	content = g_strdup_printf("%s: ", name);
	name_node = xmlnode_new_child(font_node, "b");
	xmlnode_set_content(name_node, content);
	g_free(content);

	cont_node = xmlnode_new_child(node, "font");
	xmlnode_set_content(cont_node, msg);

	xmlnode_new_child(node, "br");

	xmlnode_save_file(log->root, log->log_path);

	return HYBRID_OK;
}