Back to index

opendkim  2.6.2
dr-test00.c
Go to the documentation of this file.
00001 /*
00002 **  Copyright (c) 2011, The OpenDKIM Project.  All rights reserved.
00003 */
00004 
00005 #ifndef lint
00006 static char dr_test00_c_id[] = "@(#)$Id: t-test124.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $";
00007 #endif /* !lint */
00008 
00009 #include "build-config.h"
00010 
00011 /* system includes */
00012 #include <sys/types.h>
00013 #include <sys/select.h>
00014 #include <assert.h>
00015 #include <string.h>
00016 #include <stdio.h>
00017 
00018 #ifdef USE_GNUTLS
00019 # include <gnutls/gnutls.h>
00020 #endif /* USE_GNUTLS */
00021 
00022 /* libdkimrep includes */
00023 #include "dkim-rep.h"
00024 
00025 #define       TESTDOMAIN    "example.com"
00026 #define       TESTUSER1     "good"
00027 #define       TESTUSER2     "bad"
00028 
00029 /*
00030 **  MAIN -- program mainline
00031 **
00032 **  Parameters:
00033 **     The usual.
00034 **
00035 **  Return value:
00036 **     Exit status.
00037 */
00038 
00039 int
00040 main(int argc, char **argv)
00041 {
00042        int rep;
00043        DKIM_REP dr;
00044        void *qh = NULL;
00045        DKIM_REP_STAT status;
00046        struct timeval timeout;
00047 
00048 #ifdef USE_GNUTLS
00049        (void) gnutls_global_init();
00050 #endif /* USE_GNUTLS */
00051 
00052        printf("*** basic reputation checks\n");
00053 
00054        dr = dkim_rep_init(NULL, NULL, NULL);
00055        assert(dr != NULL);
00056 
00057        status = dkim_rep_query_start(dr, TESTUSER1, TESTDOMAIN,
00058                                      TESTDOMAIN, &qh);
00059        assert(status == DKIM_REP_DNS_SUCCESS);
00060        assert(qh != NULL);
00061 
00062        timeout.tv_sec = 5;
00063        timeout.tv_usec = 5;
00064 
00065        rep = 0;
00066        status = dkim_rep_query_check(dr, qh, &timeout, &rep);
00067        assert(status == DKIM_REP_STAT_FOUND);
00068 
00069        printf("--- %s@%s d=%s reputation %d\n", TESTUSER1, TESTDOMAIN,
00070               TESTDOMAIN, rep);
00071 
00072        status = dkim_rep_query_start(dr, TESTUSER2, TESTDOMAIN,
00073                                      TESTDOMAIN, &qh);
00074        assert(status == DKIM_REP_DNS_SUCCESS);
00075        assert(qh != NULL);
00076 
00077        timeout.tv_sec = 5;
00078        timeout.tv_usec = 5;
00079 
00080        rep = 0;
00081        status = dkim_rep_query_check(dr, qh, &timeout, &rep);
00082        assert(status == DKIM_REP_STAT_FOUND);
00083 
00084        printf("--- %s@%s d=%s reputation %d\n", TESTUSER2, TESTDOMAIN,
00085               TESTDOMAIN, rep);
00086 
00087        dkim_rep_close(dr);
00088 
00089        return 0;
00090 }