home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / snppsend.zip / TESTDLL.PAS < prev   
Pascal/Delphi Source File  |  1999-04-27  |  3KB  |  84 lines

  1. Program TestSNPPDLL;
  2. // (C)Igor Vaskov, 1998, 1999. FIDO 2:5020/207.27, Phone (095) 466-6477
  3. Uses Sockets,Strings,Delphi,OS2Base;
  4. Type
  5.   TSnppUser     = Record
  6.                     Login,Passw : PChar;
  7.                   End;
  8.  
  9.   TSnppMessage  = Record
  10.                     VServ       : Byte;
  11.                     Ext_flg     : Boolean;
  12.                     ID          : PChar;
  13.                     Passw       : PChar;
  14.                     Rep,Del     : Byte;
  15.                     DateTime    : TDateTime;
  16.                     Text        : PChar;
  17.                   End;
  18.  
  19. function OpenSock(Var Sock : TSocket) : LongInt; external 'snppsend' index 1;
  20. function ConnectSock(Var Sock : TSocket; Port : Word; HostAddr : PChar) : LongInt; external 'snppsend' index 2;
  21. function CloseSock(Var Sock : TSocket) : LongInt; external 'snppsend' index 3;
  22. function SNPPMsgSend(Var Sock : TSocket; User : TSnppUser; Msg : TSnppMessage) : LongInt; external 'snppsend' index 4;
  23.  
  24. Const
  25.   MaxIdent = 9;
  26.   IDent : array[1..MaxIdent] of String[4] = ('/LG:','/PS:','/ID:','/PI:','/TM:','/EX:','/VS:','/NF:','/IP:');
  27.  
  28. Var
  29.   Sock : TSocket;
  30.   rc   : LongInt;
  31.   Mess : TSnppMessage;
  32.   User : TSnppUser;
  33.   Param : Array[1..MaxIdent] of String;
  34.   X     : String;
  35.   i,j   : Byte;
  36.   MA    : Array[1..250] of Char;
  37.   FName : String;
  38.   hf    : LongInt;
  39. begin
  40.   for i:=1 to MaxIdent do
  41.     begin
  42.       X:=ParamStr(i);
  43.       Writeln(X);
  44.       if Length(X) > 0  then
  45.         begin
  46.           for j:=1 to MaxIdent do
  47.             begin
  48.               if Pos(IDent[j],X) > 0 then
  49.                 Param[j]:=X+#0;
  50.             end;
  51.         end;
  52.     end;
  53.   User.Login:=@Param[1][5];
  54.   User.Passw:=@Param[2][5];
  55.   Mess.ID:=@Param[3][5];
  56.   Mess.Passw:=@Param[4][5];
  57.   Mess.DateTime:=0;
  58.   Mess.Ext_flg:=(Param[6][5] = 'T') or (Param[5][5] = 't');
  59.   Mess.VServ:=1;
  60.   if Param[7][5] = '2' then Mess.VServ:=2;
  61.   FName:=Param[8];
  62.   Delete(FName,1,4);
  63.   Mess.Text:='This is test message.';
  64.   hf:=FileOpen(FName,FILE_ARCHIVED,fmOpenRead or OPEN_SHARE_DENYNONE);
  65.   if hf > 0 then
  66.     begin
  67.       FillChar(MA[1],SizeOf(MA),0);
  68.       FileRead(hf,MA[1],SizeOf(MA));
  69.       FileClose(hf);
  70.       Mess.Text:=@MA[1];
  71.     end;
  72.   rc:=OpenSock(Sock);
  73.   if rc < 1 then Writeln('OpenSock error ',rc);
  74.   rc:=ConnectSock(Sock,444,@Param[9][5]);
  75.   if rc < 1 then Writeln('ConnectSock error ',rc);
  76.   if rc = 1 then
  77.     begin
  78.       rc:=SNPPMsgSend(Sock,User,Mess);
  79.       if rc < 1 then Writeln('SNPPMsgSend error ',rc);
  80.     end;
  81.   rc:=CloseSock(Sock);
  82.   if rc < 1 then Writeln('ColoseSock error ',rc);
  83. end.
  84.