masqmail-0.2

annotate src/libident/support.c @ 179:ec3fe72a3e99

Fixed an important bug with folded headers! g_strconcat() returns a *copy* of the string, but hdr->value still pointed to the old header (which probably was a memory leak, too). If the folded part had been quite small it was likely that the new string was at the same position as the old one, thus making everything go well. But if pretty long headers were folded several times it was likely that the new string was allocated somewhere else in memory, thus breaking things. In result mails to lots of recipients (folded header) were frequently only sent to the ones in the first line. Sorry for the inconvenience.
author meillo@marmaro.de
date Fri, 03 Jun 2011 09:52:17 +0200
parents 08114f7dcc23
children
rev   line source
meillo@0 1 /*
meillo@0 2 ** support.c
meillo@0 3 **
meillo@0 4 ** Author: Pr Emanuelsson <pell@lysator.liu.se>
meillo@0 5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
meillo@0 6 */
meillo@0 7 #include <stdio.h>
meillo@0 8 #include <ctype.h>
meillo@0 9
meillo@0 10 #ifdef HAVE_ANSIHEADERS
meillo@0 11 # include <stdlib.h>
meillo@0 12 # include <string.h>
meillo@0 13 #else
meillo@0 14 # define strchr(str, c) index(str, c)
meillo@0 15 #endif
meillo@0 16
meillo@0 17 #define IN_LIBIDENT_SRC
meillo@0 18 #include "ident.h"
meillo@0 19
meillo@0 20
meillo@10 21 char*
meillo@10 22 id_strdup __P1(char *, str)
meillo@0 23 {
meillo@10 24 char *cp;
meillo@0 25
meillo@10 26 cp = (char *) malloc(strlen(str) + 1);
meillo@10 27 if (cp == NULL) {
meillo@0 28 #ifdef DEBUG
meillo@10 29 perror("libident: malloc");
meillo@0 30 #endif
meillo@10 31 return NULL;
meillo@10 32 }
meillo@0 33
meillo@10 34 strcpy(cp, str);
meillo@0 35
meillo@10 36 return cp;
meillo@0 37 }
meillo@0 38
meillo@0 39
meillo@10 40 char*
meillo@10 41 id_strtok __P3(char *, cp, char *, cs, char *, dc)
meillo@0 42 {
meillo@10 43 static char *bp = 0;
meillo@10 44
meillo@10 45 if (cp)
meillo@10 46 bp = cp;
meillo@10 47
meillo@10 48 /*
meillo@10 49 ** No delimitor cs - return whole buffer and point at end
meillo@10 50 */
meillo@10 51 if (!cs) {
meillo@10 52 while (*bp)
meillo@10 53 bp++;
meillo@10 54 return cs;
meillo@10 55 }
meillo@10 56
meillo@10 57 /*
meillo@10 58 ** Skip leading spaces
meillo@10 59 */
meillo@10 60 while (isspace(*bp))
meillo@10 61 bp++;
meillo@10 62
meillo@10 63 /*
meillo@10 64 ** No token found?
meillo@10 65 */
meillo@10 66 if (!*bp)
meillo@10 67 return 0;
meillo@10 68
meillo@10 69 cp = bp;
meillo@10 70 while (*bp && !strchr(cs, *bp))
meillo@10 71 bp++;
meillo@10 72
meillo@10 73 /*
meillo@10 74 ** Remove trailing spaces
meillo@10 75 */
meillo@10 76 *dc = *bp;
meillo@10 77 for (dc = bp - 1; dc > cp && isspace(*dc); dc--);
meillo@10 78 *++dc = '\0';
meillo@10 79
meillo@0 80 bp++;
meillo@10 81
meillo@10 82 return cp;
meillo@0 83 }