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

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