public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("POST request: {0}", p.http_url); var compnents = p.http_url.Split('?'); if (compnents.Length != 2) { Console.WriteLine("invalid url compnents: {0}", compnents.ToString()); p.writeFailure(); return; } var reqUri = compnents[0]; if (!reqUri.Equals(Uri)) { p.writeFailure(); return; } var queryPath = compnents[1]; var queryDict = new Dictionary <string, string>(); foreach (var statement in queryPath.Split("&&".ToCharArray())) { var elements = statement.Split('='); if (elements.Length == 2) { queryDict[elements[0]] = elements[1]; } } var data = inputData.ReadToEnd(); var jsonReader = new JsonReader(); var reqJson = jsonReader.Read <Dictionary <string, object> >(data); object toBuin; object toApp; object encrypt; if (!reqJson.TryGetValue("toBuin", out toBuin) || toBuin is int == false || (int)toBuin <= 0 || !reqJson.TryGetValue("toApp", out toApp) || toApp is string == false || ((string)toApp).Length == 0 || !reqJson.TryGetValue("encrypt", out encrypt) || encrypt is string == false || ((string)encrypt).Length == 0) { Console.WriteLine("invalid toBuin or toApp or encrypt"); p.writeFailure(); return; } var toBuinValue = (int)toBuin; var toAppValue = (string)toApp; var encryptValue = (string)encrypt; string timeStamp; string nonce; string signature; if (!queryDict.TryGetValue("timestamp", out timeStamp) || timeStamp == null || !queryDict.TryGetValue("nonce", out nonce) || nonce == null || !queryDict.TryGetValue("msg_signature", out signature) || signature == null) { Console.WriteLine("invalid timestamp or nonce or msg_signature"); p.writeFailure(); return; } if (toBuinValue != Buin || !toAppValue.Equals(AppId)) { Console.WriteLine("buin or appId is not matched"); p.writeFailure(); return; } var mySignature = Signature.GenerateSignature(Token, timeStamp, nonce, encryptValue); if (!signature.Equals(mySignature)) { Console.WriteLine("signature is not matched"); p.writeFailure(); return; } var decryptContent = m_crypto.Decrypt(encryptValue); //var msg = new SessionMessage().FromJson(AESCrypto.ToString(decryptContent)); var msg = new ReceiveMessage().FromJson(AESCrypto.ToString(decryptContent)); switch (msg.MsgType) { case Message.MessageTypeImage: { var msgBody = msg.MsgBody.ToImageBody(); m_appClient.DownloadFile(msgBody.MediaId, OutDir); } break; case Message.MessageTypeFile: { var msgBody = msg.MsgBody.ToFileBody(); m_appClient.DownloadFile(msgBody.MediaId, OutDir); } break; default: break; } Console.WriteLine(msg.ToString()); Console.WriteLine("packageId: {0}", msg.PackageId); p.writeSuccess(); p.outputStream.WriteLine(msg.PackageId); }
public override void handleGETRequest(HttpProcessor p) { Console.WriteLine("request: {0}", p.http_url); p.writeSuccess(); }