Skip to content

Commit

Permalink
- QueryReader use now a PacketReader (correction for packets from HTT…
Browse files Browse the repository at this point in the history
…P POST messages)
  • Loading branch information
thomasjammet committed Dec 18, 2014
1 parent dce13da commit 6f0ae2b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
7 changes: 2 additions & 5 deletions MonaCore/include/Mona/QueryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ namespace Mona {
class QueryReader : public DataReader, public virtual Object {
public:

QueryReader(const char* query) : _query(query),_current(_query),_type(END) {}
QueryReader(PacketReader& packet) : DataReader(packet),_type(END) {}

const char* query() const { return _query; }
void reset() { _current = _query; _type = END; }
void reset() { packet.reset(); _type = END; }

private:
enum {
Expand All @@ -45,8 +44,6 @@ class QueryReader : public DataReader, public virtual Object {
void writeValue(UInt8 type, DataWriter& writer);
UInt8 valueType();

const char* _query;
const char* _current;
std::string _property;
std::string _value;
Date _date;
Expand Down
3 changes: 2 additions & 1 deletion MonaCore/sources/HTTP/HTTPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void HTTPSession::receive(const shared_ptr<HTTPPacket>& pPacket) {
peer.properties().setString(it.first, it.second);

// Create parameters for onConnection or a GET onRead/onWrite/onMessage
QueryReader parameters(peer.query.c_str());
PacketReader query(BIN peer.query.data(), peer.query.size());
QueryReader parameters(query);

Exception ex;

Expand Down
2 changes: 1 addition & 1 deletion MonaCore/sources/MIME.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool MIME::CreateDataReader(Type type,PacketReader& packet,const PoolBuffers& po
pReader.reset(new AMFReader(packet));
return true;
case QUERY:
pReader.reset(new QueryReader(STR packet.data()));
pReader.reset(new QueryReader(packet));
return true;
}
pReader.reset();
Expand Down
25 changes: 17 additions & 8 deletions MonaCore/sources/QueryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ UInt8 QueryReader::followingType() {
_value.assign(value);
} else
_value = std::move(key);
return false;
return false; // we just want the first following key
});

if (!_current || Util::UnpackQuery(_current, forEach) == 0)
if (!packet.available())
return END;

SCOPED_STRINGIFY(STR packet.current(),packet.available(), if (Util::UnpackQuery(STR packet.current(), forEach) == 0) return END;)

if (hasProperty)
_type = OBJECT;
else
Expand All @@ -54,29 +56,36 @@ UInt8 QueryReader::followingType() {


bool QueryReader::readOne(UInt8 type, DataWriter& writer) {


const UInt8* cur = packet.current();
const UInt8* end = cur+packet.available();
if (type==OBJECT) {

// OBJECT
writer.beginObject();
do {
cur = packet.current();
writer.writePropertyName(_property.c_str());
writeValue(valueType(), writer);

// next!
_current = strchr(_current, '&');
while (cur<end && *cur != '&')
cur++;
packet.next(cur-packet.current() + (*cur=='&'));

_type = END;
if (_current) ++_current;
} while ((_type=followingType())==OBJECT);
} while (cur<end && (_type=followingType())==OBJECT);
writer.endObject();
return true;
}

writeValue(type, writer);

// next!
_current = strchr(_current, '&');
while (cur<end && *cur != '&')
cur++;
packet.next(cur-packet.current() + (*cur=='&'));
_type = END;
if (_current) ++_current;
return true;
}

Expand Down
10 changes: 1 addition & 9 deletions MonaServer/sources/LUAInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,6 @@ int LUAInvoker::ToXML(lua_State *pState) {
SCRIPT_CALLBACK_RETURN
}

int LUAInvoker::FromQuery(lua_State *pState) {
SCRIPT_CALLBACK(Invoker, invoker)
ScriptWriter writer(pState);
QueryReader(SCRIPT_READ_STRING(String::Empty.c_str())).read(writer);
SCRIPT_CALLBACK_RETURN
}


int LUAInvoker::AddToBlacklist(lua_State* pState) {
SCRIPT_CALLBACK(Invoker,invoker)
while(SCRIPT_READ_AVAILABLE) {
Expand Down Expand Up @@ -445,7 +437,7 @@ int LUAInvoker::Get(lua_State *pState) {
SCRIPT_WRITE_FUNCTION(LUAInvoker::ToData<Mona::QueryWriter>)
SCRIPT_CALLBACK_FIX_INDEX
} else if (strcmp(name, "fromQuery") == 0) {
SCRIPT_WRITE_FUNCTION(LUAInvoker::FromQuery)
SCRIPT_WRITE_FUNCTION(LUAInvoker::FromData<Mona::QueryReader>)
SCRIPT_CALLBACK_FIX_INDEX
} else if (strcmp(name, "absolutePath") == 0) {
SCRIPT_WRITE_FUNCTION(LUAInvoker::AbsolutePath)
Expand Down
1 change: 0 additions & 1 deletion MonaServer/sources/LUAInvoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class LUAInvoker {

static int FromXML(lua_State *pState);
static int ToXML(lua_State *pState);
static int FromQuery(lua_State *pState);

static int Time(lua_State *pState);
static int ToAMF0(lua_State *pState);
Expand Down
Binary file modified clients/samples/Meeting/VideoMeeting.swf
Binary file not shown.

0 comments on commit 6f0ae2b

Please sign in to comment.