Last commit with db. Switching to makdown articles representation
This commit is contained in:
26
include/db_op/article.h
Normal file
26
include/db_op/article.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef _ARTICLE_H
|
||||
#define _ARTICLE_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../include/db_op/db.h"
|
||||
|
||||
#ifndef ARTICLE_T_TYPE
|
||||
#define ARTICLE_T_TYPE
|
||||
|
||||
typedef struct {
|
||||
unsigned int id;
|
||||
char *header;
|
||||
char *content;
|
||||
char *author;
|
||||
char *topic;
|
||||
} article_t;
|
||||
|
||||
#endif
|
||||
|
||||
int expand_line_article(int n, char *buff, entry_s *rec);
|
||||
char *serialize_article(entry_s *rec);
|
||||
|
||||
#endif
|
@ -1,11 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *header;
|
||||
char *content;
|
||||
char **tags;
|
||||
char *author;
|
||||
unsigned int key;
|
||||
} blogpost_t;
|
@ -1,3 +1,6 @@
|
||||
#ifndef _DB_H
|
||||
#define _DB_H
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -5,13 +8,44 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "./blogpost.h"
|
||||
#ifndef ARTICLE_T_TYPE
|
||||
#define ARTICLE_T_TYPE
|
||||
|
||||
typedef struct {
|
||||
unsigned int id;
|
||||
char *header;
|
||||
char *content;
|
||||
char *author;
|
||||
char *topic;
|
||||
} article_t;
|
||||
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BLOGPOST_T,
|
||||
ARTICLE_T
|
||||
} types;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
types type;
|
||||
union {
|
||||
article_t a;
|
||||
} data;
|
||||
} entry_s;
|
||||
|
||||
#include "./article.h"
|
||||
|
||||
#define LINE_SIZE 512
|
||||
|
||||
int open_db(char *file_name, char *type, FILE **file, char ***head, int *head_length);
|
||||
int open_db(char *file_name, types type, FILE **file, char ***head, int *head_length);
|
||||
int open_table(char *file_name, FILE **file);
|
||||
int read_head(FILE *file, char ***head);
|
||||
int get_entry(FILE *file, void **rec, int type, int n, int (*process_line)(char *, void **, int));
|
||||
int append_table(FILE *file, void *rec, int type, char *(*process_line)(void *, int));
|
||||
int get_entry(FILE *file, entry_s *rec, int n, int (*process_line)(int, char *, entry_s *));
|
||||
int append_table(FILE *file, entry_s *rec, char *(*process_line)(entry_s *));
|
||||
int remove_entry(FILE *file, int n);
|
||||
int read_whole_table(FILE *file, entry_s **rec, int (*process_line)(int, char *, entry_s *));
|
||||
int find_by(FILE *file, entry_s **entries, int (*check_line)(int, char *, entry_s), int (*process_line)(int, char *, entry_s));
|
||||
|
||||
#endif
|
8
include/db_op/db_cli.h
Normal file
8
include/db_op/db_cli.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef _DB_CLI_H
|
||||
#define _DB_CLI_H
|
||||
|
||||
#include "../../include/db_op/db.h"
|
||||
|
||||
char *get_all_articles_list();
|
||||
|
||||
#endif
|
@ -1,3 +1,6 @@
|
||||
#ifndef _FILE_H
|
||||
#define _FILE_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/sendfile.h>
|
||||
@ -14,4 +17,6 @@ struct file_s
|
||||
|
||||
char *gen_file_path(char *path);
|
||||
int send_file(int cli_fd, struct file_s *file);
|
||||
struct file_s *get_file_info(char *file_path);
|
||||
struct file_s *get_file_info(char *file_path);
|
||||
|
||||
#endif
|
@ -1,3 +1,10 @@
|
||||
#ifndef _MIME_H
|
||||
#define _MIME_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *get_mime_type(char *file_path);
|
||||
#define DEFAULT_MIME_TYPE "application/octet-stream"
|
||||
|
||||
char *get_mime_type(char *file_path);
|
||||
|
||||
#endif
|
@ -1,8 +1,15 @@
|
||||
#ifndef _NETW_H
|
||||
#define _NETW_H
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#define BACKLOG 10
|
||||
|
||||
int get_listener_socket(char *port);
|
||||
void *get_in_addr(struct sockaddr *sa);
|
||||
void *get_in_addr(struct sockaddr *sa);
|
||||
|
||||
#endif
|
@ -1,3 +1,6 @@
|
||||
#ifndef _REQUEST_H
|
||||
#define _REQUEST_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -8,13 +11,19 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define FILE_SIZE 1024
|
||||
|
||||
struct header_s {
|
||||
char * str;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
void res_404(int fd, char *path);
|
||||
void res_500(int fd);
|
||||
char *get_path(char *request);
|
||||
struct header_s *gen_header(int status_code, size_t file_size, char *mime_type);
|
||||
int send_response(int fd, char *req_path);
|
||||
void handle_post_request(int fd, char *request);
|
||||
void handle_get_request(int fd, char *request);
|
||||
void handle_get_request(int fd, char *request);
|
||||
|
||||
#endif
|
@ -1,5 +1,11 @@
|
||||
#ifndef _ARR_H
|
||||
#define _ARR_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void insert_to_arr(char ***arr, size_t length, char *value);
|
||||
void free_arr(char **arr, int length);
|
||||
void free_arr(char **arr, int length);
|
||||
int check_if_contains(char **arr, size_t length, char *str);
|
||||
|
||||
#endif
|
@ -0,0 +1,20 @@
|
||||
#ifndef _LLIST_H
|
||||
#define _LLIST_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NUMBER 5
|
||||
|
||||
typedef struct llist_s
|
||||
{
|
||||
char *value;
|
||||
struct llist_s *next;
|
||||
} llist_t;
|
||||
|
||||
llist_t *find_item(llist_t *list, int n);
|
||||
void fill_with_arr(llist_t **list, char **arr, size_t n);
|
||||
void print_llist(llist_t *list);
|
||||
llist_t *add_to_list(llist_t **head, int pos, char *value);
|
||||
|
||||
#endif
|
@ -1,9 +1,14 @@
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void err_msg(char *msg);
|
||||
char *add_to_front(char **str1, char *str2);
|
||||
char *concat_to_front(char **str1, char *str2);
|
||||
char *get_status_message(int status_code);
|
||||
char *to_lower(char *str);
|
||||
char *to_lower(char *str);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user