home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / topdl / aedoor.h next >
Encoding:
C/C++ Source or Header  |  1996-02-13  |  11.5 KB  |  509 lines

  1. //    CheckMessage()    Used for sending/receiving messages
  2. //    Register()    Start up initial door-protocol
  3. //            (allocates memory, creates reply port, etc)
  4. //    ShutDown()    Shut down door-port and exit
  5. #include <exec/exec.h>
  6. #include <exec/semaphores.h>
  7. #include <proto/exec.h>
  8. #include <exec/types.h>
  9. #include <exec/ports.h>
  10. #include <exec/memory.h>
  11. #include <dos/dos.h>
  12. #include <dos.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/dos_protos.h>
  15. #include <clib/alib_protos.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. #define deletecomm DeleteComm
  21. #define shutdown ShutDown
  22. #define sendcmd SendCmd
  23. #define sendstrcmd SendStrCmd
  24. #define senddatacmd SendDataCmd
  25. #define sendstrdatacmd SendStrDataCmd
  26. #define writestr WriteStr
  27. #define showfile ShowFile
  28. #define getdt GetDT
  29. #define getstr GetStr
  30. #define hotkey Hotkey
  31.  
  32. #define NumLines 32
  33.  
  34. #define SEEK_SET 0
  35. #define FOREVER for(;;)
  36. #define NL NULL
  37. #define JH_LI 0
  38. #define JH_REGISTER 1
  39. #define JH_SHUTDOWN 2
  40. #define JH_WRITE 3
  41. #define JH_SM 4
  42. #define JH_PM 5
  43. #define JH_HK 6
  44. #define JH_SG 7
  45. #define JH_SF 8
  46. #define JH_EF 9
  47. #define JH_CO 10
  48. #define JH_BBSName 11
  49. #define JH_Sysop 12
  50. #define JH_FLAGFILE 13
  51. #define JH_SHOWFLAGS 14
  52. #define JH_DL 15
  53. #define JH_ExtHK 15
  54. #define JH_SIGBIT 16
  55. #define JH_FetchKey 17
  56. #define JH_FETCHKEY 17
  57. #define JH_SO 18
  58. #define JH_HSM 19
  59. /**************************** GET/SET Values from System ***********************/
  60.  
  61. #define DT_NAME           100
  62. #define DT_PASSWORD       101
  63. #define DT_LOCATION       102
  64. #define DT_PHONENUMBER    103
  65. #define DT_SLOTNUMBER     104
  66. #define DT_SECSTATUS      105
  67. #define DT_SECBOARD       106
  68. #define DT_SECLIBRARY     107
  69. #define DT_SECBULLETIN    108
  70. #define DT_MESSAGESPOSTED 109
  71. #define DT_UPLOADS        110
  72. #define DT_DOWNLOADS      111
  73. #define DT_TIMESCALLED    112
  74. #define DT_TIMELASTON     113
  75. #define DT_TIMEUSED       114
  76. #define DT_TIMELIMIT      115
  77. #define DT_TIMETOTAL      116
  78. #define DT_BYTESUPLOAD    117
  79. #define DT_BYTEDOWNLOAD   118
  80. #define DT_DAILYBYTELIMIT 119
  81. #define DT_DAILYBYTEDLD   120
  82. #define DT_EXPERT         121
  83. #define DT_LINELENGTH     122
  84. #define ACTIVE_NODES      123
  85. #define DT_DUMP           124
  86. #define DT_TIMEOUT        125
  87. #define BB_CONFNAME       126
  88. #define BB_CONFLOCAL      127
  89. #define BB_LOCAL          128
  90. #define BB_STATUS         129
  91. #define BB_COMMAND        130
  92. #define BB_MAINLINE       131
  93. #define NB_LOAD           132
  94. #define DT_USERLOAD       133
  95. #define BB_CONFIG         134
  96. #define CHG_USER          135
  97. #define RETURNCOMMAND     136
  98. #define ZMODEMSEND        137
  99. #define ZMODEMRECEIVE     138
  100. #define SCREEN_ADDRESS    139
  101. #define BB_TASKPRI        140
  102. #define RAWSCREEN_ADDRESS 141
  103. #define BB_CHATFLAG       142
  104. #define DT_STAMP_LASTON   143
  105. #define DT_STAMP_CTIME    144
  106. #define DT_CURR_TIME      145
  107. #define DT_CONFACCESS     146
  108. #define BB_PCONFLOCAL     147
  109. #define BB_PCONFNAME      148
  110. #define BB_NODEID         149
  111. #define BB_CALLERSLOG     150
  112. #define BB_UDLOG          151
  113. #define EXPRESS_VERSION   152
  114. #define UNICONIFY         153
  115. #define BB_CHATSET        162
  116. #define ENVSTAT           163
  117.  
  118. #define SVR_MESSAGE       177
  119. #define QN                178
  120.  
  121. #define GETKEY            500
  122. #define RAWARROW          501
  123. #define CHAIN             502
  124.  
  125. /****************** in progress ******************/
  126. #define NODE_DEVICE       503
  127. #define NODE_UNIT         504
  128. #define NODE_BAUD         505
  129. #define NODE_NUMBER       506
  130. #define JH_MCI            507
  131. /*************************************************/
  132. #define PRV_COMMAND       508
  133. #define PRV_GROUP         509
  134. #define BB_CONFNUM        510
  135. #define BB_DROPDTR        511
  136. #define BB_GETTASK        512
  137. #define BB_REMOVEPORT     513
  138. #define BB_SOPT           514
  139. #define NODE_BAUDRATE     516
  140. #define BB_LOGONTYPE      517
  141. #define BB_SCRLEFT        518
  142. #define BB_SCRTOP         519
  143. #define BB_SCRWIDTH       520
  144. #define BB_SCRHEIGHT      521
  145. #define BB_PURGELINE      522
  146. #define BB_PURGELINESTART 523
  147. #define BB_PURGELINEEND   524
  148. #define BB_NONSTOPTEXT    525
  149. #define BB_LINECOUNT      526
  150. #define DT_LANGUAGE       527
  151. #define DT_QUICKFLAG      528
  152. #define DT_GOODFILE       529
  153. #define DT_ANSICOLOR      530
  154. #define MULTICOM          531
  155. #define LOAD_ACCOUNT      532
  156. #define SAVE_ACCOUNT      533
  157. #define SAVE_CONFDB       534
  158. #define LOAD_CONFDB       535
  159. #define GET_CONFNUM       536
  160. #define SEARCH_ACCOUNT    537
  161. #define APPEND_ACCOUNT    538
  162. #define LAST_ACCOUNTNUM   539
  163. #define MOD_TYPE          540
  164. #define DT_ISANSI         541
  165. #define BATCHZMODEMSEND   542
  166. #define DT_MSGCODE        543
  167. #define ACP_COMMAND       544
  168. #define DT_FILECODE       545
  169. #define EDITOR_STRUCT     546
  170. #define BYPASS_CSI_CHECK  547
  171. #define SENTBY            548
  172. #define MCIFLAG           551
  173. #define MSGBASE_COMMAND      600
  174. #define MSGBASE_CONF         601
  175. #define MSG_LASTREAD_CONF    602
  176. #define MSG_LASTNEWREAD_CONF 603
  177. #define MSGBASE_LOCATION     604
  178. #define MSGBASE_SUPPLEMENT   605
  179. #define DT_REALNAME          606
  180. #define DT_STARTDATE         607
  181. #define QUICK_KEY            608
  182. #define DT_TOGGLE_SERIAL     609
  183. #define NETDOWNLOAD          610
  184. #define NETUPLOAD            611
  185. #define BB_CONFLIST          612
  186. #define BB_OFFHOOK           613
  187. #define IS_CONFACCESS        614            // +1 = RelCurConf
  188. #define BB_ENCRYPT           615
  189. #define BB_NONSTOPSTATUS     616
  190. #define JH_SF_NSF            617
  191. #define JH_SG_NSF            618
  192. #define BB_CHOOSEANAME       619
  193. #define DT_ATTACHFILE        620
  194. #define BB_GETMCISTR         621
  195. #define DT_XIMPORT           622
  196. #define DT_LASTMSGCMD        623
  197. #define DT_ASL               624
  198. #define DT_MSGCMDOVERIDE     625
  199. #define DT_QWKBYTECOUNT      626
  200. #define DT_RELCONF           627           // +1 = RelCurConf
  201. #define RETURNPRVCMD         628
  202. #define BB_TRANSFERABORT     629
  203. #define BB_CLEARMSGQUE       630
  204. #define BB_NOPROMPTDOWNLOAD  631
  205. #define SXVERSION         907
  206. #define DT_ADDBIT         1000
  207. #define DT_REMBIT         1001
  208. #define DT_QUERYBIT       1002
  209. #define READIT 1
  210. #define WRITEIT 0
  211. #define SHUTDOWN 1
  212. #define CHAIN_WAIT 0
  213.  
  214.  
  215.  
  216. #define NEXTMSG    1
  217. #define NONEXTMSG  2
  218. #define MSGSTATUS  0
  219. #define CONSOLE_PORT 1
  220. #define SERIAL_PORT 2
  221.  
  222.  
  223.  
  224.  
  225.  
  226. struct JHMessage *Jhmsg,*msg;
  227. struct MsgPort *port,*replymp;
  228.  
  229. #define XIM_Msg Jhmsg
  230. #define shutdown ShutDown
  231. struct JHMessage
  232. {
  233.     struct Message Msg;    /* msg structure */
  234.     char String[200];    /* info buffer */
  235.     int Data;        /* Read/Write & result indicator */
  236.     int Command;        /* Command sent from door. */
  237.     int NodeID;        /* reserved */
  238.     int LineNum;        /* reserved */
  239.     ULONG signal;        /* reserved */
  240.     struct Process *task;    /* see BB_GETTASK in doordocs */
  241.     APTR *Semi;        /* See MULTICOM in doordocs */      
  242.     APTR Filler1;
  243.     APTR Filler2;
  244.     char *str;
  245. };
  246.  
  247. struct MsgPort *CreatePort(UBYTE *name,LONG pri)
  248. {
  249.     int sigBit;
  250.     struct MsgPort *mp;
  251.   
  252.     if((sigBit=AllocSignal(-1L))==-1)
  253.     return(0);
  254.     mp=(struct MsgPort *)
  255.     AllocMem((ULONG)sizeof(struct MsgPort),(ULONG)MEMF_CLEAR|MEMF_PUBLIC);
  256.  
  257.     if(!mp)
  258.     {
  259.         FreeSignal(sigBit);
  260.         return(0);
  261.     }
  262.  
  263.     mp->mp_Node.ln_Name=name;
  264.     mp->mp_Node.ln_Pri=pri;
  265.     mp->mp_Node.ln_Type=NT_MSGPORT;
  266.     mp->mp_Flags=PA_SIGNAL;
  267.     mp->mp_SigBit=sigBit;
  268.     mp->mp_SigTask=(struct Task *)FindTask(0L);
  269.     if(name) AddPort(mp);
  270.     else NewList(&(mp->mp_MsgList));
  271.     return(mp);
  272. }
  273.  
  274.  
  275. void CheckMessage(void)
  276. {
  277.     PutMsg(port,(struct Message *)Jhmsg);
  278.     (void)WaitPort(replymp);
  279.     (void)GetMsg(replymp);
  280. }
  281.  
  282. VOID Register(int node)
  283. {
  284.     int n1=0,n2=0,n3=0,found=0;
  285.     char PortName[80];
  286.     char DoorReply[] = "AEDoorRP.000";
  287.  
  288.     Jhmsg=(struct JHMessage *)AllocMem(sizeof(struct JHMessage),MEMF_PUBLIC);
  289.  
  290.     if(Jhmsg==0) exit(30);
  291.  
  292.     while(n1<10)
  293.     {
  294.         n2=0;
  295.         while(n2<10)
  296.         {
  297.             n3=0;
  298.             while(n3<10)
  299.             {
  300.                 DoorReply[9]=n1+'0';
  301.                 DoorReply[10]=n2+'0';
  302.                 DoorReply[11]=n3+'0';
  303.                 if(FindPort(DoorReply)) { n3++; continue; }
  304.                 found=1;
  305.                 break;
  306.             }
  307.             if(found) break;
  308.             n2++;
  309.         }
  310.         if(found) break;
  311.         n1++;
  312.     }
  313.  
  314.     if(!found)
  315.     {
  316.         FreeMem(Jhmsg,sizeof(struct JHMessage));
  317.         exit(30);
  318.     }
  319.  
  320.     replymp=CreatePort(DoorReply,0L);
  321.     if(replymp==0)
  322.     {
  323.         FreeMem(Jhmsg,sizeof(struct JHMessage));
  324.         exit(30);
  325.     }
  326.  
  327.     Jhmsg->Msg.mn_Node.ln_Type=NT_MESSAGE;
  328.     Jhmsg->Msg.mn_Length=sizeof(struct JHMessage);
  329.     Jhmsg->Msg.mn_ReplyPort=replymp;
  330.     Jhmsg->Command=1;
  331.     Jhmsg->Data=2;
  332. //    Jhmsg->NodeID=-1;
  333. //    Jhmsg->LineNum=0;
  334.     sprintf(PortName,"AEDoorPort%d",node);
  335.     while(!(port=FindPort(PortName)));
  336.     PutMsg(port,(struct Message *)Jhmsg);
  337.     Wait(1<<replymp->mp_SigBit);
  338.     msg=(struct JHMessage *)GetMsg((struct MsgPort *)replymp);
  339. }
  340.  
  341. VOID ShutDown(VOID)
  342. {
  343.     Jhmsg->Command=2;
  344.     PutMsg(port,(struct Message *)Jhmsg); 
  345.     Wait(1<<replymp->mp_SigBit);
  346.     while(msg=(struct JHMessage *)GetMsg((struct MsgPort *)replymp));
  347.     DeletePort((struct MsgPort *)replymp);
  348.     FreeMem(Jhmsg,sizeof(struct JHMessage));
  349.     exit(0);
  350. }
  351.  
  352. struct XIM
  353. {
  354.     struct Message Msg;    // msg structure
  355.     char String[200];    // info buffer
  356.     int Data;        // Read/Write & result indicator
  357.     int Command;        // Command sent from door.
  358.     int NodeID;
  359.     int LineNum;
  360.     unsigned long signal;
  361.     struct Process *task;    // see BB_GETTASK in doordocs
  362.     APTR *Semi;        // See MULTICOM in doordocs
  363.     APTR Filler1;
  364.     APTR Filler2;
  365.     char *str;
  366. };
  367.  
  368. struct XIM *XIM_Msg,*msg;
  369.  
  370. int sigBit;
  371.  
  372. struct MsgPort *port,*replymp;
  373.  
  374. void CreateComm(int node)
  375. {
  376.     register int n1=0,n2=0,n3=0,found=0;
  377.     char PortName[80],DoorReply[16];
  378.  
  379.     strcpy(DoorReply,"AEDoorRP.000");
  380.  
  381.     if((XIM_Msg=(struct XIM *)AllocMem(sizeof(struct XIM),MEMF_PUBLIC))==0)exit(30);
  382.  
  383.     while(n1<10)
  384.     {
  385.         n2=0;
  386.         while(n2<10)
  387.         {
  388.             n3=0;
  389.             while(n3<10)
  390.             {
  391.                 DoorReply[9]=n1+'0';
  392.                 DoorReply[10]=n2+'0';
  393.                 DoorReply[11]=n3+'0';
  394.                 if(FindPort(DoorReply))
  395.                 {
  396.                     n3++;
  397.                     continue;
  398.                 }
  399.                 found=1;
  400.                 break;
  401.             }
  402.             if(found) break;
  403.             n2++;
  404.         }
  405.         if(found) break;
  406.         n1++;
  407.     }
  408.  
  409.     if(found)replymp=CreatePort(DoorReply,0L);
  410.  
  411.     if(!found||!replymp)
  412.     {
  413.         FreeMem(XIM_Msg,sizeof(struct XIM));
  414.         exit(30);
  415.     }
  416.  
  417.     XIM_Msg->Msg.mn_Node.ln_Type=NT_MESSAGE;
  418.     XIM_Msg->Msg.mn_Length=sizeof(struct XIM);
  419.     XIM_Msg->Msg.mn_ReplyPort=replymp;
  420.     XIM_Msg->Command=1;
  421.     XIM_Msg->Data=2;
  422.     XIM_Msg->NodeID=-1;
  423.     XIM_Msg->LineNum=0;
  424.  
  425.     sprintf(PortName,"AEDoorPort%d",node);
  426.     while(!(port=FindPort(PortName)));
  427.  
  428.     PutMsg(port,(struct Message *)XIM_Msg);
  429.     Wait(1<<replymp->mp_SigBit);
  430.     msg=(struct XIM *)GetMsg((struct MsgPort *)replymp);
  431. }
  432.  
  433. void DeleteComm(void)
  434. {
  435.     XIM_Msg->Command=2;
  436.     PutMsg(port,(struct Message *)XIM_Msg); 
  437.     Wait(1<<replymp->mp_SigBit);
  438.     while(msg=(struct XIM *)GetMsg((struct MsgPort *)replymp));
  439.     FreeSignal(sigBit);
  440.     DeletePort((struct MsgPort *)replymp);
  441.     FreeMem(XIM_Msg,sizeof(struct XIM));
  442. }
  443.  
  444. void SendStrDataCmd(int Command,char String[200],int Data)
  445. {
  446.     XIM_Msg->Command=Command;
  447.     XIM_Msg->Data=Data;
  448.     strcpy(XIM_Msg->String,String);
  449.     PutMsg(port,(struct Message *)XIM_Msg);
  450.     (void)WaitPort(replymp);
  451.     (void)GetMsg(replymp);
  452. }
  453. char *getbla(int Command)
  454. {    XIM_Msg->Command=Command;
  455.     PutMsg(port,(struct Message *)XIM_Msg);
  456.     (void)WaitPort(replymp);
  457.     (void)GetMsg(replymp);
  458.     return(XIM_Msg->String);
  459. }
  460.     
  461. void SendDataCmd(int Command,int Data)
  462. {
  463.     SendStrDataCmd(Command,"",Data);
  464. }
  465.  
  466. void SendStrCmd(int Command,char String[200])
  467. {
  468.     SendStrDataCmd(Command,String,0);
  469. }
  470.  
  471. void SendCmd(int Command)
  472. {
  473.     SendStrDataCmd(Command,"",0);
  474. }
  475.  
  476. void WriteStr(char String[200],int Data)
  477. {
  478.     SendStrDataCmd(4,String,Data);
  479. }
  480.  
  481. void ShowFile(char String[200])
  482. {
  483.     SendStrDataCmd(8,String,0);
  484. }
  485.  
  486. void GetDT(int Command,char String[200])
  487. {
  488.     SendStrDataCmd(Command,String,1);
  489. }
  490.  
  491. char *GetStr(int Data,char String[200])
  492. {
  493.     SendStrDataCmd(0,String,Data);
  494.     if(XIM_Msg->Data==-1)return(0);
  495.     return(XIM_Msg->String);
  496. }
  497.  
  498. long Hotkey(char String[200])
  499. {
  500.     SendStrDataCmd(6,String,0);
  501.     if(XIM_Msg->Data==-1)return(XIM_Msg->Data);
  502.     return(XIM_Msg->String[0]);
  503. }
  504. char *Prompt(int Data,char String[200])
  505. {
  506.     SendStrDataCmd(5,String,Data);
  507.     return(XIM_Msg->String);
  508. }
  509.