~ubuntu-branches/ubuntu/trusty/opendkim/trusty

« back to all changes in this revision

Viewing changes to reputation/repute.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2012-06-08 14:38:25 UTC
  • mfrom: (1.2.14) (3.2.7 sid)
  • Revision ID: package-import@ubuntu.com-20120608143825-ehz9xxdvii6podhh
Tags: 2.6.0-1
* New upstream release (now DFSG free so tarball repacking no longer
  required)
  - Rename libopendkim6 to libopendkim7 to match new soname
    - Update package and dependencies in debian/control
    - Rename .install and .doc files
  - Drop --enable-xtags from configure in debian/rules since it is now on by
    default
  - Update debian/copyright
  - Remove dversionmangle from debian/watch
  - Update README.Debian to reflect documentation no longer being stripped
* Correct copyright/license information in libar/ar-strl.h based on feedback
  from upstream (correction already implemented upstream for the next
  relese)
* Set --sysconfdir=/etc in configure so that generated man pages refer to
  the correct configuration file locations

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
static char repute_c_id[] = "$Id$";
7
7
#endif /* ! lint */
8
8
 
 
9
#include "build-config.h"
 
10
 
9
11
/* system includes */
10
12
#include <sys/param.h>
11
13
#include <sys/types.h>
17
19
#include <stdio.h>
18
20
#include <string.h>
19
21
 
20
 
/* libxml includes */
21
 
#include <libxml/parser.h>
22
 
#include <libxml/tree.h>
 
22
#ifdef USE_XML2
 
23
/* libxml2 includes */
 
24
# include <libxml/parser.h>
 
25
# include <libxml/tree.h>
 
26
#endif /* USE_XML2 */
 
27
 
 
28
#ifdef USE_JANSSON
 
29
/* libjansson includes */
 
30
# include <jansson.h>
 
31
#endif /* USE_JANSSON */
23
32
 
24
33
/* libcurl includes */
25
34
#include <curl/curl.h>
78
87
        { REPUTE_XML_CODE_UNKNOWN,      NULL }
79
88
};
80
89
 
 
90
#ifdef USE_XML2
81
91
/*
82
92
**  REPUTE_LIBXML2_ERRHANDLER -- error handler function provided to libxml2
83
93
**
101
111
{
102
112
        return;
103
113
}
 
114
#endif /* USE_XML2 */
104
115
 
105
116
/*
106
117
**  REPUTE_CURL_WRITEDATA -- callback for libcurl to deliver data
219
230
        time_t whentmp;
220
231
        char *p;
221
232
        const char *start;
 
233
#ifdef USE_XML2
222
234
        xmlDocPtr doc = NULL;
223
235
        xmlNode *node = NULL;
224
236
        xmlNode *reputon = NULL;
 
237
#endif /* USE_XML2 */
 
238
#ifdef USE_JANSSON
 
239
        json_t *root = NULL;
 
240
        json_t *exts = NULL;
 
241
        json_t *obj = NULL;
 
242
        json_error_t error;
 
243
#endif /* USE_JANSSON */
225
244
 
226
245
        assert(buf != NULL);
227
246
        assert(rep != NULL);
228
247
 
 
248
#ifdef USE_XML2
229
249
        xmlSetGenericErrorFunc(NULL, repute_libxml2_errhandler);
 
250
#endif /* USE_XML2 */
230
251
 
231
252
        /* skip any header found */
232
253
        /* XXX -- this should verify a desirable Content-Type */
249
270
                }
250
271
        }
251
272
 
 
273
#ifdef USE_JANSSON
 
274
        root = json_loads(buf, 0, &error);
 
275
        if (root == NULL)
 
276
                return REPUTE_STAT_PARSE;
 
277
 
 
278
        exts = json_object_get(root, REPUTE_XML_EXTENSION);
 
279
        if (exts != NULL && !json_is_object(exts))
 
280
        {
 
281
                json_decref(root);
 
282
                return REPUTE_STAT_PARSE;
 
283
        }
 
284
 
 
285
        obj = json_object_get(root, REPUTE_XML_ASSERTION);
 
286
        if (obj != NULL && json_is_string(obj) &&
 
287
            strcasecmp(json_string_value(obj), REPUTE_ASSERT_SPAM) == 0)
 
288
                found_spam = TRUE;
 
289
 
 
290
        obj = json_object_get(exts, REPUTE_EXT_ID);
 
291
        if (obj != NULL && json_is_string(obj) &&
 
292
            strcasecmp(json_string_value(obj), REPUTE_EXT_ID_DKIM) == 0)
 
293
                found_dkim = TRUE;
 
294
 
 
295
        obj = json_object_get(exts, REPUTE_EXT_RATE);
 
296
        if (obj != NULL && json_is_number(obj))
 
297
                limittmp = (unsigned long) json_integer_value(obj);
 
298
 
 
299
        obj = json_object_get(root, REPUTE_XML_RATER_AUTH);
 
300
        if (obj != NULL && json_is_number(obj))
 
301
                conftmp = (float) json_real_value(obj);
 
302
 
 
303
        obj = json_object_get(root, REPUTE_XML_RATING);
 
304
        if (obj != NULL && json_is_number(obj))
 
305
                reptmp = (float) json_real_value(obj);
 
306
 
 
307
        obj = json_object_get(root, REPUTE_XML_SAMPLE_SIZE);
 
308
        if (obj != NULL && json_is_number(obj))
 
309
                sampletmp = (unsigned long) json_integer_value(obj);
 
310
 
 
311
        obj = json_object_get(root, REPUTE_XML_UPDATED);
 
312
        if (obj != NULL && json_is_number(obj))
 
313
                whentmp = (time_t) json_integer_value(obj);
 
314
 
 
315
        if (found_dkim && found_spam)
 
316
        {
 
317
                *rep = reptmp;
 
318
                if (conf != NULL)
 
319
                        *conf = conftmp;
 
320
                if (sample != NULL)
 
321
                        *sample = sampletmp;
 
322
                if (when != NULL)
 
323
                        *when = whentmp;
 
324
                if (limit != NULL)
 
325
                        *limit = limittmp;
 
326
        }
 
327
#endif /* USE_JANSSON */
 
328
 
 
329
#ifdef USE_XML2
252
330
        doc = xmlParseMemory(buf, buflen);
253
331
        if (doc == NULL)
254
332
                return REPUTE_STAT_PARSE;
328
406
 
329
407
                          case REPUTE_XML_CODE_EXTENSION:
330
408
                                if (strcasecmp(reputon->children->content,
331
 
                                               REPUTE_EXT_ID_DKIM) == 0)
 
409
                                               REPUTE_EXT_ID_BOTH) == 0)
332
410
                                {
333
411
                                        found_dkim = TRUE;
334
412
                                }
335
413
                                else if (strncasecmp(reputon->children->content,
336
 
                                                     REPUTE_EXT_RATE,
337
 
                                                     sizeof REPUTE_EXT_RATE - 1) == 0)
 
414
                                                     REPUTE_EXT_RATE_COLON,
 
415
                                                     sizeof REPUTE_EXT_RATE_COLON - 1) == 0)
338
416
                                {
339
417
                                        errno = 0;
340
 
                                        limittmp = strtoul(reputon->children->content + sizeof REPUTE_EXT_RATE,
 
418
                                        limittmp = strtoul(reputon->children->content + sizeof REPUTE_EXT_RATE_COLON,
341
419
                                                           &p, 10);
342
420
                                        if (errno != 0)
343
421
                                                continue;
397
475
        }
398
476
 
399
477
        xmlFreeDoc(doc);
 
478
#endif /* USE_XML2 */
 
479
 
400
480
        return REPUTE_STAT_OK;
401
481
}
402
482
 
531
611
 
532
612
        rio->repute_errcode = 0;
533
613
        rio->repute_rcode = 0;
 
614
        memset(rio->repute_buf, '\0', rio->repute_alloc);
 
615
 
534
616
        cstatus = curl_easy_perform(rio->repute_curl);
535
617
        if (cstatus != CURLE_OK)
536
618
        {
681
763
void
682
764
repute_init(void)
683
765
{
 
766
#ifdef USE_XML2
684
767
        xmlInitParser();
 
768
#endif /* USE_XML2 */
685
769
 
686
770
        curl_global_init(CURL_GLOBAL_ALL);
687
771
}
864
948
 
865
949
        if (ut_keyvalue(ut, UT_KEYTYPE_STRING,
866
950
                        "subject", (void *) domain) != 0 ||
 
951
#ifdef USE_JANSSON
 
952
            ut_keyvalue(ut, UT_KEYTYPE_STRING, "format", "json") != 0 ||
 
953
#endif /* USE_JANSSON */
 
954
#ifdef USE_XML2
 
955
            ut_keyvalue(ut, UT_KEYTYPE_STRING, "format", "xml") != 0 ||
 
956
#endif /* USE_XML2 */
867
957
            ut_keyvalue(ut, UT_KEYTYPE_STRING,
868
958
                        "scheme", REPUTE_URI_SCHEME) != 0 ||
869
959
            ut_keyvalue(ut, UT_KEYTYPE_STRING,