pop.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C), 2000-2002 by Contributors to the monit codebase. 
00003  * All Rights Reserved.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <errno.h>
00024 
00025 #ifdef HAVE_STRING_H
00026 #include <string.h>
00027 #endif
00028 
00029 #include "protocol.h"
00030 
00041 int check_pop(Port_T p) {
00042 
00043   char buf[STRLEN];
00044   const char *ok= "+OK";
00045   const char *command= "QUIT\r\n";
00046 
00047   ASSERT(p);
00048   
00049   if(port_recv(p, buf, sizeof(buf), 0) <= 0) {
00050     log("POP: error receiving data -- %s\n", STRERROR);
00051     return FALSE;
00052   }
00053 
00054   chomp(buf);
00055   
00056   if(strncasecmp(buf, ok, strlen(ok)) != 0) {
00057     log("POP error: %s\n", buf);
00058     return FALSE;
00059   }
00060   
00061   if(port_send(p, command, strlen(command), 0) < 0) {
00062     log("POP: error sending data -- %s\n", STRERROR);
00063     return FALSE;
00064   }
00065 
00066   if(port_recv(p, buf, sizeof(buf), 0) <= 0) {
00067     log("POP: error receiving data -- %s\n", STRERROR);
00068     return FALSE;
00069   }
00070 
00071   chomp(buf);
00072   
00073   if(strncasecmp(buf, ok, strlen(ok)) != 0) {
00074     log("POP error: %s\n", buf);
00075     return FALSE;
00076   }
00077 
00078   return TRUE;
00079   
00080 }
00081