#ifndef ZENTIFIC_TYPES_H #define ZENTIFIC_TYPES_H #include "Common.h" //zentific session struct typedef struct _zentific_session zentific_session; struct _zentific_session { int authenticated; int uid; // userid of the client (when authenticated) char* username; // username of the client (when authenticated) char *session_id; char *client_host; char *referrer; int failures; int timestamp; //FIXME timestamp }; typedef struct _zentific_config zentific_config; struct _zentific_config { //Operation Tweaks int PORT; int THREADS; int LOG_LEVEL; gboolean SELF_HOST; gboolean DAEMONIZE; gboolean IS_VM; gboolean USE_SSL; gboolean XML_DEBUG; char *UTILS_PATH; char *VAR_PATH; char *MODULES_PATH; char *DB_MODULES_PATH; char *DB_MODULE; char *LISTEN; char *MY_UUID; char *SSL_PATH; char *SSL_CERT; char *KEY_PATH; char *WEB_ROOT; char *PID_FILE; char *LOG_FILE; char *CONF_FILE; char *LOG_TYPE; char *LOG_PREFIX; char *VM_CONF_PATH; // Database struct DB *db; }; typedef struct _DB_config DB_config; struct _DB_config { char *username; char *password; char *database; char *backend; //host:port, or path, etc void *other; }; typedef struct _DB DB; struct _DB { void *library; DB_config *config; GHashTable *dispatch; GHashTable *handles; /*DB Abstraction Functions*/ gboolean (*init)(DB *db, char *db_modules_path); gboolean (*uninit)(DB *db); gboolean (*disconnect)(void *handle); void *(*dbconnect)(DB_config *config); void *(*get_handle)(DB *db); /*API Session Functions*/ gboolean (*getSession)(DB * db, char * sessionid, struct _zentific_session *session); gboolean (*removeSession)(DB * db, char * sessionid); gboolean (*setSession)(DB * db, struct _zentific_session *session); //FIXME note the error field; experimenting with patterns here. // decide later whether a good method. GHashTable *(*checkSession)(DB *db, char *sessionid, gboolean *error); gboolean (*deauthSession)(DB *db, char *session_id); /*API Auth Functions*/ gboolean (*auth_db)(DB * db, char *user, char *pass); /*API User Functions*/ int (*getUserUID)(DB *db, char *username); char *(*getUsername)(DB *db, int uid); gboolean (*isUserUID)(DB *db, int uid); gboolean (*isActive)(DB *db, int uid); char *(*getLanguageCode)(DB *db, int id); gboolean (*addUser)(DB *db, USER *user); gboolean (*isVMowner)(DB *db, char *uuid, int uid); gboolean (*isNODEowner)(DB *db, char *uuid, int uid); gboolean (*setPassword)(DB *db, int uid, char *hash, char *salt); gboolean (*setUserAttribute)(DB *db, int uid, char *attribute, char *value); gboolean (*removeUser)(DB *db, int uid); GHashTable *(*getUser)(DB *db, int uid); GSList *(*getUsers)(DB *db); /*API Group Functionality for USER servlets*/ gboolean (*addUserGroup)(DB *db, char *name); gboolean (*userGroupExists)(DB *db, char *name); gboolean (*removeUserGroup)(DB *db, char *name); GSList *(*getUserGroups)(DB *db); GSList *(*getUserGroupMembers)(DB *db, char *name); gboolean (*addToUserGroup)(DB *db, int uid, char *name); gboolean (*removeFromUserGroup)(DB *db, int uid, char *name); gboolean (*renameUserGroup)(DB *db, char *old_name, char *new_name); /*API NETIF Functions*/ GSList *(*getVMvifs)(DB *db, char *uuid); gboolean (*updateVifStats)(DB *db, char *uuid, GSList *vifs); int (*getNumVMvifs)(DB *db, char *uuid); int (*getNumVMdisks)(DB *db, char *uuid); gboolean (*createVif)(DB *db, char *uuid); gboolean (*isVif)(DB *db, char *mac); gboolean (*updateVifConfig)(DB *db, char *uuid, int nextrevision, GSList *input_vifs); /*API NODE Functions*/ gboolean (*registerNode)(DB * db, NODE *node); gboolean (*updateNodeStats)(DB *db, char *uuid, NODE_STATS *stats); gboolean (*createNode)(DB * db, NODE *node); gboolean (*isNode)(DB * db, char *uuid); GHashTable *(*getNode)(DB * db, char *uuid); GSList *(*getNodes)(DB *db); gboolean (*pruneNodeStats)(DB *db, char * uuid, int age); GSList *(*getNodeLogs)(DB *db, char *uuid); GSList *(*getNetworks)(DB *db, char *uuid); /*API DISK Functions*/ gboolean (*isDisk)(DB *db, char *ext_dev); gboolean (*createDisk)(DB *db, char *uuid); GSList *(*getVMdisks)(DB *db, char *uuid); gboolean (*updateDiskConfig)(DB *db, char *uuid, int nextrevision, GSList *input_disks); gboolean (*updateDiskStats)(DB *db, char *uuid, GSList *disks); /*API VM Functions*/ gboolean (*isVM)(DB *db, char *uuid); char *(*getVMparentNode)(DB *db, char *uuid); gboolean (*createVM)(DB *db, char *uuid); int (*getLatestVMrev)(DB *db, char *uuid, char *type); int (*nextRevision)(DB *db, char *type); gboolean (*updateVMparentNode)(DB *db, char *uuid, char *puuid); GSList *(*getVMs)(DB *db); GHashTable *(*getVM)(DB *db, char *uuid); GSList *(*getVMsByUID)(DB *db, int uid); gboolean (*saveVMrevision)(DB *db, char *uuid, int uid, char *name, char *description); gboolean (*updateVmStats)(DB *db, VM *vm); gboolean (*updateVmConfig)(DB *db, int nextrevision, VM *input); GSList *(*getAllUsers)(DB *db, char *uuid); GSList *(*getVmLogs)(DB *db, char *uuid); int (*getPrivilege)(DB *db, char *uuid, int uid); gboolean (*grantPrivilege)(DB *db, char *uuid, int uid, int level); gboolean (*revokePrivilege)(DB *db, char *uuid, int uid, int level); char *(*getVMattribute)(DB *db, char *uuid, char *attribute); char *(*getVMstat)(DB *db, char *uuid, char *stat); char *(*getVMparentAddress)(DB *db, char *uuid); char *(*getConsoleLockSession)(DB *db, char *uuid, char *type); gboolean (*hasConsoleLock)(DB *db, char *uuid, char *type); gboolean (*acquireConsoleLock)(DB *db, char *uuid, struct _zentific_session *session, char *type, char *nodehost); gboolean (*releaseConsoleLock)(DB *db, char *uuid, char *sessionid, char *type); char *(*getConsoleClientHost)(DB *db, char *uuid, char *type); char *(*getVmNotes)(DB *db, char *uuid); gboolean (*saveVmNotes)(DB *db, char *uuid, char *notes); gboolean (*pruneVmStats)(DB *db, char * uuid, int age); gboolean (*pruneVifStats)(DB *db, char * uuid, char *mac, int age); gboolean (*pruneDiskStats)(DB *db, char * uuid, char *extdev, int age); gboolean (*needsReboot)(DB *db, char * uuid); gboolean (*configPush)(DB *db, char * address, char *nodeuuid, char *uuid); GSList *(*getTemplates)(DB *db); GHashTable *(*getTemplate)(DB *db, char *name); /* VM actions */ int (*action)(DB *db, char *uuid, char *jobtype_class, char *jobtype, char *extra, gboolean *error); gboolean (*saveGraphicalConsolePort)(DB *db, char *uuid, int tunnelport, int externalport); int (*getGraphicalConsolePort)(DB *db, char *uuid); char *(*getConsoleNodeHost)(DB *db, char *uuid, char *type); int (*getGraphicalConsoleTunnelPort)(DB *db, char *uuid); gboolean (*saveTextConsolePort)(DB *db, char *uuid, int externalport); int (*getTextConsolePort)(DB *db, char *uuid); char *(*getConsoleType)(DB *db, char *uuid, char *session_id); GSList *(*getConsoleLockVmsBySession)(DB *db, char *session_id); /*API Zentific Namespace Functions*/ char *(*getConfig)(DB *db, char *key); gboolean (*setConfig)(DB *db, char *key, char *value); GSList *(*getAllPlugins)(DB *db, char *which); GSList *(*getFrontendPlugins)(DB *db, char *which); gboolean (*isFrontendPluginEnabled)(DB *db, char *name); gboolean (*modifyPlugin)(DB *db, char *name, gboolean enabled, gboolean xmlrpc, gboolean frontend, gboolean scheduler, gboolean poller); gboolean (*cleanDB)(DB *db); /*API Job Namespace Functions*/ int (*getJobStatus)(DB *db, int jobid); GHashTable *(*getJob)(DB *db, int jobid); GSList *(*getJobsByUUID)(DB *db, char *uuid); GSList *(*getJobsByUID)(DB *db, int uid); GSList *(*getJobs)(DB *db); GSList *(*getJobsStatus)(DB *db, GSList *jobids); }; #endif //ZENTIFIC_TYPES_H