-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.h
123 lines (99 loc) · 3.29 KB
/
post.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright (c) 2009-2019 Josef 'Jeff' Sipek <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __POST_H
#define __POST_H
#include <time.h>
#include <stdbool.h>
#include <jeffpc/synch.h>
#include <jeffpc/refcnt.h>
#include <jeffpc/list.h>
#include <jeffpc/rbtree.h>
#include "vars.h"
struct post_tag {
struct rb_node node;
struct str *tag;
};
struct comment {
struct list_node list;
unsigned int id;
struct str *author;
struct str *email;
unsigned int time;
struct str *ip;
struct str *url;
struct str *body;
};
struct post {
refcnt_t refcnt;
struct lock lock;
bool preview;
bool listed;
/* from 'posts' table */
unsigned int id;
unsigned int time;
struct str *title;
unsigned int fmt;
/* from 'post_tags' table */
struct rb_tree tags;
struct rb_tree cats;
/* from 'comments' table */
struct list comments;
unsigned int numcom;
/* body */
struct str *body;
struct str *twitter_img;
/* filenames used to construct this post */
struct nvlist *files;
};
struct req;
extern void init_post_subsys(void);
extern struct str *post_get_cached_file(struct post *post, const char *path);
extern struct post *load_post(int postid, bool preview);
extern int post_refresh(struct post *post);
extern void post_destroy(struct post *post);
extern void load_posts(struct req *req, struct post **posts, int nposts,
bool moreposts);
extern int load_all_posts(void);
extern void free_all_posts(void);
extern struct nvlist *get_post(struct req *req, int postid,
const char *titlevar, bool preview);
extern void init_post_index(void);
extern struct post *index_lookup_post(unsigned int postid);
extern int index_get_posts(struct post **ret, struct str *tagname,
bool (*pred)(struct post *, void *),
void *private, int skip, int nposts);
extern void index_for_each_tag(int (*init)(void *, unsigned long),
void (*step)(void *, struct str *, unsigned long,
unsigned long, unsigned long),
void *private);
extern int index_insert_post(struct post *post);
REFCNT_INLINE_FXNS(struct post, post, refcnt, post_destroy, NULL)
static inline void post_lock(struct post *post)
{
MXLOCK(&post->lock);
}
static inline void post_unlock(struct post *post)
{
MXUNLOCK(&post->lock);
}
#define max(a,b) ((a)<(b)? (b) : (a))
#endif