Пример #1
0
    def _consume_message(self, res_obj, sock):
        assert (sock is not None)

        attr = res_obj.headers.get_field_value
        from_uri = attr("F")

        logger.info("Get message from: %s" % from_uri)

        msg = rm_markups(to_unicode_obj(res_obj.body))

        if from_uri != SERVICE_PROVIDER_URI:
            i_send_ack(res_obj, sock)
            contact = self.user.group_agent.get_contact_by_uri(from_uri)
            if not contact:
                """ This message send you before him delete you from his buddy list. """
                name = u"陌生人 (飞信号: %s) " % get_sid_from_uri(from_uri)
            else:
                name = contact.get_display_name()
        else:
            name = to_unicode_obj("系统信息")

        self.goto_or_create_tab_after_received_msg(from_uri)

        chat_history_model = self.chat_history[from_uri]
        self.chat_win.append_to_chat_history(chat_history_model, name, msg,
                                             OTHER_LOG_TPL)
Пример #2
0
def i_update_user_after_ssi_auth_success(user, res_obj, remember_passwd):
    """ get and set SSI cookie, uri, user ID, mobile No. """
    body_dom = minidom.parseString(res_obj.body)

    headers = res_obj.getheader("Set-Cookie")
    ssi_cookie = strip2(headers, "ssic=", ";")
    user.set_ssi_cookie(ssi_cookie)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.uri = user_node.getAttribute("uri")

    user.sid = get_sid_from_uri(user.uri)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.mobile_no = user_node.getAttribute("mobile-no")
    user.user_id = user_node.getAttribute("user-id")

    user.set_user_path(user.sid)
    user.set_portrait_save_path()

    set_last_login_sid(user.sid)
    if remember_passwd:
        hashed_passwd = user.get_hashed_passwd()
    else:
        hashed_passwd = None

    data = {
        "sid": user.sid,
        "mobile_no": user.mobile_no,
        "hashed_passwd": "%s%s" % (HASHED_PREFIX, hashed_passwd),
        "last_presence": user.get_presence(),
    }
    save_data_to_local_json(data, "account.json")
Пример #3
0
def _create_contact_from_buddy_xml_node(user, node):
    # Notice: a buddy could belongs to two groups
    attr = node.getAttribute

    contact = Contact(user = user)
    contact.uri = attr("u")
    contact.sid = get_sid_from_uri(contact.uri)
    contact.user_id = attr("i")
    contact.nickname = to_unicode_obj(attr("n"))
    contact.relation_status = int(attr("r"))

    buddy_list_id = attr("l")
    if buddy_list_id:
        gids = [gid for gid in buddy_list_id.split(";") if gid.strip() and int(gid) >= DEFAULT_GID]
        if len(gids) != 1:
            logger.error("!!! User (SID: %s) has multiple GID" % contact.sid)
            print "gids:", gids
        gid = int(gids[0])
    else:
        gid = DEFAULT_GID
    contact.set_gid(gid)

    contact.portrait_crc = 0

    return contact
Пример #4
0
    def _consume_add_buddy_application(self, res_obj):
        body_dom = minidom.parseString(res_obj.body)
        app_data = i_parse_add_buddy_application(body_dom)

        sid = get_sid_from_uri(app_data["uri"])
        SHOW_MSG_TPL = u"我是 %s (飞信号: %s ),想添加您为好友"
        show_msg = SHOW_MSG_TPL % (app_data["who"], sid)

        send_btn_clicked, data = ReplyAddBuddyDialog.get_data(
            parent=self, show_msg=show_msg)

        if send_btn_clicked:
            if data["accept"]:
                result = ReplyAddBuddyApplication.ACCEPT
            else:
                result = ReplyAddBuddyApplication.REFUSE
        else:
            result = ReplyAddBuddyApplication.IGNORE

        i_reply_add_buddy(self.user,
                          res_obj,
                          result,
                          data["refuse_reason"],
                          data["decline_add_req_forever"],
                          debug=True)
Пример #5
0
def i_update_user_after_ssi_auth_success(user, res_obj, remember_passwd):
    """ get and set SSI cookie, uri, user ID, mobile No. """
    body_dom = minidom.parseString(res_obj.body)

    headers = res_obj.getheader('Set-Cookie')
    ssi_cookie = strip2(headers, "ssic=", ";")
    user.set_ssi_cookie(ssi_cookie)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.uri = user_node.getAttribute("uri")

    user.sid = get_sid_from_uri(user.uri)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.mobile_no = user_node.getAttribute("mobile-no")
    user.user_id = user_node.getAttribute("user-id")

    user.set_user_path(user.sid)
    user.set_portrait_save_path()


    set_last_login_sid(user.sid)
    if remember_passwd:
        hashed_passwd = user.get_hashed_passwd()
    else:
        hashed_passwd = None

    data = {
        "sid" : user.sid,
        "mobile_no" : user.mobile_no,
        "hashed_passwd" : "%s%s" % (HASHED_PREFIX, hashed_passwd),
        "last_presence" : user.get_presence()
    }
    save_data_to_local_json(data, "account.json")
Пример #6
0
    def _consume_message(self, res_obj, sock):
        assert (sock is not None)

        attr = res_obj.headers.get_field_value
        from_uri = attr("F")

        logger.info("Get message from: %s" % from_uri)

        msg = rm_markups(to_unicode_obj(res_obj.body))

        if from_uri != SERVICE_PROVIDER_URI:
            i_send_ack(res_obj, sock)
            contact = self.user.group_agent.get_contact_by_uri(from_uri)
            if not contact:
                """ This message send you before him delete you from his buddy list. """
                name = u"陌生人 (飞信号: %s) " % get_sid_from_uri(from_uri)
            else:
                name = contact.get_display_name()
        else:
            name = to_unicode_obj("系统信息")

        self.goto_or_create_tab_after_received_msg(from_uri)

        chat_history_model = self.chat_history[from_uri]
        self.chat_win.append_to_chat_history(chat_history_model, name, msg, OTHER_LOG_TPL)
Пример #7
0
def i_download_portrait_by_uri(user, uri, debug=False):
    params = {
        "Uri": uri,
        "Size": 120,
        "c": user.get_ssi_cookie(),
    }
    config = user.get_config()

    parses = urlparse.urlparse(config.get_uri)
    root_path = [i for i in parses.path.split('/') if i][0]
    path = "/%s/getportrait.aspx" % root_path
    query = urllib.urlencode(params)
    url = "%s?%s" % (path, query)

    headers = {
        "Accept": config.portrait_file_type,
    }

    httplib.HTTPConnection.response_class = HTTPResponse
    conn = httplib.HTTPConnection(parses.netloc)

    #    if debug:
    #        debuglevel = 1
    #    else:
    #        debuglevel = 0
    #    conn.set_debuglevel(debuglevel)

    conn.request("GET", url, headers=headers)
    res_obj = conn.getresponse()
    conn.close()

    if debug:
        logger.info("request")
        print "url", url
        from pprint import pprint as pp
        print "headers:", pp(headers)

    if debug:
        logger.info("response")
        print "code:", res_obj.code
        print "msg:", res_obj.msg

    if res_obj.code == httplib.OK:
        sid = get_sid_from_uri(uri)
        ct = res_obj.headers.get_field_value('Content-Type')
        format_suffix = ct.split('/')[-1].lower()
        #format_suffix = "jpg"
        portrait_save_path = os.path.join(user.get_portrait_save_path(),
                                          "%s.%s" % (sid, format_suffix))
        with open(portrait_save_path, "wb") as f:
            f.write(res_obj.body)

    return res_obj
Пример #8
0
def i_download_portrait_by_uri(user, uri, debug = False):
    params = {
        "Uri" : uri,
        "Size" : 120,
        "c" : user.get_ssi_cookie(),
    }
    config = user.get_config()

    parses = urlparse.urlparse(config.get_uri)
    root_path = [i for i in parses.path.split('/') if i][0]
    path = "/%s/getportrait.aspx" % root_path
    query = urllib.urlencode(params)
    url = "%s?%s" % (path, query)
    
    headers = {
        "Accept" : config.portrait_file_type,
        }

    httplib.HTTPConnection.response_class = HTTPResponse
    conn = httplib.HTTPConnection(parses.netloc)

#    if debug:
#        debuglevel = 1
#    else:
#        debuglevel = 0
#    conn.set_debuglevel(debuglevel)

    conn.request("GET", url, headers = headers)
    res_obj = conn.getresponse()
    conn.close()

    if debug:
        logger.info("request")
        print "url", url
        from pprint import pprint as pp
        print "headers:", pp(headers)

    if debug:
        logger.info("response")
        print "code:", res_obj.code
        print "msg:", res_obj.msg

    if res_obj.code == httplib.OK:
        sid = get_sid_from_uri(uri)
        ct = res_obj.headers.get_field_value('Content-Type')
        format_suffix = ct.split('/')[-1].lower()
        #format_suffix = "jpg"
        portrait_save_path = os.path.join(user.get_portrait_save_path(), "%s.%s" % (sid, format_suffix))
        with open(portrait_save_path, "wb") as f:
            f.write(res_obj.body)

    return res_obj
Пример #9
0
def _parse_blacklist_node(user, contact_list_node):
    blacklist_node = contact_list_node.getElementsByTagName("blacklist")[0]

    for cat_node in blacklist_node.childNodes:
        if cat_node.nodeType == minidom.Node.TEXT_NODE:
            continue

        contact = Contact(user)
        contact.set_gid(BLACKLIST_GROUP_GID)
        attr = cat_node.getAttribute
        contact.uri = attr("u")
        contact.sid = get_sid_from_uri(contact.uri)
        contact.user_id = attr("i")
        user.group_agent.add_contact(contact)
Пример #10
0
def _parse_chat_friends_node(user, contact_list_node):
    # strangers group list
    chat_friends_node = contact_list_node.getElementsByTagName("chat-friends")[0]

    for cat_node in chat_friends_node.childNodes:
        if cat_node.nodeType == minidom.Node.TEXT_NODE:
            continue

        contact = Contact(user)
        contact.set_gid(STRANGER_GROUP_GID)
        attr = cat_node.getAttribute
        contact.uri = attr("u")
        contact.sid = get_sid_from_uri(contact.uri)
        contact.user_id = attr("i")
        user.group_agent.add_contact(contact)
Пример #11
0
    def _consume_add_buddy_application(self, res_obj):
        body_dom = minidom.parseString(res_obj.body)
        app_data = i_parse_add_buddy_application(body_dom)

        sid = get_sid_from_uri(app_data["uri"])
        SHOW_MSG_TPL = u"我是 %s (飞信号: %s ),想添加您为好友"
        show_msg = SHOW_MSG_TPL % (app_data["who"], sid)

        send_btn_clicked, data = ReplyAddBuddyDialog.get_data(parent = self,
                                        show_msg = show_msg)

        if send_btn_clicked:
            if data["accept"]:
                result = ReplyAddBuddyApplication.ACCEPT
            else:
                result = ReplyAddBuddyApplication.REFUSE
        else:
            result = ReplyAddBuddyApplication.IGNORE

        i_reply_add_buddy(self.user, res_obj, result,
                          data["refuse_reason"], data["decline_add_req_forever"],
                          debug = True)