[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi BaseAGIScript.java,1.1,1.2
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-08-07 19:07:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv831/src/java/net/sf/asterisk/fastagi Modified Files: BaseAGIScript.java Log Message: Added check for invalid thread access to sendCommand() Index: BaseAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/BaseAGIScript.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- BaseAGIScript.java 6 Aug 2005 18:43:24 -0000 1.1 +++ BaseAGIScript.java 7 Aug 2005 19:06:46 -0000 1.2 @@ -76,8 +76,7 @@ public abstract class BaseAGIScript impl * hung up.<br> * 0 disables the autohangup feature. */ - protected void setAutoHangup(int time) - throws AGIException + protected void setAutoHangup(int time) throws AGIException { sendCommand(new SetAutoHangupCommand(time)); } @@ -87,8 +86,7 @@ public abstract class BaseAGIScript impl * * @param callerId the raw caller id to set, for example "John Doe<1234>". */ - protected void setCallerId(String callerId) - throws AGIException + protected void setCallerId(String callerId) throws AGIException { sendCommand(new SetCallerIdCommand(callerId)); } @@ -107,8 +105,7 @@ public abstract class BaseAGIScript impl * @param musicOnHoldClass the music on hold class to play music from as * configures in Asterisk's <code><musiconhold.conf/code>. */ - protected void playMusicOnHold(String musicOnHoldClass) - throws AGIException + protected void playMusicOnHold(String musicOnHoldClass) throws AGIException { sendCommand(new SetMusicOnCommand(musicOnHoldClass)); } @@ -153,8 +150,7 @@ public abstract class BaseAGIScript impl * @param file the name of the file to play * @return a String containing the DTMF the user entered */ - protected String getData(String file) - throws AGIException + protected String getData(String file) throws AGIException { AGIReply reply; @@ -173,8 +169,7 @@ public abstract class BaseAGIScript impl * (essentially never times out). * @return a String containing the DTMF the user entered */ - protected String getData(String file, int timeout) - throws AGIException + protected String getData(String file, int timeout) throws AGIException { AGIReply reply; @@ -196,8 +191,8 @@ public abstract class BaseAGIScript impl * enter * @return a String containing the DTMF the user entered */ - protected String getData(String file, int timeout, - int maxDigits) throws AGIException + protected String getData(String file, int timeout, int maxDigits) + throws AGIException { AGIReply reply; @@ -218,8 +213,8 @@ public abstract class BaseAGIScript impl * press. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char getOption(String file, - String escapeDigits) throws AGIException + protected char getOption(String file, String escapeDigits) + throws AGIException { AGIReply reply; @@ -240,13 +235,12 @@ public abstract class BaseAGIScript impl * esacpe digits was presses while streaming. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char getOption(String file, - String escapeDigits, int timeout) throws AGIException + protected char getOption(String file, String escapeDigits, int timeout) + throws AGIException { AGIReply reply; - reply = sendCommand(new GetOptionCommand(file, escapeDigits, - timeout)); + reply = sendCommand(new GetOptionCommand(file, escapeDigits, timeout)); return reply.getResultCodeAsChar(); } @@ -258,8 +252,7 @@ public abstract class BaseAGIScript impl * @return the return code of the application of -2 if the application was * not found. */ - protected int exec(String application) - throws AGIException + protected int exec(String application) throws AGIException { AGIReply reply; @@ -277,8 +270,7 @@ public abstract class BaseAGIScript impl * @return the return code of the application of -2 if the application was * not found. */ - protected int exec(String application, String options) - throws AGIException + protected int exec(String application, String options) throws AGIException { AGIReply reply; @@ -291,8 +283,7 @@ public abstract class BaseAGIScript impl * * @param context the context for continuation upon exiting the application. */ - protected void setContext(String context) - throws AGIException + protected void setContext(String context) throws AGIException { sendCommand(new SetContextCommand(context)); } @@ -303,8 +294,7 @@ public abstract class BaseAGIScript impl * @param extension the extension for continuation upon exiting the * application. */ - protected void setExtension(String extension) - throws AGIException + protected void setExtension(String extension) throws AGIException { sendCommand(new SetExtensionCommand(extension)); } @@ -315,8 +305,7 @@ public abstract class BaseAGIScript impl * @param priority the priority for continuation upon exiting the * application. */ - protected void setPriority(int priority) - throws AGIException + protected void setPriority(int priority) throws AGIException { sendCommand(new SetPriorityCommand(priority)); } @@ -326,8 +315,7 @@ public abstract class BaseAGIScript impl * * @param file name of the file to play. */ - protected void streamFile(String file) - throws AGIException + protected void streamFile(String file) throws AGIException { sendCommand(new StreamFileCommand(file)); } @@ -341,8 +329,8 @@ public abstract class BaseAGIScript impl * user to escape. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char streamFile(String file, - String escapeDigits) throws AGIException + protected char streamFile(String file, String escapeDigits) + throws AGIException { AGIReply reply; @@ -355,8 +343,7 @@ public abstract class BaseAGIScript impl * * @param digits the digit string to say. */ - protected void sayDigits(String digits) - throws AGIException + protected void sayDigits(String digits) throws AGIException { sendCommand(new SayDigitsCommand(digits)); } @@ -370,8 +357,8 @@ public abstract class BaseAGIScript impl * user to escape. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char sayDigits(String digits, - String escapeDigits) throws AGIException + protected char sayDigits(String digits, String escapeDigits) + throws AGIException { AGIReply reply; @@ -384,8 +371,7 @@ public abstract class BaseAGIScript impl * * @param number the number to say. */ - protected void sayNumber(String number) - throws AGIException + protected void sayNumber(String number) throws AGIException { sendCommand(new SayNumberCommand(number)); } @@ -399,8 +385,8 @@ public abstract class BaseAGIScript impl * user to escape. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char sayNumber(String number, - String escapeDigits) throws AGIException + protected char sayNumber(String number, String escapeDigits) + throws AGIException { AGIReply reply; @@ -413,8 +399,7 @@ public abstract class BaseAGIScript impl * * @param text the text to say. */ - protected void sayPhonetic(String text) - throws AGIException + protected void sayPhonetic(String text) throws AGIException { sendCommand(new SayPhoneticCommand(text)); } @@ -428,8 +413,8 @@ public abstract class BaseAGIScript impl * user to escape. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char sayPhonetic(String text, - String escapeDigits) throws AGIException + protected char sayPhonetic(String text, String escapeDigits) + throws AGIException { AGIReply reply; @@ -442,8 +427,7 @@ public abstract class BaseAGIScript impl * * @param text the text to say. */ - protected void sayAlpha(String text) - throws AGIException + protected void sayAlpha(String text) throws AGIException { sendCommand(new SayAlphaCommand(text)); } @@ -485,8 +469,7 @@ public abstract class BaseAGIScript impl * user to escape. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char sayTime(long time, String escapeDigits) - throws AGIException + protected char sayTime(long time, String escapeDigits) throws AGIException { AGIReply reply; @@ -501,8 +484,7 @@ public abstract class BaseAGIScript impl * @return the value of the given variable or <code>null</code> if not * set. */ - protected String getVariable(String name) - throws AGIException + protected String getVariable(String name) throws AGIException { AGIReply reply; @@ -520,8 +502,7 @@ public abstract class BaseAGIScript impl * @param name the name of the variable to retrieve. * @param value the new value to set. */ - protected void setVariable(String name, String value) - throws AGIException + protected void setVariable(String name, String value) throws AGIException { sendCommand(new SetVariableCommand(name, value)); } @@ -533,8 +514,7 @@ public abstract class BaseAGIScript impl * receive a DTMF digit, -1 will wait forever. * @return the DTMF digit pressed or 0x0 if none was pressed. */ - protected char waitForDigit(int timeout) - throws AGIException + protected char waitForDigit(int timeout) throws AGIException { AGIReply reply; @@ -554,6 +534,12 @@ public abstract class BaseAGIScript impl AGIChannel channel; channel = AGIConnectionHandler.getChannel(); + if (channel == null) + { + throw new RuntimeException( + "Trying to send command from an invalid thread"); + } + return channel.sendCommand(command); } } |