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);
43 q->skindir = cwa_strndup (WEBGIT_SKINDIR_DEFAULT, SIZE_MAX);
44 q->webskindir = cwa_strndup (WEBGIT_WEBSKINDIR_DEFAULT, SIZE_MAX);
53 q->skin = cwa_strndup (WEBGIT_DEFAULT_SKIN, SIZE_MAX);
56 llist_init (&q->repos);
60 webgit_query_destroy (struct webgit_query* q)
62 cgi_free (q->request);
64 free (q->content_type);
77 LLIST_WHILE_HEAD (&q->repos, head)
78 webgit_repoinfo_free ((struct webgit_repo_info*) head);
85 webgit_query_add_repo (struct webgit_query* q, const char* path)
87 struct webgit_repo_info* ri = webgit_repoinfo_new (q, path);
92 LLIST_FOREACH (&q->repos, node)
94 struct webgit_repo_info* n = (struct webgit_repo_info*)node;
95 if (strcmp (n->name, ri->name) > 0)
99 llist_insert_next (p, &ri->node);
103 webgit_validate_string (const char *s, size_t v_sz)
105 for (const char* c = ";$&|<>!`#"; *c; ++c)
106 if (memchr (s, *c, v_sz))
109 if (cwa_memmem (s, v_sz, "..", 2))
116 webgit_repo_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
119 struct webgit_query* q = (struct webgit_query*) u_dat;
121 /* TODO validate that v is a probably legal repo name (alnum()) */
122 if (webgit_validate_string (v, v_sz))
125 q->repo = cwa_strndup (v, v_sz);
131 webgit_action_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
134 struct webgit_query* q = (struct webgit_query*) u_dat;
136 /* TODO validate that v is a probably legal action name alpha() */
137 if (webgit_validate_string (v, v_sz))
140 q->action = cwa_strndup (v, v_sz);
146 webgit_object_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
149 struct webgit_query* q = (struct webgit_query*) u_dat;
152 q->action = cwa_strndup ("object", SIZE_MAX);
154 /* TODO validate that v is a probably sha1 (<=40 chars, hex) */
155 if (webgit_validate_string (v, v_sz))
158 q->object = cwa_strndup (v, v_sz);
164 webgit_ref_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
167 struct webgit_query* q = (struct webgit_query*) u_dat;
169 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
170 if (webgit_validate_string (v, v_sz))
173 q->head = cwa_strndup (v, v_sz);
179 webgit_path_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
182 struct webgit_query* q = (struct webgit_query*) u_dat;
184 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
185 if (webgit_validate_string (v, v_sz))
188 q->path = cwa_strndup (v, v_sz);
194 webgit_blob_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
197 struct webgit_query* q = (struct webgit_query*) u_dat;
200 q->blob = cwa_malloc (v_sz + 1);
202 memcpy (q->blob, v, v_sz);
203 q->blob[v_sz] = '\0';
208 webgit_skin_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
211 struct webgit_query* q = (struct webgit_query*) u_dat;
213 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
214 if (webgit_validate_string (v, v_sz))
217 q->skin = cwa_strndup (v, v_sz);
223 webgit_count_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
226 struct webgit_query* q = (struct webgit_query*) u_dat;
228 /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
229 if (webgit_validate_string (v, v_sz))
237 webgit_param_dispatch (const Cgi self,
243 #define WEBGIT_PARAM(name, _) {#name, webgit_##name##_param},
246 void (*cb)(const Cgi, const char* v, size_t v_sz, void* u_dat);
247 } cmds[] = {WEBGIT_PARAMS {"", NULL}};
250 for (struct param_table* j = cmds; j->cb; ++j)
252 if (!strcmp (j->name, name))
254 j->cb (self, value, value_len, user_data);
263 // c-file-style: "gnu"
264 // indent-tabs-mode: nil