|
diff --git a/cgit.h b/cgit.h index f8f0316..0baa679 100644 --- a/ cgit.h+++ b/ cgit.h |
|
@@ -1,276 +1,277 @@ |
1 | #ifndef CGIT_H |
1 | #ifndef CGIT_H |
2 | #define CGIT_H |
2 | #define CGIT_H |
3 | |
3 | |
4 | |
4 | |
5 | #include <git-compat-util.h> |
5 | #include <git-compat-util.h> |
6 | #include <cache.h> |
6 | #include <cache.h> |
7 | #include <grep.h> |
7 | #include <grep.h> |
8 | #include <object.h> |
8 | #include <object.h> |
9 | #include <tree.h> |
9 | #include <tree.h> |
10 | #include <commit.h> |
10 | #include <commit.h> |
11 | #include <tag.h> |
11 | #include <tag.h> |
12 | #include <diff.h> |
12 | #include <diff.h> |
13 | #include <diffcore.h> |
13 | #include <diffcore.h> |
14 | #include <refs.h> |
14 | #include <refs.h> |
15 | #include <revision.h> |
15 | #include <revision.h> |
16 | #include <log-tree.h> |
16 | #include <log-tree.h> |
17 | #include <archive.h> |
17 | #include <archive.h> |
18 | #include <xdiff/xdiff.h> |
18 | #include <xdiff/xdiff.h> |
19 | |
19 | |
20 | |
20 | |
21 | /* |
21 | /* |
22 | * The valid cgit repo-commands |
22 | * The valid cgit repo-commands |
23 | */ |
23 | */ |
24 | #define CMD_LOG 1 |
24 | #define CMD_LOG 1 |
25 | #define CMD_COMMIT 2 |
25 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF 3 |
26 | #define CMD_DIFF 3 |
27 | #define CMD_TREE 4 |
27 | #define CMD_TREE 4 |
28 | #define CMD_BLOB 5 |
28 | #define CMD_BLOB 5 |
29 | #define CMD_SNAPSHOT 6 |
29 | #define CMD_SNAPSHOT 6 |
30 | #define CMD_TAG 7 |
30 | #define CMD_TAG 7 |
31 | #define CMD_REFS 8 |
31 | #define CMD_REFS 8 |
32 | |
32 | |
33 | /* |
33 | /* |
34 | * Dateformats used on misc. pages |
34 | * Dateformats used on misc. pages |
35 | */ |
35 | */ |
36 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
36 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
37 | #define FMT_SHORTDATE "%Y-%m-%d" |
37 | #define FMT_SHORTDATE "%Y-%m-%d" |
38 | |
38 | |
39 | |
39 | |
40 | /* |
40 | /* |
41 | * Limits used for relative dates |
41 | * Limits used for relative dates |
42 | */ |
42 | */ |
43 | #define TM_MIN 60 |
43 | #define TM_MIN 60 |
44 | #define TM_HOUR (TM_MIN * 60) |
44 | #define TM_HOUR (TM_MIN * 60) |
45 | #define TM_DAY (TM_HOUR * 24) |
45 | #define TM_DAY (TM_HOUR * 24) |
46 | #define TM_WEEK (TM_DAY * 7) |
46 | #define TM_WEEK (TM_DAY * 7) |
47 | #define TM_YEAR (TM_DAY * 365) |
47 | #define TM_YEAR (TM_DAY * 365) |
48 | #define TM_MONTH (TM_YEAR / 12.0) |
48 | #define TM_MONTH (TM_YEAR / 12.0) |
49 | |
49 | |
50 | |
50 | |
51 | typedef void (*configfn)(const char *name, const char *value); |
51 | typedef void (*configfn)(const char *name, const char *value); |
52 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
52 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
53 | typedef void (*linediff_fn)(char *line, int len); |
53 | typedef void (*linediff_fn)(char *line, int len); |
54 | |
54 | |
55 | struct cacheitem { |
55 | struct cacheitem { |
56 | char *name; |
56 | char *name; |
57 | struct stat st; |
57 | struct stat st; |
58 | int ttl; |
58 | int ttl; |
59 | int fd; |
59 | int fd; |
60 | }; |
60 | }; |
61 | |
61 | |
62 | struct repoinfo { |
62 | struct repoinfo { |
63 | char *url; |
63 | char *url; |
64 | char *name; |
64 | char *name; |
65 | char *path; |
65 | char *path; |
66 | char *desc; |
66 | char *desc; |
67 | char *owner; |
67 | char *owner; |
68 | char *defbranch; |
68 | char *defbranch; |
69 | char *group; |
69 | char *group; |
70 | char *module_link; |
70 | char *module_link; |
71 | char *readme; |
71 | char *readme; |
72 | int snapshots; |
72 | int snapshots; |
73 | int enable_log_filecount; |
73 | int enable_log_filecount; |
74 | int enable_log_linecount; |
74 | int enable_log_linecount; |
75 | }; |
75 | }; |
76 | |
76 | |
77 | struct repolist { |
77 | struct repolist { |
78 | int length; |
78 | int length; |
79 | int count; |
79 | int count; |
80 | struct repoinfo *repos; |
80 | struct repoinfo *repos; |
81 | }; |
81 | }; |
82 | |
82 | |
83 | struct commitinfo { |
83 | struct commitinfo { |
84 | struct commit *commit; |
84 | struct commit *commit; |
85 | char *author; |
85 | char *author; |
86 | char *author_email; |
86 | char *author_email; |
87 | unsigned long author_date; |
87 | unsigned long author_date; |
88 | char *committer; |
88 | char *committer; |
89 | char *committer_email; |
89 | char *committer_email; |
90 | unsigned long committer_date; |
90 | unsigned long committer_date; |
91 | char *subject; |
91 | char *subject; |
92 | char *msg; |
92 | char *msg; |
93 | }; |
93 | }; |
94 | |
94 | |
95 | struct taginfo { |
95 | struct taginfo { |
96 | char *tagger; |
96 | char *tagger; |
97 | char *tagger_email; |
97 | char *tagger_email; |
98 | int tagger_date; |
98 | int tagger_date; |
99 | char *msg; |
99 | char *msg; |
100 | }; |
100 | }; |
101 | |
101 | |
102 | struct refinfo { |
102 | struct refinfo { |
103 | const char *refname; |
103 | const char *refname; |
104 | struct object *object; |
104 | struct object *object; |
105 | union { |
105 | union { |
106 | struct taginfo *tag; |
106 | struct taginfo *tag; |
107 | struct commitinfo *commit; |
107 | struct commitinfo *commit; |
108 | }; |
108 | }; |
109 | }; |
109 | }; |
110 | |
110 | |
111 | struct reflist { |
111 | struct reflist { |
112 | struct refinfo **refs; |
112 | struct refinfo **refs; |
113 | int alloc; |
113 | int alloc; |
114 | int count; |
114 | int count; |
115 | }; |
115 | }; |
116 | |
116 | |
117 | extern const char *cgit_version; |
117 | extern const char *cgit_version; |
118 | |
118 | |
119 | extern struct repolist cgit_repolist; |
119 | extern struct repolist cgit_repolist; |
120 | extern struct repoinfo *cgit_repo; |
120 | extern struct repoinfo *cgit_repo; |
121 | extern int cgit_cmd; |
121 | extern int cgit_cmd; |
122 | |
122 | |
123 | extern char *cgit_root_title; |
123 | extern char *cgit_root_title; |
124 | extern char *cgit_css; |
124 | extern char *cgit_css; |
125 | extern char *cgit_logo; |
125 | extern char *cgit_logo; |
126 | extern char *cgit_index_header; |
126 | extern char *cgit_index_header; |
127 | extern char *cgit_logo_link; |
127 | extern char *cgit_logo_link; |
128 | extern char *cgit_module_link; |
128 | extern char *cgit_module_link; |
129 | extern char *cgit_agefile; |
129 | extern char *cgit_agefile; |
130 | extern char *cgit_virtual_root; |
130 | extern char *cgit_virtual_root; |
131 | extern char *cgit_script_name; |
131 | extern char *cgit_script_name; |
132 | extern char *cgit_cache_root; |
132 | extern char *cgit_cache_root; |
133 | extern char *cgit_repo_group; |
133 | extern char *cgit_repo_group; |
134 | |
134 | |
135 | extern int cgit_nocache; |
135 | extern int cgit_nocache; |
136 | extern int cgit_snapshots; |
136 | extern int cgit_snapshots; |
137 | extern int cgit_enable_index_links; |
137 | extern int cgit_enable_index_links; |
138 | extern int cgit_enable_log_filecount; |
138 | extern int cgit_enable_log_filecount; |
139 | extern int cgit_enable_log_linecount; |
139 | extern int cgit_enable_log_linecount; |
140 | extern int cgit_max_lock_attempts; |
140 | extern int cgit_max_lock_attempts; |
141 | extern int cgit_cache_root_ttl; |
141 | extern int cgit_cache_root_ttl; |
142 | extern int cgit_cache_repo_ttl; |
142 | extern int cgit_cache_repo_ttl; |
143 | extern int cgit_cache_dynamic_ttl; |
143 | extern int cgit_cache_dynamic_ttl; |
144 | extern int cgit_cache_static_ttl; |
144 | extern int cgit_cache_static_ttl; |
145 | extern int cgit_cache_max_create_time; |
145 | extern int cgit_cache_max_create_time; |
146 | extern int cgit_summary_log; |
146 | extern int cgit_summary_log; |
147 | extern int cgit_summary_tags; |
147 | extern int cgit_summary_tags; |
148 | extern int cgit_summary_branches; |
148 | extern int cgit_summary_branches; |
149 | |
149 | |
150 | extern int cgit_max_msg_len; |
150 | extern int cgit_max_msg_len; |
151 | extern int cgit_max_repodesc_len; |
151 | extern int cgit_max_repodesc_len; |
152 | extern int cgit_max_commit_count; |
152 | extern int cgit_max_commit_count; |
153 | |
153 | |
154 | extern int cgit_query_has_symref; |
154 | extern int cgit_query_has_symref; |
155 | extern int cgit_query_has_sha1; |
155 | extern int cgit_query_has_sha1; |
156 | |
156 | |
157 | extern char *cgit_querystring; |
157 | extern char *cgit_querystring; |
158 | extern char *cgit_query_repo; |
158 | extern char *cgit_query_repo; |
159 | extern char *cgit_query_page; |
159 | extern char *cgit_query_page; |
160 | extern char *cgit_query_search; |
160 | extern char *cgit_query_search; |
161 | extern char *cgit_query_head; |
161 | extern char *cgit_query_head; |
162 | extern char *cgit_query_sha1; |
162 | extern char *cgit_query_sha1; |
163 | extern char *cgit_query_sha2; |
163 | extern char *cgit_query_sha2; |
164 | extern char *cgit_query_path; |
164 | extern char *cgit_query_path; |
165 | extern char *cgit_query_name; |
165 | extern char *cgit_query_name; |
166 | extern int cgit_query_ofs; |
166 | extern int cgit_query_ofs; |
167 | |
167 | |
168 | extern int htmlfd; |
168 | extern int htmlfd; |
169 | |
169 | |
170 | extern int cgit_get_cmd_index(const char *cmd); |
170 | extern int cgit_get_cmd_index(const char *cmd); |
171 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
171 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
172 | extern void cgit_global_config_cb(const char *name, const char *value); |
172 | extern void cgit_global_config_cb(const char *name, const char *value); |
173 | extern void cgit_repo_config_cb(const char *name, const char *value); |
173 | extern void cgit_repo_config_cb(const char *name, const char *value); |
174 | extern void cgit_querystring_cb(const char *name, const char *value); |
174 | extern void cgit_querystring_cb(const char *name, const char *value); |
175 | |
175 | |
176 | extern int chk_zero(int result, char *msg); |
176 | extern int chk_zero(int result, char *msg); |
177 | extern int chk_positive(int result, char *msg); |
177 | extern int chk_positive(int result, char *msg); |
178 | extern int chk_non_negative(int result, char *msg); |
178 | extern int chk_non_negative(int result, char *msg); |
179 | |
179 | |
180 | extern int hextoint(char c); |
180 | extern int hextoint(char c); |
181 | extern char *trim_end(const char *str, char c); |
181 | extern char *trim_end(const char *str, char c); |
182 | |
182 | |
183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
185 | int flags, void *cb_data); |
185 | int flags, void *cb_data); |
186 | |
186 | |
187 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
187 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
188 | |
188 | |
189 | extern int cgit_diff_files(const unsigned char *old_sha1, |
189 | extern int cgit_diff_files(const unsigned char *old_sha1, |
190 | const unsigned char *new_sha1, |
190 | const unsigned char *new_sha1, |
191 | linediff_fn fn); |
191 | linediff_fn fn); |
192 | |
192 | |
193 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
193 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
194 | const unsigned char *new_sha1, |
194 | const unsigned char *new_sha1, |
195 | filepair_fn fn, const char *prefix); |
195 | filepair_fn fn, const char *prefix); |
196 | |
196 | |
197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
198 | |
198 | |
199 | extern char *fmt(const char *format,...); |
199 | extern char *fmt(const char *format,...); |
200 | |
200 | |
201 | extern void html(const char *txt); |
201 | extern void html(const char *txt); |
202 | extern void htmlf(const char *format,...); |
202 | extern void htmlf(const char *format,...); |
203 | extern void html_txt(char *txt); |
203 | extern void html_txt(char *txt); |
204 | extern void html_ntxt(int len, char *txt); |
204 | extern void html_ntxt(int len, char *txt); |
205 | extern void html_attr(char *txt); |
205 | extern void html_attr(char *txt); |
206 | extern void html_hidden(char *name, char *value); |
206 | extern void html_hidden(char *name, char *value); |
| |
207 | extern void html_option(char *value, char *text, char *selected_value); |
207 | extern void html_link_open(char *url, char *title, char *class); |
208 | extern void html_link_open(char *url, char *title, char *class); |
208 | extern void html_link_close(void); |
209 | extern void html_link_close(void); |
209 | extern void html_filemode(unsigned short mode); |
210 | extern void html_filemode(unsigned short mode); |
210 | extern int html_include(const char *filename); |
211 | extern int html_include(const char *filename); |
211 | |
212 | |
212 | extern int cgit_read_config(const char *filename, configfn fn); |
213 | extern int cgit_read_config(const char *filename, configfn fn); |
213 | extern int cgit_parse_query(char *txt, configfn fn); |
214 | extern int cgit_parse_query(char *txt, configfn fn); |
214 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
215 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
215 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
216 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
216 | extern void cgit_parse_url(const char *url); |
217 | extern void cgit_parse_url(const char *url); |
217 | |
218 | |
218 | extern char *cache_safe_filename(const char *unsafe); |
219 | extern char *cache_safe_filename(const char *unsafe); |
219 | extern int cache_lock(struct cacheitem *item); |
220 | extern int cache_lock(struct cacheitem *item); |
220 | extern int cache_unlock(struct cacheitem *item); |
221 | extern int cache_unlock(struct cacheitem *item); |
221 | extern int cache_cancel_lock(struct cacheitem *item); |
222 | extern int cache_cancel_lock(struct cacheitem *item); |
222 | extern int cache_exist(struct cacheitem *item); |
223 | extern int cache_exist(struct cacheitem *item); |
223 | extern int cache_expired(struct cacheitem *item); |
224 | extern int cache_expired(struct cacheitem *item); |
224 | |
225 | |
225 | extern char *cgit_repourl(const char *reponame); |
226 | extern char *cgit_repourl(const char *reponame); |
226 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
227 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
227 | const char *filename, const char *query); |
228 | const char *filename, const char *query); |
228 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
229 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
229 | const char *query); |
230 | const char *query); |
230 | |
231 | |
231 | extern const char *cgit_repobasename(const char *reponame); |
232 | extern const char *cgit_repobasename(const char *reponame); |
232 | |
233 | |
233 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
234 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
234 | char *rev, char *path); |
235 | char *rev, char *path); |
235 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
236 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
236 | char *rev, char *path, int ofs); |
237 | char *rev, char *path, int ofs); |
237 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
238 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
238 | char *rev); |
239 | char *rev); |
239 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, |
240 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, |
240 | char *rev, char *path); |
241 | char *rev, char *path); |
241 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
242 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
242 | char *head, char *rev, char *archivename); |
243 | char *head, char *rev, char *archivename); |
243 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
244 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
244 | char *new_rev, char *old_rev, char *path); |
245 | char *new_rev, char *old_rev, char *path); |
245 | |
246 | |
246 | extern void cgit_object_link(struct object *obj); |
247 | extern void cgit_object_link(struct object *obj); |
247 | |
248 | |
248 | extern void cgit_print_error(char *msg); |
249 | extern void cgit_print_error(char *msg); |
249 | extern void cgit_print_date(time_t secs, char *format); |
250 | extern void cgit_print_date(time_t secs, char *format); |
250 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
251 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
251 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
252 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
252 | extern void cgit_print_docend(); |
253 | extern void cgit_print_docend(); |
253 | extern void cgit_print_pageheader(char *title, int show_search); |
254 | extern void cgit_print_pageheader(char *title, int show_search); |
254 | extern void cgit_print_snapshot_start(const char *mimetype, |
255 | extern void cgit_print_snapshot_start(const char *mimetype, |
255 | const char *filename, |
256 | const char *filename, |
256 | struct cacheitem *item); |
257 | struct cacheitem *item); |
257 | extern void cgit_print_branches(int maxcount); |
258 | extern void cgit_print_branches(int maxcount); |
258 | extern void cgit_print_tags(int maxcount); |
259 | extern void cgit_print_tags(int maxcount); |
259 | |
260 | |
260 | extern void cgit_print_repolist(struct cacheitem *item); |
261 | extern void cgit_print_repolist(struct cacheitem *item); |
261 | extern void cgit_print_summary(); |
262 | extern void cgit_print_summary(); |
262 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
263 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
263 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
264 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
264 | extern void cgit_print_tree(const char *rev, char *path); |
265 | extern void cgit_print_tree(const char *rev, char *path); |
265 | extern void cgit_print_commit(char *hex); |
266 | extern void cgit_print_commit(char *hex); |
266 | extern void cgit_print_refs(); |
267 | extern void cgit_print_refs(); |
267 | extern void cgit_print_tag(char *revname); |
268 | extern void cgit_print_tag(char *revname); |
268 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); |
269 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); |
269 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
270 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
270 | const char *hex, const char *prefix, |
271 | const char *hex, const char *prefix, |
271 | const char *filename, int snapshot); |
272 | const char *filename, int snapshot); |
272 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
273 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
273 | const char *hex, int snapshots); |
274 | const char *hex, int snapshots); |
274 | extern int cgit_parse_snapshots_mask(const char *str); |
275 | extern int cgit_parse_snapshots_mask(const char *str); |
275 | |
276 | |
276 | #endif /* CGIT_H */ |
277 | #endif /* CGIT_H */ |
|
|
diff --git a/html.c b/html.c index 76fa6c4..6c9cc8b 100644 --- a/ html.c+++ b/ html.c |
|
@@ -1,182 +1,194 @@ |
1 | /* html.c: helper functions for html output |
1 | /* html.c: helper functions for html output |
2 | * |
2 | * |
3 | * Copyright (C) 2006 Lars Hjemli |
3 | * Copyright (C) 2006 Lars Hjemli |
4 | * |
4 | * |
5 | * Licensed under GNU General Public License v2 |
5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
10 | |
10 | |
11 | char *fmt(const char *format, ...) |
11 | char *fmt(const char *format, ...) |
12 | { |
12 | { |
13 | static char buf[8][1024]; |
13 | static char buf[8][1024]; |
14 | static int bufidx; |
14 | static int bufidx; |
15 | int len; |
15 | int len; |
16 | va_list args; |
16 | va_list args; |
17 | |
17 | |
18 | bufidx++; |
18 | bufidx++; |
19 | bufidx &= 7; |
19 | bufidx &= 7; |
20 | |
20 | |
21 | va_start(args, format); |
21 | va_start(args, format); |
22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
23 | va_end(args); |
23 | va_end(args); |
24 | if (len>sizeof(buf[bufidx])) |
24 | if (len>sizeof(buf[bufidx])) |
25 | die("[html.c] string truncated: %s", format); |
25 | die("[html.c] string truncated: %s", format); |
26 | return buf[bufidx]; |
26 | return buf[bufidx]; |
27 | } |
27 | } |
28 | |
28 | |
29 | void html(const char *txt) |
29 | void html(const char *txt) |
30 | { |
30 | { |
31 | write(htmlfd, txt, strlen(txt)); |
31 | write(htmlfd, txt, strlen(txt)); |
32 | } |
32 | } |
33 | |
33 | |
34 | void htmlf(const char *format, ...) |
34 | void htmlf(const char *format, ...) |
35 | { |
35 | { |
36 | static char buf[65536]; |
36 | static char buf[65536]; |
37 | va_list args; |
37 | va_list args; |
38 | |
38 | |
39 | va_start(args, format); |
39 | va_start(args, format); |
40 | vsnprintf(buf, sizeof(buf), format, args); |
40 | vsnprintf(buf, sizeof(buf), format, args); |
41 | va_end(args); |
41 | va_end(args); |
42 | html(buf); |
42 | html(buf); |
43 | } |
43 | } |
44 | |
44 | |
45 | void html_txt(char *txt) |
45 | void html_txt(char *txt) |
46 | { |
46 | { |
47 | char *t = txt; |
47 | char *t = txt; |
48 | while(t && *t){ |
48 | while(t && *t){ |
49 | int c = *t; |
49 | int c = *t; |
50 | if (c=='<' || c=='>' || c=='&') { |
50 | if (c=='<' || c=='>' || c=='&') { |
51 | *t = '\0'; |
51 | *t = '\0'; |
52 | html(txt); |
52 | html(txt); |
53 | *t = c; |
53 | *t = c; |
54 | if (c=='>') |
54 | if (c=='>') |
55 | html(">"); |
55 | html(">"); |
56 | else if (c=='<') |
56 | else if (c=='<') |
57 | html("<"); |
57 | html("<"); |
58 | else if (c=='&') |
58 | else if (c=='&') |
59 | html("&"); |
59 | html("&"); |
60 | txt = t+1; |
60 | txt = t+1; |
61 | } |
61 | } |
62 | t++; |
62 | t++; |
63 | } |
63 | } |
64 | if (t!=txt) |
64 | if (t!=txt) |
65 | html(txt); |
65 | html(txt); |
66 | } |
66 | } |
67 | |
67 | |
68 | void html_ntxt(int len, char *txt) |
68 | void html_ntxt(int len, char *txt) |
69 | { |
69 | { |
70 | char *t = txt; |
70 | char *t = txt; |
71 | while(t && *t && len--){ |
71 | while(t && *t && len--){ |
72 | int c = *t; |
72 | int c = *t; |
73 | if (c=='<' || c=='>' || c=='&') { |
73 | if (c=='<' || c=='>' || c=='&') { |
74 | *t = '\0'; |
74 | *t = '\0'; |
75 | html(txt); |
75 | html(txt); |
76 | *t = c; |
76 | *t = c; |
77 | if (c=='>') |
77 | if (c=='>') |
78 | html(">"); |
78 | html(">"); |
79 | else if (c=='<') |
79 | else if (c=='<') |
80 | html("<"); |
80 | html("<"); |
81 | else if (c=='&') |
81 | else if (c=='&') |
82 | html("&"); |
82 | html("&"); |
83 | txt = t+1; |
83 | txt = t+1; |
84 | } |
84 | } |
85 | t++; |
85 | t++; |
86 | } |
86 | } |
87 | if (t!=txt) { |
87 | if (t!=txt) { |
88 | char c = *t; |
88 | char c = *t; |
89 | *t = '\0'; |
89 | *t = '\0'; |
90 | html(txt); |
90 | html(txt); |
91 | *t = c; |
91 | *t = c; |
92 | } |
92 | } |
93 | if (len<0) |
93 | if (len<0) |
94 | html("..."); |
94 | html("..."); |
95 | } |
95 | } |
96 | |
96 | |
97 | void html_attr(char *txt) |
97 | void html_attr(char *txt) |
98 | { |
98 | { |
99 | char *t = txt; |
99 | char *t = txt; |
100 | while(t && *t){ |
100 | while(t && *t){ |
101 | int c = *t; |
101 | int c = *t; |
102 | if (c=='<' || c=='>' || c=='\'') { |
102 | if (c=='<' || c=='>' || c=='\'') { |
103 | *t = '\0'; |
103 | *t = '\0'; |
104 | html(txt); |
104 | html(txt); |
105 | *t = c; |
105 | *t = c; |
106 | if (c=='>') |
106 | if (c=='>') |
107 | html(">"); |
107 | html(">"); |
108 | else if (c=='<') |
108 | else if (c=='<') |
109 | html("<"); |
109 | html("<"); |
110 | else if (c=='\'') |
110 | else if (c=='\'') |
111 | html(""e;"); |
111 | html(""e;"); |
112 | txt = t+1; |
112 | txt = t+1; |
113 | } |
113 | } |
114 | t++; |
114 | t++; |
115 | } |
115 | } |
116 | if (t!=txt) |
116 | if (t!=txt) |
117 | html(txt); |
117 | html(txt); |
118 | } |
118 | } |
119 | |
119 | |
120 | void html_hidden(char *name, char *value) |
120 | void html_hidden(char *name, char *value) |
121 | { |
121 | { |
122 | html("<input type='hidden' name='"); |
122 | html("<input type='hidden' name='"); |
123 | html_attr(name); |
123 | html_attr(name); |
124 | html("' value='"); |
124 | html("' value='"); |
125 | html_attr(value); |
125 | html_attr(value); |
126 | html("'/>"); |
126 | html("'/>"); |
127 | } |
127 | } |
128 | |
128 | |
| |
129 | void html_option(char *value, char *text, char *selected_value) |
| |
130 | { |
| |
131 | html("<option value='"); |
| |
132 | html_attr(value); |
| |
133 | html("'"); |
| |
134 | if (selected_value && !strcmp(selected_value, value)) |
| |
135 | html(" selected"); |
| |
136 | html(">"); |
| |
137 | html_txt(text); |
| |
138 | html("</option>\n"); |
| |
139 | } |
| |
140 | |
129 | void html_link_open(char *url, char *title, char *class) |
141 | void html_link_open(char *url, char *title, char *class) |
130 | { |
142 | { |
131 | html("<a href='"); |
143 | html("<a href='"); |
132 | html_attr(url); |
144 | html_attr(url); |
133 | if (title) { |
145 | if (title) { |
134 | html("' title='"); |
146 | html("' title='"); |
135 | html_attr(title); |
147 | html_attr(title); |
136 | } |
148 | } |
137 | if (class) { |
149 | if (class) { |
138 | html("' class='"); |
150 | html("' class='"); |
139 | html_attr(class); |
151 | html_attr(class); |
140 | } |
152 | } |
141 | html("'>"); |
153 | html("'>"); |
142 | } |
154 | } |
143 | |
155 | |
144 | void html_link_close(void) |
156 | void html_link_close(void) |
145 | { |
157 | { |
146 | html("</a>"); |
158 | html("</a>"); |
147 | } |
159 | } |
148 | |
160 | |
149 | void html_fileperm(unsigned short mode) |
161 | void html_fileperm(unsigned short mode) |
150 | { |
162 | { |
151 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
163 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
152 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
164 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
153 | } |
165 | } |
154 | |
166 | |
155 | void html_filemode(unsigned short mode) |
167 | void html_filemode(unsigned short mode) |
156 | { |
168 | { |
157 | if (S_ISDIR(mode)) |
169 | if (S_ISDIR(mode)) |
158 | html("d"); |
170 | html("d"); |
159 | else if (S_ISLNK(mode)) |
171 | else if (S_ISLNK(mode)) |
160 | html("l"); |
172 | html("l"); |
161 | else if (S_ISGITLINK(mode)) |
173 | else if (S_ISGITLINK(mode)) |
162 | html("m"); |
174 | html("m"); |
163 | else |
175 | else |
164 | html("-"); |
176 | html("-"); |
165 | html_fileperm(mode >> 6); |
177 | html_fileperm(mode >> 6); |
166 | html_fileperm(mode >> 3); |
178 | html_fileperm(mode >> 3); |
167 | html_fileperm(mode); |
179 | html_fileperm(mode); |
168 | } |
180 | } |
169 | |
181 | |
170 | int html_include(const char *filename) |
182 | int html_include(const char *filename) |
171 | { |
183 | { |
172 | FILE *f; |
184 | FILE *f; |
173 | char buf[4096]; |
185 | char buf[4096]; |
174 | size_t len; |
186 | size_t len; |
175 | |
187 | |
176 | if (!(f = fopen(filename, "r"))) |
188 | if (!(f = fopen(filename, "r"))) |
177 | return -1; |
189 | return -1; |
178 | while((len = fread(buf, 1, 4096, f)) > 0) |
190 | while((len = fread(buf, 1, 4096, f)) > 0) |
179 | write(htmlfd, buf, len); |
191 | write(htmlfd, buf, len); |
180 | fclose(f); |
192 | fclose(f); |
181 | return 0; |
193 | return 0; |
182 | } |
194 | } |
|