~ubuntu-branches/ubuntu/precise/xbuffy/precise-security

« back to all changes in this revision

Viewing changes to header_cmp.c

  • Committer: Bazaar Package Importer
  • Author(s): Joel Rosdahl
  • Date: 2001-10-02 08:21:23 UTC
  • Revision ID: james.westby@ubuntu.com-20011002082123-6nt02amum9m80oey
Tags: upstream-3.3.bl.3
ImportĀ upstreamĀ versionĀ 3.3.bl.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* this is from elm 2.4 so: */
 
2
 
 
3
/*******************************************************************************
 
4
*                      Copyright (c) 1988-1992 USENET Community Trust
 
5
*                      Copyright (c) 1986,1987 Dave Taylor
 
6
********************************************************************************/
 
7
 
 
8
 
 
9
/**
 
10
        compare a header, ignoring case and allowing linear white space
 
11
        around the :.  Header must be anchored to the start of the line.
 
12
 
 
13
        returns NULL if no match, or first character after trailing linear
 
14
        white space of the :.
 
15
 
 
16
**/
 
17
#include <stdio.h>
 
18
#include <ctype.h>
 
19
#include "xbuffy.h"
 
20
 
 
21
 
 
22
#define whitespace(c)    (c == ' ' || c == '\t')
 
23
 
 
24
#ifdef BSD
 
25
#undef tolower
 
26
#endif
 
27
 
 
28
 
 
29
char *header_cmp(header, prefix, suffix)
 
30
char *header;
 
31
char *prefix;
 
32
char *suffix;
 
33
{
 
34
        int len;
 
35
 
 
36
        len = NEWstrlen(prefix);
 
37
        if (strincmp(header, prefix, len))
 
38
                return (NULL);
 
39
 
 
40
        /* skip over while space if any */
 
41
        header += len;
 
42
 
 
43
        if (*header != ':')                     /* headers must end in a : */
 
44
                return (NULL);
 
45
 
 
46
        /* skip over while space if any */
 
47
        header++;
 
48
 
 
49
        while (*header)
 
50
        {
 
51
                if (!whitespace(*header))
 
52
                        break;
 
53
                header++;
 
54
        }
 
55
 
 
56
        if (suffix != NULL)
 
57
        {
 
58
                len = NEWstrlen(suffix);
 
59
                if (len > 0)
 
60
                        if (strincmp(header, suffix, len))
 
61
                                return (NULL);
 
62
        }
 
63
 
 
64
        return (header);
 
65
}