"Fossies" - the Fresh Open Source Software Archive

Member "libping-1.15/lib/pop3.c" (28 Mar 2002, 3456 Bytes) of package /linux/privat/old/libping-1.15.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pop3.c" see the Fossies "Dox" file reference documentation.

    1 /**
    2  * POP3 module
    3  *
    4  * Copyright (C) 2001, 2002 by
    5  * Jeffrey Fulmer <jdfulmer@armstrong.com>
    6  * This file is part of LIBPING
    7  *
    8  * This program is free software; you can redistribute it and/or modify
    9  * it under the terms of the GNU General Public License as published by
   10  * the Free Software Foundation; either version 2 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This program is distributed in the hope that it will be useful,
   14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  * GNU General Public License for more details.
   17  *
   18  * You should have received a copy of the GNU General Public License
   19  * along with this program; if not, write to the Free Software
   20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   21  *
   22  */
   23 #include <pop3.h>
   24 #include <setup.h>
   25 
   26 #ifdef HAVE_CONFIG_H
   27 # include <config.h>
   28 #endif/*HAVE_CONFIG_H*/
   29 
   30 #include <sock.h>
   31 #include <util.h>
   32 #include <stdlib.h>
   33 #include <stdio.h>
   34  
   35 #ifdef HAVE_SYS_TIMES_H
   36 # include <sys/times.h>
   37 #endif /*HAVE_SYS_TIMES_H*/
   38 #if TIME_WITH_SYS_TIME
   39 # include <sys/time.h>
   40 # include <time.h>
   41 #else
   42 # if HAVE_SYS_TIME_H
   43 #  include <sys/time.h>
   44 # else
   45 #  include <time.h>
   46 # endif
   47 #endif /*TIME_WITH_SYS_TIME*/ 
   48 
   49 #include <signal.h>
   50 #include <setjmp.h> 
   51 
   52 #define MSGBUF  1024
   53 
   54 int send_cmd( CONN *C, char *cmd, char *val );
   55 
   56 int
   57 mypop3( POP3DATA *P )
   58 {
   59   CONN *C;
   60   char buf[MSGBUF];
   61   int x;
   62   int len  = 0;
   63   int ret  = 0;
   64   struct timeval mytime;
   65 
   66   C = (CONN*)xmalloc( sizeof( CONN ));
   67   C->port    =   110;
   68   C->timeout = ( P->timeout == 0 )?60:P->timeout; 
   69   
   70   if(( C->sock = JOEsocket( C, P->hostname )) <= 0 ){
   71     return -1;
   72   }   
   73 
   74   /* set the rrt timer */
   75   (void) gettimeofday( &mytime, (struct timezone *)NULL); 
   76 
   77   if(( ret = JOEreadline( C, buf, MSGBUF )) < 0 ){
   78     return ret;
   79   }
   80   if( !strncmp( buf, "+OK", 3 )) ret = 1; 
   81     
   82   if(( ret = send_cmd( C, "QUIT", NULL )) < 0 ){
   83     return ret; 
   84   }
   85 
   86   JOEclose( C );
   87   P->rtt = elapsed_time( &mytime ); 
   88 
   89   return ret;
   90 }
   91 
   92 int
   93 send_cmd( CONN *C, char *cmd, char *val )
   94 {
   95   char buf[256];
   96   char rec[MSGBUF];
   97   int  len;
   98 
   99   if( val )
  100     snprintf( buf, sizeof( buf ), "%s %s\r\n", cmd, val );
  101   else
  102     snprintf( buf, sizeof( buf ), "%s\r\n", cmd );
  103 
  104   if( JOEsocket_write( C, buf, sizeof( buf ))  < 0 )
  105     return -1;
  106 
  107   JOEreadline( C, rec, MSGBUF );
  108   *rec='\0';
  109 
  110   if( !strncmp( rec, "-ERR", 4 )){
  111     return -1;
  112   }
  113 
  114   return 1; 
  115 }
  116 
  117 int 
  118 pingpop3( const char *hostname )
  119 {
  120   POP3DATA *P;
  121   int ret;
  122  
  123   P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
  124   P->hostname = (char*)strdup( hostname );
  125   P->timeout = 0;
  126  
  127   return mypop3( P );
  128 }
  129 
  130 int
  131 pingtpop3( const char *hostname, int t )
  132 {
  133   POP3DATA *P;
  134   int ret;
  135  
  136   P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
  137   P->hostname = (char*)strdup( hostname );
  138   P->timeout = t;
  139  
  140   ret = mypop3( P ); 
  141 
  142   return mypop3( P );
  143 }
  144 
  145 int
  146 tpingpop3( const char *hostname )
  147 {
  148   POP3DATA *P;
  149   int ret;
  150  
  151   P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
  152   P->hostname = (char*)strdup( hostname );
  153   P->timeout = 0;
  154  
  155   ret = mypop3( P ); 
  156 
  157   if( ret > 0 ){ return P->rtt; }
  158   else         { return ret; }
  159 }
  160  
  161 int
  162 tpingtpop3( const char *hostname, int t )
  163 {
  164   POP3DATA *P;
  165   int ret;
  166  
  167   P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
  168   P->hostname = (char*)strdup( hostname );
  169   P->timeout = t; 
  170   
  171   ret = mypop3( P );
  172  
  173   if( ret > 0 ){ return P->rtt; }
  174   else         { return ret; }
  175  
  176 }