Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2005 Pekka Riikonen
+ Copyright (C) 2005 - 2006 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
line = strdup(value);
if (strrchr(line, '"')) {
*strrchr(line, '"') = '\0';
- snprintf(b, sizeof(b) - 1, "--%s", line + 1);
+ silc_silc_snprintf(b, sizeof(b) - 1, "--%s", line + 1);
mime->boundary = strdup(line + 1);
} else {
- snprintf(b, sizeof(b) - 1, "--%s", line);
+ silc_silc_snprintf(b, sizeof(b) - 1, "--%s", line);
mime->boundary = strdup(line);
}
silc_free(line);
}
}
} else {
- /* Get data area */
- if (i >= data_len)
+ /* Get data area. If we are at the end and we have fields present
+ there is no data area present, but, if fields are not present we
+ only have data area. */
+ if (i >= data_len && !silc_hash_table_count(mime->fields))
i = 0;
SILC_LOG_DEBUG(("Data len %d", data_len - i));
- silc_mime_add_data(mime, tmp + i, data_len - i);
+ if (data_len - i)
+ silc_mime_add_data(mime, tmp + i, data_len - i);
}
return mime;
while (silc_hash_table_get(&htl, (void **)&field, (void **)&value)) {
memset(tmp, 0, sizeof(tmp));
SILC_LOG_DEBUG(("Header %s: %s", field, value));
- snprintf(tmp, sizeof(tmp) - 1, "%s: %s\r\n", field, value);
+ silc_silc_snprintf(tmp, sizeof(tmp) - 1, "%s: %s\r\n", field, value);
silc_buffer_strformat(&buf, tmp, SILC_STRFMT_END);
i++;
}
/* If fields are not present, add extra CRLF */
if (!silc_hash_table_count(part->fields))
- snprintf(tmp2, sizeof(tmp2) - 1, "\r\n");
- snprintf(tmp, sizeof(tmp) - 1, "%s--%s\r\n%s",
+ silc_silc_snprintf(tmp2, sizeof(tmp2) - 1, "\r\n");
+ silc_silc_snprintf(tmp, sizeof(tmp) - 1, "%s--%s\r\n%s",
i != 0 ? "\r\n" : "", mime->boundary, tmp2);
i = 1;
}
memset(tmp, 0, sizeof(tmp));
- snprintf(tmp, sizeof(tmp) - 1, "\r\n--%s--\r\n", mime->boundary);
+ silc_silc_snprintf(tmp, sizeof(tmp) - 1, "\r\n--%s--\r\n", mime->boundary);
buffer = silc_buffer_realloc(buffer, silc_buffer_truelen(buffer) +
strlen(tmp));
if (!buffer)
memset(type, 0, sizeof(type));
gethostname(type, sizeof(type) - 1);
srand((time(NULL) + buf_len) ^ rand());
- snprintf(id, sizeof(id) - 1, "%X%X%X%s",
+ silc_silc_snprintf(id, sizeof(id) - 1, "%X%X%X%s",
(unsigned int)rand(), (unsigned int)time(NULL),
(unsigned int)buf_len, type);
silc_mime_add_field(partial, "MIME-Version", "1.0");
memset(type, 0, sizeof(type));
- snprintf(type, sizeof(type) - 1,
+ silc_silc_snprintf(type, sizeof(type) - 1,
"message/partial; id=\"%s\"; number=1", id);
silc_mime_add_field(partial, "Content-Type", type);
silc_mime_add_data(partial, buf, max_size);
silc_mime_add_field(partial, "MIME-Version", "1.0");
if (len > max_size) {
- snprintf(type, sizeof(type) - 1,
+ silc_silc_snprintf(type, sizeof(type) - 1,
"message/partial; id=\"%s\"; number=%d",
id, num++);
silc_mime_add_data(partial, buf + off, max_size);
off += max_size;
len -= max_size;
} else {
- snprintf(type, sizeof(type) - 1,
+ silc_silc_snprintf(type, sizeof(type) - 1,
"message/partial; id=\"%s\"; number=%d; total=%d",
id, num, num);
silc_mime_add_data(partial, buf + off, len);
return mime->data;
}
+/* Steal data */
+
+unsigned char *silc_mime_steal_data(SilcMime mime, SilcUInt32 *data_len)
+{
+ unsigned char *data;
+
+ if (!mime)
+ return NULL;
+
+ if (data_len)
+ *data_len = mime->data_len;
+
+ data = mime->data;
+
+ mime->data = NULL;
+ mime->data_len = 0;
+
+ return data;
+}
+
/* Returns TRUE if partial message */
SilcBool silc_mime_is_partial(SilcMime mime)
return;
memset(tmp, 0, sizeof(tmp));
- snprintf(tmp, sizeof(tmp) - 1, "multipart/%s; boundary=%s", type, boundary);
+ silc_silc_snprintf(tmp, sizeof(tmp) - 1, "multipart/%s; boundary=%s", type, boundary);
silc_mime_add_field(mime, "Content-Type", tmp);
silc_free(mime->boundary);
mime->boundary = strdup(boundary);