home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / NWTP04 / NWMESS.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-01  |  13KB  |  386 lines

  1. {$X+,B-,V-}
  2. UNIT nwMess;
  3.  
  4. { nwMess unit as of 931228 / NwTP 0.4 API. (c) 1994, R.Spronk }
  5.  
  6. INTERFACE
  7.  
  8. Uses nwMisc;
  9.  
  10. { Function:                             Interrupt: comments:
  11.  
  12. * BroadcastToConsole                    (F215/09)
  13.   DisableStationBroadcast               (F215/02)
  14.   EnableStationBroadcast                (F215/03)
  15. * GetBroadcastMessage                   (F215/01)
  16. * GetBroadcastMode                      (DE..(..04))
  17. * SendBroadcastMessage                  (F215/00)
  18. * SendConsoleBroadcast                  (F217/D1)
  19. * SetBroadcastMode                      (DE..(..0x)), x= 0,1,2,3
  20.  
  21. NOT IMPLEMENTED:
  22.  
  23. - CheckPipeStatus                       (F215/08)  (1)
  24. - CloseMessagePipe                      (F215/07)  (1)
  25. - GetPersonalMessage                    (F215/05)  (1)
  26. - LogNetworkMessage                     (F215/0D)  (2)
  27. - OpenMessagePipe                       (F215/06)  (1)
  28. - SendPersonalMessage                   (F215/04)  (1)
  29.  
  30. Secondary Functions:
  31.  
  32. * SendMessageToUser
  33.  
  34. Notes:
  35.  (1) These calls are NOT supported by Netware 386 versions shipped after
  36.      December 1990, because they use pipe mechanisms, which cause a
  37.      considerable deal of server overhead.
  38.      These functions are not implemented in this unit.
  39.      Use IPX/SPX peer-to-peer communication instead (nwComm).
  40.  (2) Network msg file no longer supported by 3.x
  41. }
  42.  
  43. Var result:word;
  44.  
  45. {F215/09 [2.15c+]}
  46. Function BroadcastToConsole(message:string):boolean;
  47. { broadcast a message to the file server console.
  48.   The message (max 60 chars, in ascii range [$20..$7E]) will be displayed
  49.   at the bottom of the console screen.
  50.   This function truncates the messagelength to 60 and repaces illegal
  51.   characters with a . }
  52.  
  53. {F215/02 [ ? ]}
  54. Function DisableStationBroadcast:boolean;
  55. { Allows a station to refuse broadcast messages. }
  56.  
  57. {F215/03 [ ? ]}
  58. Function EnableStationBroadcast:boolean;
  59. { Allows a station to accept broadcast messages. }
  60.  
  61. {F215/01 [2.15c+]}
  62. Function GetBroadcastMessage(var bmessage: string):boolean;
  63. { An application should poll this to see if there is a broadcastmessage
  64.   stored (for this workstation) at the default server.
  65.   The message mode must be 2 or 3. (No Notification by Shell)
  66.   If no message was stored at the server, or the message was empty,
  67.   this function will return FALSE and an errorcode of $103. }
  68.  
  69. {DE..(..04) [1.x/2.x/ 3.x]}
  70. Function GetBroadcastMode(var bmode:byte):boolean;
  71. { Returns the message mode.
  72.  
  73.   00 Server Stores : Netware Messages and User Messages,
  74.      Shell automaticly displays messages.
  75.   01 Server Stores : Server Messages. (User messages discarded)
  76.      Shell automaticly displays messages.
  77.   02 Server stores : Server messages only.
  78.      Applications have to use GetBroadCastMessage to see if there is a message.
  79.   03 Server stores : Server messages and User messages.
  80.      Applications have to use GetBroadCastMessage to see if there is a message. }
  81.  
  82.  
  83. {F215/00 [2.15c+]}
  84. Function SendBroadcastMessage( message:string;
  85.                                connCount:byte;
  86.                                connList:TconnectionList;
  87.                                VAR resultlist:TconnectionList ):boolean;
  88. { Sends a broadcast message to a number of logical connections.
  89.   The connectionlist is an array[1..connCount] of logical connection numbers,
  90.   the result of the broadcast can be found in the resultList parameter. }
  91.  
  92. {DE..(..0n) n=0,1,2,3 [1.x/2.x/3.x]}
  93. Function SetBroadcastMode(bmode:byte):boolean;
  94.  
  95.  
  96. {F217/D1 [2.15c+]}
  97. Function SendConsoleBroadcast(message:string; connCount:byte;
  98.                               connList:TconnectionList       ):boolean;
  99. {Sends a message to a number of connections, as if the message was send
  100.  by a console broadcast command. Console oprator privileges required.
  101.  If connCount equals 0, then the message is send to all connections. }
  102.  
  103. {--------------------Secondary Functions-------------------------------}
  104.  
  105. Procedure SendMessageToUser(UserName,Message:String);
  106. { sends a message to a (group of) users.
  107.   The username may contain wildcards (* and ?).
  108.   The message will not be received by stations whose status is CASTOFF.}
  109.  
  110.  
  111. IMPLEMENTATION {============================================================}
  112.  
  113. USES Dos,nwConn;
  114.  
  115. Var UnitReqBuffer:array[1..576] of byte;
  116.     UnitReplyBuffer:array[1..576] of byte;
  117.     UnitRegs:registers;
  118.  
  119. Procedure F2SystemCall(subf:byte;req_size,rep_size:word);
  120. begin
  121. With UnitRegs
  122.  do begin
  123.     DS := Seg(UnitReqBuffer);  SI := Ofs(UnitReqBuffer);   CX := Req_size;
  124.     ES := Seg(UnitReplyBuffer);DI := Ofs(UnitReplyBuffer); DX := rep_size;
  125.     AH := $F2; AL := subf;
  126.     MSDOS(UnitRegs);
  127.     Result:=al;
  128.     end;
  129. end;
  130.  
  131. {DE..(..04) [1.x/2.x/ 3.x]}
  132. Function GetBroadcastMode(var bmode:byte):boolean;
  133. { Returns the message mode.
  134.  
  135.   00 Server Stores : Netware Messages and User Messages,
  136.      Shell automaticly displays messages.
  137.   01 Server Stores : Server Messages. (User messages discarded)
  138.      Shell automaticly displays messages.
  139.   02 Server stores : Server messages only.
  140.      Applications have to use GetBroadCastMessage to see if there is a message.
  141.   03 Server stores : Server messages and User messages.
  142.      Applications have to use GetBroadCastMessage to see if there is a message. }
  143. var regs : registers;
  144. begin
  145. regs.ah := $de;
  146. regs.dl := $04;
  147. msdos(regs);
  148. bmode := regs.al;
  149. result:=$00; { the call has no return codes }
  150. GetBroadCastMode:=True;
  151. end;
  152.  
  153.  
  154. {DE..(..0n) n=0,1,2,3 [1.x/2.x/3.x]}
  155. Function SetBroadcastMode(bmode:byte):boolean;
  156. { Sets the new message mode.
  157.  
  158.   possible resultcode: $FF ( illegal broadcastmode supplied or
  159.                              the broadcastmode after the call is not equal
  160.                              to the intended broadcast mode )
  161.  
  162.   00 Server Stores : Netware Messages and User Messages,
  163.      Shell automaticly displays messages.
  164.   01 Server Stores : Server Messages. (User messages discarded)
  165.      Shell automaticly displays messages.
  166.   02 Server stores : Server messages only.
  167.      Applications have to use GetBroadCastMessage to see if there is a message.
  168.   03 Server stores : Server messages and User messages.
  169.      Applications have to use GetBroadCastMessage to see if there is a message.     }
  170. var regs : registers;
  171. begin
  172. if (bmode <4)
  173.  then begin
  174.       regs.ah := $de;
  175.       regs.dl := bmode;
  176.       msdos(regs);
  177.       if regs.al<>bmode  { if confirmation of new mode unequal desired mode }
  178.        then result:=$FF
  179.        else result:=$00;
  180.       end
  181.  else result:=$FF;
  182. SetBroadcastMode:=(result=0);
  183. end;
  184.  
  185.  
  186.  
  187. {F215/01 [2.15c+]}
  188. Function GetBroadcastMessage(var bmessage: string):boolean;
  189. { An application should poll this to see if there is a broadcastmessage
  190.   stored (for this workstation) at the default server.
  191.   The message mode must be 2 or 3. (No Notification by Shell)
  192.   If no message was stored at the server, or the message was empty,
  193.   this function will return FALSE and an errorcode of $103. }
  194. Var req:record
  195.         len      :word;
  196.         subF     :byte;
  197.         end                      ABSOLUTE UnitReqBuffer;
  198.     reply:record
  199.           _message:string[55];
  200.           end                    ABSOLUTE UnitReplyBuffer;
  201. BEGIN
  202. With req
  203.  do begin
  204.     subF:=$01;
  205.     len:=1;
  206.     end;
  207. F2SystemCall($15,sizeOf(req),sizeOf(reply));
  208. If result=0
  209.  then bmessage:=reply._message;
  210.  
  211. if bmessage[0]=#0 then result:=$103; { whups! empty message }
  212.  
  213. GetBroadCastMessage:=(result=0);
  214. { returncodes:
  215.   00 Successful; FC Message Queue Full;
  216.   FE I/O failure: Lack of dynamic workspace.
  217.   103 No msgs stored at server. }
  218. end;
  219.  
  220.  
  221. {F215/00 [2.15c+]}
  222. Function SendBroadcastMessage( message:string;
  223.                                connCount:byte;
  224.                                connList:TconnectionList;
  225.                                VAR resultlist:TconnectionList ):boolean;
  226. { Sends a broadcast message to a number of logical connections.
  227.   The connectionlist is an array[1..connCount] of logical connection numbers,
  228.   the result of the broadcast can be found in the resultList parameter.
  229.   example:
  230.     connCount=5
  231.     connList=  [ 4,9,1,5,2 ]
  232.  
  233.     resultList= [$00, $00, $FC, $FD, $FF]
  234.  
  235.     possible codes in resultList:
  236.       $00: broadcast to this logical connnection was successful.
  237.       $FC: message rejected, buffer for this station already contains a message,
  238.       $FD: invalid connection number
  239.       $FF: The target connection has blocked incoming messages,
  240.            or the target connection is not in use. }
  241. Var req:record
  242.         len      :word;
  243.         subF     :byte;
  244.         _connCount     :byte;
  245.         connLandMessage:array[1..306] of byte; { 250 conn, 56 msg }
  246.         end                                ABSOLUTE UnitReqBuffer;
  247.     reply:record
  248.           connCount:byte;
  249.           _ResultList:TconnectionList;
  250.           end                              ABSOLUTE UnitReplyBuffer;
  251.    t:byte;
  252. BEGIN
  253. With req
  254.  do begin
  255.     subF:=$00;
  256.     _connCount:=connCount;
  257.     move(connList[1],connLandMessage[1],connCount);
  258.     t:=ord(message[0]); if t>55 then t:=55;
  259.     move(message[0],connLandMessage[connCount+1],t+1);
  260.     len:=3+connCount+t; { 2 bytes + [connList] + len(str) + str[0] }
  261.     end;
  262. F2SystemCall($15,sizeOf(req),sizeOf(reply));
  263. If result=0
  264.  then with reply
  265.        do begin
  266.           resultList:=_resultlist;
  267.           end;
  268.  
  269. SendBroadcastMessage:=(result=0);
  270. end;
  271.  
  272.  
  273. {F215/09 [2.15c+]}
  274. Function BroadcastToConsole(message:string):boolean;
  275. { broadcast a message to the file server console.
  276.   The message (max 60 chars, in ascii range [$20..$7E]) will be displayed
  277.   at the bottom of the console screen.
  278.   This function truncates the messagelength to 60 and repaces illegal
  279.   characters with a . }
  280. Var req:record
  281.         len      :word;
  282.         subF     :byte;
  283.         _message :string;
  284.         end               ABSOLUTE UnitReqBuffer;
  285.    t:byte;
  286. BEGIN
  287. With req
  288.  do begin
  289.     subF:=$09;
  290.     PstrCopy(_message,message,60);
  291.     for t:=1 to 60
  292.       do if (_message[t]<>#$0) and
  293.             ((_message[t]<#$20) or (_message[t]>#$7E))
  294.          then _message[t]:='.';
  295.     len:=62;
  296.     end;
  297. F2SystemCall($15,sizeOf(req),0);
  298. BroadcastToConsole:=(result=0);
  299. { resultcodes:  00 success ; $FC message queue full ;
  300.                $FE I/O failure: lack of dynamic workspace }
  301. end;
  302.  
  303.  
  304. {F215/02 [2.15c+]}
  305. Function DisableStationBroadcast:boolean;
  306.  
  307. Var req:record
  308.         len      :word;
  309.         subF     :byte;
  310.         end                 ABSOLUTE UnitReqBuffer;
  311. BEGIN
  312. With req
  313.  do begin
  314.     subF:=$02;
  315.     len:=1;
  316.     end;
  317. F2SystemCall($15,SizeOf(req),0);
  318. DisableStationBroadcast:=(result=0);
  319. end;
  320.  
  321.  
  322. {F215/03 [2.15c+]}
  323. Function EnableStationBroadcast:boolean;
  324. Var req:record
  325.         len      :word;
  326.         subF     :byte;
  327.         end                ABSOLUTE UnitReqBuffer;
  328. BEGIN
  329. With req
  330.  do begin
  331.     subF:=$03;
  332.     len:=1;
  333.     end;
  334. F2SystemCall($15,sizeOf(req),0);
  335. EnableStationBroadcast:=(result=0);
  336. end;
  337.  
  338.  
  339.  
  340. {F217/D1 [2.15c+]}
  341. Function SendConsoleBroadcast(message:string; connCount:byte;
  342.                               connList:TconnectionList       ):boolean;
  343. {Sends a message to a number of connections, as if the message was send
  344.  by a console oprator. Console oprator privileges required.
  345.  If connCount equals 0, then the message is send to all connections. }
  346. Var req:record
  347.         len      :word;
  348.         subF     :byte;
  349.         _ConnCount:byte;
  350.         _connAndMess:array[1..306] of byte;
  351.         end                           ABSOLUTE UnitReqBuffer;
  352.    t:byte;
  353. BEGIN
  354. With req
  355.  do begin
  356.     subF:=$D1;
  357.     _connCount:=connCount;
  358.     Move(connList[1],_connAndMess[1],connCount);
  359.     t:=ord(message[0]); if t>55 then t:=55;
  360.     {!! to do: strip hi-bit of message.. }
  361.     Move(message[0],_connAndMess[connCount+1],t+1);
  362.     len:=t+connCount+3;
  363.     end;
  364. F2SystemCall($17,sizeOf(req),0);
  365. SendConsoleBroadcast:=(result=0);
  366. {Resultcodes: $00 success; $C6 No Console Rights}
  367. end;
  368.  
  369. {=================== Secondary Functions ===================================}
  370.  
  371. Procedure SendMessageToUser(UserName,Message:String);
  372. { sends a message to a (group of) users.
  373.   The username may contain wildcards (* and ?).
  374.   The message will not be received by stations whose status is CASTOFF.}
  375. { calls nwConn.getObjectConnectionNumber and nwMess.SendBroadcastMessage }
  376. Var NbrOfConn:byte;
  377.     connList,ResultList:TconnectionList;
  378. begin
  379. IF NwConn.GetObjectConnectionNumbers(UserName,1 {OT_USER},NbrOfConn,connList)
  380.    AND (NbrOfConn>0)
  381.  then SendBroadcastMessage(Message,NbrOfConn,connList,ResultList);
  382. end;
  383.  
  384.  
  385. end. {unit nwMess}
  386.