void TwitterFeedService::HandleAuthResponse(Eegeo::Web::IWebResponse& webResponse)
 {
     m_pCurrentAuthRequest = NULL;
     
     if(webResponse.GetHttpStatusCode() != 200)
     {
         m_currentServiceState = OFFLINE;
         
         ClearAccountNameQueue();
         
         return;
     }
     
     size_t resultSize = webResponse.GetBodyData().size();
     std::string serialized(reinterpret_cast<char const*>(&(webResponse.GetBodyData().front())), resultSize);
     
     rapidjson::Document document;
     
     document.Parse<0>(serialized.c_str());
     
     Eegeo_ASSERT(!document.HasParseError(), "Error parsing auth response");
     Eegeo_ASSERT(document.HasMember(AccessTokenKey.c_str()), "Auth response doesn't contain access code: %s", serialized.c_str());
     
     m_accessToken = std::string(document[AccessTokenKey.c_str()].GetString());
     
     LoadNextTimeLine();
 }
Ejemplo n.º 2
0
 Json::Value MapObject::serialize() const {
   Json::Value serialized(Json::objectValue);
   serialized["type"] = Json::Value(type());
   serialized["location"] = location().serialize();
   
   return serialized;
 }
Ejemplo n.º 3
0
QString KisShortcutConfiguration::serialize()
{
    QString serialized("{");

    serialized.append(QString::number(d->mode, 16));
    serialized.append(';');
    serialized.append(QString::number(d->type, 16));
    serialized.append(";[");

    for (QList<Qt::Key>::iterator itr = d->keys.begin(); itr != d->keys.end(); ++itr) {
        serialized.append(QString::number(*itr, 16));

        if (itr + 1 != d->keys.end()) {
            serialized.append(',');
        }
    }

    serialized.append("];");

    serialized.append(QString::number(d->buttons, 16));
    serialized.append(';');
    serialized.append(QString::number(d->wheel, 16));
    serialized.append(';');
    serialized.append(QString::number(d->gesture, 16));
    serialized.append('}');

    return serialized;
}
Ejemplo n.º 4
0
		void Response::tryEmptyResponse()
		{
			::Spin::Details::Response response("HTTP/1.1", ::Spin::Details::Response::ok__);
			std::vector< char > _serialized(serialize(response));
			std::string serialized(_serialized.begin(), _serialized.end());
			CPPUNIT_ASSERT(serialized == "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
		}
TransactionStatement::operator OTString() const
{
    auto output = String::Factory();

    Tag serialized("nymData");

    serialized.add_attribute("version", version_);
    serialized.add_attribute("nymID", nym_id_);

    if (0 < issued_.size()) {
        NumList issuedList(issued_);
        auto issued = String::Factory();
        issuedList.Output(issued);
        TagPtr issuedTag(
            new Tag("issuedNums", Armored::Factory(issued)->Get()));
        issuedTag->add_attribute("notaryID", notary_);
        serialized.add_tag(issuedTag);
    }

    if (0 < available_.size()) {
        NumList availableList(available_);
        auto available = String::Factory();
        availableList.Output(available);
        TagPtr availableTag(
            new Tag("transactionNums", Armored::Factory(available)->Get()));
        availableTag->add_attribute("notaryID", notary_);
        serialized.add_tag(availableTag);
    }

    std::string result;
    serialized.output(result);

    return String::Factory(result.c_str());
}
Ejemplo n.º 6
0
bool DesignNetDocument::save(QString *errorString, const QString &fileName, bool autoSave)
{
	Utils::XmlSerializer x;
	x.serialize("DesignNetSpace", *(d->space));
	emit serialized(x);
	x.write(fileName);
    return true;
}
Ejemplo n.º 7
0
		// Result publisher (executed within subscription thread)
		bool publishResult(Event const& event, SockPair::SOCKET_ptr const* socks) {
			// Convert Wind event into K object
			std::string error;
			q::K_ptr data;
			if (event.ErrCode != WQERR_OK) {
				std::cerr << "<WQ> subscription error: " << util::error2Text(event.ErrCode) << std::endl;
				return false;
			}
			try {
				data.reset(event.parse());
			}
			catch (std::string const& ex) {
				std::cerr << "<WQ> response format error: " << ex << std::endl;
				return false;
			}

			// Serialize K object into bytes
			static_assert(std::is_same<::WQID, J>::value, "WQID data type mismatch");
#			if KX_USE_OKX
			q::K_ptr serialized(b9(1, data.get()));
#			else
			q::K_ptr serialized(b9(-1, data.get()));
#			endif
			assert((serialized->t == KG) && (serialized->n > 0));

			// Send tuple (WQID, len, serialized_K) over to the main thread
#			define SEND_CHECK(expectedSize, errorMsg)	\
			if (sent != (expectedSize)) {	\
				std::cerr << "<send> " << (errorMsg) << ": " << sent << " < " << (expectedSize) << std::endl;	\
				return false;	\
			}
			int sent = ::send(*socks[SERVER], reinterpret_cast<char const*>(&event.RequestID), sizeof(::WQID), 0);
			SEND_CHECK(sizeof(::WQID), "WQID incomplete");
			std::size_t const len = static_cast<std::size_t>(serialized->n);
			if (len > static_cast<std::size_t>(std::numeric_limits<int>::max())) {
				std::cerr << "<send> serialized data (" << len << ") > 2G" << std::endl;
				return false;
			}
			sent = ::send(*socks[SERVER], reinterpret_cast<char const*>(&len), sizeof(len), 0);
			SEND_CHECK(sizeof(len), "size incomplete");
			sent = ::send(*socks[SERVER], reinterpret_cast<char const*>(kG(serialized.get())), len, 0);
			SEND_CHECK(serialized->n, "data incomplete");
#			undef SEND_CHECK

			return true;
		}
Ejemplo n.º 8
0
Data DirEntryList::serialize() const {
    Data serialized(_serializedSize());
    unsigned int offset = 0;
    for (const auto &entry : _entries) {
        entry.serialize(static_cast<uint8_t*>(serialized.dataOffset(offset)));
        offset += entry.serializedSize();
    }
    return serialized;
}
Ejemplo n.º 9
0
      std::string	JSONSerialization::List(const std::list< std::unique_ptr<Serial> >& list) {
	std::string	serialized("[\n");
	std::size_t	end = list.size();

	std::for_each(list.begin(), list.end(), [this, &end, &serialized]
		      (typename std::remove_const< typename std::remove_reference< decltype(list) >::type >::type::const_reference value) -> void {
			serialized += std::string(level, '\t') + '"' + Serializer::serialize(*value) + (end ? ",\n" : "\n"); -- end;
		      });
	return serialized +  "}\n";
      }
Ejemplo n.º 10
0
Data DirEntryList::serialize() const {
    Data serialized(_serializedSize());
    unsigned int offset = 0;
    for (auto iter = _entries.begin(); iter != _entries.end(); ++iter) {
        ASSERT(iter == _entries.begin() || std::less<Key>()((iter-1)->key(), iter->key()), "Invariant hurt: Directory entries should be ordered by key and not have duplicate keys.");
        iter->serialize(static_cast<uint8_t*>(serialized.dataOffset(offset)));
        offset += iter->serializedSize();
    }
    return serialized;
}
Ejemplo n.º 11
0
      std::string	JSONSerialization::Map(const std::map< std::string, std::unique_ptr<Serial> >& map) {
	std::string	serialized("{[\n");
	std::size_t	end = map.size();

	std::for_each(map.begin(), map.end(), [this, &end, &serialized]
		      (typename std::remove_const< typename std::remove_reference<decltype(map)>::type >::type::const_reference pair) -> void {
			serialized += std::string(level, '\t' ) + '"' + pair.first + "\" : " + Serializer::serialize(*(pair.second)) + (end ? ",\n" : ","); --end;
		      });
	serialized += "]}\n";
	return serialized;
      }
Ejemplo n.º 12
0
		// Data processor (executed within q's main thread)
		K invokeCallback(I socket) {
			static_assert(sizeof(::SOCKET) == sizeof(I), "SOCKET vs I: type mismatch!");
			::SOCKET sock = socket;
			assert(sock != INVALID_SOCKET);

			// Receive (WQID, len, serialized_K) from subscription thread
#			define RECV_CHECK(expectedSize, errorMsg)	\
			if (recvd != (expectedSize)) {	\
				std::cerr << "<recv> " << (errorMsg) << ": " << recvd << " < " << (expectedSize) << std::endl;	\
				return K_NIL;	\
			}
			::WQID qid = 0;
			int recvd = ::recv(sock, reinterpret_cast<char*>(&qid), sizeof(::WQID), 0);
			RECV_CHECK(sizeof(::WQID), "WQID incomplete");
			std::size_t len = 0;
			recvd = ::recv(sock, reinterpret_cast<char*>(&len), sizeof(len), 0);
			RECV_CHECK(sizeof(len), "size incomplete");
			if (len > static_cast<std::size_t>(std::numeric_limits<int>::max())) {
				std::cerr << "<recv> serialized data (" << len << ") > 2G" << std::endl;
				return K_NIL;
			}
			q::K_ptr serialized(ktn(KB, len));
			std::memset(kG(serialized.get()), 0, len);
			recvd = ::recv(sock, reinterpret_cast<char*>(kG(serialized.get())), len, 0);
			RECV_CHECK(len, "data incomplete");
#			undef RECV_CHECK

			// Deserialize K object
#			if KX_USE_OKX
			//@ref https://groups.google.com/forum/#!topic/personal-kdbplus/pjsugT7590A
			if (!okx(serialized.get())) {
				std::cerr << "<recv> bad data: ["
					<< util::hexBytes(kG(serialized.get()), static_cast<std::size_t>(serialized->n))
					<< ']' << std::endl;
				return K_NIL;
			}
#			endif
			q::K_ptr result(d9(serialized.get()));

			// Identify the origial query and callback
			std::string const callback = REGISTRY[qid];
			if (callback.empty()) {
				std::cerr << "unknown WQID: " << qid << std::endl;
				return K_NIL;
			}

			static_assert(std::is_same<::WQID, J>::value, "WQID data type mismatch");
			q::K_ptr output(k(0, const_cast<S>(callback.c_str()), kj(qid), result.release(), K_NIL));
			if (output->t == -128) {
				std::cerr << "<q> '" << output->s << std::endl;
			}
			return output.release();
		}
Ejemplo n.º 13
0
static void OnData(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *value, void *info) {
    switch (type) {
        case kCFSocketDataCallBack:
            CFDataRef data(reinterpret_cast<CFDataRef>(value));
            Client *client(reinterpret_cast<Client *>(info));

            if (client->message_ == NULL)
                client->message_ = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, TRUE);

            if (!CFHTTPMessageAppendBytes(client->message_, CFDataGetBytePtr(data), CFDataGetLength(data)))
                CFLog(kCFLogLevelError, CFSTR("CFHTTPMessageAppendBytes()"));
            else if (CFHTTPMessageIsHeaderComplete(client->message_)) {
                CFURLRef url(CFHTTPMessageCopyRequestURL(client->message_));
                Boolean absolute;
                CFStringRef path(CFURLCopyStrictPath(url, &absolute));
                CFRelease(client->message_);

                CFStringRef code(CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, path, CFSTR("")));
                CFRelease(path);

                JSStringRef script(JSStringCreateWithCFString(code));
                CFRelease(code);

                JSValueRef result(JSEvaluateScript(CYGetJSContext(), script, NULL, NULL, 0, NULL));
                JSStringRelease(script);

                CFHTTPMessageRef response(CFHTTPMessageCreateResponse(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1));
                CFHTTPMessageSetHeaderFieldValue(response, CFSTR("Content-Type"), CFSTR("application/json; charset=utf-8"));

                CFStringRef json(CYCopyJSONString(CYGetJSContext(), result, NULL));
                CFDataRef body(CFStringCreateExternalRepresentation(kCFAllocatorDefault, json, kCFStringEncodingUTF8, NULL));
                CFRelease(json);

                CFStringRef length(CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"), CFDataGetLength(body)));
                CFHTTPMessageSetHeaderFieldValue(response, CFSTR("Content-Length"), length);
                CFRelease(length);

                CFHTTPMessageSetBody(response, body);
                CFRelease(body);

                CFDataRef serialized(CFHTTPMessageCopySerializedMessage(response));
                CFRelease(response);

                CFSocketSendData(socket, NULL, serialized, 0);
                CFRelease(serialized);

                CFRelease(url);
            }
        break;
    }
}
Ejemplo n.º 14
0
      std::string	JSONSerialization::Object(const std::type_info& type_info, const std::map< std::string, std::unique_ptr<Serial> >& object) {
	std::string	serialized(
				   "{\n" +
				   std::string(level, '\t') + "\"type\" : \"" + Serializer::nameById(type_info) + "\"\n" +
				   std::string(level, '\t') + "\"object\" : "
				   );
	std::size_t	end = object.size();

	std::for_each(object.begin(), object.end(), [this, &end, &serialized]
		      (typename std::remove_const< typename std::remove_reference<decltype(object)>::type >::type::const_reference pair) -> void {
			serialized += std::string(level, '\t' ) + '"' + pair.first + "\" : " + Serializer::serialize(*(pair.second)) + (end ? ",\n" : ","); --end;
		      });
	serialized += "}\n";
	return serialized;
      }
void CBBListenerImpl::IncomingTuple(const CBBTuple* aTuple)
{
	iTimer->Wait(KMaxAckInterval);

	TTupleName tn= { aTuple->iTupleMeta.iModuleUid(), aTuple->iTupleMeta.iModuleId() };

	auto_ptr<HBufC8> serialized(HBufC8::NewL(1024));

	if (! iSeenIds->SeenIdL(aTuple->iTupleId()) ) {
		PutTupleL(tn, aTuple->iTupleMeta.iSubName(),
			aTuple->iData(), aTuple->iExpires());
		iSeenIds->SetAsSeenL(aTuple->iTupleId());
	}

	iToAck->AppendL(aTuple->iTupleId());
}
 ApplicationConfiguration ApplicationConfigurationService::LoadConfiguration(const std::string& path)
 {
     std::string serialized(m_reader.ReadApplicationConfiguration(path));
     const ApplicationConfiguration& parsedConfig = m_parser.ParseConfiguration(serialized);
     
     const std::string combinedVersionString = m_productVersion + "." + m_buildNumber;
     
     return ApplicationConfiguration(parsedConfig.Name(),
                                     parsedConfig.InterestLocation(),
                                     parsedConfig.DistanceToInterestMetres(),
                                     parsedConfig.OrientationDegrees(),
                                     parsedConfig.TryStartAtGpsLocation(),
                                     parsedConfig.GoogleAnalyticsReferrerToken(),
                                     m_productVersion,
                                     m_buildNumber,
                                     combinedVersionString);
 }
Ejemplo n.º 17
0
void Switch::sendFrame(Frame* frame, int port)
{
	std::vector<unsigned char> serialized(frame->serialize());

	struct KernelComMsg *msg = (struct KernelComMsg*) malloc(serialized.size() + 12);

	msg->control.port = port;
	msg->control.type = 0; //packet - TODO: define as constant
	msg->control.len = serialized.size();

	memmove(msg->frame, serialized.data(), serialized.size());

	netlinkCom.send((unsigned char*) msg, msg->control.len + 12);

	free(msg);
	delete frame;
}
 void TwitterFeedService::HandleTimeLineResponse(Eegeo::Web::IWebResponse& webResponse)
 {
     m_pCurrentTimeLineRequest = NULL;
     
     if(webResponse.GetHttpStatusCode() != 200)
     {
         m_currentServiceState = OFFLINE;
         
         ClearAccountNameQueue();
         
         return;
     }
     
     size_t resultSize = webResponse.GetBodyData().size();
     std::string serialized(reinterpret_cast<char const*>(&(webResponse.GetBodyData().front())), resultSize);
     
     rapidjson::Document document;
     
     document.Parse<0>(serialized.c_str());
     
     Eegeo_ASSERT(!document.HasParseError(), "Error parsing timeline request response")
     Eegeo_ASSERT(document.IsArray(), "Timeline request response unrecognised: %s", serialized.c_str());
     
     std::map<std::string, TweetRepository*>::iterator repositoryIt = m_repositoryMap.find(m_accountNameQueue.front());
     
     if(repositoryIt == m_repositoryMap.end())
     {
         repositoryIt = m_repositoryMap.insert(std::pair<std::string, TweetRepository*>(m_accountNameQueue.front(), Eegeo_NEW(TweetRepository)())).first;
     }
     
     TweetRepository* currentRepository = (*repositoryIt).second;
     
     for(rapidjson::SizeType i = 0; i < document.Size(); ++i)
     {
         currentRepository->AddItem(TweetModel::GetNewTweetModelFromJsonDocument(document, i));
     }
     
     m_feedLoadedCallbacks.ExecuteCallbacks(m_accountNameQueue.front(), *currentRepository);
     
     m_accountNameQueue.pop();
     
     LoadNextTimeLine();
 }
Ejemplo n.º 19
0
void
OpenDDS::DCPS::ReliableMulticast::detail::PacketHandler::send_packet_to(
  const Packet& packet,
  const ACE_INET_Addr& dest
  )
{
  size_t buffer_size = 0;
  PacketSerializer packetSerializer;
  ACE_Auto_Basic_Array_Ptr<char> serialized(
    packetSerializer.getBuffer(packet, buffer_size)
    );
  char* begin = packetSerializer.serializeFromTo(packet, serialized.get(), buffer_size);

  OpenDDS::DCPS::ReliableMulticast::detail::EventHandler::send(
    begin,
    buffer_size - (begin - serialized.get()),
    dest
    );
}
void CBBListenerImpl::PutTupleL(const TTupleName& aTuple,
	const TDesC& aSubName, const MBBData* aData, const TTime& aExpires)
{
	if (!aData) {
		TRequestStatus s;
		iBBClient.Delete(aTuple, aSubName, s);
		User::WaitForRequest(s);
		if (s.Int()==KErrNone || s.Int()==KErrNotFound) return;
		User::Leave(s.Int());
	}

	auto_ptr<HBufC8> serialized(HBufC8::NewL(1024));
	TInt err=KErrOverflow;
	while (err==KErrOverflow) {
		TPtr8 bufp(serialized->Des());
		RDesWriteStream ws(bufp);

		aData->Type().ExternalizeL(ws);
		CC_TRAP(err, aData->ExternalizeL(ws));
		if (err==KErrNone) {
			ws.CommitL();
		} else if (err==KErrOverflow) {
			serialized.reset( HBufC8::NewL(
				serialized->Des().MaxLength()*2) );
		}
	}
	User::LeaveIfError(err);

	TUint id;
	TRequestStatus s;

	TBool replace=ETrue;
	if (aTuple==KRemoteLocaLogicTuple) replace=EFalse;
	if (aTuple==KRemoteBluetoothTuple) replace=EFalse;

	iBBClient.Put(aTuple, aSubName,
		KNoComponent, *serialized, EBBPriorityNormal,
		replace, id, s, aExpires, ETrue, EFalse);
	User::WaitForRequest(s);
	User::LeaveIfError(s.Int());
}
Ejemplo n.º 21
0
bool send<serializable>(socket_t socket, const serializable& orig, size_t size)
{
    buffer<> serialized(orig.size());
    orig.serialize(serialized);
    return send(socket, serialized, orig.size());
}
Ejemplo n.º 22
0
void Network::make_receive_event(const Packet& packet)
{
  std::string serialized(packet.bytes.begin(), packet.bytes.end());

  push_deserialized_event(json_t::parse(serialized), packet.ip, events);
}