Example #1
0
void file_message(LwqqClient* lc,LwqqMsgFileMessage* file)
{
    qq_account* ac = lwqq_client_userdata(lc);
    if(file->mode == MODE_RECV) {
        PurpleAccount* account = ac->account;
        LwqqClient* lc = ac->qq;
        //for(i=0;i<file->file_count;i++){
        LwqqBuddy* buddy = lc->find_buddy_by_uin(lc,file->from);
        if(buddy == NULL ) return;
        const char* key = try_get(buddy->qqnumber,buddy->uin);
        PurpleXfer* xfer = purple_xfer_new(account,PURPLE_XFER_RECEIVE,key);
        purple_xfer_set_filename(xfer,file->recv.name);
        purple_xfer_set_init_fnc(xfer,recv_file_init);
        purple_xfer_set_request_denied_fnc(xfer,recv_file_request_denied);
        purple_xfer_set_cancel_recv_fnc(xfer,recv_file_cancel);
        LwqqMsgFileMessage* fdup = s_malloc(sizeof(*fdup));
        memcpy(fdup,file,sizeof(*fdup));
        file->from = file->to = file->reply_ip = file->recv.name = NULL;
        xfer->data = fdup;
        purple_xfer_request(xfer);
    } else if(file->mode == MODE_REFUSE) {
        if(file->refuse.cancel_type == CANCEL_BY_USER) {
            qq_sys_msg_write(ac, LWQQ_MT_BUDDY_MSG, file->from, "对方取消文件传输", PURPLE_MESSAGE_SYSTEM, time(NULL));
        } else if(file->refuse.cancel_type == CANCEL_BY_OVERTIME) {
            qq_sys_msg_write(ac, LWQQ_MT_BUDDY_MSG, file->from, "文件传输超时", PURPLE_MESSAGE_SYSTEM, time(NULL));
        }

    }

}
Example #2
0
//the entrience for recv file messages
void file_message(LwqqClient* lc,LwqqMsgFileMessage* file)
{
	qq_account* ac = lwqq_client_userdata(lc);
	if(file->mode == MODE_RECV) {
		PurpleAccount* account = ac->account;
		LwqqClient* lc = ac->qq;
		LwqqBuddy* buddy = lc->find_buddy_by_uin(lc,file->super.from);
		if(buddy == NULL ) return;
		const char* key = try_get(buddy->qqnumber,buddy->uin);
		PurpleXfer* xfer = purple_xfer_new(account,PURPLE_XFER_RECEIVE,key);
		purple_xfer_set_filename(xfer,file->recv.name);
		purple_xfer_set_init_fnc(xfer,recv_file_init);
		purple_xfer_set_request_denied_fnc(xfer,recv_file_request_denied);
		purple_xfer_set_cancel_recv_fnc(xfer,recv_file_cancel);
		LwqqMsgFileMessage* fdup = s_malloc0(sizeof(*fdup));
		lwqq_msg_move(fdup,file);
		xfer->data = fdup;
		purple_xfer_request(xfer);
	} else if(file->mode == MODE_REFUSE) {
		if(file->refuse.cancel_type == CANCEL_BY_USER) 
			qq_sys_msg_write(ac, LWQQ_MS_BUDDY_MSG, file->super.from, 
					_("Other canceled file transport"), 
					PURPLE_MESSAGE_SYSTEM, 
					time(NULL));
		else if(file->refuse.cancel_type == CANCEL_BY_OVERTIME) 
			qq_sys_msg_write(ac, LWQQ_MS_BUDDY_MSG, file->super.from, 
					_("File transport timeout"), 
					PURPLE_MESSAGE_SYSTEM, 
					time(NULL));
	}
}
Example #3
0
	std::size_t try_get(uint8_t* dest, std::size_t len)
	{
		// TODO: Can optimize this
		for(std::size_t i = 0; i < len; ++i)
		{
			stream::read_status s = try_get(dest[i]);
			if(s != stream::read_ok)
			{
				return i;
			}
		}

		return len;
	}
Example #4
0
bool
cql::cql_hosts_t::set_down(
    const cql::cql_endpoint_t& endpoint)
{
    boost::mutex::scoped_lock     lock(_mutex);
	boost::shared_ptr<cql_host_t> host;

	if (try_get(endpoint, &host)) {
		return host->set_down();
    }
	else {
		return false;
    }
}
void odata_json_writer_minimal::handle_serialize_odata_value(::utility::stringstream_t& ss, 
    const std::shared_ptr<edm_named_type>& property_type, const std::shared_ptr<odata_value>& property_value)
{
	if (!property_type || !property_value)
	{
		ss << "null";

		return ;
	}

    switch(property_type->get_type_kind())
	{
	case edm_type_kind_t::Primitive:
		{
			auto p_value = std::dynamic_pointer_cast<odata_primitive_value>(property_value);
			auto p_primitive_type = std::dynamic_pointer_cast<edm_primitive_type>(property_type);

			if (p_value && p_primitive_type)
			{
				handle_serialize_primitive_value(ss, p_primitive_type, p_value);
			}
			else
			{
				ss << "null";
			}
		}
		break;
	case edm_type_kind_t::Enum:
		{
			auto p_value = std::dynamic_pointer_cast<odata_enum_value>(property_value);
			
			if (p_value)
			{
				handle_serialize_enum_value(ss, p_value);
			}
			else
			{
				ss << "null";
			}
		}
		break;
	case edm_type_kind_t::PayloadAnnotation:
		{
			auto p_value = std::dynamic_pointer_cast<odata_primitive_value>(property_value);

			if (p_value)
			{
				ss << U('"') << p_value->to_string() << U('"');
			}
			else
			{
				ss << "null";
			}
		}
		break;
	case edm_type_kind_t::Complex:
		{
			auto p_value = std::dynamic_pointer_cast<odata_complex_value>(property_value);

			if (p_value)
			{
				::utility::string_t type_link;
				if (p_value->try_get(PAYLOAD_ANNOTATION_TYPE, type_link) && !type_link.empty())
				{
					if (type_link.find(U("#")) != 0)
					{
						type_link = U("#") + type_link;
						p_value->set_value(PAYLOAD_ANNOTATION_TYPE, 
							std::make_shared<odata_primitive_value>(std::make_shared<edm_payload_annotation_type>(PAYLOAD_ANNOTATION_TYPE), type_link));
					}
				}

				handle_serialize_odata_properties(ss, p_value->properties());
			}
			else
			{
				ss << "null";
			}
		}
		break;
	case edm_type_kind_t::Collection:
		{
			auto p_value = std::dynamic_pointer_cast<odata_collection_value>(property_value);

			if (p_value)
			{
				handle_serialize_collection_value(ss, p_value);
			}
			else
			{
				ss << "[]";
			}
		}
		break;
	case edm_type_kind_t::Entity:
		{
			auto p_value = std::dynamic_pointer_cast<odata_entity_value>(property_value);

			if (p_value)
			{
				::utility::string_t type_link;
				if (p_value->try_get(PAYLOAD_ANNOTATION_TYPE, type_link) && !type_link.empty())
				{
					if (type_link.find(U("#")) != 0)
					{
						type_link = U("#") + type_link;
						p_value->set_value(PAYLOAD_ANNOTATION_TYPE, 
							std::make_shared<odata_primitive_value>(std::make_shared<edm_payload_annotation_type>(PAYLOAD_ANNOTATION_TYPE), type_link));
					}
				}

				handle_serialize_odata_properties(ss, p_value->properties());
			}
			else
			{
				ss << "null";
			}
		}
		break;
	default:
		{
			throw std::runtime_error("write unsupported property type!");  
		}
		break;
	}
}