Author: derek Date: Mon Nov 13 16:22:10 2006 New Revision: 185 Modified: sofaswitch/trunk/callflow/src/callstartstop.cpp sofaswitch/trunk/callflow/src/eventer.cpp sofaswitch/trunk/callflow/src/loadnewgraph.cpp sofaswitch/trunk/callflow/src/python.cpp sofaswitch/trunk/callflow/src/requestnode.cpp sofaswitch/trunk/callflow/src/senddtmf.cpp sofaswitch/trunk/callflow/src/shapelist.cpp sofaswitch/trunk/callflow/src/transfermedia.cpp Log: Protect every usage of the Python eval and exec with a try/except clause. Thus, the user cannot terminate execution of everything with a minor syntax error. Further, we get a more useful printout of what is wrong. Modified: sofaswitch/trunk/callflow/src/callstartstop.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/callstartstop.cpp (original) +++ sofaswitch/trunk/callflow/src/callstartstop.cpp Mon Nov 13 16:22:10 2006 @@ -41,15 +41,25 @@ { wxString header = wxString::Format(" def %s(self, sTuple):", (kind == MakeCall ? "Make_Call" : "End_Call")); file.AddLine(header); - file.AddLine(" a,b,c = sTuple "); - file.AddLine(" rhost = eval(self.data[a][\"worker node\"]) "); + file.AddLine(" a,b,c = sTuple "); + file.AddLine(" try: "); + file.AddLine(" self.rhost = eval(self.data[a][\"worker node\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"The worker node string \", self.data[a][\"worker node\"], \" could not be evaluated as a python string\" "); + file.AddLine(" self.rhost = None "); + file.AddLine(" try: "); + file.AddLine(" self.dest = eval(self.data[a][\"call destination\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"The destination string \", self.data[a][\"call destination\"], \" could not be evaluated as a python string\" "); + file.AddLine(" self.dest = None "); + if (kind == MakeCall) - file.AddLine(" rhost += \":CALLNODE \" + eval(self.data[a][\"call destination\"]) + \"\\0\" "); + file.AddLine(" self.rhost += \":CALLNODE \" + self.dest + \"\\0\" "); else - file.AddLine(" rhost += \":HANGUP \\0\" "); - file.AddLine(" self.transport.write(rhost) "); - file.AddLine(" return self.data[a][\"Output\"] "); - file.AddLine(""); + file.AddLine(" self.rhost += \":HANGUP \\0\" "); + file.AddLine(" self.transport.write(self.rhost) "); + file.AddLine(" return self.data[a][\"Output\"] "); + file.AddLine(" "); return true; } Modified: sofaswitch/trunk/callflow/src/eventer.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/eventer.cpp (original) +++ sofaswitch/trunk/callflow/src/eventer.cpp Mon Nov 13 16:22:10 2006 @@ -124,7 +124,11 @@ file.AddLine(" a,b,c = sTuple "); file.AddLine(" pVbl = self.data[a][\"Event Variable\"] "); file.AddLine(" pVbl += \" = None\" "); - file.AddLine(" exec(pVbl) "); + file.AddLine(" try: "); + file.AddLine(" exec(pVbl) "); + file.AddLine(" except: "); + file.AddLine(" pVbl = self.data[a][\"Event Variable\"] "); + file.AddLine(" print \"The Python variable \", pVbl, \" to hold event output could not be initialisd\" "); file.AddLine(" ePyn = self.data[a][\"Event Python\"] "); file.AddLine(" eReg = self.data[a][\"Event RegExp\"] "); file.AddLine(" if len(ePyn) > 0: "); Modified: sofaswitch/trunk/callflow/src/loadnewgraph.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/loadnewgraph.cpp (original) +++ sofaswitch/trunk/callflow/src/loadnewgraph.cpp Mon Nov 13 16:22:10 2006 @@ -68,10 +68,14 @@ { file.AddLine(" def Load_New_Graph(self, sTuple): "); file.AddLine(" a,b,c = sTuple "); - file.AddLine(" fname = eval(self.data[a][\"new graph file\"]) "); + file.AddLine(" try: "); + file.AddLine(" self.fname = eval(self.data[a][\"new graph file\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"The new graph file \", self.data[a][\"new graph file\"], \" is not a valid Python string\" "); + file.AddLine(" self.fname = None "); file.AddLine(" f = MyFactory() "); file.AddLine(" f.isMaster = False "); - file.AddLine(" f.setGraph(fname) "); + file.AddLine(" f.setGraph(self.fname) "); file.AddLine(" f.setMaster(False) "); file.AddLine(" reactor.connectTCP(sofaServer, 5000, f) "); file.AddLine(" return self.data[a][\"Output\"] "); Modified: sofaswitch/trunk/callflow/src/python.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/python.cpp (original) +++ sofaswitch/trunk/callflow/src/python.cpp Mon Nov 13 16:22:10 2006 @@ -56,10 +56,13 @@ bool DndShapePython::WriteSystemCode(wxTextFile & file) { - file.AddLine(" def Python(self, sTuple): "); - file.AddLine(" a,b,c = sTuple"); - file.AddLine(" exec(self.data[a][\"Python Code\"])"); - file.AddLine(" return self.data[a][\"Output\"]"); + file.AddLine(" def Python(self, sTuple): "); + file.AddLine(" a,b,c = sTuple "); + file.AddLine(" try: "); + file.AddLine(" exec(self.data[a][\"Python Code\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"Python code \", self.data[a][\"Python Code\"], \" could not be executed\" "); + file.AddLine(" return self.data[a][\"Output\"] "); file.AddLine(""); return true; Modified: sofaswitch/trunk/callflow/src/requestnode.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/requestnode.cpp (original) +++ sofaswitch/trunk/callflow/src/requestnode.cpp Mon Nov 13 16:22:10 2006 @@ -81,10 +81,18 @@ file.AddLine(" self.pendingEvents[eName] = a "); file.AddLine(" reactor.callLater(self.data[a][\"Timer period\"], self.timerObjectExpired, eName)"); file.AddLine(" rhost = self.data[a][\"Request node from\"] "); - file.AddLine(" rhost = eval(rhost) + \":REQUESTNEWID \" "); + file.AddLine(" try: "); + file.AddLine(" rhost = eval(rhost) + \":REQUESTNEWID \" "); + file.AddLine(" except: "); + file.AddLine(" print \"Could not process \", self.data[a][\"Request node from\"], \" as a python string\" "); + file.AddLine(" return self.data[a][\"Output\"] "); file.AddLine(" additional = self.data[a][\"Additional info\"] "); file.AddLine(" if len(additional) > 0: "); - file.AddLine(" rhost += eval(additional) "); + file.AddLine(" try: "); + file.AddLine(" rhost += eval(additional) "); + file.AddLine(" except: "); + file.AddLine(" print \"Could not process \", additional, \" as a Python string \" "); + file.AddLine(" return self.data[a][\"Output\"] "); file.AddLine(" rhost += \"\\0\" "); file.AddLine(" self.transport.write(rhost) "); file.AddLine(" return self.data[a][\"Output\"] "); Modified: sofaswitch/trunk/callflow/src/senddtmf.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/senddtmf.cpp (original) +++ sofaswitch/trunk/callflow/src/senddtmf.cpp Mon Nov 13 16:22:10 2006 @@ -39,8 +39,19 @@ { file.AddLine(" def Send_Dtmf(self, sTuple): "); file.AddLine(" a,b,c = sTuple "); - file.AddLine(" rhost = eval(self.data[a][\"worker node\"]) "); - file.AddLine(" rhost += \":SENDDTMF \" + eval(self.data[a][\"dtmf to send\"]) + \"\\0\" "); + file.AddLine(" try: "); + file.AddLine(" rhost = eval(self.data[a][\"worker node\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"Could not process \", self.data[a][\"worker node\"], \" as a Python string\" "); + file.AddLine(" return self.data[a][\"Output\"] "); + + file.AddLine(" self.sendDtmf= self.data[a][\"dtmf to send\"] "); + file.AddLine(" try: "); + file.AddLine(" rhost += \":SENDDTMF \" + eval(self.sendDtmf) + \"\\0\" "); + file.AddLine(" except: "); + file.AddLine(" print \"Could not process \", self.sendDtmf, \" as a Python string\" "); + file.AddLine(" return self.data[a][\"Output\"] "); + file.AddLine(" self.transport.write(rhost) "); file.AddLine(" return self.data[a][\"Output\"] "); file.AddLine(""); Modified: sofaswitch/trunk/callflow/src/shapelist.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/shapelist.cpp (original) +++ sofaswitch/trunk/callflow/src/shapelist.cpp Mon Nov 13 16:22:10 2006 @@ -388,7 +388,10 @@ file.AddLine(" eHandler = self.data[eventNode][\"Event Handler\"] "); file.AddLine(" pVbl = self.data[eventNode][\"Event Variable\"] "); file.AddLine(" pVbl += \" = \" + self.quote + eventData + self.quote "); - file.AddLine(" exec(pVbl) "); + file.AddLine(" try: "); + file.AddLine(" exec(pVbl) "); + file.AddLine(" except: "); + file.AddLine(" print \"An internal error processing \", pVbl "); file.AddLine(" self.DoWork(eHandler) "); file.AddLine(" self.generatedEvents.clear() "); file.AddLine(" "); Modified: sofaswitch/trunk/callflow/src/transfermedia.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/transfermedia.cpp (original) +++ sofaswitch/trunk/callflow/src/transfermedia.cpp Mon Nov 13 16:22:10 2006 @@ -69,12 +69,24 @@ bool DndShapeTransferMedia::WriteSystemCode(wxTextFile & file) { - file.AddLine(" def Transfer_Media(self, sTuple): "); - file.AddLine(" a,b,c = sTuple "); - file.AddLine(" rhost = eval(self.data[a][\"worker node\"]) "); - file.AddLine(" rhost += \":TRANSFERUDP \" + eval(self.data[a][\"worker receiver\"]) + \"\\0\" "); - file.AddLine(" self.transport.write(rhost) "); - file.AddLine(" return self.data[a][\"Output\"] "); + file.AddLine(" def Transfer_Media(self, sTuple): "); + file.AddLine(" a,b,c = sTuple "); + file.AddLine(" self.tMedia = self.data[a][\"worker node\"] "); + file.AddLine(" try: "); + file.AddLine(" self.rhost = eval(self.tMedia) "); + file.AddLine(" except: "); + file.AddLine(" print \"The Worker node Python \", self.tMedia, \" could not be evaluated\" "); + file.AddLine(" return self.data[a][\"Output\"] "); + + file.AddLine(" self.wNode = self.data[a][\"worker receiver\"] "); + file.AddLine(" try: "); + file.AddLine(" self.rhost += \":TRANSFERUDP \" + eval(self.wNode) + \"\\0\" "); + file.AddLine(" except: "); + file.AddLine(" print \"The node to transfer media to \", self.wNode, \" could not be evaluated\" "); + file.AddLine(" return self.data[a][\"Output\"] "); + + file.AddLine(" self.transport.write(self.rhost) "); + file.AddLine(" return self.data[a][\"Output\"] "); file.AddLine(""); return true;