2016-12-18 15:50:56 +00:00
|
|
|
/* $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.
|
|
|
|
*/
|
2017-01-08 15:30:06 +00:00
|
|
|
#include "ksql.h"
|
|
|
|
|
2016-12-18 15:50:56 +00:00
|
|
|
#ifndef EXTERN_H
|
|
|
|
#define EXTERN_H
|
|
|
|
|
2017-01-15 10:43:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define debug(r, ...) kutil_logx(r, "DEBUG", NULL, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define debug(r, ...)
|
|
|
|
#endif
|
|
|
|
|
2016-12-29 20:02:58 +00:00
|
|
|
/*
|
2016-12-30 09:10:55 +00:00
|
|
|
* A book series.
|
2016-12-29 20:02:58 +00:00
|
|
|
*/
|
2016-12-30 09:10:55 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int64_t id;
|
|
|
|
char *name;
|
|
|
|
} Series;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A book. Generic data.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int64_t id;
|
2016-12-29 20:02:58 +00:00
|
|
|
char *title;
|
2016-12-30 10:26:26 +00:00
|
|
|
double s_idx; /* series index */
|
2016-12-30 09:10:55 +00:00
|
|
|
Series s;
|
|
|
|
} Book;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An author.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int64_t id;
|
|
|
|
char *name;
|
|
|
|
} Author;
|
|
|
|
|
2017-01-07 18:16:11 +00:00
|
|
|
/*
|
|
|
|
* Author and number of books.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Author a;
|
|
|
|
int count;
|
|
|
|
} AuthorAdv;
|
|
|
|
|
2017-01-01 14:44:51 +00:00
|
|
|
/*
|
|
|
|
* Downloadable book data.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int64_t size;
|
|
|
|
char *format;
|
|
|
|
char *name;
|
|
|
|
} BookData;
|
|
|
|
|
2016-12-30 09:10:55 +00:00
|
|
|
/*
|
|
|
|
* A book. Advanced data: authors, tags.
|
|
|
|
*/
|
2016-12-30 10:19:23 +00:00
|
|
|
typedef struct
|
2016-12-30 09:10:55 +00:00
|
|
|
{
|
|
|
|
Book b;
|
2016-12-30 14:40:21 +00:00
|
|
|
Author **a;
|
2016-12-30 10:19:23 +00:00
|
|
|
size_t asize;
|
2017-01-03 18:14:19 +00:00
|
|
|
char **tags;
|
|
|
|
size_t tsize;
|
2016-12-30 10:19:23 +00:00
|
|
|
} BookAdv;
|
2016-12-29 20:02:58 +00:00
|
|
|
|
2017-01-07 18:16:11 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Author a;
|
|
|
|
BookAdv **books;
|
|
|
|
size_t bsize;
|
|
|
|
} AuthorFull;
|
|
|
|
|
2016-12-31 14:33:09 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BookAdv ba;
|
2017-01-01 14:44:51 +00:00
|
|
|
BookData **data;
|
|
|
|
size_t dsize;
|
2016-12-31 14:33:09 +00:00
|
|
|
int64_t timestamp;
|
|
|
|
int64_t pubdate;
|
|
|
|
char *isbn;
|
|
|
|
char *lccn;
|
|
|
|
char *path;
|
|
|
|
char *uuid;
|
|
|
|
int64_t has_cover;
|
|
|
|
char *lang;
|
|
|
|
char *publisher;
|
|
|
|
} BookFull;
|
|
|
|
|
2017-01-08 15:30:06 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2016-12-18 15:50:56 +00:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2017-01-14 13:36:01 +00:00
|
|
|
int kvalid_term(struct kpair *p);
|
|
|
|
|
|
|
|
int db_books_search(struct kreq *r, int limit, Book** books, const char **terms, int num, int all);
|
2016-12-31 14:33:09 +00:00
|
|
|
BookFull *db_book_load(struct kreq *r, int64_t id);
|
2017-01-13 19:40:51 +00:00
|
|
|
int db_books_load(struct kreq *r, BookAdv **books, const char *sort, const char *order, int limit, int offset);
|
2017-01-01 14:44:51 +00:00
|
|
|
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);
|
2017-01-08 15:30:06 +00:00
|
|
|
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);
|
2016-12-30 10:19:23 +00:00
|
|
|
|
2017-01-15 14:44:44 +00:00
|
|
|
int db_authors_search(struct kreq *r, int limit, Author** authors, const char **terms, int num, int all);
|
2017-01-08 15:30:06 +00:00
|
|
|
void db_author_unfill(Author *p);
|
2017-01-07 18:16:11 +00:00
|
|
|
AuthorFull *db_author_load(struct kreq *r, int64_t id);
|
2017-01-13 19:40:51 +00:00
|
|
|
int db_authors_load(struct kreq *r, AuthorAdv **authors, const char *sort, const char *order,
|
|
|
|
int limit, int offset);
|
2017-01-07 11:19:00 +00:00
|
|
|
void db_author_free(Author *p);
|
2017-01-07 18:16:11 +00:00
|
|
|
void db_author_adv_free(AuthorAdv *p);
|
2017-01-07 11:19:00 +00:00
|
|
|
|
2017-01-15 14:44:44 +00:00
|
|
|
int db_series_search(struct kreq *r, int limit, Series** series, const char **terms, int num, int all);
|
2017-01-08 15:30:06 +00:00
|
|
|
void db_series_unfill(Series *p);
|
2017-01-13 19:40:51 +00:00
|
|
|
int db_series_load(struct kreq *r, SeriesAdv **series, const char *sort, const char *order,
|
|
|
|
int limit, int offset);
|
2017-01-08 15:30:06 +00:00
|
|
|
SeriesFull *db_serie_load(struct kreq *r, int64_t id);
|
2017-01-01 14:44:51 +00:00
|
|
|
void db_series_free(Series *p);
|
2017-01-08 15:30:06 +00:00
|
|
|
void db_series_adv_free(SeriesAdv *p);
|
2016-12-29 20:02:58 +00:00
|
|
|
|
2017-01-08 15:30:06 +00:00
|
|
|
char * strornull(struct ksqlstmt *stmt, int col);
|
2017-01-01 14:44:51 +00:00
|
|
|
void db_close(struct kreq *);
|
2016-12-18 15:50:56 +00:00
|
|
|
int db_open(struct kreq *, const char *);
|
|
|
|
|
2017-01-01 14:44:51 +00:00
|
|
|
void json_emptydoc(struct kreq *);
|
2016-12-18 15:50:56 +00:00
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|