home *** CD-ROM | disk | FTP | other *** search
/ BUG 14 / BUGCD1998_05.ISO / internet / tcp4u / tcp4u330.exe / tcp4u.330 / src / tn_proto.c < prev    next >
C/C++ Source or Header  |  1998-03-05  |  3KB  |  94 lines

  1. /*
  2.  * Tcp4u v 3.30          Last Revision 27/02/1998  3.30
  3.  *
  4.  *===========================================================================
  5.  *
  6.  * Project: Tcp4u,      Library for tcp protocol
  7.  * File:    tn_proto.c
  8.  * Purpose: telnet based-protocol transactions
  9.  *
  10.  *===========================================================================
  11.  *
  12.  * This software is Copyright (c) 1996-1998 by Philippe Jounin
  13.  *
  14.  * This library is free software; you can redistribute it and/or
  15.  * modify it under the terms of the GNU Library General Public
  16.  * License as published by the Free Software Foundation; either
  17.  * version 2 of the License, or (at your option) any later version.
  18.  * 
  19.  * This library is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22.  * Library General Public License for more details.
  23.  * 
  24.  * You should have received a copy of the GNU Library General Public
  25.  * License along with this library; if not, write to the
  26.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  27.  * Boston, MA  02111-1307, USA.
  28.  *
  29.  *
  30.  *  If you make modifications to this software that you feel
  31.  *  increases it usefulness for the rest of the community, please
  32.  *  email the changes, enhancements, bug fixes as well as any and
  33.  *  all ideas to me. This software is going to be maintained and
  34.  *  enhanced as deemed necessary by the community.
  35.  *
  36.  *
  37.  *             Philippe Jounin (ph.jounin@computer.org)
  38.  */
  39.  
  40.  
  41. #include "build.h"
  42.  
  43.  
  44. /* ------------------------------------------------------------------------- */
  45. /* This function does the dirty job of any protocol a la telnet              */
  46. /* it sends an order accepting variable length parameter, then waits for the */
  47. /* response. The response is compared with an array if strings passed by the */
  48. /* calling function. The result is the matching integer if any or            */
  49. /* TN_UNEXPECTED                                                             */
  50. /* ------------------------------------------------------------------------- */
  51. int API4U TnProtoExchange (SOCKET s, 
  52.                      LPCSTR szCommande,
  53.                      LPSTR  szResponse, 
  54.                      UINT uBufSize, 
  55.                      TNPROTOEXCHG_CBK TnProtoRecv,
  56.                      struct S_TnProto far *tTranslation, 
  57.                      int    nTabSize,
  58.                      BOOL   bCaseCmp,
  59.                      UINT   uTimeout,
  60.                      HFILE  hLogFile)
  61. {
  62. int     Rc;
  63. int     Ark;
  64. int (far * fCompare) (LPCSTR, LPCSTR, size_t);
  65. #define XX_RETURN(x)  { \
  66.     Tcp4uLog (LOG4U_EXIT, "TnReadAnswerCode: return code %d", x); \
  67.      return (x); }
  68.  
  69.  
  70.    Tcp4uLog (LOG4U_PROC, "TnProtoExchange");
  71.  
  72.    if (szCommande != NULL)
  73.    {
  74.      Rc = TnSend (s, szCommande, FALSE, hLogFile);
  75.      if (Rc != TN_SUCCESS)   XX_RETURN (Rc);
  76.    }
  77.  
  78.    /* waits for answer. NOte the final test */
  79.    Rc = TnProtoRecv (s, szResponse, uBufSize, uTimeout, hLogFile);
  80.    if (Rc<TN_SUCCESS)  XX_RETURN (Rc);
  81.  
  82.    /* choose the function for string compare */
  83.    fCompare = bCaseCmp ? strncmp : Tcp4uStrncasecmp;
  84.  
  85.    /* translate the code */
  86.    for ( Ark=0 ;  Ark<nTabSize &&  tTranslation[Ark].szString!=NULL;  Ark++)
  87.    {
  88.        if (fCompare (szResponse, tTranslation[Ark].szString, Strlen (tTranslation[Ark].szString)) == 0)
  89.             XX_RETURN (tTranslation[Ark].iCode);
  90.    }
  91. XX_RETURN (TN_UNEXPECTED);
  92. } /* TnProtoExchange */
  93.  
  94.