1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
/* -*- Mode: C++-C -*-
*
* Copyright 1994 Christopher B. Liebman
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name Christopher B. Liebman not
* be used in advertising or publicity pertaining to distribution of this
* software without specific, written prior permission.
*
* THIS SOFTWARE IS PROVIDED `AS-IS'. CHRISTOPHER B. LIEBMAN, DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
* LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL CHRISTOPHER
* B. LIEBMAN, BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING SPECIAL,
* INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, OR
* PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
* WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author : Chris Liebman
* Created On : Tue Jan 11 14:11:30 1994
* Last Modified By: Chris Liebman
* Last Modified On: Sun Mar 6 22:49:00 1994
* Update Count : 61
* Status : Released
*
* HISTORY
* 13-Feb-1994 Chris Liebman
* Last Modified: Mon Jan 31 22:39:36 1994 #39 (Chris Liebman)
* Added a label field to the bindings.
*
* 31-Jan-1994 Chris Liebman
* Last Modified: Mon Jan 31 22:34:33 1994 #38 (Chris Liebman)
* Moved SkipChars() and ParseToken() to string.c
*
* 18-Jan-1994 Chris Liebman
* Last Modified: Tue Jan 18 15:18:09 1994 #9 (Chris Liebman)
* Changed the binding parser to expect two and three tokens instead
* of one and two. Now expects <field name> <pattern> [<file>].
*
* 14-Jan-1994 Chris Liebman
* Last Modified: Tue Jan 11 14:16:14 1994 #1 (Chris Liebman)
* added flag to FaceBindingParse to allow the ignoreMessages
* bindings to be parsed also.
*
* PURPOSE
* Parse the binding lines from the resource file. Bindings contain a
* list of patterns then a file name for an image or sound if the pattern
* is matched.
*/
#ifndef lint
static char *RCSid = "$Id: face_binding.c,v 1.11 1994/03/07 20:24:10 liebman Exp $";
#endif
#include "faces.h"
#include <stdlib.h>
/*
* Parse the bindings.
*/
FaceBinding *
FaceBindingParse(str, has_value, has_label)
String str;
int has_value;
int has_label;
{
FaceBinding *fb;
FaceBinding *list = NULL;
String pair = NULL;
String name = NULL;
String pattern = NULL;
String value = NULL;
String label = NULL;
String annop;
int anno;
char* p;
if (str == NULL)
{
return(NULL);
}
while((pair = ParseToken(&str, "\n")) != NULL)
{
anno = 1;
pair = SkipChars(pair, "\t \n");
/*
* Field name to check.
*/
name = ParseToken(&pair, "\t \n");
/*
* Parse out the expression.
*/
pair = SkipChars(pair, "\t \n");
if (!has_value)
{
if (strlen(pair) == 0)
{
continue;
}
pattern = pair;
value = NULL;
}
else
{
if ((pattern = ParseToken(&pair, ":")) == NULL)
{
continue;
}
if (!has_label)
{
value = SkipChars(pair, "\t ");
}
else
{
value = ParseToken(&pair, "\t \n");
label = SkipChars(pair, "\t ");
/*
* If there is an annotation number then grab it, otherwise it
* defaults to 1.
*/
annop = rindex(label, ':');
if (annop != NULL)
{
*annop++ = '\0';
anno = atoi(annop);
}
if (anno < 1 || anno > TheFacesResources.annotation_count)
{
anno = 1;
}
}
}
fb = XtNew(FaceBinding);
/*
* If the field name starts with a '|' then we should be case
* insensitive.
*/
if (*name == '|')
{
++name;
fb->casesensitive = 0;
for(p = pattern; *p != '\0'; ++p)
{
if (isupper(*p))
{
*p = tolower(*p);
}
}
}
else
{
fb->casesensitive = 1;
}
/*
* If the field name is "*" then all fields are searched. If the
* field name has a leading
*/
if (strcmp(name, "*") == 0)
{
fb->name = NULL;
}
else
{
fb->name = XtNewString(name);
}
/*
* Compile the regular expression.
*/
fb->patsrc = XtNewString(pattern);
fb->pattern = regcomp(pattern);
/*
* If we don't need a value then net the file to NULL.
*/
if (!has_value)
{
fb->file = NULL;
}
else
{
fb->file = XtNewString(value);
fb->label = XtNewString(label);
fb->anno = anno;
}
/*
* place binding on list.
*/
fb->next = list;
list = fb;
}
return(list);
}
/*
* Check a binding list agains a header list for a match.
*/
FaceBinding*
FaceBindingCheck(headers, bindings)
MailHeader* headers;
FaceBinding* bindings;
{
MailHeader* header;
FaceBinding* binding;
char* value;
char* p;
int result;
for (binding = bindings; binding != NULL; binding = binding->next)
{
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: pattern: <%s>\n", binding->patsrc);
#endif
/*
* See if we only need to check one header for this binding.
*/
if (binding->name != NULL)
{
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: check <%s> header.\n",
binding->name);
#endif
if ((header = MailHeaderFind(binding->name, headers)) != NULL)
{
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: <%s> value: <%s>.\n",
binding->name, header->value);
#endif
/*
* if we are not case sensitive then copy the header value
* and make it lower case.
*/
if (!binding->casesensitive)
{
value = XtNewString(header->value);
for(p = value; *p != '\0'; ++p)
{
if (isupper(*p))
{
*p = tolower(*p);
}
}
#ifdef BINDING_DEBUG
fprintf(stderr,
"FaceBindingCheck: lowered value: <%s>\n", value);
#endif
}
else
{
value = header->value;
}
result = regexec(binding->pattern, value);
if (!binding->casesensitive)
{
XtFree(value);
value = NULL;
}
if (result)
{
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: matched!\n");
#endif
return binding;
}
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: no match.\n");
#endif
}
}
else
{
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: check all headers.\n");
#endif
/*
* Search all headers.
*/
for (header = headers; header != NULL; header = header->next)
{
#ifdef BINDING_DEBUG
fprintf(stderr,
"FaceBindingCheck: checking: <%s> value: <%s>.\n",
header->name, header->value);
#endif
/*
* if we are not case sensitive then copy the header value
* and make it lower case.
*/
if (!binding->casesensitive)
{
value = XtNewString(header->value);
for(p = value; *p != '\0'; ++p)
{
if (isupper(*p))
{
*p = tolower(*p);
}
}
#ifdef BINDING_DEBUG
fprintf(stderr,
"FaceBindingCheck: lowered value: <%s>\n", value);
#endif
}
else
{
value = header->value;
}
result = regexec(binding->pattern, value);
if (!binding->casesensitive)
{
XtFree(value);
value = NULL;
}
if (result)
{
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: matched!\n");
#endif
return binding;
}
#ifdef BINDING_DEBUG
fprintf(stderr, "FaceBindingCheck: no match.\n");
#endif
}
}
}
return NULL;
}
|