2 cehtehs git web frontend
5 2007, Christian Thaeter <ct@pipapo.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 webgit_query_init (struct webgit_query* q)
38 q->content_type = cwa_strndup ("text/html", SIZE_MAX);
42 q->skindir = cwa_strndup (WEBGIT_SKINDIR_DEFAULT, SIZE_MAX);
43 q->webskindir = cwa_strndup (WEBGIT_WEBSKINDIR_DEFAULT, SIZE_MAX);
52 q->skin = cwa_strndup (WEBGIT_DEFAULT_SKIN, SIZE_MAX);
55 llist_init (&q->repos);
59 webgit_query_destroy (struct webgit_query* q)
61 cgi_free (q->request);
63 free (q->content_type);
76 LLIST_WHILE_HEAD (&q->repos, head)
77 webgit_repoinfo_free ((struct webgit_repo_info*) head);
84 webgit_query_add_repo (struct webgit_query* q, const char* path)
86 struct webgit_repo_info* ri = webgit_repoinfo_new (q, path);
91 LLIST_FOREACH (&q->repos, node)
93 struct webgit_repo_info* n = (struct webgit_repo_info*)node;
94 if (strcmp (n->name, ri->name) > 0)
98 llist_insert_next (p, &ri->node);
102 webgit_validate_string (const char *s, size_t v_sz)
104 for (const char* c = ";$&|<>!`#"; *c; ++c)
105 if (memchr (s, *c, v_sz))
108 if (cwa_memmem (s, v_sz, "..", 2))
115 webgit_repo_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
118 struct webgit_query* q = (struct webgit_query*) u_dat;
120 /* TODO validate that v is a probably legal repo name (alnum()) */
121 if (webgit_validate_string (v, v_sz))
124 q->repo = cwa_strndup (v, v_sz);
130 webgit_action_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
133 struct webgit_query* q = (struct webgit_query*) u_dat;
135 /* TODO validate that v is a probably legal action name alpha() */
136 if (webgit_validate_string (v, v_sz))
139 q->action = cwa_strndup (v, v_sz);
145 webgit_object_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
148 struct webgit_query* q = (struct webgit_query*) u_dat;
151 q->action = cwa_strndup ("object", SIZE_MAX);
153 /* TODO validate that v is a probably sha1 (<=40 chars, hex) */
154 if (webgit_validate_string (v, v_sz))
157 q->object = cwa_strndup (v, v_sz);
163 webgit_ref_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
166 struct webgit_query* q = (struct webgit_query*) u_dat;
168 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
169 if (webgit_validate_string (v, v_sz))
172 q->head = cwa_strndup (v, v_sz);
178 webgit_path_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
181 struct webgit_query* q = (struct webgit_query*) u_dat;
183 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
184 if (webgit_validate_string (v, v_sz))
187 q->path = cwa_strndup (v, v_sz);
193 webgit_blob_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
196 struct webgit_query* q = (struct webgit_query*) u_dat;
199 q->blob = cwa_malloc (v_sz + 1);
201 memcpy (q->blob, v, v_sz);
202 q->blob[v_sz] = '\0';
207 webgit_skin_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
210 struct webgit_query* q = (struct webgit_query*) u_dat;
212 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
213 if (webgit_validate_string (v, v_sz))
216 q->skin = cwa_strndup (v, v_sz);
222 webgit_count_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
225 struct webgit_query* q = (struct webgit_query*) u_dat;
227 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
228 if (webgit_validate_string (v, v_sz))
236 webgit_param_dispatch (const Cgi self,
242 #define WEBGIT_PARAM(name, _) {#name, webgit_##name##_param},
245 void (*cb)(const Cgi, const char* v, size_t v_sz, void* u_dat);
246 } cmds[] = {WEBGIT_PARAMS {"", NULL}};
249 for (struct param_table* j = cmds; j->cb; ++j)
251 if (!strcmp (j->name, name))
253 j->cb (self, value, value_len, user_data);
262 // c-file-style: "gnu"
263 // indent-tabs-mode: nil