home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Fax / AVMN199D.LHA / avminstall / rexx / answerfax.avm < prev    next >
Encoding:
Text File  |  1995-08-19  |  10.8 KB  |  442 lines

  1. /* TITLE: avm:rexx/answerfax.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername faxscript datascript distinctivering 'CID$' acidname '$' acidnumber '$'
  23. call setclip(address() || 'FAXSCRIPT', faxscript)
  24. call setclip(address() || 'DATASCRIPT', datascript)
  25. call setclip(address() || 'CIDNAME', acidname)
  26. call setclip(address() || 'CIDNUMBER', acidnumber)
  27.  
  28. startup:
  29. mailbox = 'anonymous'
  30. signal stdfax
  31. exit
  32.  
  33. /* TITLE: avm:rexx/simplestdtail.avm */
  34. /* This is the standard tail */
  35. exit
  36.  
  37. exit
  38.  
  39. mailboxDir: procedure
  40.     parse arg mailbox
  41.  
  42.     return 'avmmbox:' || mailbox || '/'
  43.  
  44. logFile: procedure
  45.     parse arg mailbox, magiccookie
  46.  
  47.     return 'avmmbox:' || mailbox || '/logs/' || magiccookie
  48.  
  49. voiceFile: procedure
  50.     parse arg mailbox, magiccookie
  51.  
  52.         if (verify(magiccookie, '/:', 'M') = 0) then
  53.           return 'avmmbox:' || mailbox || '/voices/' || magiccookie
  54.         else
  55.           return magiccookie
  56.  
  57. makeUniqueFile: procedure
  58.     if arg() ~= 0 then do
  59.         rc = "makeUniqueFile: bad args"
  60.         signal error
  61.     end
  62.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  63.  
  64. convertToDate: procedure
  65.     if arg() ~= 1 then do
  66.         rc = "convertToDate: bad args"
  67.         signal error
  68.     end
  69.     parse arg timeInC
  70.  
  71.     actualTime = (timeInC - (2922)*86400) // (86400)
  72.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  73.  
  74.     return actualDate /* returning it in 'internal' format */
  75.  
  76. convertToTime: procedure
  77.     if arg() ~= 1 then do
  78.         rc = "convertToTime: bad args"
  79.         signal error
  80.     end
  81.     parse arg timeInC
  82.     
  83.     actualTime = (timeInC - (2922)*86400) // (86400)
  84.  
  85.     return actualTime
  86.  
  87. cTime: procedure
  88.     /* 2922 = 8*365 + 2 */
  89.     /* 86400 = 24*60*60 */
  90.     return (date('i')+2922)*86400 + time('s')
  91.  
  92. /* this returns a handle that you must use after initializing log. */
  93. initLogEntry: procedure expose log.
  94.     if arg() ~= 0 then do
  95.         rc = "initLogEntry: bad args"
  96.         signal error
  97.     end
  98.     
  99.     drop log.
  100.         log. = ''
  101.  
  102.         acidname = getclip(address() || 'CIDNAME')
  103.         acidnumber = getclip(address() || 'CIDNUMBER')
  104.  
  105.     /* 2922 = 8*365 + 2 */
  106.     /* 86400 = 24*60*60 */
  107.     log.time = (date('i')+2922)*86400 + time('s')
  108.     log.cidname = acidname
  109.     log.cidnumber = acidnumber
  110.  
  111.     return
  112.  
  113. loadLogEntry: procedure expose log.
  114.     if arg() ~= 2 then do
  115.         rc = "loadLogEntry: bad args"
  116.         signal error
  117.     end
  118.     parse arg mailbox, handle
  119.  
  120.         drop log.
  121.         log. = ''
  122.  
  123.     if ~exists(mailboxDir(mailbox)) then do
  124.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  125.         return
  126.     end
  127.  
  128.     opened = open(handle, logFile(mailbox, handle), 'r')
  129.         if opened then do
  130.         call showDebugger('Loading entry' logFile(mailbox, handle))
  131.         do while ~eof(handle)
  132.             line = readln(handle)
  133.             parse upper var line variable '=' value
  134.             log.variable = value
  135.         end
  136.         call close(handle)
  137.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  138.     return
  139.  
  140. /* pass a handle here */
  141. saveLogEntry: procedure expose log.
  142.     if arg() ~= 2 then do
  143.         rc = "saveLogEntry: bad args"
  144.         signal error
  145.     end
  146.     parse arg mailbox, handle
  147.  
  148.     if ~exists(mailboxDir(mailbox)) then do
  149.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  150.         return
  151.     end
  152.  
  153.     opened = open(handle, logFile(mailbox, handle), 'w')
  154.  
  155.     if opened then do
  156.         call showDebugger('Saving entry' logFile(mailbox, handle))
  157.         call writeln(handle, 'TYPE=' || log.type)
  158.         call writeln(handle, 'TIME=' || log.time)
  159.         call writeln(handle, 'LENGTH=' || log.length)
  160.  
  161.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  162.  
  163.         call writeln(handle, 'CIDNAME=' || log.cidname)
  164.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  165.  
  166.         call writeln(handle, 'COMMENT=' || log.comment)
  167.  
  168.         call writeln(handle, 'FILENAME=' || log.filename)
  169.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  170.  
  171.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  172.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  173.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  174.  
  175.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  176.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  177.  
  178.         call close(handle)
  179.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  180.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  181.  
  182.     return
  183.  
  184. /* pass a handle here */
  185. updateLogEntry: procedure expose log.
  186.     if arg() ~= 2 then do
  187.         rc = "updateLogEntry: bad args"
  188.         signal error
  189.     end
  190.     parse arg mailbox, handle
  191.  
  192.     if ~exists(mailboxDir(mailbox)) then do
  193.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  194.         return
  195.     end
  196.  
  197.     if ~exists(logFile(mailbox, handle)) then do
  198.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  199.         return
  200.     end
  201.     opened = open(handle, logFile(mailbox, handle), 'w')
  202.  
  203.     if opened then do
  204.         call showDebugger('Updating entry' logFile(mailbox, handle))
  205.         call writeln(handle, 'TYPE=' || log.type)
  206.         call writeln(handle, 'TIME=' || log.time)
  207.         call writeln(handle, 'LENGTH=' || log.length)
  208.  
  209.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  210.  
  211.         call writeln(handle, 'CIDNAME=' || log.cidname)
  212.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  213.  
  214.         call writeln(handle, 'COMMENT=' || log.comment)
  215.  
  216.         call writeln(handle, 'FILENAME=' || log.filename)
  217.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  218.  
  219.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  220.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  221.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  222.  
  223.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  224.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  225.  
  226.         call close(handle)
  227.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  228.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  229.  
  230.     return
  231.  
  232.  
  233.  
  234. showDebugger: procedure
  235.     if arg() ~= 1 then do
  236.         say "showDebugger: ERROR"
  237.         exit 20
  238.     end
  239.  
  240.     parse arg debuggerInfo
  241.     
  242.     firstLine = sourceline(1)
  243.     parse var firstLine '/*' 'TITLE:' title '*/'
  244.     if showlist('p', 'AVMLOGGER') then
  245.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  246.     else
  247.         say title ':' debuggerInfo
  248.  
  249.     return 
  250.  
  251. /*-----------------------------------------------------------------------*/
  252. /*                         signal processing                             */
  253.  
  254. arexxerror:
  255. error:
  256.     call showDebugger("Error" rc "at line" sigl)
  257.     exit 20
  258.  
  259. break_c:
  260. halt:
  261.     call showDebugger("Halt/Break_C at line" sigl)
  262.     exit 20
  263.  
  264. novalue:
  265.     call showDebugger("No value at line" sigl)
  266.     exit 20
  267.  
  268. syntax:
  269.     call showDebugger("Syntax error" rc "at line" sigl)
  270.     exit 20
  271.  
  272. /* TITLE: avm:rexx/stdplayvoice.avm */
  273. stdPlayXX:
  274. procedure
  275. parse arg ret
  276.  
  277. rs.normal = 0
  278. rs.keydetected = 1
  279. rs.quietdetected = 2
  280. rs.silencedetected = 3
  281. rs.faxdetected = 4
  282. rs.datadetected = 5
  283. rs.busydetected = 8
  284. rs.timedout = 10
  285. rs.signaldetected = 12
  286. rs.overflow = 14
  287. rs.error = 16
  288. /* CB 0000 */
  289.  
  290. select
  291.   when ret=rs.faxdetected then signal stdfax
  292.   when ret=rs.datadetected then signal stddata
  293.   when ret=rs.busydetected then signal stdbusy
  294.   when ret=rs.signaldetected then signal stdabort
  295.   when ret=rs.overflow then signal stderror
  296.   when ret=rs.error then signal stderror
  297.   otherwise nop
  298. end
  299. return
  300.  
  301.  
  302. aapresentmenu:
  303. /* TITLE: avm:rexx/presentmenu.avm */
  304. procedure expose pmRetries pmTimesAround
  305. parse arg filename, valid, retries
  306. timesaround = retries
  307. pmTimesAround = timesaround
  308. pmRetries = retries
  309.  
  310. rs.normal = 0
  311. rs.keydetected = 1
  312. rs.quietdetected = 2
  313. rs.silencedetected = 3
  314. rs.faxdetected = 4
  315. rs.datadetected = 5
  316. rs.busydetected = 8
  317. rs.timedout = 10
  318. rs.signaldetected = 12
  319. rs.overflow = 14
  320. rs.error = 16
  321. /* CB 0000 */
  322.  
  323. aapresentmenuloop:
  324. 'playvoice' filename
  325. a_=rc
  326. if 0 then nop
  327. else if a_=4 then do;return rs.faxdetected;end
  328. else if a_=5 then do;return rs.datadetected;end
  329. else if a_=8 then do;return rs.busydetected;end
  330. else if a_=12 then do;return rs.signaldetected;end
  331. else if a_=14 then do;return rs.error;end
  332. else if a_=16 then do;return rs.error;end
  333.  
  334. 'readnkeys' '1' '5'
  335. a_=rc
  336. if a_=0 then value=result
  337. if 0 then nop
  338. else if a_=0 then signal aapresentmenuvalue
  339. else if a_=4 then do;return rs.faxdetected;end
  340. else if a_=5 then do;return rs.datadetected;end
  341. else if a_=8 then do;return rs.busydetected;end
  342. else if a_=10 then signal aapresentmenutimeout
  343. else if a_=12 then do;return rs.signaldetected;end
  344. else if a_=14 then do;return rs.error;end
  345. else if a_=16 then do;return rs.error;end
  346. return rs.error
  347.  
  348. aapresentmenutimeout:
  349. 'flushphonebuffer'
  350.  
  351. 'playvoice' 'avm:voices/TimedOut'
  352. a_=rc
  353. if 0 then nop
  354. else if a_=4 then do;return rs.faxdetected;end
  355. else if a_=5 then do;return rs.datadetected;end
  356. else if a_=8 then do;return rs.busydetected;end
  357. else if a_=12 then do;return rs.signaldetected;end
  358. else if a_=14 then do;return rs.error;end
  359. else if a_=16 then do;return rs.error;end
  360.  
  361. timesaround = timesaround - 1; pmTimesAround = timesaround
  362. if timesaround <= 0 then return rs.timedout
  363. signal aapresentmenuloop
  364.  
  365. aapresentmenuvalue:
  366. if pos(value, valid) = 0 then signal aainvalid
  367. return '=' || value
  368.  
  369. aainvalid:
  370. 'flushphonebuffer'
  371.  
  372. 'playvoice' 'avm:voices/BadChoice'
  373. a_=rc
  374. if 0 then nop
  375. else if a_=4 then do;return rs.faxdetected;end
  376. else if a_=5 then do;return rs.datadetected;end
  377. else if a_=8 then do;return rs.busydetected;end
  378. else if a_=12 then do;return rs.signaldetected;end
  379. else if a_=14 then do;return rs.error;end
  380. else if a_=16 then do;return rs.error;end
  381.  
  382. timesaround = timesaround - 1; pmTimesAround = timesaround
  383. if timesaround <= 0 then return rs.timedout
  384. signal aapresentmenuloop
  385.  
  386.  
  387. stdabort:
  388. exit
  389.  
  390. stdbusy:
  391. exit
  392.  
  393. stderror:
  394. exit
  395.  
  396. stdtimedout:
  397. exit
  398.  
  399. stdfaxinstruct:
  400. 'playvoice' 'avm:voices/FaxStarting'
  401. a_=rc
  402. if 0 then nop
  403. else if a_=1 then do;call checkifabort;end
  404. else if a_=8 then signal stdbusy
  405. else if a_=12 then signal stdabort
  406.  
  407. stdfax:
  408. faxscript = getclip(address() || 'FAXSCRIPT')
  409. if faxscript = '' then faxscript = 'handlefax'
  410. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  411. else address rexx faxscript address() 'anonymous'
  412. exit
  413.  
  414. stddatainstruct:
  415. 'playvoice' 'avm:voices/DataStarting'
  416. a_=rc
  417. if 0 then nop
  418. else if a_=1 then do;call checkifabort;end
  419. else if a_=8 then signal stdbusy
  420. else if a_=12 then signal stdabort
  421.  
  422. stddata:
  423. datascript = getclip(address() || 'DATASCRIPT')
  424. if datascript = '' then datascript = 'handledata'
  425. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  426. else address rexx datascript address()
  427. exit
  428.  
  429. checkifabort:
  430. 'readnkeys' '1' '3'
  431. a_=rc
  432. if a_=0 then value=result
  433. if 0 then nop
  434. else if a_=0 then do;if value = '*' then signal stdabort;end
  435. else if a_=8 then signal stdbusy
  436. else if a_=12 then signal stdabort
  437. else if a_=14 then signal stderror
  438. else if a_=16 then signal stderror
  439. return
  440.  
  441.  
  442.