summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-04-03 11:55:28 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2010-04-03 11:55:28 +0000
commit49810d8191e9a806ceb8a92c68369d8dac261f0d (patch)
treed57d82c882eb92f0d0bcf409b43a54beadc91e04
parent6835a312b7df68c23fec9930b8e0aec94b537e5f (diff)
downloadnetsurf-49810d8191e9a806ceb8a92c68369d8dac261f0d.tar.gz
netsurf-49810d8191e9a806ceb8a92c68369d8dac261f0d.tar.bz2
Use mutator to modify content's title field.
svn path=/trunk/netsurf/; revision=10231
-rw-r--r--content/content.c14
-rw-r--r--content/content_protected.h1
-rw-r--r--image/bmp.c11
-rw-r--r--image/gif.c12
-rw-r--r--image/ico.c11
-rw-r--r--image/jpeg.c11
-rw-r--r--image/mng.c21
-rw-r--r--image/png.c14
-rw-r--r--render/html.c16
9 files changed, 53 insertions, 58 deletions
diff --git a/content/content.c b/content/content.c
index 548e08418..782e1a370 100644
--- a/content/content.c
+++ b/content/content.c
@@ -1038,6 +1038,20 @@ void content_add_error(struct content *c, const char *token,
{
}
+bool content__set_title(struct content *c, const char *title)
+{
+ char *new_title = talloc_strdup(c, title);
+ if (new_title == NULL)
+ return false;
+
+ if (c->title != NULL)
+ talloc_free(c->title);
+
+ c->title = new_title;
+
+ return true;
+}
+
/**
* Retrieve type of content
*
diff --git a/content/content_protected.h b/content/content_protected.h
index 261ee7bcb..013a9645f 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -204,6 +204,7 @@ void content_add_error(struct content *c, const char *token,
void content__reformat(struct content *c, int width, int height);
+bool content__set_title(struct content *c, const char *title);
content_type content__get_type(struct content *c);
const char *content__get_url(struct content *c);
diff --git a/image/bmp.c b/image/bmp.c
index d4584f85d..23ea740e9 100644
--- a/image/bmp.c
+++ b/image/bmp.c
@@ -72,6 +72,7 @@ bool nsbmp_convert(struct content *c)
uint32_t swidth;
const char *data;
unsigned long size;
+ char title[100];
/* set the bmp data */
bmp = c->data.bmp.bmp;
@@ -98,12 +99,11 @@ bool nsbmp_convert(struct content *c)
c->width = bmp->width;
c->height = bmp->height;
LOG(("BMP width %u height %u", c->width, c->height));
- c->title = malloc(100);
- if (c->title)
- snprintf(c->title, 100, messages_get("BMPTitle"), c->width,
- c->height, size);
+ snprintf(title, sizeof(title), messages_get("BMPTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
swidth = bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bitmap) * bmp->width;
- c->size += (swidth * bmp->height) + 16 + 44 + 100;
+ c->size += (swidth * bmp->height) + 16 + 44;
/* exit as a success */
c->bitmap = bmp->bitmap;
@@ -159,7 +159,6 @@ void nsbmp_destroy(struct content *c)
{
bmp_finalise(c->data.bmp.bmp);
free(c->data.bmp.bmp);
- free(c->title);
}
diff --git a/image/gif.c b/image/gif.c
index 8c5025af6..01ea57420 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -86,6 +86,7 @@ bool nsgif_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
/* Get the animation */
gif = c->data.gif.gif;
@@ -123,12 +124,10 @@ bool nsgif_convert(struct content *c)
/* Store our content width and description */
c->width = gif->width;
c->height = gif->height;
- c->title = malloc(100);
- if (c->title) {
- snprintf(c->title, 100, messages_get("GIFTitle"), c->width,
- c->height, size);
- }
- c->size += (gif->width * gif->height * 4) + 16 + 44 + 100;
+ snprintf(title, sizeof(title), messages_get("GIFTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
+ c->size += (gif->width * gif->height * 4) + 16 + 44;
/* Schedule the animation if we have one */
c->data.gif.current_frame = 0;
@@ -195,7 +194,6 @@ void nsgif_destroy(struct content *c)
schedule_remove(nsgif_animate, c);
gif_finalise(c->data.gif.gif);
free(c->data.gif.gif);
- free(c->title);
}
diff --git a/image/ico.c b/image/ico.c
index 233018cea..3335a6a58 100644
--- a/image/ico.c
+++ b/image/ico.c
@@ -60,6 +60,7 @@ bool nsico_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
/* set the ico data */
ico = c->data.ico.ico;
@@ -86,11 +87,10 @@ bool nsico_convert(struct content *c)
/* Store our content width and description */
c->width = ico->width;
c->height = ico->height;
- c->title = malloc(100);
- if (c->title)
- snprintf(c->title, 100, messages_get("ICOTitle"), c->width,
- c->height, size);
- c->size += (ico->width * ico->height * 4) + 16 + 44 + 100;
+ snprintf(title, sizeof(title), messages_get("ICOTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
+ c->size += (ico->width * ico->height * 4) + 16 + 44;
/* exit as a success */
bmp = ico_find(c->data.ico.ico, 255, 255);
@@ -167,7 +167,6 @@ void nsico_destroy(struct content *c)
{
ico_finalise(c->data.ico.ico);
free(c->data.ico.ico);
- free(c->title);
}
#endif
diff --git a/image/jpeg.c b/image/jpeg.c
index dd86d6ac9..af28fe6fa 100644
--- a/image/jpeg.c
+++ b/image/jpeg.c
@@ -91,6 +91,7 @@ bool nsjpeg_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
data = content__get_source_data(c, &size);
@@ -162,11 +163,10 @@ bool nsjpeg_convert(struct content *c)
c->width = width;
c->height = height;
c->bitmap = bitmap;
- c->title = malloc(100);
- if (c->title)
- snprintf(c->title, 100, messages_get("JPEGTitle"),
- width, height, size);
- c->size += height * rowstride + 100;
+ snprintf(title, sizeof(title), messages_get("JPEGTitle"),
+ width, height, size);
+ content__set_title(c, title);
+ c->size += height * rowstride;
c->status = CONTENT_STATUS_DONE;
/* Done: update status bar */
content_set_status(c, "");
@@ -284,7 +284,6 @@ void nsjpeg_destroy(struct content *c)
{
if (c->bitmap)
bitmap_destroy(c->bitmap);
- free(c->title);
}
#endif /* WITH_JPEG */
diff --git a/image/mng.c b/image/mng.c
index 2c9d6fd8a..012301d98 100644
--- a/image/mng.c
+++ b/image/mng.c
@@ -302,10 +302,9 @@ bool nsmng_process_data(struct content *c, char *data, unsigned int size)
bool nsmng_convert(struct content *c)
{
mng_retcode status;
-
- union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
assert(c != NULL);
@@ -319,25 +318,19 @@ bool nsmng_convert(struct content *c)
/* Set the title
*/
- c->title = malloc(100);
- if (!c->title) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
if (c->type == CONTENT_MNG) {
- snprintf(c->title, 100, messages_get("MNGTitle"),
+ snprintf(title, sizeof(title), messages_get("MNGTitle"),
c->width, c->height, size);
} else if (c->type == CONTENT_PNG) {
- snprintf(c->title, 100, messages_get("PNGTitle"),
+ snprintf(title, sizeof(title), messages_get("PNGTitle"),
c->width, c->height, size);
} else {
- snprintf(c->title, 100, messages_get("JNGTitle"),
+ snprintf(title, sizeof(title), messages_get("JNGTitle"),
c->width, c->height, size);
}
+ content__set_title(c, title);
- c->size += c->width * c->height * 4 + 100;
+ c->size += c->width * c->height * 4;
c->status = CONTENT_STATUS_DONE;
/* Done: update status bar */
content_set_status(c, "");
@@ -528,8 +521,6 @@ void nsmng_destroy(struct content *c)
if (c->bitmap)
bitmap_destroy(c->bitmap);
-
- free(c->title);
}
diff --git a/image/png.c b/image/png.c
index 3e9b21a9e..0cef6ec6a 100644
--- a/image/png.c
+++ b/image/png.c
@@ -51,9 +51,6 @@
#define png_set_expand_gray_1_2_4_to_8(png) png_set_gray_1_2_4_to_8(png)
#endif
-/* I hate doing this, but without g_strdup_printf or similar, we're a tad stuck. */
-#define NSPNG_TITLE_LEN (100)
-
/* libpng uses names starting png_, so use nspng_ here to avoid clashes */
static void info_callback(png_structp png, png_infop info);
@@ -265,6 +262,7 @@ bool nspng_convert(struct content *c)
{
const char *data;
unsigned long size;
+ char title[100];
assert(c->data.png.png != NULL);
assert(c->data.png.info != NULL);
@@ -273,14 +271,11 @@ bool nspng_convert(struct content *c)
png_destroy_read_struct(&c->data.png.png, &c->data.png.info, 0);
- c->title = malloc(NSPNG_TITLE_LEN);
-
- if (c->title != NULL) {
- snprintf(c->title, NSPNG_TITLE_LEN, messages_get("PNGTitle"),
+ snprintf(title, sizeof(title), messages_get("PNGTitle"),
c->width, c->height, size);
- }
+ content__set_title(c, title);
- c->size += (c->width * c->height * 4) + NSPNG_TITLE_LEN;
+ c->size += (c->width * c->height * 4);
assert(c->data.png.bitmap != NULL);
@@ -296,7 +291,6 @@ bool nspng_convert(struct content *c)
void nspng_destroy(struct content *c)
{
- free(c->title);
if (c->data.png.bitmap != NULL) {
bitmap_destroy(c->data.png.bitmap);
}
diff --git a/render/html.c b/render/html.c
index 3b3abb782..b74c24225 100644
--- a/render/html.c
+++ b/render/html.c
@@ -510,14 +510,12 @@ bool html_head(struct content *c, xmlNode *head)
xmlNode *node;
xmlChar *s;
- c->title = 0;
-
for (node = head->children; node != 0; node = node->next) {
if (node->type != XML_ELEMENT_NODE)
continue;
LOG(("Node: %s", node->name));
- if (!c->title && strcmp((const char *) node->name,
+ if (c->title == NULL && strcmp((const char *) node->name,
"title") == 0) {
xmlChar *title = xmlNodeGetContent(node);
char *title2;
@@ -527,10 +525,12 @@ bool html_head(struct content *c, xmlNode *head)
xmlFree(title);
if (!title2)
return false;
- c->title = talloc_strdup(c, title2);
- free(title2);
- if (!c->title)
+ if (content__set_title(c, title2) == false) {
+ free(title2);
return false;
+ }
+
+ free(title2);
} else if (strcmp((const char *) node->name, "base") == 0) {
char *href = (char *) xmlGetProp(node,
@@ -1747,8 +1747,8 @@ void html_destroy(struct content *c)
imagemap_destroy(c);
if (c->bitmap) {
- bitmap_destroy(c->bitmap);
- c->bitmap = NULL;
+ bitmap_destroy(c->bitmap);
+ c->bitmap = NULL;
}
if (c->data.html.parser_binding)