Check-in [9a6c6c2cda]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Get the smtp_mx_host() routine working on Windows in addition to Linux.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:9a6c6c2cdacf4d8dc84377f62d0ccd884ae1341f5db65deb434f9d2340f16713
User & Date: drh 2018-07-12 13:15:24
Context
2018-07-12
14:09
Add "Truncate" and "Download" buttons to the /errorlog display. Provide a link to the error log on the /setup page. check-in: 8e3bad04ee user: drh tags: trunk
13:15
Get the smtp_mx_host() routine working on Windows in addition to Linux. check-in: 9a6c6c2cda user: drh tags: trunk
13:13
Fix a compiler warning on the mac build. Closed-Leaf check-in: b6b5048a1b user: drh tags: smtp-win
06:46
Make sure -ldl is appended after -lcrypto; Fixes link errors with static build. check-in: efbc319c32 user: ashepilko tags: trunk
Changes

Changes to src/makemake.tcl.

   937    937   LIB += -lkernel32 -lws2_32
   938    938   else
   939    939   LIB += -lnetapi32 -lkernel32 -luser32 -ladvapi32 -lws2_32
   940    940   endif
   941    941   else
   942    942   LIB += -lkernel32 -lws2_32
   943    943   endif
          944  +
          945  +#### Library required for DNS lookups.
          946  +#
          947  +LIB += ldnsapi
   944    948   
   945    949   #### Tcl shell for use in running the fossil test suite.  This is only
   946    950   #    used for testing.
   947    951   #
   948    952   TCLSH = tclsh
   949    953   
   950    954   #### Nullsoft installer MakeNSIS location
................................................................................
  1311   1315   
  1312   1316   #SSL   =  -DFOSSIL_ENABLE_SSL=1
  1313   1317   SSL    =
  1314   1318   
  1315   1319   CFLAGS = -o
  1316   1320   BCC    = $(DMDIR)\bin\dmc $(CFLAGS)
  1317   1321   TCC    = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
  1318         -LIBS   = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
         1322  +LIBS   = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
  1319   1323   }
  1320   1324   writeln "SQLITE_OPTIONS = [join $SQLITE_OPTIONS { }]\n"
  1321   1325   writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS { }]\n"
  1322   1326   writeln -nonewline "SRC   ="
  1323   1327   foreach s [lsort $src] {
  1324   1328     writeln -nonewline " ${s}_.c"
  1325   1329   }
................................................................................
  1703   1707   CFLAGS    = $(CFLAGS) $(CRTFLAGS) /O2
  1704   1708   !endif
  1705   1709   
  1706   1710   BCC       = $(CC) $(CFLAGS)
  1707   1711   TCC       = $(CC) /c $(CFLAGS) $(MSCDEF) $(INCL)
  1708   1712   RCC       = $(RC) /D_WIN32 /D_MSC_VER $(MSCDEF) $(INCL)
  1709   1713   MTC       = mt
  1710         -LIBS      = ws2_32.lib advapi32.lib
         1714  +LIBS      = ws2_32.lib advapi32.lib dnsapi.lib
  1711   1715   LIBDIR    =
  1712   1716   
  1713   1717   !if $(FOSSIL_DYNAMIC_BUILD)!=0
  1714   1718   TCC       = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
  1715   1719   RCC       = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
  1716   1720   !endif
  1717   1721   
................................................................................
  2096   2100   B=..
  2097   2101   SRCDIR=$(B)/src/
  2098   2102   WINDIR=$(B)/win/
  2099   2103   ZLIBSRCDIR=../../zlib/
  2100   2104   
  2101   2105   # define linker command and options
  2102   2106   LINK=$(PellesCDir)/bin/polink.exe
  2103         -LINKFLAGS=-subsystem:console -machine:$(TARGETMACHINE_LN) /LIBPATH:$(PellesCDir)\lib\win$(TARGETEXTEND) /LIBPATH:$(PellesCDir)\lib kernel32.lib advapi32.lib delayimp$(TARGETEXTEND).lib Wsock32.lib Crtmt$(TARGETEXTEND).lib
         2107  +LINKFLAGS=-subsystem:console -machine:$(TARGETMACHINE_LN) /LIBPATH:$(PellesCDir)\lib\win$(TARGETEXTEND) /LIBPATH:$(PellesCDir)\lib kernel32.lib advapi32.lib delayimp$(TARGETEXTEND).lib Wsock32.lib dnsapi.lib Crtmt$(TARGETEXTEND).lib
  2104   2108   
  2105   2109   # define standard C-compiler and flags, used to compile
  2106   2110   # the fossil binary. Some special definitions follow for
  2107   2111   # special files follow
  2108   2112   CC=$(PellesCDir)\bin\pocc.exe
  2109   2113   DEFINES=-D_pgmptr=g.argv[0]
  2110   2114   CCFLAGS=-T$(TARGETMACHINE_CC)-coff -Ot -W2 -Gd -Go -Ze -MT $(DEFINES)

Changes to src/smtp.c.

    17     17   **
    18     18   ** Implementation of SMTP (Simple Mail Transport Protocol) according
    19     19   ** to RFC 5321.
    20     20   */
    21     21   #include "config.h"
    22     22   #include "smtp.h"
    23     23   #include <assert.h>
    24         -
    25         -#ifdef __linux__
    26         -# define FOSSIL_ENABLE_DNS_LOOKUP
    27         -#endif
    28         -
    29         -#if defined(FOSSIL_ENABLE_DNS_LOOKUP)
           24  +#if defined(__linux__)
    30     25   #  include <sys/types.h>
    31     26   #  include <netinet/in.h>
    32     27   #  include <arpa/nameser.h>
    33     28   #  include <resolv.h>
    34         -#endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */
           29  +#  define FOSSIL_UNIX_STYLE_DNS 1
           30  +#endif
           31  +#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
           32  +#  include <windows.h>
           33  +#  include <windns.h>
           34  +#  define FOSSIL_WINDOWS_STYLE_DNS 1
           35  +#endif
    35     36   
    36     37   
    37     38   /*
    38     39   ** Find the hostname for receiving email for the domain given
    39     40   ** in zDomain.  Return NULL if not found or not implemented.
    40     41   ** If multiple email receivers are advertized, pick the one with
    41     42   ** the lowest preference number.
    42     43   **
    43     44   ** The returned string is obtained from fossil_malloc()
    44     45   ** and should be released using fossil_free().
    45     46   */
    46     47   char *smtp_mx_host(const char *zDomain){
    47         -#if defined(FOSSIL_ENABLE_DNS_LOOKUP)
           48  +#if defined(FOSSIL_UNIX_STYLE_DNS)
    48     49     int nDns;                       /* Length of the DNS reply */
    49     50     int rc;                         /* Return code from various APIs */
    50     51     int i;                          /* Loop counter */
    51     52     int iBestPriority = 9999999;    /* Best priority */
    52     53     int nRec;                       /* Number of answers */
    53     54     ns_msg h;                       /* DNS reply parser */
    54     55     const unsigned char *pBest = 0; /* RDATA for the best answer */
................................................................................
    78     79       }
    79     80     }
    80     81     if( pBest ){
    81     82       ns_name_uncompress(aDns, aDns+nDns, pBest+2,
    82     83                          zHostname, sizeof(zHostname));
    83     84       return fossil_strdup(zHostname);
    84     85     }
    85         -#endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */
           86  +  return 0;
           87  +#elif defined(FOSSIL_WINDOWS_STYLE_DNS)
           88  +  DNS_STATUS status;           /* Return status */
           89  +  PDNS_RECORDA pDnsRecord, p;  /* Pointer to DNS_RECORD structure */
           90  +  int iBestPriority = 9999999; /* Best priority */
           91  +  char *pBest = 0;             /* RDATA for the best answer */
           92  +
           93  +  status = DnsQuery_UTF8(zDomain,            /* Domain name */
           94  +                         DNS_TYPE_MX,        /* DNS record type */
           95  +                         DNS_QUERY_STANDARD, /* Query options */
           96  +                         NULL,               /* List of DNS servers */
           97  +                         &pDnsRecord,        /* Query results */
           98  +                         NULL);              /* Reserved */
           99  +  if( status ) return NULL;
          100  +
          101  +  p = pDnsRecord;
          102  +  while( p ){
          103  +    if( p->Data.MX.wPreference<iBestPriority ){
          104  +      iBestPriority = p->Data.MX.wPreference;
          105  +      pBest = p->Data.MX.pNameExchange;
          106  +    }
          107  +    p = p->pNext;
          108  +  }
          109  +  if( pBest ){
          110  +    pBest = fossil_strdup(pBest); 
          111  +  }
          112  +  DnsRecordListFree(pDnsRecord, DnsFreeRecordListDeep);
          113  +  return pBest;
          114  +#else
    86    115     return 0;
          116  +#endif /* defined(FOSSIL_WINDOWS_STYLE_DNS) */
    87    117   }
    88    118   
    89    119   /*
    90    120   ** COMMAND: test-find-mx
    91    121   **
    92    122   ** Usage: %fossil test-find-mx DOMAIN ...
    93    123   **
    94    124   ** Do a DNS MX lookup to find the hostname for sending email for
    95    125   ** DOMAIN.
    96    126   */
    97    127   void test_find_mx(void){
    98    128     int i;
    99         -  if( g.argc<2 ){
          129  +  if( g.argc<=2 ){
   100    130       usage("DOMAIN ...");
   101    131     }
   102    132     for(i=2; i<g.argc; i++){
   103    133       char *z = smtp_mx_host(g.argv[i]);
   104    134       fossil_print("%s: %s\n", g.argv[i], z);
   105    135       fossil_free(z);
   106    136     }

Changes to win/Makefile.PellesCGMake.

    56     56   B=..
    57     57   SRCDIR=$(B)/src/
    58     58   WINDIR=$(B)/win/
    59     59   ZLIBSRCDIR=../../zlib/
    60     60   
    61     61   # define linker command and options
    62     62   LINK=$(PellesCDir)/bin/polink.exe
    63         -LINKFLAGS=-subsystem:console -machine:$(TARGETMACHINE_LN) /LIBPATH:$(PellesCDir)\lib\win$(TARGETEXTEND) /LIBPATH:$(PellesCDir)\lib kernel32.lib advapi32.lib delayimp$(TARGETEXTEND).lib Wsock32.lib Crtmt$(TARGETEXTEND).lib
           63  +LINKFLAGS=-subsystem:console -machine:$(TARGETMACHINE_LN) /LIBPATH:$(PellesCDir)\lib\win$(TARGETEXTEND) /LIBPATH:$(PellesCDir)\lib kernel32.lib advapi32.lib delayimp$(TARGETEXTEND).lib Wsock32.lib dnsapi.lib Crtmt$(TARGETEXTEND).lib
    64     64   
    65     65   # define standard C-compiler and flags, used to compile
    66     66   # the fossil binary. Some special definitions follow for
    67     67   # special files follow
    68     68   CC=$(PellesCDir)\bin\pocc.exe
    69     69   DEFINES=-D_pgmptr=g.argv[0]
    70     70   CCFLAGS=-T$(TARGETMACHINE_CC)-coff -Ot -W2 -Gd -Go -Ze -MT $(DEFINES)

Changes to win/Makefile.dmc.

    20     20   
    21     21   #SSL   =  -DFOSSIL_ENABLE_SSL=1
    22     22   SSL    =
    23     23   
    24     24   CFLAGS = -o
    25     25   BCC    = $(DMDIR)\bin\dmc $(CFLAGS)
    26     26   TCC    = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
    27         -LIBS   = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
           27  +LIBS   = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
    28     28   
    29     29   SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB
    30     30   
    31     31   SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
    32     32   
    33     33   SRC   = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c email_.c encode_.c etag_.c event_.c export_.c file_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c glob_.c graph_.c gzip_.c hname_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c webmail_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
    34     34   

Changes to win/Makefile.mingw.

   405    405   LIB += -lkernel32 -lws2_32
   406    406   else
   407    407   LIB += -lnetapi32 -lkernel32 -luser32 -ladvapi32 -lws2_32
   408    408   endif
   409    409   else
   410    410   LIB += -lkernel32 -lws2_32
   411    411   endif
          412  +
          413  +#### Library required for DNS lookups.
          414  +#
          415  +LIB += -ldnsapi
   412    416   
   413    417   #### Tcl shell for use in running the fossil test suite.  This is only
   414    418   #    used for testing.
   415    419   #
   416    420   TCLSH = tclsh
   417    421   
   418    422   #### Nullsoft installer MakeNSIS location
................................................................................
  2414   2418   	$(XTCC) -c $(SRCDIR)/th_lang.c -o $@
  2415   2419   
  2416   2420   $(OBJDIR)/th_tcl.o:	$(SRCDIR)/th_tcl.c
  2417   2421   	$(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
  2418   2422   
  2419   2423   $(OBJDIR)/miniz.o:	$(SRCDIR)/miniz.c
  2420   2424   	$(XTCC) $(MINIZ_OPTIONS) -c $(SRCDIR)/miniz.c -o $@
  2421         -

Changes to win/Makefile.msc.

   243    243   CFLAGS    = $(CFLAGS) $(CRTFLAGS) /O2
   244    244   !endif
   245    245   
   246    246   BCC       = $(CC) $(CFLAGS)
   247    247   TCC       = $(CC) /c $(CFLAGS) $(MSCDEF) $(INCL)
   248    248   RCC       = $(RC) /D_WIN32 /D_MSC_VER $(MSCDEF) $(INCL)
   249    249   MTC       = mt
   250         -LIBS      = ws2_32.lib advapi32.lib
          250  +LIBS      = ws2_32.lib advapi32.lib dnsapi.lib
   251    251   LIBDIR    =
   252    252   
   253    253   !if $(FOSSIL_DYNAMIC_BUILD)!=0
   254    254   TCC       = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1
   255    255   RCC       = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1
   256    256   !endif
   257    257