Back to index

opendkim  2.6.2
t-test100.c
Go to the documentation of this file.
00001 /*
00002 **  Copyright (c) 2005-2008 Sendmail, Inc. and its suppliers.
00003 **    All rights reserved.
00004 **
00005 **  Copyright (c) 2009, 2011, The OpenDKIM Project.  All rights reserved.
00006 */
00007 
00008 #ifndef lint
00009 static char t_test100_c_id[] = "@(#)$Id: t-test100.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $";
00010 #endif /* !lint */
00011 
00012 #include "build-config.h"
00013 
00014 /* system includes */
00015 #include <sys/types.h>
00016 #include <assert.h>
00017 #include <string.h>
00018 #include <stdio.h>
00019 #include <limits.h>
00020 
00021 #ifdef USE_GNUTLS
00022 # include <gnutls/gnutls.h>
00023 #endif /* USE_GNUTLS */
00024 
00025 /* libopendkim includes */
00026 #include "../dkim.h"
00027 #include "t-testdata.h"
00028 
00029 #define       MAXHEADER     4096
00030 
00031 #define SIG "v=1; a=rsa-sha1; c=relaxed/relaxed; d=example.com; s=test;\r\n\tt=1172620939; bh=Z9ONHHsBrKN0pbfrOu025VfbdR4=; h=Received:Received:\r\n\t Received:From:To:Date:Subject:Message-ID; b=Gb2p2FRiCK0vAI+F5+EQ/l\r\n\tKrk9MdARHyw4noadY4R40VJrIrKgUtUL24frvN2NSf3kZaB1Edrksj/TYKsfzyPCUr/\r\n\tTTzf8Q/OWTEHAehsnUWZFK134WpidjMdn0kk1bNeVP7VWeQHgYh8eigji5pqbydusou\r\n\tMtlSHgKtSEKwi5o="
00032 #define SIG2 "v=1; a=rsa-sha1; c=relaxed/relaxed; d=example.com; s=test;\r\n\tt=1172620939; bh=Z9ONHHsBrKN0pbfrOu025VfbdR4=; l=340; h=Received:\r\n\t Received:Received:From:To:Date:Subject:Message-ID; b=NiN+5WZz+O0jY\r\n\t+OH1mCVhv3zM+SrJ6i0wTrhoaDOawOTwW10dF/ZTaMdFmrjJkQfxQenKQN0hmxRNm0Q\r\n\tabHoiaaO1N5owKY0/cUV78U5Z05bNjGl9P9goSgNsLGukRgjb+ellUI8U97Xi9mFjOG\r\n\tWm1iJ2FIq31Bh1mybmvlveKA="
00033 
00034 /*
00035 **  MAIN -- program mainline
00036 **
00037 **  Parameters:
00038 **     The usual.
00039 **
00040 **  Return value:
00041 **     Exit status.
00042 */
00043 
00044 int
00045 main(int argc, char **argv)
00046 {
00047        u_int flags;
00048        DKIM_STAT status;
00049        DKIM *dkim;
00050        DKIM *dkim2;
00051        DKIM_LIB *lib;
00052        dkim_query_t qtype = DKIM_QUERY_FILE;
00053        unsigned char hdr[MAXHEADER + 1];
00054 
00055        printf("*** exercise dkim_minbody()\n");
00056 
00057 #ifdef USE_GNUTLS
00058        (void) gnutls_global_init();
00059 #endif /* USE_GNUTLS */
00060 
00061        /* instantiate the library */
00062        lib = dkim_init(NULL, NULL);
00063        assert(lib != NULL);
00064 
00065 #ifdef TEST_KEEP_FILES
00066        /* set flags */
00067        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00068        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00069                            sizeof flags);
00070 #endif /* TEST_KEEP_FILES */
00071 
00072        (void) dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_FLAGS, &flags,
00073                            sizeof flags);
00074        flags |= DKIM_LIBFLAGS_SIGNLEN;
00075        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00076                            sizeof flags);
00077 
00078        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00079                            &qtype, sizeof qtype);
00080        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00081                            KEYFILE, strlen(KEYFILE));
00082 
00083        dkim = dkim_verify(lib, JOBID, NULL, &status);
00084        assert(dkim != NULL);
00085        dkim2 = dkim_verify(lib, JOBID, NULL, &status);
00086        assert(dkim2 != NULL);
00087 
00088        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG);
00089        status = dkim_header(dkim, hdr, strlen(hdr));
00090        assert(status == DKIM_STAT_OK);
00091 
00092        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00093        status = dkim_header(dkim2, hdr, strlen(hdr));
00094        assert(status == DKIM_STAT_OK);
00095 
00096        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00097        assert(status == DKIM_STAT_OK);
00098        status = dkim_header(dkim2, HEADER01, strlen(HEADER01));
00099        assert(status == DKIM_STAT_OK);
00100 
00101        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00102        assert(status == DKIM_STAT_OK);
00103        status = dkim_header(dkim2, HEADER02, strlen(HEADER02));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00107        assert(status == DKIM_STAT_OK);
00108        status = dkim_header(dkim2, HEADER03, strlen(HEADER03));
00109        assert(status == DKIM_STAT_OK);
00110 
00111        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00112        assert(status == DKIM_STAT_OK);
00113        status = dkim_header(dkim2, HEADER04, strlen(HEADER04));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00117        assert(status == DKIM_STAT_OK);
00118        status = dkim_header(dkim2, HEADER05, strlen(HEADER05));
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00122        assert(status == DKIM_STAT_OK);
00123        status = dkim_header(dkim2, HEADER06, strlen(HEADER05));
00124        assert(status == DKIM_STAT_OK);
00125 
00126        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00127        assert(status == DKIM_STAT_OK);
00128        status = dkim_header(dkim2, HEADER07, strlen(HEADER07));
00129        assert(status == DKIM_STAT_OK);
00130 
00131        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00132        assert(status == DKIM_STAT_OK);
00133        status = dkim_header(dkim2, HEADER08, strlen(HEADER08));
00134        assert(status == DKIM_STAT_OK);
00135 
00136        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00137        assert(status == DKIM_STAT_OK);
00138        status = dkim_header(dkim2, HEADER09, strlen(HEADER09));
00139        assert(status == DKIM_STAT_OK);
00140 
00141        status = dkim_eoh(dkim);
00142        assert(status == DKIM_STAT_OK);
00143        status = dkim_eoh(dkim2);
00144        assert(status == DKIM_STAT_OK);
00145 
00146        assert(dkim_minbody(dkim) == ULONG_MAX);
00147        assert(dkim_minbody(dkim2) == 340);
00148 
00149        status = dkim_body(dkim, BODY00, strlen(BODY00));
00150        assert(status == DKIM_STAT_OK);
00151        status = dkim_body(dkim2, BODY00, strlen(BODY00));
00152        assert(status == DKIM_STAT_OK);
00153 
00154        status = dkim_body(dkim, BODY01, strlen(BODY01));
00155        assert(status == DKIM_STAT_OK);
00156        status = dkim_body(dkim2, BODY01, strlen(BODY01));
00157        assert(status == DKIM_STAT_OK);
00158 
00159        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00160        assert(status == DKIM_STAT_OK);
00161        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00162        assert(status == DKIM_STAT_OK);
00163        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00164        assert(status == DKIM_STAT_OK);
00165        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00166        assert(status == DKIM_STAT_OK);
00167        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00168        assert(status == DKIM_STAT_OK);
00169 
00170        status = dkim_body(dkim2, BODY01A, strlen(BODY01A));
00171        assert(status == DKIM_STAT_OK);
00172        status = dkim_body(dkim2, BODY01B, strlen(BODY01B));
00173        assert(status == DKIM_STAT_OK);
00174        status = dkim_body(dkim2, BODY01C, strlen(BODY01C));
00175        assert(status == DKIM_STAT_OK);
00176        status = dkim_body(dkim2, BODY01D, strlen(BODY01D));
00177        assert(status == DKIM_STAT_OK);
00178        status = dkim_body(dkim2, BODY01E, strlen(BODY01E));
00179        assert(status == DKIM_STAT_OK);
00180 
00181        status = dkim_body(dkim, BODY02, strlen(BODY02));
00182        assert(status == DKIM_STAT_OK);
00183        status = dkim_body(dkim2, BODY02, strlen(BODY02));
00184        assert(status == DKIM_STAT_OK);
00185 
00186        status = dkim_body(dkim, BODY03, strlen(BODY03));
00187        assert(status == DKIM_STAT_OK);
00188        status = dkim_body(dkim2, BODY03, strlen(BODY03));
00189        assert(status == DKIM_STAT_OK);
00190 
00191        status = dkim_body(dkim, BODY04, strlen(BODY04));
00192        assert(status == DKIM_STAT_OK);
00193        status = dkim_body(dkim2, BODY04, strlen(BODY04));
00194        assert(status == DKIM_STAT_OK);
00195 
00196        status = dkim_body(dkim, BODY03, strlen(BODY03));
00197        assert(status == DKIM_STAT_OK);
00198        status = dkim_body(dkim2, BODY03, strlen(BODY03));
00199        assert(status == DKIM_STAT_OK);
00200 
00201        status = dkim_body(dkim, BODY03, strlen(BODY03));
00202        assert(status == DKIM_STAT_OK);
00203        status = dkim_body(dkim2, BODY03, strlen(BODY03));
00204        assert(status == DKIM_STAT_OK);
00205 
00206        status = dkim_body(dkim, BODY05, strlen(BODY05));
00207        assert(status == DKIM_STAT_OK);
00208        status = dkim_body(dkim2, BODY05, strlen(BODY05));
00209        assert(status == DKIM_STAT_OK);
00210 
00211        status = dkim_body(dkim, BODY03, strlen(BODY03));
00212        assert(status == DKIM_STAT_OK);
00213        status = dkim_body(dkim2, BODY03, strlen(BODY03));
00214        assert(status == DKIM_STAT_OK);
00215 
00216        status = dkim_body(dkim, BODY03, strlen(BODY03));
00217        assert(status == DKIM_STAT_OK);
00218        status = dkim_body(dkim2, BODY03, strlen(BODY03));
00219        assert(status == DKIM_STAT_OK);
00220 
00221        status = dkim_body(dkim, BODY06, strlen(BODY06));
00222        assert(status == DKIM_STAT_OK);
00223        status = dkim_body(dkim2, BODY06, strlen(BODY06));
00224        assert(status == DKIM_STAT_OK);
00225 
00226        assert(dkim_minbody(dkim) == ULONG_MAX);
00227        assert(dkim_minbody(dkim2) == 0);
00228 
00229        status = dkim_free(dkim);
00230        assert(status == DKIM_STAT_OK);
00231        status = dkim_free(dkim2);
00232        assert(status == DKIM_STAT_OK);
00233 
00234        dkim_close(lib);
00235 
00236        return 0;
00237 }