summaryrefslogtreecommitdiffabout
path: root/shared.c
authorLars Hjemli <hjemli@gmail.com>2008-04-08 19:11:36 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-04-08 19:11:36 (UTC)
commite87e89633383b8b75c68c98be3e0c14212109de2 (patch) (unidiff)
treef57e131ab854b58023387aee8efc0e4ee54653b5 /shared.c
parent20a33548b9a87a6eb23162ee5d137daa46d78613 (diff)
downloadcgit-e87e89633383b8b75c68c98be3e0c14212109de2.zip
cgit-e87e89633383b8b75c68c98be3e0c14212109de2.tar.gz
cgit-e87e89633383b8b75c68c98be3e0c14212109de2.tar.bz2
Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring()
This is a generic http-function. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c12
1 files changed, 0 insertions, 12 deletions
diff --git a/shared.c b/shared.c
index 48002ac..f5875e4 100644
--- a/shared.c
+++ b/shared.c
@@ -28,140 +28,128 @@ int chk_positive(int result, char *msg)
28 28
29int chk_non_negative(int result, char *msg) 29int chk_non_negative(int result, char *msg)
30{ 30{
31 if (result < 0) 31 if (result < 0)
32 die("%s: %s",msg, strerror(errno)); 32 die("%s: %s",msg, strerror(errno));
33 return result; 33 return result;
34} 34}
35 35
36struct cgit_repo *cgit_add_repo(const char *url) 36struct cgit_repo *cgit_add_repo(const char *url)
37{ 37{
38 struct cgit_repo *ret; 38 struct cgit_repo *ret;
39 39
40 if (++cgit_repolist.count > cgit_repolist.length) { 40 if (++cgit_repolist.count > cgit_repolist.length) {
41 if (cgit_repolist.length == 0) 41 if (cgit_repolist.length == 0)
42 cgit_repolist.length = 8; 42 cgit_repolist.length = 8;
43 else 43 else
44 cgit_repolist.length *= 2; 44 cgit_repolist.length *= 2;
45 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 45 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
46 cgit_repolist.length * 46 cgit_repolist.length *
47 sizeof(struct cgit_repo)); 47 sizeof(struct cgit_repo));
48 } 48 }
49 49
50 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 50 ret = &cgit_repolist.repos[cgit_repolist.count-1];
51 ret->url = trim_end(url, '/'); 51 ret->url = trim_end(url, '/');
52 ret->name = ret->url; 52 ret->name = ret->url;
53 ret->path = NULL; 53 ret->path = NULL;
54 ret->desc = "[no description]"; 54 ret->desc = "[no description]";
55 ret->owner = NULL; 55 ret->owner = NULL;
56 ret->group = ctx.cfg.repo_group; 56 ret->group = ctx.cfg.repo_group;
57 ret->defbranch = "master"; 57 ret->defbranch = "master";
58 ret->snapshots = ctx.cfg.snapshots; 58 ret->snapshots = ctx.cfg.snapshots;
59 ret->enable_log_filecount = ctx.cfg.enable_log_filecount; 59 ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
60 ret->enable_log_linecount = ctx.cfg.enable_log_linecount; 60 ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
61 ret->module_link = ctx.cfg.module_link; 61 ret->module_link = ctx.cfg.module_link;
62 ret->readme = NULL; 62 ret->readme = NULL;
63 return ret; 63 return ret;
64} 64}
65 65
66struct cgit_repo *cgit_get_repoinfo(const char *url) 66struct cgit_repo *cgit_get_repoinfo(const char *url)
67{ 67{
68 int i; 68 int i;
69 struct cgit_repo *repo; 69 struct cgit_repo *repo;
70 70
71 for (i=0; i<cgit_repolist.count; i++) { 71 for (i=0; i<cgit_repolist.count; i++) {
72 repo = &cgit_repolist.repos[i]; 72 repo = &cgit_repolist.repos[i];
73 if (!strcmp(repo->url, url)) 73 if (!strcmp(repo->url, url))
74 return repo; 74 return repo;
75 } 75 }
76 return NULL; 76 return NULL;
77} 77}
78 78
79void *cgit_free_commitinfo(struct commitinfo *info) 79void *cgit_free_commitinfo(struct commitinfo *info)
80{ 80{
81 free(info->author); 81 free(info->author);
82 free(info->author_email); 82 free(info->author_email);
83 free(info->committer); 83 free(info->committer);
84 free(info->committer_email); 84 free(info->committer_email);
85 free(info->subject); 85 free(info->subject);
86 free(info->msg); 86 free(info->msg);
87 free(info->msg_encoding); 87 free(info->msg_encoding);
88 free(info); 88 free(info);
89 return NULL; 89 return NULL;
90} 90}
91 91
92int hextoint(char c)
93{
94 if (c >= 'a' && c <= 'f')
95 return 10 + c - 'a';
96 else if (c >= 'A' && c <= 'F')
97 return 10 + c - 'A';
98 else if (c >= '0' && c <= '9')
99 return c - '0';
100 else
101 return -1;
102}
103
104char *trim_end(const char *str, char c) 92char *trim_end(const char *str, char c)
105{ 93{
106 int len; 94 int len;
107 char *s, *t; 95 char *s, *t;
108 96
109 if (str == NULL) 97 if (str == NULL)
110 return NULL; 98 return NULL;
111 t = (char *)str; 99 t = (char *)str;
112 len = strlen(t); 100 len = strlen(t);
113 while(len > 0 && t[len - 1] == c) 101 while(len > 0 && t[len - 1] == c)
114 len--; 102 len--;
115 103
116 if (len == 0) 104 if (len == 0)
117 return NULL; 105 return NULL;
118 106
119 c = t[len]; 107 c = t[len];
120 t[len] = '\0'; 108 t[len] = '\0';
121 s = xstrdup(t); 109 s = xstrdup(t);
122 t[len] = c; 110 t[len] = c;
123 return s; 111 return s;
124} 112}
125 113
126char *strlpart(char *txt, int maxlen) 114char *strlpart(char *txt, int maxlen)
127{ 115{
128 char *result; 116 char *result;
129 117
130 if (!txt) 118 if (!txt)
131 return txt; 119 return txt;
132 120
133 if (strlen(txt) <= maxlen) 121 if (strlen(txt) <= maxlen)
134 return txt; 122 return txt;
135 result = xmalloc(maxlen + 1); 123 result = xmalloc(maxlen + 1);
136 memcpy(result, txt, maxlen - 3); 124 memcpy(result, txt, maxlen - 3);
137 result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; 125 result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.';
138 result[maxlen] = '\0'; 126 result[maxlen] = '\0';
139 return result; 127 return result;
140} 128}
141 129
142char *strrpart(char *txt, int maxlen) 130char *strrpart(char *txt, int maxlen)
143{ 131{
144 char *result; 132 char *result;
145 133
146 if (!txt) 134 if (!txt)
147 return txt; 135 return txt;
148 136
149 if (strlen(txt) <= maxlen) 137 if (strlen(txt) <= maxlen)
150 return txt; 138 return txt;
151 result = xmalloc(maxlen + 1); 139 result = xmalloc(maxlen + 1);
152 memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); 140 memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3);
153 result[0] = result[1] = result[2] = '.'; 141 result[0] = result[1] = result[2] = '.';
154 return result; 142 return result;
155} 143}
156 144
157void cgit_add_ref(struct reflist *list, struct refinfo *ref) 145void cgit_add_ref(struct reflist *list, struct refinfo *ref)
158{ 146{
159 size_t size; 147 size_t size;
160 148
161 if (list->count >= list->alloc) { 149 if (list->count >= list->alloc) {
162 list->alloc += (list->alloc ? list->alloc : 4); 150 list->alloc += (list->alloc ? list->alloc : 4);
163 size = list->alloc * sizeof(struct refinfo *); 151 size = list->alloc * sizeof(struct refinfo *);
164 list->refs = xrealloc(list->refs, size); 152 list->refs = xrealloc(list->refs, size);
165 } 153 }
166 list->refs[list->count++] = ref; 154 list->refs[list->count++] = ref;
167} 155}