Fossil SCM

Fixed a memory leak in tagview_page_list_tags(). Minor other refactorings.

stephan 2008-02-03 18:00 trunk
Commit 2cb3290e6767e51d190f746abbac4f330ae14517
1 file changed +17 -8
+17 -8
--- src/tagview.c
+++ src/tagview.c
@@ -26,10 +26,18 @@
2626
** Implementation of the Tag View page
2727
*/
2828
#include <assert.h>
2929
#include "config.h"
3030
#include "tagview.h"
31
+
32
+
33
+#if 1
34
+# define TAGVIEW_DEFAULT_FILTER "AND t.tagname NOT GLOB 'wiki-*' "
35
+#else
36
+# define TAGVIEW_DEFAULT_FILTER
37
+#endif
38
+
3139
3240
/**
3341
tagview_strxform_f is a typedef for funcs with the following policy:
3442
3543
They accept a const string which they then transform into some other
@@ -59,11 +67,11 @@
5967
{
6068
const int offset = 10;
6169
char shortname[offset+1];
6270
shortname[offset] = '\0';
6371
memcpy( shortname, uuid, offset );
64
- return mprintf( "<tt><a href='%s/vinfo/%s'><strong>%s</strong>%s</a></tt>",
72
+ return mprintf( "<tt><a href='%s/vinfo/%s'><span style='font-size:1.5em'>%s</span>%s</a></tt>",
6573
g.zBaseURL, uuid, shortname, uuid+offset );
6674
}
6775
6876
/** Returns a hyperlink to the given tag. */
6977
static char * tagview_xf_link_to_tagid( char const * tagid )
@@ -186,24 +194,24 @@
186194
@ <h2>Tags matching [%s(likeclause)]:</h2>
187195
}
188196
else
189197
{
190198
limitstr = mprintf( "LIMIT %d", limit );
191
- @ <h2>%d(limit) most recent non-wiki tags:</h2>
199
+ @ <h2>%d(limit) most recent tags:</h2>
192200
}
193201
char * sql = mprintf(
194202
"SELECT t.tagid, t.tagname, DATETIME(tx.mtime), b.uuid "
195203
"FROM tag t, tagxref tx, blob b "
196204
"WHERE (t.tagid=tx.tagid) and (tx.srcid=b.rid) "
197205
"AND (tx.tagtype != 0) %s "
198
- "AND t.tagname NOT GLOB 'wiki-*' "
206
+ TAGVIEW_DEFAULT_FILTER
199207
"ORDER BY tx.mtime DESC %s",
200208
likeclause ? likeclause : " ",
201209
limitstr ? limitstr : " "
202210
);
203
- /* " AND t.tagname NOT GLOB 'wiki-*'" // Do we want this?? */
204
-
211
+ if( limitstr ) free(limitstr);
212
+ if( likeclause ) free(likeclause);
205213
char const * const colnames[] = {
206214
"Tag ID", "Name", "Timestamp", "Version"
207215
};
208216
tagview_strxform_f xf[] = {
209217
tagview_xf_link_to_tagid,
@@ -244,11 +252,11 @@
244252
@ <h2>Tag #%d(tagid):</h2>
245253
char * sql = mprintf(
246254
"SELECT DISTINCT (t.tagname), DATETIME(tx.mtime), b.uuid "
247255
"FROM tag t, tagxref tx, blob b "
248256
"WHERE (t.tagid=%d) AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
249
- "AND t.tagname NOT GLOB 'wiki-*' "
257
+ TAGVIEW_DEFAULT_FILTER
250258
"ORDER BY tx.mtime DESC",
251259
tagid);
252260
char const * const colnames[] = {
253261
"Tag Name", "Timestamp", "Version"
254262
};
@@ -269,11 +277,11 @@
269277
@ <h2>Tag '%s(tagname)':</h2>
270278
char * sql = mprintf(
271279
"SELECT DISTINCT t.tagid, DATETIME(tx.mtime), b.uuid "
272280
"FROM tag t, tagxref tx, blob b "
273281
"WHERE (t.tagname='%q') AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
274
- "AND t.tagname NOT GLOB 'wiki-*' "
282
+ TAGVIEW_DEFAULT_FILTER
275283
"ORDER BY tx.mtime DESC",
276284
tagname);
277285
char const * const colnames[] = {
278286
"Tag ID", "Timestamp", "Version"
279287
};
@@ -289,11 +297,10 @@
289297
290298
/*
291299
** WEBPAGE: /tagview
292300
*/
293301
void tagview_page(void){
294
-
295302
login_check_credentials();
296303
if( !g.okRdWiki ){
297304
login_needed();
298305
}
299306
style_header("Tags");
@@ -316,5 +323,7 @@
316323
{
317324
tagview_page_default();
318325
}
319326
style_footer();
320327
}
328
+
329
+#undef TAGVIEW_DEFAULT_FILTER
321330
--- src/tagview.c
+++ src/tagview.c
@@ -26,10 +26,18 @@
26 ** Implementation of the Tag View page
27 */
28 #include <assert.h>
29 #include "config.h"
30 #include "tagview.h"
 
 
 
 
 
 
 
 
31
32 /**
33 tagview_strxform_f is a typedef for funcs with the following policy:
34
35 They accept a const string which they then transform into some other
@@ -59,11 +67,11 @@
59 {
60 const int offset = 10;
61 char shortname[offset+1];
62 shortname[offset] = '\0';
63 memcpy( shortname, uuid, offset );
64 return mprintf( "<tt><a href='%s/vinfo/%s'><strong>%s</strong>%s</a></tt>",
65 g.zBaseURL, uuid, shortname, uuid+offset );
66 }
67
68 /** Returns a hyperlink to the given tag. */
69 static char * tagview_xf_link_to_tagid( char const * tagid )
@@ -186,24 +194,24 @@
186 @ <h2>Tags matching [%s(likeclause)]:</h2>
187 }
188 else
189 {
190 limitstr = mprintf( "LIMIT %d", limit );
191 @ <h2>%d(limit) most recent non-wiki tags:</h2>
192 }
193 char * sql = mprintf(
194 "SELECT t.tagid, t.tagname, DATETIME(tx.mtime), b.uuid "
195 "FROM tag t, tagxref tx, blob b "
196 "WHERE (t.tagid=tx.tagid) and (tx.srcid=b.rid) "
197 "AND (tx.tagtype != 0) %s "
198 "AND t.tagname NOT GLOB 'wiki-*' "
199 "ORDER BY tx.mtime DESC %s",
200 likeclause ? likeclause : " ",
201 limitstr ? limitstr : " "
202 );
203 /* " AND t.tagname NOT GLOB 'wiki-*'" // Do we want this?? */
204
205 char const * const colnames[] = {
206 "Tag ID", "Name", "Timestamp", "Version"
207 };
208 tagview_strxform_f xf[] = {
209 tagview_xf_link_to_tagid,
@@ -244,11 +252,11 @@
244 @ <h2>Tag #%d(tagid):</h2>
245 char * sql = mprintf(
246 "SELECT DISTINCT (t.tagname), DATETIME(tx.mtime), b.uuid "
247 "FROM tag t, tagxref tx, blob b "
248 "WHERE (t.tagid=%d) AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
249 "AND t.tagname NOT GLOB 'wiki-*' "
250 "ORDER BY tx.mtime DESC",
251 tagid);
252 char const * const colnames[] = {
253 "Tag Name", "Timestamp", "Version"
254 };
@@ -269,11 +277,11 @@
269 @ <h2>Tag '%s(tagname)':</h2>
270 char * sql = mprintf(
271 "SELECT DISTINCT t.tagid, DATETIME(tx.mtime), b.uuid "
272 "FROM tag t, tagxref tx, blob b "
273 "WHERE (t.tagname='%q') AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
274 "AND t.tagname NOT GLOB 'wiki-*' "
275 "ORDER BY tx.mtime DESC",
276 tagname);
277 char const * const colnames[] = {
278 "Tag ID", "Timestamp", "Version"
279 };
@@ -289,11 +297,10 @@
289
290 /*
291 ** WEBPAGE: /tagview
292 */
293 void tagview_page(void){
294
295 login_check_credentials();
296 if( !g.okRdWiki ){
297 login_needed();
298 }
299 style_header("Tags");
@@ -316,5 +323,7 @@
316 {
317 tagview_page_default();
318 }
319 style_footer();
320 }
 
 
321
--- src/tagview.c
+++ src/tagview.c
@@ -26,10 +26,18 @@
26 ** Implementation of the Tag View page
27 */
28 #include <assert.h>
29 #include "config.h"
30 #include "tagview.h"
31
32
33 #if 1
34 # define TAGVIEW_DEFAULT_FILTER "AND t.tagname NOT GLOB 'wiki-*' "
35 #else
36 # define TAGVIEW_DEFAULT_FILTER
37 #endif
38
39
40 /**
41 tagview_strxform_f is a typedef for funcs with the following policy:
42
43 They accept a const string which they then transform into some other
@@ -59,11 +67,11 @@
67 {
68 const int offset = 10;
69 char shortname[offset+1];
70 shortname[offset] = '\0';
71 memcpy( shortname, uuid, offset );
72 return mprintf( "<tt><a href='%s/vinfo/%s'><span style='font-size:1.5em'>%s</span>%s</a></tt>",
73 g.zBaseURL, uuid, shortname, uuid+offset );
74 }
75
76 /** Returns a hyperlink to the given tag. */
77 static char * tagview_xf_link_to_tagid( char const * tagid )
@@ -186,24 +194,24 @@
194 @ <h2>Tags matching [%s(likeclause)]:</h2>
195 }
196 else
197 {
198 limitstr = mprintf( "LIMIT %d", limit );
199 @ <h2>%d(limit) most recent tags:</h2>
200 }
201 char * sql = mprintf(
202 "SELECT t.tagid, t.tagname, DATETIME(tx.mtime), b.uuid "
203 "FROM tag t, tagxref tx, blob b "
204 "WHERE (t.tagid=tx.tagid) and (tx.srcid=b.rid) "
205 "AND (tx.tagtype != 0) %s "
206 TAGVIEW_DEFAULT_FILTER
207 "ORDER BY tx.mtime DESC %s",
208 likeclause ? likeclause : " ",
209 limitstr ? limitstr : " "
210 );
211 if( limitstr ) free(limitstr);
212 if( likeclause ) free(likeclause);
213 char const * const colnames[] = {
214 "Tag ID", "Name", "Timestamp", "Version"
215 };
216 tagview_strxform_f xf[] = {
217 tagview_xf_link_to_tagid,
@@ -244,11 +252,11 @@
252 @ <h2>Tag #%d(tagid):</h2>
253 char * sql = mprintf(
254 "SELECT DISTINCT (t.tagname), DATETIME(tx.mtime), b.uuid "
255 "FROM tag t, tagxref tx, blob b "
256 "WHERE (t.tagid=%d) AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
257 TAGVIEW_DEFAULT_FILTER
258 "ORDER BY tx.mtime DESC",
259 tagid);
260 char const * const colnames[] = {
261 "Tag Name", "Timestamp", "Version"
262 };
@@ -269,11 +277,11 @@
277 @ <h2>Tag '%s(tagname)':</h2>
278 char * sql = mprintf(
279 "SELECT DISTINCT t.tagid, DATETIME(tx.mtime), b.uuid "
280 "FROM tag t, tagxref tx, blob b "
281 "WHERE (t.tagname='%q') AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
282 TAGVIEW_DEFAULT_FILTER
283 "ORDER BY tx.mtime DESC",
284 tagname);
285 char const * const colnames[] = {
286 "Tag ID", "Timestamp", "Version"
287 };
@@ -289,11 +297,10 @@
297
298 /*
299 ** WEBPAGE: /tagview
300 */
301 void tagview_page(void){
 
302 login_check_credentials();
303 if( !g.okRdWiki ){
304 login_needed();
305 }
306 style_header("Tags");
@@ -316,5 +323,7 @@
323 {
324 tagview_page_default();
325 }
326 style_footer();
327 }
328
329 #undef TAGVIEW_DEFAULT_FILTER
330

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button