#ifndef __COMMAND_H_INCLUDED #define __COMMAND_H_INCLUDED /// @name Command Family /// @{ #define CMD_FAMILY_REQUEST 0x01 #define CMD_FAMILY_RESPONSE 0x02 /// @} /// @name Request Type /// @{ #define CMD_REQUEST_SCAN_LOCAL 0x01 #define CMD_REQUEST_SCAN_REMOTE 0x02 /// @} /// @name Parameter Type /// @{ #define CMD_PARAM_SENDER 0x004 #define CMD_PARAM_RECIPIENT 0x008 #define CMD_PARAM_HEADER 0x010 #define CMD_PARAM_QID 0x020 #define CMD_PARAM_CLIENTID 0x040 #define CMD_PARAM_SRVIP 0x080 #define CMD_PARAM_REJECTMSG 0x100 /// @} /// @name Scan Result /// @{ // MTA-related actions #define CMD_MTA_NOACTION 0x0000 /** Explicitly let pass */ #define CMD_MTA_ACTION_DROP 0x0001 /** Tell the MTA to drop the message */ #define CMD_MTA_ACTION_REJECT 0x0002 /** Reject the message */ #define CMD_MTA_ACTION_REPLACE 0x0004 /** Replace with processed */ #define CMD_MTA_ACTION_MAKETEXT 0x0008 /** Make the email text/plain */ #define CMD_MTA_ACTION_TEMPFAIL 0x0010 /** Processing error */ #define CMD_MTA_ACTION_REPLHDRS 0x0020 /** Replace only the headers */ /// @} /** * @brief Keeps one parameter */ struct kavParamStruct { /// Parameter type unsigned int id; /// Pointer to value char *value; /// Size of value unsigned int size; }; /** * @brief Linked-list holding the parameters */ struct kavParamList { /// Parameter data struct kavParamStruct data; /// Pointer to next item in linked-list struct kavParamList *next; }; /** * @brief Holds the request/response for a command */ struct kavCommandStruct { /// Command Family unsigned int family; /// MTA action unsigned int maction; /// Number of parameters unsigned int params_count; /// Pointer to parameter linked-list struct kavParamList *params; }; /** * @brief Initializes Command structure * @param[in] family Type of command * @return Pointer to newly allocated Command structure */ struct kavCommandStruct *kavCommandConstruct(unsigned int family); /** * @brief Destroys a Command structure * @param[in,out] cmd Command structure */ void kavCommandDestroy(struct kavCommandStruct **cmd); /** * @brief Adds a parameter to a Command structure * @param[in] cmd Command structure * @param[in] id Parameter ID * @param[in] value Parameter value * @param[in] size Length of value * @return In case of success it returns a pointer to the newly allocated parameter, in case of error it returns 0 */ struct kavParamList *kavCommandParamAdd(struct kavCommandStruct *cmd, unsigned int id, const char *value, unsigned int size); /** * @brief Serializes a Command structure to an opened socket * @param[in] cmd Command structure * @param[in] fd Socket * @return Returns -1 in case of errors, or a values greater or equal to 0 in case of success */ int kavCommandSerialize(struct kavCommandStruct *cmd, int fd); /** * @brief De-serializes a Command structure from an opened socket * @param[in] cmd Command structure * @param[in] fd Socket * @return Returns -1 in case of errors, or a values greater or equal to 0 in case of success */ int kavCommandDeserialize(struct kavCommandStruct *cmd, int fd); #ifdef __COMMAND_C static void kavCommandParamAppend(struct kavCommandStruct *cmd, struct kavParamList *p); static void kavCommandParamDestroy(struct kavParamList **p); #endif #endif // __COMMAND_H_INCLUDED