1 /* GKrellM 2 | Copyright (C) 1999-2019 Bill Wilson 3 | 4 | Author: Bill Wilson billw@gkrellm.net 5 | Latest versions might be found at: http://gkrellm.net 6 | 7 | 8 | GKrellM is free software: you can redistribute it and/or modify it 9 | under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | GKrellM is distributed in the hope that it will be useful, but WITHOUT 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 16 | 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, see http://www.gnu.org/licenses/ 20 | 21 | 22 | Additional permission under GNU GPL version 3 section 7 23 | 24 | If you modify this program, or any covered work, by linking or 25 | combining it with the OpenSSL project's OpenSSL library (or a 26 | modified version of that library), containing parts covered by 27 | the terms of the OpenSSL or SSLeay licenses, you are granted 28 | additional permission to convey the resulting work. 29 | Corresponding Source for a non-source form of such a combination 30 | shall include the source code for the parts of OpenSSL used as well 31 | as that of the covered work. 32 */ 33 #ifndef GKRELLMD_H 34 #define GKRELLMD_H 35 36 #include "log.h" 37 38 #include <glib.h> 39 #include <glib/gstdio.h> 40 41 #include <stdio.h> 42 #include <stdlib.h> 43 #include <string.h> 44 #include <ctype.h> 45 #include <fcntl.h> 46 #include <time.h> 47 48 #if (defined(__sun) && defined(__SVR4)) || defined(SOLARIS_8) 49 #define __solaris__ 50 #endif 51 52 #if !defined(WIN32) 53 #include <unistd.h> 54 #include <utime.h> 55 #include <sys/socket.h> 56 #include <sys/time.h> 57 #include <netinet/in.h> 58 #include <arpa/inet.h> 59 #include <netdb.h> 60 #include <sys/ioctl.h> 61 #include <pwd.h> 62 #include <grp.h> 63 #if defined(__solaris__) 64 #include <sys/filio.h> 65 #endif /* defined(__solaris__) */ 66 #include <sys/select.h> 67 #include <sys/wait.h> 68 #else 69 #include <winsock2.h> 70 #include <ws2tcpip.h> 71 typedef int sa_family_t; // WIN32 uses int for ai_family; 72 #include <stdint.h> // defines uint32_t 73 #endif /* !defined(WIN32) */ 74 75 #include <sys/stat.h> 76 #include <sys/types.h> 77 #include <locale.h> 78 #include <signal.h> 79 #include <errno.h> 80 81 82 #if !defined(PACKAGE_D) 83 #define PACKAGE_D "gkrellmd" 84 #endif 85 86 /* Internationalization support. 87 */ 88 #if defined (ENABLE_NLS) 89 #include <libintl.h> 90 # undef _ 91 # define _(String) dgettext(PACKAGE_D,String) 92 # if defined(gettext_noop) 93 # define N_(String) gettext_noop(String) 94 # else 95 # define N_(String) (String) 96 # endif /* gettext_noop */ 97 #else 98 # define _(String) (String) 99 # define N_(String) (String) 100 # define textdomain(String) (String) 101 # define gettext(String) (String) 102 # define dgettext(Domain,String) (String) 103 # define dcgettext(Domain,String,Type) (String) 104 # define bindtextdomain(Domain,Directory) (Domain) 105 #endif /* ENABLE_NLS */ 106 107 /* ------------------------------------------------------------------- 108 */ 109 #define GKRELLMD_VERSION_MAJOR 2 110 #define GKRELLMD_VERSION_MINOR 3 111 #define GKRELLMD_VERSION_REV 11 112 #define GKRELLMD_EXTRAVERSION "" 113 //#define GKRELLMD_EXTRAVERSION "-pre1" 114 115 #define GKRELLMD_CHECK_VERSION(major,minor,rev) \ 116 (GKRELLMD_VERSION_MAJOR > (major) || \ 117 (GKRELLMD_VERSION_MAJOR == (major) && GKRELLMD_VERSION_MINOR > (minor)) || \ 118 (GKRELLMD_VERSION_MAJOR == (major) && GKRELLMD_VERSION_MINOR == (minor) && \ 119 GKRELLMD_VERSION_REV >= (rev))) 120 121 #define GKRELLMD_CONFIG "gkrellmd.conf" 122 #if defined(WIN32) 123 // no dot in front of config-filename on win32 124 #define GKRELLMD_USER_CONFIG GKRELLMD_CONFIG 125 #else 126 #define GKRELLMD_USER_CONFIG ".gkrellmd.conf" 127 #endif 128 129 #define GKRELLMD_PLUGINS_DIR ".gkrellm2/plugins-gkrellmd" 130 #if !defined(WIN32) 131 #define GKRELLMD_LOCAL_PLUGINS_DIR "/usr/local/lib/gkrellm2/plugins-gkrellmd" 132 #if !defined(GKRELLMD_SYSTEM_PLUGINS_DIR) 133 #define GKRELLMD_SYSTEM_PLUGINS_DIR "/usr/lib/gkrellm2/plugins-gkrellmd" 134 #endif 135 #if !defined(GKRELLMD_SYS_ETC) 136 #define GKRELLMD_SYS_ETC "/etc" 137 #endif 138 #if 0 139 #define GKRELLMD_LOCAL_ETC "/usr/local/etc" 140 #endif 141 #endif // !defined(WIN32) 142 143 144 typedef struct _GkrellmdClient 145 { 146 gint major_version, 147 minor_version, 148 rev_version; 149 gchar *hostname; 150 151 gint fd; 152 gboolean served, 153 alive, 154 last_client; 155 gboolean feature_subdisk; 156 GString *input_gstring; 157 void (*input_func)(struct _GkrellmdClient *, gchar *); 158 } 159 GkrellmdClient; 160 161 162 typedef struct 163 { 164 gint timer_ticks, 165 second_tick, 166 two_second_tick, 167 five_second_tick, 168 ten_second_tick, 169 minute_tick; 170 } 171 GkrellmdTicks; 172 173 extern GkrellmdTicks GK; 174 175 176 typedef struct 177 { 178 gboolean need_serve; 179 const gchar *serve_name; 180 gboolean serve_name_sent; 181 GString *serve_gstring; 182 GkrellmdClient *client; 183 184 GList *config_list; 185 186 gboolean is_plugin; 187 void *handle; 188 gchar *path; 189 void (*client_input_func)(GkrellmdClient *, gchar *); 190 } 191 GkrellmdMonitorPrivate; 192 193 194 typedef struct _GkrellmdMonitor 195 { 196 gchar *name; 197 void (*update_monitor)(struct _GkrellmdMonitor *mon, 198 gboolean first_update); 199 void (*serve_data)(struct _GkrellmdMonitor *mon, 200 gboolean first_serve); 201 void (*serve_setup)(struct _GkrellmdMonitor *mon); 202 203 GkrellmdMonitorPrivate 204 *privat; 205 } 206 GkrellmdMonitor; 207 208 209 210 /* gkrellmd serve data functions used by builtins and plugins. 211 */ 212 void gkrellmd_plugin_serve_setup(GkrellmdMonitor *mon, 213 gchar *name, gchar *line); 214 void gkrellmd_need_serve(GkrellmdMonitor *mon); 215 void gkrellmd_set_serve_name(GkrellmdMonitor *mon, const gchar *name); 216 void gkrellmd_serve_data(GkrellmdMonitor *mon, gchar *line); 217 void gkrellmd_add_serveflag_done(gboolean *); 218 gboolean gkrellmd_check_client_version(GkrellmdMonitor *mon, 219 gint major, gint minor, gint rev); 220 221 const gchar *gkrellmd_config_getline(GkrellmdMonitor *mon); 222 223 void gkrellmd_client_input_connect(GkrellmdMonitor *mon, 224 void (*func)(GkrellmdClient *, gchar *)); 225 226 227 /* Small set of useful functions duplicated from src/utils.c. 228 | These really should just be in the gkrellm_ namespace for sysdep code 229 | common to gkrellm and gkrellmd, but for convenience, offer them in 230 | both gkrellm_ and gkrellmd_ namespaces. 231 */ 232 void gkrellmd_free_glist_and_data(GList **list_head); 233 gboolean gkrellmd_getline_from_gstring(GString **, gchar *, gint); 234 gchar *gkrellmd_dup_token(gchar **string, gchar *delimeters); 235 gboolean gkrellmd_dup_string(gchar **dst, gchar *src); 236 237 void gkrellm_free_glist_and_data(GList **list_head); 238 gboolean gkrellm_getline_from_gstring(GString **, gchar *, gint); 239 gchar *gkrellm_dup_token(gchar **string, gchar *delimeters); 240 gboolean gkrellm_dup_string(gchar **dst, gchar *src); 241 242 243 /* Plugins should use above data serve functions instead of this. 244 */ 245 gint gkrellmd_send_to_client(GkrellmdClient *client, gchar *buf); 246 247 248 /* Misc 249 */ 250 void gkrellmd_add_mailbox(gchar *); 251 GkrellmdTicks *gkrellmd_ticks(void); 252 gint gkrellmd_get_timer_ticks(void); 253 254 #endif // GKRELLMD_H 255