// // wap.cpp // // Copyright 2005 Vladimir Vyskocil // All rights reserved. // // Authors: Vladimir Vyskocil // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation files // (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #include #include #include #define RETURN_NO_VALUE \ Py_INCREF(Py_None); \ return Py_None; #define RETURN_TRUE \ Py_INCREF(Py_True); \ return Py_True; #define RETURN_FALSE \ Py_INCREF(Py_False); \ return Py_False; #define WAIT_STAT(stat) \ Py_BEGIN_ALLOW_THREADS;\ User::WaitForRequest(stat);\ Py_END_ALLOW_THREADS #define MODULE_NAME wap //:ulwp COMP_NAME #define MODULE_NAME_STRING "wap" //:usp COMP_NAME.inspect #define MODULE_INIT_FUNC init##MODULE_NAME #include // RFs #include #include #include #include #define MAXSIZE 150000 // #define errCode Py_BuildValue("i",-1) // ---------------------------------------------------------------------- static PyObject* wap_getFile(PyObject* self, PyObject* args){ RWAPServ iWapServ; RWSPCOConn iWapConn; CCapCodec* iCap; char *fileName, *uri, *gw; int uriLen, fileNameLen, gwLen; if(!PyArg_ParseTuple(args, "u#s#u#", &uri, &uriLen, &gw, &gwLen, &fileName, &fileNameLen)){ return NULL; } TPtrC aFileName((TUint16*)fileName, fileNameLen); TPtrC8 aGw((TUint8*)gw, gwLen); TPtrC aURI((TUint16*)uri, uriLen); iWapServ.Connect(); iCap = CCapCodec::NewL(); iCap->SetServerSDUSize(MAXSIZE+3000); iCap->SetClientSDUSize(MAXSIZE+3000); RFs fs; fs.Connect(); RFile file; file.Replace(fs, aFileName, EFileWrite|EFileShareAny|EFileStreamText); TInt ret; TBuf8<512> data; _LIT8(KEmptyString,""); if(iWapConn.Open(iWapServ, aGw, 9201, 0, EIP, EFalse)!=KErrNone) { return errCode; } if(iWapConn.Connect(KEmptyString, iCap)!=KErrNone) { return errCode; } RWSPCOConn::TSessionState sessionstate; RWSPCOTrans trans; //RWSPCOTrans::TState state; RWSPCOConn::TEvent event; do { iWapConn.GetEvent(event, trans); if(event() == RWSPCOConn::EDisconnect_ind_s || event() == RWSPCOConn::EException_ind_e || event() == RWSPCOConn::ERedirect_ind_s || event() == RWSPCOConn::ESuspend_ind_s) break; } while(event() != RWSPCOConn::EConnect_cnf_s); if(event() == RWSPCOConn::EConnect_cnf_s) { // if(iWapConn.GetSessionState(sessionstate)!=KErrNone) return errCode; // if(sessionstate!=RWSPCOConn::EConnected) return errCode; if(iWapConn.CreateTransaction(RWAPConn::EGet, aURI, KEmptyString, KEmptyString, trans)==KErrNone) { do { iWapConn.GetEvent(event, trans); if(event() == RWSPCOConn::EAbort_ind_t || event() == RWSPCOConn::EException_ind_e) break; } while(event() != RWSPCOConn::EMethodResult_ind_t); if(event() == RWSPCOConn::EMethodResult_ind_t){ do { ret = trans.GetData(data, RWSPCOTrans::EResultBody); file.Write(data); } while(ret==RWAPConn::EMoreData); trans.Release(); } else { return errCode; } } else { return errCode; } } else { return errCode; } iWapConn.Close(); iWapServ.Close(); delete iCap; file.Close(); fs.Close(); return Py_BuildValue("i", 0); } static const PyMethodDef wap_methods[] = { {"get_file", (PyCFunction)wap_getFile, METH_VARARGS, "Download a file by WAP connection."}, {NULL, NULL} /* sentinel */ }; #define MODULE_METHODS const_cast(&wap_methods[0]) DL_EXPORT(void) MODULE_INIT_FUNC() { PyObject* module = Py_InitModule(MODULE_NAME_STRING, MODULE_METHODS); if (!module) { return; } } GLDEF_C TInt E32Dll(TDllReason) { return KErrNone; }