ASFUNCTIONBODY(NetConnection,connect) { NetConnection* th=Class<NetConnection>::cast(obj); //This takes 1 required parameter and an unspecified number of optional parameters assert_and_throw(argslen>0); //This seems strange: //LOCAL_WITH_FILE may not use connect(), even if it tries to connect to a local file. //I'm following the specification to the letter. Testing showed //that the official player allows connect(null) in localWithFile. if(args[0]->getObjectType() != T_NULL && sys->securityManager->evaluateSandbox(SecurityManager::LOCAL_WITH_FILE)) throw Class<SecurityError>::getInstanceS("SecurityError: NetConnection::connect " "from LOCAL_WITH_FILE sandbox"); //Null argument means local file or web server, the spec only mentions NULL, but youtube uses UNDEFINED, so supporting that too. if(args[0]->getObjectType()==T_NULL || args[0]->getObjectType()==T_UNDEFINED) { th->_connected = false; } //String argument means Flash Remoting/Flash Media Server else { th->_connected = false; ASString* command = static_cast<ASString*>(args[0]); th->uri = URLInfo(command->toString()); if(sys->securityManager->evaluatePoliciesURL(th->uri, true) != SecurityManager::ALLOWED) { //TODO: find correct way of handling this case throw Class<SecurityError>::getInstanceS("SecurityError: connection to domain not allowed by securityManager"); } if(!(th->uri.getProtocol() == "rtmp" || th->uri.getProtocol() == "rtmpe" || th->uri.getProtocol() == "rtmps")) { throw UnsupportedException("NetConnection::connect: only RTMP is supported"); } // We actually create the connection later in // NetStream::play(). For now, we support only // streaming, not remoting (NetConnection.call() is // not implemented). } //When the URI is undefined the connect is successful (tested on Adobe player) th->incRef(); getVm()->addEvent(_MR(th), _MR(Class<NetStatusEvent>::getInstanceS("status", "NetConnection.Connect.Success"))); return NULL; }
int JSON::parseNumber(const tiny_string &jsonstring, int pos, ASObject** parent, const multiname& key) { int len = jsonstring.numBytes(); tiny_string res; bool done = false; while (!done && pos < len) { char c = jsonstring.charAt(pos); switch(c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '-': case '+': case '.': case 'E': case 'e': res += c; pos++; break; default: done = true; break; } } ASString* numstr = Class<ASString>::getInstanceS(res); number_t num = numstr->toNumber(); if (std::isnan(num)) throwError<SyntaxError>(kJSONInvalidParseInput); if (*parent == NULL) *parent = Class<Number>::getInstanceS(num); else { (*parent)->setVariableByMultiname(key,Class<Number>::getInstanceS(num),ASObject::CONST_NOT_ALLOWED); } return pos; }
bool Vector::isValidMultiname(const multiname& name, uint32_t& index) { //First of all the multiname has to contain the null namespace //As the namespace vector is sorted, we check only the first one assert_and_throw(name.ns.size()!=0); if(name.ns[0].name!="") return false; index=0; switch(name.name_type) { //We try to convert this to an index, otherwise bail out case multiname::NAME_STRING: { if(name.name_s.empty()) return false; ASString* s = Class<ASString>::getInstanceS(name.name_s); number_t n = s->toNumber(); delete s; if(!Number::isInteger(n) || n<0) return false; index = n; break; } //This is already an int, so its good enough case multiname::NAME_INT: if(name.name_i < 0) throw Class<RangeError>::getInstanceS("Error #1125"); index=name.name_i; break; case multiname::NAME_NUMBER: if(!Number::isInteger(name.name_d) || name.name_d < 0) throw Class<RangeError>::getInstanceS("Error #1125"); index = name.name_d; break; case multiname::NAME_OBJECT: //TODO: should be use toPrimitive here? return false; default: throw UnsupportedException("Vector::isValidMultiname not completely implemented"); } return true; }
ASFUNCTIONBODY(NetConnection,connect) { NetConnection* th=Class<NetConnection>::cast(obj); //This takes 1 required parameter and an unspecified number of optional parameters assert_and_throw(argslen>0); //This seems strange: //LOCAL_WITH_FILE may not use connect(), even if it tries to connect to a local file. //I'm following the specification to the letter if(sys->securityManager->evaluateSandbox(SecurityManager::LOCAL_WITH_FILE)) throw Class<SecurityError>::getInstanceS("SecurityError: NetConnection::connect " "from LOCAL_WITH_FILE sandbox"); //Null argument means local file or web server, the spec only mentions NULL, but youtube uses UNDEFINED, so supporting that too. if(args[0]->getObjectType()==T_NULL || args[0]->getObjectType()==T_UNDEFINED) { th->_connected = false; } //String argument means Flash Remoting/Flash Media Server else { th->_connected = false; ASString* command = static_cast<ASString*>(args[0]); th->uri = URLInfo(command->toString()); if(sys->securityManager->evaluatePoliciesURL(th->uri, true) != SecurityManager::ALLOWED) { //TODO: find correct way of handling this case throw Class<SecurityError>::getInstanceS("SecurityError: connection to domain not allowed by securityManager"); } throw UnsupportedException("NetConnection::connect to FMS"); } //When the URI is undefined the connect is successful (tested on Adobe player) Event* status=Class<NetStatusEvent>::getInstanceS("status", "NetConnection.Connect.Success"); getVm()->addEvent(th, status); status->decRef(); return NULL; }