protocol.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 <stdlib.h>
00024 
00025 #ifdef HAVE_STRING_H
00026 #include <string.h>
00027 #endif
00028 
00029 #include "protocol.h"
00030 
00031 /* Private variables */
00032 static Protocol_T mydefault= NULL;
00033 static Protocol_T myhttp= NULL;
00034 static Protocol_T myftp= NULL;
00035 static Protocol_T mysmtp= NULL;
00036 static Protocol_T mypop= NULL;
00037 static Protocol_T myimap= NULL;
00038 static Protocol_T mynntp= NULL;
00039 
00040 
00053 /* ------------------------------------------------------------------ Public */
00054 
00055 
00056 void gc_protocols() {
00057 
00058   free(mydefault); mydefault= NULL;
00059   free(myhttp);    myhttp= NULL;
00060   free(myftp);     myftp= NULL;
00061   free(mysmtp);    mysmtp= NULL;
00062   free(mypop);     mypop= NULL;
00063   free(myimap);    myimap= NULL;
00064   free(mynntp);    mynntp= NULL;
00065 
00066 }
00067 
00068 
00069 void *create_default() {
00070 
00071   if ( mydefault == NULL ) {
00072     static const char *name= "DEFAULT";
00073     mydefault= NEW(mydefault);
00074     mydefault->name= name;
00075     mydefault->check= check_default;
00076   }
00077 
00078   return mydefault;
00079 
00080 }
00081 
00082 
00083 void *create_http() {
00084 
00085   if ( myhttp == NULL ) {
00086     static const char *name= "HTTP";
00087     myhttp= NEW(myhttp);
00088     myhttp->name= name;
00089     myhttp->check= check_http;
00090   }
00091 
00092   return myhttp;
00093 
00094 }
00095 
00096 
00097 void *create_ftp() {
00098 
00099   if ( myftp == NULL ) {
00100     static const char *name= "FTP";
00101     myftp= NEW(myftp);
00102     myftp->name= name;
00103     myftp->check= check_ftp;
00104   }
00105 
00106   return myftp;
00107 
00108 }
00109 
00110 
00111 void *create_smtp() {
00112 
00113   if ( mysmtp == NULL ) {
00114     static const char *name= "SMTP";
00115     mysmtp= NEW(mysmtp);
00116     mysmtp->name= name;
00117     mysmtp->check= check_smtp;
00118   }
00119 
00120   return mysmtp;
00121 
00122 }
00123 
00124 
00125 void *create_pop() {
00126 
00127   if ( mypop == NULL ) {
00128     static const char *name= "POP";
00129     mypop= NEW(mypop);
00130     mypop->name= name;
00131     mypop->check= check_pop;
00132   }
00133 
00134   return mypop;
00135 
00136 }
00137 
00138 
00139 void *create_imap() {
00140 
00141   if ( myimap == NULL ) {
00142     static const char *name= "IMAP";
00143     myimap= NEW(myimap);
00144     myimap->name= name;
00145     myimap->check= check_imap;
00146   }
00147 
00148   return myimap;
00149 
00150 }
00151 
00152 
00153 void *create_nntp() {
00154 
00155   if ( mynntp == NULL ) {
00156     static const char *name= "NNTP";
00157     mynntp= NEW(mynntp);
00158     mynntp->name= name;
00159     mynntp->check= check_nntp;
00160   }
00161 
00162   return mynntp;
00163 
00164 }