Ejemplo n.º 1
0
gint
hybrid_pref_init(void)
{
    const gchar *body;
    gchar       *config_path;

    hybrid_pref = g_new0(HybridPref, 1);

    if (!(config_path = hybrid_config_get_path())) {

        hybrid_debug_error("pref", "get config path error.");

        return HYBRID_ERROR;
    }

    hybrid_pref->filename = g_strdup_printf("%s/pref.xml", config_path);

    g_free(config_path);

    if (!(hybrid_pref->root = 
                xmlnode_root_from_file(hybrid_pref->filename))) {

        body = "<pref></pref>";

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

        hybrid_pref_save();
    }

    return HYBRID_OK;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
/**
 * Parse the ssi authentication response string. then we can
 * get the following information: sipuri/mobileno/sid/ssic.
 */
static gint
parse_ssi_response(fetion_account *ac, const gchar *response)
{
    gchar   *prop;
    xmlnode *node;
    xmlnode *root = xmlnode_root(response, strlen(response));

    if (!root) {
        goto ssi_term;
    }

    prop = xmlnode_prop(root, "status-code");
    if (g_strcmp0(prop, "200") != 0) {
        g_free(prop);
        goto ssi_term;
    }

    g_free(prop);

    node = xmlnode_find(root, "user");

    prop = xmlnode_prop(node, "uri");
    fetion_account_set_sipuri(ac, prop);
    g_free(prop);

    if (!ac->sid || *(ac->sid) == '\0') {
        g_free(ac->sid);
        ac->sid = get_sid_from_sipuri(ac->sipuri);
        fetion_sip_set_from(ac->sip, ac->sid);
    }

    prop = xmlnode_prop(node, "mobile-no");
    fetion_account_set_mobileno(ac, prop);
    g_free(prop);

    prop = xmlnode_prop(node, "user-id");
    fetion_account_set_userid(ac, prop);
    g_free(prop);

#if 0
    node = xmlnode_find(root, "credential");
    prop = xmlnode_prop(node, "c");
    fetion_account_set_ssic(ac, prop);
    g_free(prop);
#endif

    return HYBRID_OK;
ssi_term:
    hybrid_account_error_reason(ac->account, _("ssi authencation"));
    xmlnode_free(root);
    return HYBRID_ERROR;
}
Ejemplo n.º 4
0
Archivo: logs.c Proyecto: 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;
}
Ejemplo n.º 5
0
/**
 * Generate the sipc authentication request message body.
 */
static gchar*
generate_auth_body(fetion_account *ac)
{
    gchar root_raw[] = "<args></args>";
    xmlnode *node;
    xmlnode *subnode;
    gchar   *res;
    xmlnode *root    = xmlnode_root(root_raw, strlen(root_raw));

    node = xmlnode_new_child(root, "device");
    xmlnode_new_prop(node, "machine-code", "001676C0E351");

    node = xmlnode_new_child(root, "caps");
    xmlnode_new_prop(node, "value", "1ff");

    node = xmlnode_new_child(root, "events");
    xmlnode_new_prop(node, "value", "7f");

    node = xmlnode_new_child(root, "user-info");
    xmlnode_new_prop(node, "mobile-no", ac->mobileno);
    xmlnode_new_prop(node, "user-id", ac->userid);

    subnode = xmlnode_new_child(node, "personal");
    xmlnode_new_prop(subnode, "version", ac->personal_version);
    xmlnode_new_prop(subnode, "attributes", "v4default");

    subnode = xmlnode_new_child(node, "custom-config");
    xmlnode_new_prop(subnode, "version", ac->custom_config_version);

    subnode = xmlnode_new_child(node, "contact-list");
    xmlnode_new_prop(subnode, "version", ac->contact_list_version);
    xmlnode_new_prop(subnode, "buddy-attributes", "v4default");

    node = xmlnode_new_child(root, "presence");
    subnode = xmlnode_new_child(node, "basic");
    xmlnode_new_prop(subnode, "value", "0");
    xmlnode_new_prop(subnode, "desc", "");

    res = xmlnode_to_string(root);

    xmlnode_free(root);

    return res;
}
Ejemplo n.º 6
0
static gchar*
generate_get_info_body(const gchar *userid)
{
	xmlnode *root;
	xmlnode *node;
	gchar *res;

	gchar body[] = "<args></args>";

	root = xmlnode_root(body, strlen(body));
	node = xmlnode_new_child(root, "contact");
	xmlnode_new_prop(node, "user-id", userid);

	res = xmlnode_to_string(root);

	xmlnode_free(root);

	return res;
}
Ejemplo n.º 7
0
/**
 * Generate the xml body of the cfg-downloading request. We will get
 * the following output:
 *
 * <config>
 *     <user mobile-no="152********"/>
 *     <client type="PC" version="4.3.0980" platform="W5.1"/>
 *     <servers version="0"/>
 *     <parameters version="0"/>
 *     <hints version="0"/>
 *  </config>
 */
static gchar*
generate_configuration_body(fetion_account *ac)
{
    xmlnode *root;
    xmlnode *node;
    gchar root_node[] = "<config></config>";
    gchar   *res;

    g_return_val_if_fail(ac != NULL, NULL);

    root = xmlnode_root(root_node, strlen(root_node));

    node = xmlnode_new_child(root, "user");

    if (ac->mobileno && *(ac->mobileno) != '\0') {
        xmlnode_new_prop(node, "mobile-no", ac->mobileno);

    } else {
        xmlnode_new_prop(node, "sid", ac->sid);
    }

    node = xmlnode_new_child(root, "client");
    xmlnode_new_prop(node, "type", "HYBRID");
    xmlnode_new_prop(node, "version", PROTO_VERSION);
    xmlnode_new_prop(node, "platform", "W5.1");

    node = xmlnode_new_child(root, "servers");
    xmlnode_new_prop(node, "version", ac->cfg_server_version);

    node = xmlnode_new_child(root, "parameters");
    xmlnode_new_prop(node, "version", ac->cfg_param_version);

    node = xmlnode_new_child(root, "hints");
    xmlnode_new_prop(node, "version", ac->cfg_hint_version);

    res = xmlnode_to_string(root);

    xmlnode_free(root);

    return res;
}
Ejemplo n.º 8
0
static gchar*
generate_buddy_add_body(const gchar *no, const gchar *groupid,
		const gchar *localname, const gchar *desc)
{
	const gchar *body;
	gchar *sipuri;
	xmlnode *root;
	xmlnode *node;
	gchar *res;

	body = "<args></args>";

	root = xmlnode_root(body, strlen(body));

	node = xmlnode_new_child(root, "contacts");
	node = xmlnode_new_child(node, "buddies");
	node = xmlnode_new_child(node, "buddy");

	if (strlen(no) < 11) {
		sipuri = g_strdup_printf("sip:%s", no);

	} else {
		sipuri = g_strdup_printf("tel:%s", no);
	}

	xmlnode_new_prop(node, "uri", sipuri);
	xmlnode_new_prop(node, "local-name", localname);
	xmlnode_new_prop(node, "buddy-lists", groupid);
	xmlnode_new_prop(node, "desc", desc);
	xmlnode_new_prop(node, "expose-mobile-no", "1");
	xmlnode_new_prop(node, "expose-name", "1");
	xmlnode_new_prop(node, "addbuddy-phrase-id", "0");

	g_free(sipuri);

	res = xmlnode_to_string(root);

	xmlnode_free(root);

	return res;
}
Ejemplo n.º 9
0
static gchar*
generate_subscribe_body(void)
{
	xmlnode *root;
	xmlnode *node;
	gchar *body;
	gchar xml_raw[] = "<args></args>";

	root = xmlnode_root(xml_raw, strlen(xml_raw));

	node = xmlnode_new_child(root, "subscription");
	xmlnode_new_prop(node, "self", "v4default;mail-count");
	xmlnode_new_prop(node, "buddy", "v4default");
	xmlnode_new_prop(node, "version", "0");

	body = xmlnode_to_string(root);

	xmlnode_free(root);

	return body;
}
Ejemplo n.º 10
0
static gint
parse_ssi_fail_resp(fetion_account *ac, const gchar *response)
{
    xmlnode      *root;
    xmlnode      *node;
    Verification *ver;
    gchar        *pos;

    ver = fetion_verification_create();

    if (!(pos = strstr(response, "\r\n\r\n"))) {
        return HYBRID_ERROR;
    }

    pos += 4;

    root = xmlnode_root(pos, strlen(pos));

    if (!(node = xmlnode_find(root, "results"))) {
        return HYBRID_ERROR;
    }

    if (xmlnode_has_prop(node, "desc")) {
        ver->desc = xmlnode_prop(node, "desc");
    }

    if (!(node = xmlnode_find(root, "verification"))) {
        return HYBRID_ERROR;
    }

    if (xmlnode_has_prop(node, "algorithm")) {
        ver->algorithm = xmlnode_prop(node, "algorithm");
    }

    ac->verification = ver;

    return HYBRID_OK;
}
Ejemplo n.º 11
0
static gchar*
generate_rename_buddy_body(const gchar *userid, const gchar *name)
{
	const gchar *body;
	xmlnode *root;
	xmlnode *node;
	gchar *res;

	body = "<args></args>";

	root = xmlnode_root(body, strlen(body));

	node = xmlnode_new_child(root, "contacts");
	node = xmlnode_new_child(node, "contact");
	xmlnode_new_prop(node, "user-id", userid);
	xmlnode_new_prop(node, "local-name", name);

	res = xmlnode_to_string(root);

	xmlnode_free(root);

	return res;
}
Ejemplo n.º 12
0
gint
fetion_message_parse_sysmsg(const gchar *sipmsg, gchar **content, gchar **url)
{
	gchar *pos;
	xmlnode *root;
	xmlnode *node;

	if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
		goto sysmsg_error;
	}

	if (!(root = xmlnode_root(pos, strlen(pos)))) {
		goto sysmsg_error;
	}

	if (!(node = xmlnode_find(root, "content"))) {
		xmlnode_free(root);
		goto sysmsg_error;
	}

	*content = xmlnode_content(node);

	if ((node = xmlnode_find(root, "url"))) {
		*url = xmlnode_content(node);

	} else {
		*url = NULL;
	}

	xmlnode_free(root);

	return HYBRID_OK;

sysmsg_error:
	hybrid_debug_error("fetion", "invalid system message");
	return HYBRID_ERROR;
}
Ejemplo n.º 13
0
static gchar*
generate_invite_buddy_body(const gchar *sipuri)
{
	const gchar *body;
	xmlnode *root;
	xmlnode *node;
	gchar *res;

	g_return_val_if_fail(sipuri != NULL, NULL);

	body = "<args></args>";

	root = xmlnode_root(body, strlen(body));

	node = xmlnode_new_child(root, "contacts");
	node = xmlnode_new_child(node, "contact");
	xmlnode_new_prop(node, "uri", sipuri);

	res = xmlnode_to_string(root);

	xmlnode_free(root);
	
	return res;
}
Ejemplo n.º 14
0
gint
sip_parse_appbuddy(const gchar *sipmsg, gchar **userid,
                   gchar **sipuri, gchar **desc)
{
    gchar   *pos;
    xmlnode *root;
    xmlnode *node;

    if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
        return HYBRID_ERROR;
    }

    pos += 4;

    if (!(root = xmlnode_root(pos, strlen(pos)))) {
        return HYBRID_ERROR;
    }

    if (!(node = xmlnode_find(root, "application"))) {
        return HYBRID_ERROR;
    }

    if (xmlnode_has_prop(node, "uri") && sipuri != NULL) {
        *sipuri = xmlnode_prop(node, "uri");
    }

    if (xmlnode_has_prop(node, "user-id") && userid != NULL) {
        *userid = xmlnode_prop(node, "user-id");
    }

    if (xmlnode_has_prop(node, "desc") && desc != NULL) {
        *desc = xmlnode_prop(node, "desc");
    }

    return HYBRID_OK;
}
Ejemplo n.º 15
0
static gint
buddy_add_cb(fetion_account *account, const gchar *sipmsg,
			fetion_transaction *trans)
{
	gint code;
	gchar *pos;
	gchar *value;
	gchar *name;
	fetion_buddy *buddy;
	HybridGroup *group;
	HybridBuddy *bd;
	xmlnode *root;
	xmlnode *node;

	hybrid_debug_info("fetion", "add buddy, recv:\n%s", sipmsg);

	if ((code = fetion_sip_get_code(sipmsg)) != 200) {

		hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
				"Add buddy error. Server response with %d", code);

		return HYBRID_ERROR;
	}

	if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
		goto add_buddy_unknown_err;
	}

	pos += 4;

	if (!(root = xmlnode_root(pos, strlen(pos)))) {
		goto add_buddy_unknown_err;
	}

	if (!(node = xmlnode_find(root, "buddy"))) {

		xmlnode_free(root);

		goto add_buddy_unknown_err;
	}

	if (xmlnode_has_prop(node, "status-code")) {
		
		value = xmlnode_prop(node, "status-code");

		code = atoi(value);

		g_free(value);

		if (code == 200) {
			goto add_buddy_ok;
		}

		xmlnode_free(node);

		if (code == 521) {

			hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
					"The buddy has already been in your buddy list,\n"
					"Please don't add it duplicately.");

			return HYBRID_ERROR;
		}

		if (code == 404) {

			hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
					"The buddy you try to add doesn't exist.");

			return HYBRID_ERROR;
		}

		if (code == 486) {
			
			hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
					"You have reached the daily limit of adding buddies,\n"
					"please try another day.");

			return HYBRID_ERROR;
		}

		goto add_buddy_unknown_err;
	}

add_buddy_ok:

	if (!xmlnode_has_prop(node, "user-id") ||
		!xmlnode_has_prop(node, "local-name") ||
		!xmlnode_has_prop(node, "uri") ||
		!xmlnode_has_prop(node, "buddy-lists")) {

		xmlnode_free(root);

		goto add_buddy_unknown_err;
	}

	buddy = fetion_buddy_create();

	buddy->userid    = xmlnode_prop(node, "user-id");
	buddy->localname = xmlnode_prop(node, "local-name");
	buddy->sipuri    = xmlnode_prop(node, "uri");
	buddy->groups    = xmlnode_prop(node, "buddy-lists");

	xmlnode_free(root);

	account->buddies = g_slist_append(account->buddies, buddy);

	if (!(group = hybrid_blist_find_group(account->account, buddy->groups))) {
		fetion_buddy_destroy(buddy);
		account->buddies = g_slist_remove(account->buddies, buddy);

		goto add_buddy_unknown_err;
	}

	if (buddy->localname && *(buddy->localname) == '\0') {
		name = get_sid_from_sipuri(buddy->sipuri);

	} else {
		name = g_strdup(buddy->localname);
	}

	bd = hybrid_blist_add_buddy(account->account, group, buddy->userid, name);
	hybrid_blist_set_buddy_status(bd, FALSE);

	g_free(name);

	return HYBRID_OK;

add_buddy_unknown_err:
	hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
			"Add buddy error. Unknown reason.");
	
	return HYBRID_ERROR;
}
Ejemplo n.º 16
0
/**
 * Parse the configuration information. We will get:
 * sipc-proxy,get-url, servers-version, parameters-version,
 * and hints-version
 */
static gint
parse_configuration(fetion_account *ac, const gchar *cfg)
{
    xmlnode *node;
    xmlnode *root;
    gchar   *value;
    gchar   *version;
    gchar   *pos, *pos1;

    g_return_val_if_fail(cfg != NULL, 0);

    root = xmlnode_root(cfg, strlen(cfg));

    if (!root) {
        goto cfg_parse_err;
    }

    if ((node = xmlnode_find(root, "servers"))) {
        version = xmlnode_prop(node, "version");
        if (g_strcmp0(version, ac->cfg_server_version) != 0) {
            g_free(ac->cfg_server_version);
            ac->cfg_server_version = version;

            if (!(node = xmlnode_find(root, "sipc-proxy"))) {
                goto cfg_parse_err;
            }

            value = xmlnode_content(node);

            for (pos = value; *pos && *pos != ':'; pos ++ );

            if (*pos == '\0') {
                g_free(value);
                goto cfg_parse_err;
            }

            ac->sipc_proxy_ip = g_strndup(value, pos - value);
            ac->sipc_proxy_port = atoi(pos + 1);

            g_free(value);

            if (!(node = xmlnode_find(root, "get-uri"))) {
                goto cfg_parse_err;
            }

            value = xmlnode_content(node);

            for (pos1 = value; *pos1 && *pos1 != '/'; pos1 ++);
            if (*pos1 == '\0' || *(pos1 + 1) != '/') {
                goto cfg_parse_err;
            }

            pos1 += 2;

            for (pos = pos1; *pos && *pos != '/'; pos ++);
            if (*pos == '\0') {
                goto cfg_parse_err;
            }

            ac->portrait_host_name = g_strndup(pos1, pos - pos1);

            pos1 = pos + 1;

            for (pos = pos1; *pos && *pos != '/'; pos ++);
            if (*pos == '\0') {
                goto cfg_parse_err;
            }

            ac->portrait_host_path = g_strndup(pos1, pos - pos1);

        } else {
            g_free(version);
        }
    }

    if ((node = xmlnode_find(root, "parameters"))) {
        g_free(ac->cfg_param_version);
        ac->cfg_param_version = xmlnode_prop(node, "version");
    }

    if ((node = xmlnode_find(root, "hints"))) {
        g_free(ac->cfg_hint_version);
        ac->cfg_hint_version = xmlnode_prop(node, "version");
    }

    if ((node = xmlnode_find(root, "client"))) {
        g_free(ac->cfg_client_version);
        ac->cfg_client_version = xmlnode_prop(node, "version");
    }

    xmlnode_free(root);

    return HYBRID_OK;

cfg_parse_err:
    xmlnode_free(root);
    hybrid_debug_error("fetion", "parse cfg body");
    return HYBRID_ERROR;
}
Ejemplo n.º 17
0
GSList*
sip_parse_presence(fetion_account *ac, const gchar *sipmsg)
{
    gchar        *pos;
    gchar        *temp;
    xmlnode      *root;
    xmlnode      *node;
    xmlnode      *pnode;
    GSList       *list = NULL;
    fetion_buddy *buddy;

    if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
        return list;
    }

    pos += 4;

    root = xmlnode_root(pos, strlen(pos));
    node = xmlnode_find(root, "contacts");
    node = xmlnode_child(node);

    while (node) {

        temp = xmlnode_prop(node, "id");

        if (!(buddy = fetion_buddy_find_by_userid(ac, temp))) {
            /* Maybe yourself's presence, we just ignore it. */
            g_free(temp);
            node = node->next;
            continue;
        }

        g_free(temp);

        list = g_slist_append(list, buddy);

        if ((pnode = xmlnode_find(node, "p"))) {

            if (xmlnode_has_prop(pnode, "m")) {
                temp = xmlnode_prop(pnode, "m");
                g_free(buddy->mobileno);
                buddy->mobileno = g_strdup(temp);
                g_free(temp);
            }

            if (xmlnode_has_prop(pnode, "n")) {
                temp = xmlnode_prop(pnode, "n");
                g_free(buddy->nickname);
                buddy->nickname = g_strdup(temp);
                g_free(temp);
            }

            if (xmlnode_has_prop(pnode, "i")) {
                temp = xmlnode_prop(pnode, "i");
                g_free(buddy->mood_phrase);
                buddy->mood_phrase = g_strdup(temp);
                g_free(temp);
            }

            if (xmlnode_has_prop(pnode, "c")) {
                temp = xmlnode_prop(pnode, "c");
                g_free(buddy->carrier);
                buddy->carrier = g_strdup(temp);
                g_free(temp);
            }

            if (xmlnode_has_prop(pnode, "p")) {
                temp = xmlnode_prop(pnode, "p");
                g_free(buddy->portrait_crc);

                if (*temp == '\0') {
                    g_free(temp);
                    temp = g_strdup("0");
                }
                buddy->portrait_crc = temp;
            } else {
                g_free(buddy->portrait_crc);
                buddy->portrait_crc = g_strdup("0");
            }

            if (xmlnode_has_prop(pnode, "cs")) {
                temp = xmlnode_prop(pnode, "cs");
                buddy->carrier_status = atoi(temp);
                g_free(temp);
            }
        }

        if ((pnode = xmlnode_find(node, "pr"))) {
            
            if (xmlnode_has_prop(pnode, "b")) {
                temp = xmlnode_prop(pnode, "b");
                buddy->state = atoi(temp);
                g_free(temp);
            }
        }

        node = node->next;
    }

    xmlnode_free(root);

    return list;
}
Ejemplo n.º 18
0
GSList*
sip_parse_sync(fetion_account *account, const gchar *sipmsg)
{
    gchar        *pos;
    gchar        *action;
    gchar        *userid;
    gchar        *status;
    xmlnode      *root;
    xmlnode      *node;
    fetion_buddy *buddy;
    GSList       *list = NULL;

    if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
        goto sync_info_err;
    }

    pos += 4;

    if (!(root = xmlnode_root(pos, strlen(pos)))) {
        goto sync_info_err;
    }

    if (!(node = xmlnode_find(root, "buddies"))) {

        xmlnode_free(root);

        return list;
    }

    node = xmlnode_child(node);

    while (node) {
        if (!xmlnode_has_prop(node, "action")) {
            goto next;
        }

        action = xmlnode_prop(node, "action");

        if (g_strcmp0(action, "update") == 0) {
            
            if (!xmlnode_has_prop(node, "user-id") ||
                !xmlnode_has_prop(node, "relation-status")) {

                g_free(action);

                goto next;
            }

            userid = xmlnode_prop(node, "user-id");
            status = xmlnode_prop(node, "relation-status");

            if (!(buddy = fetion_buddy_find_by_userid(account, userid))) {

                g_free(action);
                g_free(userid);
                g_free(status);

                goto next;
            }

            buddy->status = atoi(status);

            list = g_slist_append(list, buddy);

            g_free(status);
            g_free(userid);
        }

        g_free(action);
next:
        node = xmlnode_next(node);
    }

    return list;

sync_info_err:
    hybrid_debug_error("fetion", "invalid sync info");

    return list;
}
Ejemplo n.º 19
0
void
sip_parse_notify(const gchar *sipmsg, gint *notify_type, gint *event_type)
{
    gchar   *attr;
    gchar   *pos;
    gchar   *event;
    xmlnode *root = NULL;
    xmlnode *node;

    g_return_if_fail(sipmsg != NULL);

    if (!(attr = sip_header_get_attr(sipmsg, "N"))) {
        *notify_type = NOTIFICATION_TYPE_UNKNOWN;
        *event_type = NOTIFICATION_EVENT_UNKNOWN;
        return;
    }

    if (g_strcmp0(attr, "PresenceV4") == 0) {
        *notify_type = NOTIFICATION_TYPE_PRESENCE;

    } else if (g_strcmp0(attr, "Conversation") == 0) {
        *notify_type = NOTIFICATION_TYPE_CONVERSATION;

    } else if (g_strcmp0(attr, "contact") == 0) {
        *notify_type = NOTIFICATION_TYPE_CONTACT;

    } else if (g_strcmp0(attr, "registration") == 0) {
        *notify_type = NOTIFICATION_TYPE_REGISTRATION;

    } else if (g_strcmp0(attr, "SyncUserInfoV4") == 0) {
        *notify_type = NOTIFICATION_TYPE_SYNCUSERINFO;

    } else if (g_strcmp0(attr, "PGGroup") == 0) {
        *notify_type = NOTIFICATION_TYPE_PGGROUP;

    } else {
        *notify_type = NOTIFICATION_TYPE_UNKNOWN;
    }

    g_free(attr);

    if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
        goto notify_err;
    }

    pos += 4;

    if (!(root = xmlnode_root(pos, strlen(pos)))) {
        goto notify_err;
    }

    if (!(node = xmlnode_find(root, "event"))) {
        goto notify_err;
    }

    if (!(event = xmlnode_prop(node, "type"))) {
        goto notify_err;
    }

    if (g_strcmp0(event, "Support") == 0) {
        if (!(node = xmlnode_next(node))) {
            goto notify_err;
        }

        if (g_strcmp0(node->name, "event") != 0) {
            goto notify_err;
        }

        if (!(event = xmlnode_prop(node, "type"))) {
            goto notify_err;
        }

    }

    if (g_strcmp0(event, "PresenceChanged") == 0) {
        *event_type = NOTIFICATION_EVENT_PRESENCECHANGED;

    } else if (g_strcmp0(event, "UserEntered") == 0) {
        *event_type = NOTIFICATION_EVENT_USERENTER;

    } else if (g_strcmp0(event, "UserLeft") == 0) {
        *event_type = NOTIFICATION_EVENT_USERLEFT;

    } else if (g_strcmp0(event, "deregistered") == 0) {
        *event_type = NOTIFICATION_EVENT_DEREGISTRATION;

    } else if (g_strcmp0(event, "SyncUserInfo") == 0) {
        *event_type = NOTIFICATION_EVENT_SYNCUSERINFO;

    } else if (g_strcmp0(event, "AddBuddyApplication") == 0) {
        *event_type = NOTIFICATION_EVENT_ADDBUDDYAPPLICATION;

    } else if (g_strcmp0(event, "PGGetGroupInfo") == 0) {
        *event_type = NOTIFICATION_EVENT_PGGETGROUPINFO;

    } else {
        *event_type = NOTIFICATION_EVENT_UNKNOWN;
    }

    xmlnode_free(root);
    return;

notify_err:
    xmlnode_free(root);
    *event_type = NOTIFICATION_EVENT_UNKNOWN;
    return;
}
Ejemplo n.º 20
0
fetion_buddy*
fetion_buddy_parse_info(fetion_account *ac, 
		const gchar *userid, const gchar *sipmsg)
{
	xmlnode *root;
	xmlnode *node;
	gchar *pos;
	gchar *temp;
	gchar *value;
	fetion_buddy *buddy;
	gint code;

	code = fetion_sip_get_code(sipmsg);

	if (code != 200) {
		hybrid_debug_error("fetion", "get information with code:%d", code);
		return NULL;
	}

	if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
		goto get_info_error;
	}

	pos += 4;

	if (!(root = xmlnode_root(pos, strlen(pos)))) {
		goto get_info_error;
	}

	if (!(node = xmlnode_find(root, "contact"))) {
		xmlnode_free(root);
		goto get_info_error;
	}

	if (!(buddy = fetion_buddy_find_by_userid(ac, userid))) {
		xmlnode_free(root);
		goto get_info_error;
	}

	if (xmlnode_has_prop(node, "sid")) {
		value = xmlnode_prop(node, "sid");
		g_free(buddy->sid);
		buddy->sid = g_strdup(value);
		g_free(value);
	}

	if (xmlnode_has_prop(node, "mobile-no")) {
		value = xmlnode_prop(node, "mobile-no");
		g_free(buddy->mobileno);
		buddy->mobileno = g_strdup(value);
		g_free(value);
	}

	if (xmlnode_has_prop(node, "impresa")) {
		value = xmlnode_prop(node, "impresa");
		g_free(buddy->mood_phrase);
		buddy->mood_phrase = g_strdup(value);
		g_free(value);
	}

	if (xmlnode_has_prop(node, "nickname")) {
		value = xmlnode_prop(node, "nickname");
		g_free(buddy->nickname);
		buddy->nickname = g_strdup(value);
		g_free(value);
	}

	if (xmlnode_has_prop(node, "gender")) {
		value = xmlnode_prop(node, "gender");
		buddy->gender = atoi(value);
		g_free(value);
	}

	if (xmlnode_has_prop(node, "carrier-region")) {
		value = xmlnode_prop(node, "carrier-region");

		for (pos = value; *pos && *pos != '.'; pos ++);
		g_free(buddy->country);
		buddy->country = g_strndup(value, pos - value);

		for (pos ++, temp = pos; *pos && *pos != '.'; pos ++);
		g_free(buddy->province);
		buddy->province = g_strndup(temp, pos - temp);

		for (pos ++, temp = pos; *pos && *pos != '.'; pos ++);
		g_free(buddy->city);
		buddy->city = g_strndup(temp, pos - temp);

	}

	xmlnode_free(node);

	return buddy;

get_info_error:
	hybrid_debug_error("fetion", "invalid get-info response");
	return NULL;
}
Ejemplo n.º 21
0
static gboolean
pic_read_cb(gint sk, gpointer user_data)
{
    gint     n, len;
    gchar    sipmsg[BUF_LENGTH];
    gchar   *code, *pos;
    guchar  *pic;
    gint     piclen;
    xmlnode *root;
    xmlnode *node;

    fetion_account *ac = (fetion_account*)user_data;

    len    = ac->buffer ? strlen(ac->buffer) : 0;

    if((n = recv(sk, sipmsg, strlen(sipmsg), 0)) == -1) {
        return -1;
    }

    sipmsg[n] = 0;

    if(n == 0) {
           g_source_remove(ac->source);
        ac->source = 0;
        close(sk);

        if(! ac->buffer) {
            return 0;
        }

        hybrid_debug_info("fetion", "read message resp:\n%s", ac->buffer);

        if (200 != hybrid_get_http_code(ac->buffer)) {
            goto read_pic_err;
        }

        if(!(pos = strstr(ac->buffer, "\r\n\r\n"))) {
            goto read_pic_err;
        }

        pos += 4;

        if (!(root = xmlnode_root(pos, strlen(pos)))) {
            goto read_pic_err;
        }

        if (!(node = xmlnode_find(root, "pic-certificate"))) {
            xmlnode_free(root);
            goto read_pic_err;
        }

        if (!xmlnode_has_prop(node, "id") || !xmlnode_has_prop(node, "pic")) {
            xmlnode_free(root);
            goto read_pic_err;
        }

        ac->verification->guid = xmlnode_prop(node, "id");
        code                   = xmlnode_prop(node, "pic");

        pic = hybrid_base64_decode(code, &piclen);

        hybrid_confirm_window_create(ac->account, pic, piclen,
                                     pic_code_ok_cb, pic_code_cancel_cb, ac);

        g_free(code);
        g_free(pic);
        xmlnode_free(root);
        g_free(ac->buffer);
        ac->buffer = (gchar*)0;

        return FALSE;
    }

    ac->buffer = (gchar*)realloc(ac->buffer, len + n + 1);
    memcpy(ac->buffer + len, sipmsg, n + 1);

    return TRUE;

 read_pic_err:
    hybrid_debug_error("fetion", "read pic code error.");

    g_free(ac->buffer);
    ac->buffer = (gchar *)0;

    hybrid_account_error_reason(ac->account, _("read pic code error."));
    return FALSE;
}
Ejemplo n.º 22
0
static gint
handle_request_cb(fetion_account *account, const gchar *sipmsg,
			fetion_transaction *trans)
{
	gchar *pos;
	gchar *value;
	fetion_buddy *buddy;
	xmlnode *root;
	xmlnode *node;
	HybridGroup *group;
	HybridBuddy *bd;
	gchar *name;

	if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
		return HYBRID_ERROR;
	}

	pos += 4;

	if (!(root = xmlnode_root(pos, strlen(pos)))) {
		return HYBRID_ERROR;
	}

	if (!(node = xmlnode_find(root, "buddy"))) {
		return HYBRID_ERROR;
	}

	if (!xmlnode_has_prop(node, "uri") ||
		!xmlnode_has_prop(node, "user-id")) {
		return HYBRID_ERROR;
	}

	buddy = fetion_buddy_create();
	buddy->sipuri = xmlnode_prop(node, "uri");
	buddy->userid = xmlnode_prop(node, "user-id");
	buddy->sid = get_sid_from_sipuri(buddy->sipuri);

	account->buddies = g_slist_append(account->buddies, buddy);

	if (xmlnode_has_prop(node, "local-name")) {
		buddy->localname = xmlnode_prop(node, "localname");
	}

	if (xmlnode_has_prop(node, "buddy-lists")) {
		buddy->groups = xmlnode_prop(node, "buddy-lists");

	} else {
		buddy->groups = "0";
	}

	if (xmlnode_has_prop(node, "relation-status")) {
		value = xmlnode_prop(node, "relation-status");
		buddy->status = atoi(value);
		g_free(value);

	} else {
		buddy->status = 0;
	}

	if (!(group = hybrid_blist_find_group(account->account, buddy->groups))) {
		account->buddies = g_slist_remove(account->buddies, buddy);
		fetion_buddy_destroy(buddy);
		return HYBRID_ERROR;
	}

	if (buddy->localname && *(buddy->localname) == '\0') {
		name = get_sid_from_sipuri(buddy->sipuri);

	} else {
		name = g_strdup(buddy->localname);
	}

	bd = hybrid_blist_add_buddy(account->account, group, buddy->userid, name);
	hybrid_blist_set_buddy_status(bd, buddy->status == 1 ? TRUE: FALSE);

	g_free(name);

	return HYBRID_OK;
}
Ejemplo n.º 23
0
/**
 * parse the sipc authentication response, we can get the basic
 * information and the contact list of this account.
 */
static void
parse_sipc_resp(fetion_account *ac, const gchar *body, gint len)
{
    xmlnode *root;
    xmlnode *node;
    gchar   *version;

    g_return_if_fail(ac != NULL);
    g_return_if_fail(body != NULL);
    g_return_if_fail(len != 0);

    root = xmlnode_root(body, len);

    /* login info */
    node                = xmlnode_find(root, "client");
    ac->last_login_ip   = xmlnode_prop(root, "last-login-ip");
    ac->public_ip       = xmlnode_prop(root, "public-ip");
    ac->last_login_time = xmlnode_prop(root, "last-login-time");

    /* personal info */
    node    = xmlnode_find(root, "personal");
    version = xmlnode_prop(node, "version");

    if (g_strcmp0(version, ac->personal_version) == 0) {
        /* load from disk. */
        g_free(version);

        xmlnode *personal_root;
        xmlnode *personal_node;

        if (!(personal_root = fetion_config_load_personal(ac))) {
            hybrid_debug_error("fetion", "invalid personal.xml");
            xmlnode_free(root);
            return;
        }

        if (!(personal_node = xmlnode_find(personal_root, "personal"))) {
            hybrid_debug_error("fetion", "invalid personal.xml");
            xmlnode_free(personal_root);
            xmlnode_free(root);
            return;
        }
        get_personal(ac, personal_node);
        xmlnode_free(personal_root);

    } else {
        /* update the version */
        g_free(ac->personal_version);
        ac->personal_version = version;
        /* get the personal information */
        get_personal(ac, node);
        /* save the personal information */
        fetion_config_save_personal(ac, node);
    }


    /* contact list version */
    node    = xmlnode_find(root, "contact-list");
    version = xmlnode_prop(node, "version");

    if (g_strcmp0(version, ac->contact_list_version) == 0) {
        /* load from disk. */
        g_free(version);

        xmlnode *contact_root;
        xmlnode *contact_node;

        if (!(contact_root = fetion_config_load_buddies(ac))) {
            hybrid_debug_error("fetion", "invalid buddies.xml");
            xmlnode_free(root);
            return;
        }

        if (!(contact_node = xmlnode_find(contact_root, "contact-list"))) {
            hybrid_debug_error("fetion", "invalid buddies.xml");
            xmlnode_free(contact_root);
            xmlnode_free(root);
            return;
        }

        get_contact_list(ac, contact_node);
        xmlnode_free(contact_root);

    } else {

        /* the cache is out-of-data, drop it. */
        hybrid_account_clear_buddy(ac->account);

        /* update the version */
        g_free(ac->contact_list_version);
        ac->contact_list_version = version;
        /* get the contact list */
        get_contact_list(ac, node);
        /* save the contact list */
        fetion_config_save_buddies(ac, node);
    }


    /* custom config */
    node = xmlnode_find(root, "custom-config");
    version = xmlnode_prop(node, "version");

    if (g_strcmp0(version, ac->custom_config_version) != 0) {
        g_free(ac->custom_config);
        g_free(ac->custom_config_version);
        ac->custom_config = xmlnode_content(node);
        ac->custom_config_version = version;
    }

    xmlnode_free(root);

    /*
     * OK, now we need to save the account's version information, so
     * next time we can use it to register to sipc server.
     */
    fetion_config_save_account(ac);
}
Ejemplo n.º 24
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;
}