diff options
author | Jiri Moskovcak <jmoskovc@redhat.com> | 2010-07-08 16:38:19 +0200 |
---|---|---|
committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2010-07-09 11:42:30 +0200 |
commit | 6c4ea60aa257907deebcdb346a9d68bbe722837e (patch) | |
tree | 9169a621bdb63de41ccc6711636f8e5b6a432c49 /inc | |
parent | 27572201de598e6c097dac708826a724e4154659 (diff) | |
download | abrt-6c4ea60aa257907deebcdb346a9d68bbe722837e.tar.gz abrt-6c4ea60aa257907deebcdb346a9d68bbe722837e.tar.xz abrt-6c4ea60aa257907deebcdb346a9d68bbe722837e.zip |
mv devel header files to inc/ and install them
- header files are required to write the custom plugins plugins
without downloading the whole git tree, user just need to install
abrt-devel package
Diffstat (limited to 'inc')
-rw-r--r-- | inc/Action.h | 44 | ||||
-rw-r--r-- | inc/Analyzer.h | 55 | ||||
-rw-r--r-- | inc/CommLayerInner.h | 45 | ||||
-rw-r--r-- | inc/DBusCommon.h | 28 | ||||
-rw-r--r-- | inc/Database.h | 118 | ||||
-rw-r--r-- | inc/DebugDump.h | 67 | ||||
-rw-r--r-- | inc/Makefile.am | 20 | ||||
-rw-r--r-- | inc/Observer.h | 33 | ||||
-rw-r--r-- | inc/Plugin.h | 142 | ||||
-rw-r--r-- | inc/Reporter.h | 47 | ||||
-rw-r--r-- | inc/abrt_xmlrpc.h | 48 | ||||
-rw-r--r-- | inc/xfuncs.h | 96 |
12 files changed, 742 insertions, 1 deletions
diff --git a/inc/Action.h b/inc/Action.h new file mode 100644 index 00000000..fc56277b --- /dev/null +++ b/inc/Action.h @@ -0,0 +1,44 @@ +/* + Action.h - header file for action plugin + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef ACTION_H_ +#define ACTION_H_ + +#include "Plugin.h" + +/** + * An abstract class. The class defines an action plugin interface. + */ +class CAction : public CPlugin +{ + public: + /** + * A Method which performs particular action. As the first parameter it + * takes an action directory. It could be either a directory of actual + * crash or it could be a directory contains all crashes. It depends on + * who call the plugin. The plugin can takes arguments, but the plugin + * has to parse them by itself. + * @param pActionDir An actual directory. + * @param pArgs Plugin's arguments. + */ + virtual void Run(const char *pActionDir, const char *pArgs, int force) = 0; +}; + +#endif diff --git a/inc/Analyzer.h b/inc/Analyzer.h new file mode 100644 index 00000000..a45bd0e8 --- /dev/null +++ b/inc/Analyzer.h @@ -0,0 +1,55 @@ +/* + Analyzer.h - header file for analyzer plugin + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef ANALYZER_H_ +#define ANALYZER_H_ + +#include <string> +#include "Plugin.h" + +/** + * An abstract class. The class defines an analyzer plugin interface. + */ +class CAnalyzer : public CPlugin +{ + public: + /** + * A method, which gets a local UUID of particular crash. The local + * UUID is usualy computed from data which are stored in debugdump dir. + * @param pDebugDumpPath A debugdump dir containing all necessary data. + * @return A local UUID. + */ + virtual std::string GetLocalUUID(const char *pDebugDumpDir) = 0; + /** + * A method, which gets a global UUID of particular crash. + * @param pDebugDumpPath A debugdump dir containing all necessary data. + * @return A global UUID. + */ + virtual std::string GetGlobalUUID(const char *pDebugDumpDir) = 0; + /** + * A method, which takes care of getting all additional data needed + * for computing UUIDs and creating a report. This report could be send + * somewhere afterwards. + * @param pDebugDumpPath A debugdump dir containing all necessary data. + */ + virtual void CreateReport(const char *pDebugDumpDir, int force) = 0; +}; + +#endif /*ANALYZER_H_*/ diff --git a/inc/CommLayerInner.h b/inc/CommLayerInner.h new file mode 100644 index 00000000..353cfc76 --- /dev/null +++ b/inc/CommLayerInner.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef COMMLAYERINNER_H_ +#define COMMLAYERINNER_H_ + +#include "Observer.h" + +void init_daemon_logging(CObserver *pObs); + +/* + * Set client's name (dbus ID). NULL unsets it. + */ +void set_client_name(const char* name); + +/* + * Ask a client to warn the user about a non-fatal, but unexpected condition. + * In GUI, it will usually be presented as a popup message. + * Usually there is no need to call it directly, just use [p]error_msg(). + */ +//now static: void warn_client(const char *msg); + +/* + * Logs a message to a client. + * In UI, it will usually appear as a new status line message in GUI, + * or as a new message line in CLI. + */ +void update_client(const char *fmt, ...); + +#endif diff --git a/inc/DBusCommon.h b/inc/DBusCommon.h new file mode 100644 index 00000000..58b4c8dc --- /dev/null +++ b/inc/DBusCommon.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef DBUSCOMMON_H_ +#define DBUSCOMMON_H_ + +#include "CrashTypes.h" + +#define ABRTD_DBUS_NAME "com.redhat.abrt" +#define ABRTD_DBUS_PATH "/com/redhat/abrt" +#define ABRTD_DBUS_IFACE "com.redhat.abrt" + +#endif diff --git a/inc/Database.h b/inc/Database.h new file mode 100644 index 00000000..a698bcbc --- /dev/null +++ b/inc/Database.h @@ -0,0 +1,118 @@ +/* + Database.h - header file for database plugin + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef DATABASE_H_ +#define DATABASE_H_ + +#include <string> +#include <vector> +#include "Plugin.h" + +/** + * Table + * ===== + * UUID | UID| DebugDumpPath | Count | Reported | Time | Message + * + * primary key (UUID, UID) + */ + +/** + * A struct contains one database row. + */ +typedef struct database_row_t +{ + std::string m_sUUID; /**< A local UUID.*/ + std::string m_sUID; /**< An UID of an user.*/ + std::string m_sInformAll; + std::string m_sDebugDumpDir; /**< A debugdump directory of a crash.*/ + std::string m_sCount; /**< Crash rate.*/ + std::string m_sReported; /**< Is a row reported?*/ + std::string m_sMessage; /**< if a row is reported, then there can be store message abotu that*/ + std::string m_sTime; /**< Time of last occurred crash with same local UUID*/ +} database_row_t; + +/** + * A vector contains one or more database rows. + */ +typedef std::vector<database_row_t> vector_database_rows_t; + +/** + * An abstract class. The class defines a database plugin interface. + */ +class CDatabase : public CPlugin +{ + public: + /** + * A method, which connects to a database. + */ + virtual void Connect() = 0; + /** + * A method, which disconnects from a database. + */ + virtual void DisConnect() = 0; + /** + * A method, which inserts one row to a database. + * @param pUUID A local UUID of a crash. + * @param pUID An UID of an user. + * @param pDebugDumpPath A debugdump path. + * @param pTime Time when a crash occurs. + */ + virtual void Insert_or_Update(const char *crash_id, + bool inform_all_users, + const char *pDebugDumpPath, + const char *pTime) = 0; + /** + * A method, which deletes one row in a database. + * @param pUUID A lodal UUID of a crash. + * @param pUID An UID of an user. + */ + virtual void DeleteRow(const char *crash_id) = 0; + virtual void DeleteRows_by_dir(const char *dump_dir) = 0; + /** + * A method, which sets that particular row was reported. + * @param pUUID A local UUID of a crash. + * @param pUID An UID of an user. + * @param pMessage A text explanation of reported problem + * (where it is stored etc)... + */ + virtual void SetReported(const char *crash_id, + const char *pMessage) = 0; + virtual void SetReportedPerReporter(const char *crash_id, + const char *reporter, + const char *pMessage) = 0; + /** + * A method, which gets all rows which belongs to particular user. + * If the user is root, then all rows are returned. If there are no + * rows, empty vector is returned. + * @param pUID An UID of an user. + * @return A vector of matched rows. + */ + virtual vector_database_rows_t GetUIDData(long caller_uid) = 0; + /** + * A method, which returns one row accordind to UUID of a crash and + * UID of an user. If there are no row, empty row is returned. + * @param pUUID A UUID of a crash. + * @param pUID An UID of an user. + * @return A matched row. + */ + virtual database_row_t GetRow(const char *crash_id) = 0; +}; + +#endif diff --git a/inc/DebugDump.h b/inc/DebugDump.h new file mode 100644 index 00000000..f8487a65 --- /dev/null +++ b/inc/DebugDump.h @@ -0,0 +1,67 @@ +/* + DebugDump.h - header file for the library caring of writing new reports + to the specific directory + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef DEBUGDUMP_H_ +#define DEBUGDUMP_H_ + +#include <string> + +class CDebugDump +{ + private: + std::string m_sDebugDumpDir; + DIR* m_pGetNextFileDir; + bool m_bOpened; + bool m_bLocked; + uid_t m_uid; + gid_t m_gid; + + void Lock(); + void UnLock(); + + public: + CDebugDump(); + ~CDebugDump(); + + void Open(const char *pDir); + void Create(const char *pDir, uid_t uid); + void Delete(); + void Close(); + + bool Exist(const char* pFileName); + + void LoadText(const char* pName, std::string& pData); + + void SaveText(const char* pName, const char *pData); + void SaveBinary(const char* pName, const char* pData, unsigned pSize); + + void InitGetNextFile(); + /* Pointers may be NULL */ + bool GetNextFile(std::string *short_name, std::string *full_name); +}; + +/** + * Deletes particular debugdump directory. + * @param pDebugDumpDir A debugdump directory. + */ +void delete_debug_dump_dir(const char *pDebugDumpDir); + +#endif diff --git a/inc/Makefile.am b/inc/Makefile.am index 2ccc714f..e668b48a 100644 --- a/inc/Makefile.am +++ b/inc/Makefile.am @@ -1 +1,19 @@ -EXTRA_DIST = ABRTException.h CrashTypes.h abrtlib.h abrt_types.h +HEADER_FILES = \ + ABRTException.h \ + abrtlib.h \ + abrt_types.h \ + abrt_xmlrpc.h \ + Action.h \ + Analyzer.h \ + CommLayerInner.h \ + CrashTypes.h \ + Database.h \ + DBusCommon.h \ + DebugDump.h \ + Observer.h \ + Plugin.h \ + Reporter.h \ + xfuncs.h + +lib_includedir=$(includedir)/abrt/ +lib_include_HEADERS = $(HEADER_FILES) diff --git a/inc/Observer.h b/inc/Observer.h new file mode 100644 index 00000000..ec7dfa7b --- /dev/null +++ b/inc/Observer.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef OBSERVER_H_ +#define OBSERVER_H_ + +#include <string> +#include <stdint.h> +#include "DBusCommon.h" + +class CObserver { + public: + virtual ~CObserver() {} + virtual void Status(const char *pMessage, const char* peer) = 0; + virtual void Warning(const char *pMessage, const char* peer) = 0; +}; + +#endif diff --git a/inc/Plugin.h b/inc/Plugin.h new file mode 100644 index 00000000..367739ff --- /dev/null +++ b/inc/Plugin.h @@ -0,0 +1,142 @@ +/* + Plugin.h - header file for plugin. It contains mandatory macros + and common function for plugins + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef PLUGIN_H_ +#define PLUGIN_H_ + +#include "abrt_types.h" +#include "CrashTypes.h" +#if HAVE_CONFIG_H +# include <config.h> +#endif +#if ENABLE_NLS +# include <libintl.h> +# define _(S) gettext(S) +#else +# define _(S) (S) +#endif + +#define PLUGINS_MAGIC_NUMBER 6 + +#define PLUGINS_CONF_EXTENSION "conf" +#define PLUGINS_LIB_EXTENSION "so" +#define PLUGINS_LIB_PREFIX "lib" + +/** + * An abstract class. The class defines a common plugin interface. If a plugin + * has some settings, then a *Settings(*) method has to be written. + */ +class CPlugin +{ + protected: + map_plugin_settings_t m_pSettings; + + public: + CPlugin(); + /** + * A destructor. + */ + virtual ~CPlugin(); + /** + * A method, which initializes a plugin. It is not mandatory method. + */ + virtual void Init(); + /** + * A method, which deinitializes a plugin. It is not mandatory method. + */ + virtual void DeInit(); + /** + * A method, which takes a settings and apply them. It is not a mandatory method. + * @param pSettings Plugin's settings + */ + virtual void SetSettings(const map_plugin_settings_t& pSettings); + /** + * A method, which return current settings. It is not mandatory method. + * @return Plugin's settings + */ + virtual const map_plugin_settings_t& GetSettings(); +}; + +/** + * An enum of plugin types. + */ +typedef enum { + ANALYZER, /**< An analyzer plugin*/ + ACTION, /**< An action plugin*/ + REPORTER, /**< A reporter plugin*/ + DATABASE, /**< A database plugin*/ + MAX_PLUGIN_TYPE = DATABASE, +} plugin_type_t; + +/** + * A struct contains all needed data about particular plugin. + */ +typedef struct SPluginInfo +{ + const plugin_type_t m_Type; /**< Plugin type.*/ + const char *const m_sName; /**< Plugin name.*/ + const char *const m_sVersion; /**< Plugin version.*/ + const char *const m_sDescription; /**< Plugin description.*/ + const char *const m_sEmail; /**< Plugin author's email.*/ + const char *const m_sWWW; /**< Plugin's home page.*/ + const char *const m_sGTKBuilder; /**< Plugin's gui description.*/ + const int m_nMagicNumber; /**< Plugin magical number.*/ +} plugin_info_t; + +#define PLUGIN_INFO(type, plugin_class, name, version, description, email, www, gtk_builder)\ + extern "C" CPlugin* plugin_new()\ + {\ + return new plugin_class();\ + }\ + extern "C" const plugin_info_t plugin_info =\ + {\ + type,\ + name,\ + version,\ + description,\ + email,\ + www,\ + gtk_builder,\ + PLUGINS_MAGIC_NUMBER,\ + }; + +/* helper functions */ +std::string make_description_bz(const map_crash_data_t& pCrashData); +std::string make_description_reproduce_comment(const map_crash_data_t& pCrashData); +std::string make_description_logger(const map_crash_data_t& pCrashData); + +/** + * Loads settings and stores it in second parameter. On success it + * returns true, otherwise returns false. + * + * @param path A path of config file. + * Config file consists of "key=value" lines. + * @param settings A readed plugin's settings. + * @param skipKeysWithoutValue + * If true, lines in format "key=" (without value) are skipped. + * Otherwise empty value "" is inserted into pSettings. + * @return if it success it returns true, otherwise it returns false. + */ +extern bool LoadPluginSettings(const char *pPath, + map_plugin_settings_t& pSettings, + bool skipKeysWithoutValue = true); + +#endif diff --git a/inc/Reporter.h b/inc/Reporter.h new file mode 100644 index 00000000..4144ec33 --- /dev/null +++ b/inc/Reporter.h @@ -0,0 +1,47 @@ +/* + Reporter.h - header file for reporter plugin + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef REPORTER_H_ +#define REPORTER_H_ + +#include <string> +#include "Plugin.h" +#include "CrashTypes.h" + +/** + * An abstract class. The class defines a reporter plugin interface. + */ +class CReporter : public CPlugin +{ + public: + /** + * A method, which reports a crash report to particular receiver. + * The plugin can takes arguments, but the plugin has to parse them + * by itself. + * @param pCrashData A crash report. + * @param pArgs Plugin's arguments. + * @retun A message which can be displayed after a report is created. + */ + virtual std::string Report(const map_crash_data_t& pCrashData, + const map_plugin_settings_t& pSettings, + const char *pArgs) = 0; +}; + +#endif /* REPORTER_H_ */ diff --git a/inc/abrt_xmlrpc.h b/inc/abrt_xmlrpc.h new file mode 100644 index 00000000..ce770384 --- /dev/null +++ b/inc/abrt_xmlrpc.h @@ -0,0 +1,48 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef ABRT_XMLRPC_H_ +#define ABRT_XMLRPC_H_ 1 + +#include <curl/curl.h> +#include <xmlrpc-c/base.h> +#include <xmlrpc-c/client.h> + +/* + * Simple class holding XMLRPC connection data. + * Used mainly to ensure we always destroy xmlrpc client and server_info + * on return or throw. + */ + +struct abrt_xmlrpc_conn { + xmlrpc_client* m_pClient; + xmlrpc_server_info* m_pServer_info; + + abrt_xmlrpc_conn(const char* url, bool no_ssl_verify) { new_xmlrpc_client(url, no_ssl_verify); } + /* this never throws exceptions - calls C functions only */ + ~abrt_xmlrpc_conn() { destroy_xmlrpc_client(); } + + void new_xmlrpc_client(const char* url, bool no_ssl_verify); + void destroy_xmlrpc_client(); +}; + +/* Utility functions */ +void throw_xml_fault(xmlrpc_env *env); +void throw_if_xml_fault_occurred(xmlrpc_env *env); + +#endif diff --git a/inc/xfuncs.h b/inc/xfuncs.h new file mode 100644 index 00000000..de785c8e --- /dev/null +++ b/inc/xfuncs.h @@ -0,0 +1,96 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef ABRT_XFUNCS_H +#define ABRT_XFUNCS_H + +#include <sys/socket.h> +#include <sys/stat.h> +#include <dirent.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +extern int ndelay_on(int fd); +extern int ndelay_off(int fd); +extern int close_on_exec_on(int fd); + +extern void* xmalloc(size_t size); +extern void* xrealloc(void *ptr, size_t size); +extern void* xzalloc(size_t size); +extern char* xstrdup(const char *s); +extern char* xstrndup(const char *s, int n); + +extern void xpipe(int filedes[2]); +extern void xdup(int from); +extern void xdup2(int from, int to); +extern void xmove_fd(int from, int to); + +extern void xwrite(int fd, const void *buf, size_t count); +extern void xwrite_str(int fd, const char *str); + +extern off_t xlseek(int fd, off_t offset, int whence); + +extern void xchdir(const char *path); + +extern char* xvasprintf(const char *format, va_list p); +extern char* xasprintf(const char *format, ...); + +extern void xsetenv(const char *key, const char *value); +extern int xsocket(int domain, int type, int protocol); +extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); +extern void xlisten(int s, int backlog); +extern ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, socklen_t tolen); +extern void xstat(const char *name, struct stat *stat_buf); + +extern int xopen3(const char *pathname, int flags, int mode); +extern int xopen(const char *pathname, int flags); +extern void xunlink(const char *pathname); + +/* Just testing dent->d_type == DT_REG is wrong: some filesystems + * do not report the type, they report DT_UNKNOWN for every dirent + * (and this is not a bug in filesystem, this is allowed by standards). + * This function handles this case. Note: it returns 0 on symlinks + * even if they point to regular files. + */ +extern int is_regular_file(struct dirent *dent, const char *dirname); +extern bool dot_or_dotdot(const char *filename); +extern char *last_char_is(const char *s, int c); + +extern bool string_to_bool(const char *s); + +extern void xseteuid(uid_t euid); +extern void xsetegid(gid_t egid); +extern void xsetreuid(uid_t ruid, uid_t euid); +extern void xsetregid(gid_t rgid, gid_t egid); + +/* Returns getpwuid(uid)->pw_dir or NULL */ +extern const char *get_home_dir(uid_t uid); + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +std::string ssprintf(const char *format, ...); +std::string concat_path_file(const char *path, const char *filename); +#endif + +#endif |