www.pudn.com > Ftpwork > Def.h


/***************************************************************************
                          Def.h  -  description
                             -------------------
    begin                : Wed Nov 6 2002
    copyright            : (C) 2002 by 
    email                : 
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifdef HAVE_CONFIG_H
#include 
#endif

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define SERVER_PORT 5431
#define MAX_LINE 1100
#define MAX_PENDING 1
#define RETURN 1
#define TRUE 1
#define FALSE 0
#define MAX_PATH 500

sem_t sem;

char RootPath[MAX_PATH];


struct ThreadState{
   int SockID;
   char Validate[1];
   char Path[MAX_PATH];
};

void clrscr(void)
{
    printf("\033[2J");		        /* Clear the entire screen.		*/
    printf("\033[0;0f");		/* Move cursor to the top left hand corner */
}

int ShortRecv(int SockID,char *buf,int len,int flags,int *SockState)
{
  int a;
  a=recv(SockID, buf,MAX_LINE, 0);
  char b[2]="a";
  *SockState=send( SockID, b, 2, MSG_NOSIGNAL );
  return a;
}

int ShortSend(int SockID,char *buf,int len,int flag)
{
  size_t sentlen=0;

  sentlen= send( SockID, buf,len,flag );

  char ackbuf[2];
  recv( SockID, ackbuf, MAX_LINE ,0 );
  if(ackbuf[0]=='a')
     return TRUE;
   else
      return FALSE;
}

long MyRecv(int SockID,char *buf,unsigned long len,int flags,int *SockState)
{
  char tem[11];
  if( ShortRecv( SockID, tem, len, flags, SockState) ){
      unsigned long a=atol( tem );
      if(a>len)return FALSE;
      else{
         char *recvbuf;
         long b;
         if( ((long) (a/1024)) *1024==a)b=a/1024 - 1;
         else b=((long)(a/1024));
         for( long i=0;i<=b;i++){
            recvbuf=buf + i*1024;
            ShortRecv( SockID, recvbuf, 1024, flags, SockState);
         }
         return a;
      }
  }
 return 0;
}

int MySend(int SockID,char *buf,unsigned long len,int flag)
{
  char tem[11];
  sprintf(tem,"%d",len);
  ShortSend( SockID, tem, 11, MSG_NOSIGNAL );
  char *sendbuf;
  long a;
  if( ((long) (len/1024)) *1024==len)a=len/1024 - 1;
  else a=((long)(len/1024));
  for( long i=0;i<=a-1;i++){
      sendbuf=buf + i*1024;
      ShortSend( SockID, sendbuf, 1024, MSG_NOSIGNAL );
  }
  sendbuf=buf + a*1024;
  ShortSend( SockID, sendbuf, len-a*1024, MSG_NOSIGNAL );
  return len;
}

int StringCompare(char *s1, char *s2)
{
    int Ret;

    if (strcmp(s1, s2))
    {
        Ret = 0;
    }
    else
    {
        Ret = 1;
    }

    return (Ret);
}