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 static Protocol_T myssh= NULL;
00040 
00041 
00054 /* ------------------------------------------------------------------ Public */
00055 
00056 
00057 void gc_protocols() {
00058 
00059   free(mydefault); mydefault= NULL;
00060   free(myhttp);    myhttp= NULL;
00061   free(myftp);     myftp= NULL;
00062   free(mysmtp);    mysmtp= NULL;
00063   free(mypop);     mypop= NULL;
00064   free(myimap);    myimap= NULL;
00065   free(mynntp);    mynntp= NULL;
00066   free(myssh);     myssh= NULL;
00067 
00068 }
00069 
00070 
00071 void *create_default() {
00072 
00073   if(mydefault == NULL) {
00074     static const char *name= "DEFAULT";
00075     mydefault= NEW(mydefault);
00076     mydefault->name= name;
00077     mydefault->check= check_default;
00078   }
00079 
00080   return mydefault;
00081 
00082 }
00083 
00084 
00085 void *create_http() {
00086 
00087   if(myhttp == NULL) {
00088     static const char *name= "HTTP";
00089     myhttp= NEW(myhttp);
00090     myhttp->name= name;
00091     myhttp->check= check_http;
00092   }
00093 
00094   return myhttp;
00095 
00096 }
00097 
00098 
00099 void *create_ftp() {
00100 
00101   if(myftp == NULL) {
00102     static const char *name= "FTP";
00103     myftp= NEW(myftp);
00104     myftp->name= name;
00105     myftp->check= check_ftp;
00106   }
00107 
00108   return myftp;
00109 
00110 }
00111 
00112 
00113 void *create_smtp() {
00114 
00115   if(mysmtp == NULL) {
00116     static const char *name= "SMTP";
00117     mysmtp= NEW(mysmtp);
00118     mysmtp->name= name;
00119     mysmtp->check= check_smtp;
00120   }
00121 
00122   return mysmtp;
00123 
00124 }
00125 
00126 
00127 void *create_pop() {
00128 
00129   if(mypop == NULL) {
00130     static const char *name= "POP";
00131     mypop= NEW(mypop);
00132     mypop->name= name;
00133     mypop->check= check_pop;
00134   }
00135 
00136   return mypop;
00137 
00138 }
00139 
00140 
00141 void *create_imap() {
00142 
00143   if(myimap == NULL) {
00144     static const char *name= "IMAP";
00145     myimap= NEW(myimap);
00146     myimap->name= name;
00147     myimap->check= check_imap;
00148   }
00149 
00150   return myimap;
00151 
00152 }
00153 
00154 
00155 void *create_nntp() {
00156 
00157   if(mynntp == NULL) {
00158     static const char *name= "NNTP";
00159     mynntp= NEW(mynntp);
00160     mynntp->name= name;
00161     mynntp->check= check_nntp;
00162   }
00163 
00164   return mynntp;
00165 
00166 }
00167 
00168 
00169 void *create_ssh() {
00170   
00171   if(myssh == NULL) {
00172     static const char *name= "SSH";
00173     myssh= NEW(myssh);
00174     myssh->name= name;
00175     myssh->check= check_ssh;
00176   }
00177   
00178   return myssh;
00179 
00180 }