bouquins-bchs/extern.h

192 lines
4.0 KiB
C

/* $Id$ */
/*
* Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "ksql.h"
#ifndef EXTERN_H
#define EXTERN_H
#ifdef DEBUG
#define debug(r, ...) kutil_logx(r, "DEBUG", NULL, __VA_ARGS__)
#else
#define debug(r, ...)
#endif
/*
* A book series.
*/
typedef struct
{
int64_t id;
char *name;
} Series;
/*
* A book. Generic data.
*/
typedef struct
{
int64_t id;
char *title;
double s_idx; /* series index */
Series s;
} Book;
/*
* An author.
*/
typedef struct
{
int64_t id;
char *name;
} Author;
/*
* Author and number of books.
*/
typedef struct
{
Author a;
int count;
} AuthorAdv;
/*
* Downloadable book data.
*/
typedef struct
{
int64_t size;
char *format;
char *name;
} BookData;
/*
* A book. Advanced data: authors, tags.
*/
typedef struct
{
Book b;
Author **a;
size_t asize;
char **tags;
size_t tsize;
} BookAdv;
typedef struct
{
Author a;
BookAdv **books;
size_t bsize;
} AuthorFull;
typedef struct
{
BookAdv ba;
BookData **data;
size_t dsize;
int64_t timestamp;
int64_t pubdate;
char *isbn;
char *lccn;
char *path;
char *uuid;
int64_t has_cover;
char *lang;
char *publisher;
} BookFull;
typedef struct
{
Series s;
int64_t books;
Author **a;
size_t asize;
} SeriesAdv;
typedef struct
{
SeriesAdv s;
Book **b;
} SeriesFull;
/*
* Linked list authors of book.
*/
struct bookauth {
Author *a;
BookAdv *b;
struct bookauth *p;
};
/*
* Linked list tags of book.
*/
struct booktag {
char *tag;
BookAdv *b;
struct booktag *p;
};
/*
* Linked list book data.
*/
struct bookdata {
BookData *d;
BookFull *b;
struct bookdata *p;
};
__BEGIN_DECLS
int kvalid_term(struct kpair *p);
int db_books_search(struct kreq *r, int limit, Book** books, const char **terms, int num, int all);
BookFull *db_book_load(struct kreq *r, int64_t id);
int db_books_load(struct kreq *r, BookAdv **books, const char *sort, const char *order, int limit, int offset);
int db_books_count(struct kreq *r);
void db_book_free(Book *p);
void db_book_adv_free(BookAdv *p);
void db_book_full_free(BookFull *p);
void db_book_fill(Book *book, struct ksqlstmt *stmt);
struct bookauth * db_load_books_authors(BookAdv **books, int count, struct ksqlstmt *stmt);
void db_assign_book_authors(struct bookauth *list);
int db_authors_search(struct kreq *r, int limit, Author** authors, const char **terms, int num, int all);
void db_author_unfill(Author *p);
AuthorFull *db_author_load(struct kreq *r, int64_t id);
int db_authors_load(struct kreq *r, AuthorAdv **authors, const char *sort, const char *order,
int limit, int offset);
void db_author_free(Author *p);
void db_author_adv_free(AuthorAdv *p);
int db_series_search(struct kreq *r, int limit, Series** series, const char **terms, int num, int all);
void db_series_unfill(Series *p);
int db_series_load(struct kreq *r, SeriesAdv **series, const char *sort, const char *order,
int limit, int offset);
SeriesFull *db_serie_load(struct kreq *r, int64_t id);
void db_series_free(Series *p);
void db_series_adv_free(SeriesAdv *p);
char * strornull(struct ksqlstmt *stmt, int col);
void db_close(struct kreq *);
int db_open(struct kreq *, const char *);
void json_emptydoc(struct kreq *);
__END_DECLS
#endif