1 /* vim: set textwidth=80 tabstop=4: */ 2 3 /* 4 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client 5 * Copyright (C) 1999-2017 Michael Rasmussen and the Claws Mail Team 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef __CLAMD_PLUGIN_H__ 23 #define __CLAMD_PLUGIN_H__ 24 25 #include <glib.h> 26 27 typedef enum _Type Type; 28 enum _Type { UNIX_SOCKET, INET_SOCKET }; 29 30 typedef enum _Clamd_Stat Clamd_Stat; 31 enum _Clamd_Stat { OK, VIRUS, NO_SOCKET, NO_CONNECTION, SCAN_ERROR }; 32 33 typedef struct _Clamd_Socket Clamd_Socket; 34 struct _Clamd_Socket { 35 Type type; 36 union { 37 struct { 38 gchar* path; 39 }; 40 struct { 41 gchar* host; 42 int port; 43 }; 44 } socket; 45 }; 46 47 typedef struct { 48 enum { AUTOMATIC, MANUAL } ConfigType; 49 union { 50 struct { 51 gchar* folder; 52 } automatic; 53 struct { 54 gchar* host; 55 int port; 56 } manual; 57 }; 58 } Config; 59 60 typedef struct _response response; 61 struct _response { 62 gchar* msg; 63 }; 64 65 void clamd_create_config_automatic(const gchar* path); 66 67 void clamd_create_config_manual(const gchar* host, int port); 68 69 gchar* int2char(int i); 70 71 gchar* long2char(long l); 72 73 /** 74 * Function which looks for clamd.conf the default places 75 * and configures the plugin according to the information 76 * found. 77 * @return <b>TRUE</b> if clamd.conf found which means all 78 * information need to make a connection has been found. 79 * <b>FALSE</b> otherwise. 80 */ 81 gboolean clamd_find_socket(); 82 83 /** 84 * Function to get current configuration 85 * @return the current configuration for clamd or <b>NULL</b> 86 */ 87 Config* clamd_get_config(); 88 89 /** 90 * Function to retrieve virus name from msg 91 * @param msg Message returned from clamd 92 * @return virus name or <b>NULL</b> if no virus name found 93 */ 94 gchar* clamd_get_virus_name(gchar* msg); 95 96 /** 97 * Function to initialize the connection to clamd. 98 * @param config A pointer to a struct _Clamd_Socket having 99 * the required information. If clamd_find_socket returned 100 * TRUE config should be <b>NULL</b> because all the needed 101 * information is already present @see clamd_find_socket. 102 * @return Clamd_Stat. @see _Clamd_Stat. 103 */ 104 Clamd_Stat clamd_init(Clamd_Socket* config); 105 106 /** 107 * Function returning the current socket information. 108 * @return reference to the current Clamd_Socket. @see _Clamd_Socket. 109 */ 110 Clamd_Socket* clamd_get_socket(); 111 112 /** 113 * Function which is checks a specific email for known viruses 114 * @param path Absolut path to email to check. 115 * @param msg String to which result of scan will be copied. Will be 116 * <b>NULL</b> if no virus was found. 117 * @return Clamd_Stat. @see _Clamd_Stat. 118 */ 119 Clamd_Stat clamd_verify_email(const gchar* path, response* result); 120 121 /** 122 * Function which is checks files in a specific directory for 123 * known viruses. Dont stop when a virus is found but keeps going 124 * @param path Absolut path to directory to check. 125 * @return list of list with virus or <b>NULL</b>. 126 */ 127 GSList* clamd_verify_dir(const gchar* path); 128 129 /** 130 * Function to free all memory assigned to a GSList 131 * @param list The GSList to free 132 */ 133 void clamd_free_gslist(GSList* list); 134 135 /** 136 * Function which frees all memory assigned to clamd_plugin 137 */ 138 void clamd_free(); 139 140 Config* clamd_config_new(); 141 142 void clamd_config_free(Config* c); 143 144 #endif 145