2021-05-15 19:18:42 +02:00
|
|
|
#ifndef FILE_T_H
|
|
|
|
#define FILE_T_H
|
|
|
|
|
2021-06-01 00:08:30 +02:00
|
|
|
#include <openssl/md5.h> /* md5sum */
|
|
|
|
|
2021-05-15 19:18:42 +02:00
|
|
|
#include "exception_t.h"
|
|
|
|
|
2021-05-31 22:07:06 +02:00
|
|
|
typedef enum filepath_t {
|
|
|
|
FILEPATH_ABSOLUTE,
|
2021-06-12 11:02:56 +02:00
|
|
|
FILEPATH_RELATIVE,
|
|
|
|
FILEPATH_HOME
|
2021-05-31 22:07:06 +02:00
|
|
|
} filepath_t;
|
|
|
|
|
2021-05-15 19:18:42 +02:00
|
|
|
/**
|
|
|
|
* Wrapper to file
|
|
|
|
*/
|
|
|
|
typedef struct file_t {
|
|
|
|
char *name; /**< Absolute path to file */
|
2021-06-01 00:08:30 +02:00
|
|
|
unsigned char hash[MD5_DIGEST_LENGTH]; /**< MD5sum hash */
|
2021-05-15 19:18:42 +02:00
|
|
|
char *hash_str; /**< MD5sum hash as char* */
|
2021-06-03 00:33:26 +02:00
|
|
|
filepath_t fp;
|
2021-05-15 19:18:42 +02:00
|
|
|
} file_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialise file_t
|
|
|
|
* Adds $HOME to @filename and sets MD5 strings to NULL
|
|
|
|
* @param filename Relative path () to file
|
|
|
|
* @param e Exception
|
|
|
|
* @return Pointer to file_t
|
|
|
|
*/
|
|
|
|
file_t*
|
2021-05-31 22:07:06 +02:00
|
|
|
file_init(const char *filename, filepath_t FILEPATH, exception_t *e);
|
2021-05-15 19:18:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy file_t
|
|
|
|
* @param Pointer to file_t
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
file_close(file_t *file);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate MD5sum hash from file
|
|
|
|
* @return MD5sum hash of file
|
|
|
|
*/
|
|
|
|
unsigned char*
|
|
|
|
file_md5_gen(file_t *f, exception_t *e);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert MD5sum hash to string
|
|
|
|
* @param md5 MD5sum hash
|
|
|
|
* @return NULL-terminated string
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
file_md5_str(file_t *f, exception_t *e);
|
|
|
|
|
2021-06-03 00:33:26 +02:00
|
|
|
char*
|
|
|
|
file_abs(const file_t *f);
|
|
|
|
|
2021-05-15 19:18:42 +02:00
|
|
|
#endif
|