#1 Patch chm_http tool
Merged 4 years ago by peter. Opened 4 years ago by ferdnyc.
rpms/ ferdnyc/chmlib patches-1  into  master

@@ -0,0 +1,25 @@ 

+ From ad27f1981415f9b9df179099e36d793327ce6d8c Mon Sep 17 00:00:00 2001

+ From: "FeRD (Frank Dana)" <ferdnyc@gmail.com>

+ Date: Thu, 11 Jul 2019 20:57:19 -0400

+ Subject: [PATCH] Change the default binding to 127.0.0.1

+ 

+ ---

+  src/chm_http.c | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/src/chm_http.c b/src/chm_http.c

+ index 237e85a..ddffe55 100644

+ --- a/src/chm_http.c

+ +++ b/src/chm_http.c

+ @@ -50,7 +50,7 @@

+  #include <getopt.h>

+  

+  int config_port = 8080;

+ -char config_bind[65536] = "0.0.0.0";

+ +char config_bind[65536] = "127.0.0.1";

+  

+  static void usage(const char *argv0)

+  {

+ -- 

+ 2.21.0

+ 

@@ -0,0 +1,78 @@ 

+ From 472396d694ae1d8b77f8b349ab13e387b9eae629 Mon Sep 17 00:00:00 2001

+ From: "FeRD (Frank Dana)" <ferdnyc@gmail.com>

+ Date: Thu, 11 Jul 2019 21:16:43 -0400

+ Subject: [PATCH] Print URL for server, quiet option suppresses

+ 

+ This will display a line of text on stdout immediately after

+ binding to the configured address and port:

+ `Server running at http://<address>:<port>/`

+ An option `-q` / `--quiet` is added, to suppress the output.

+ ---

+  src/chm_http.c | 18 +++++++++++++++---

+  1 file changed, 15 insertions(+), 3 deletions(-)

+ 

+ diff --git a/src/chm_http.c b/src/chm_http.c

+ index 237e85a..84304f9 100644

+ --- a/src/chm_http.c

+ +++ b/src/chm_http.c

+ @@ -51,13 +51,14 @@

+  

+  int config_port = 8080;

+  char config_bind[65536] = "127.0.0.1";

+ +char config_quiet = 0;

+  

+  static void usage(const char *argv0)

+  {

+  #ifdef CHM_HTTP_SIMPLE

+ -    fprintf(stderr, "usage: %s <filename>\n", argv0);

+ +    fprintf(stderr, "usage: %s [--quiet] <filename>\n", argv0);

+  #else

+ -    fprintf(stderr, "usage: %s [--port=PORT] [--bind=IP] <filename>\n", argv0);

+ +    fprintf(stderr, "usage: %s [--quiet] [--port=PORT] [--bind=IP] <filename>\n", argv0);

+  #endif

+      exit(1);

+  }

+ @@ -80,6 +81,7 @@ int main(int c, char **v)

+      {

+          { "port", required_argument, 0, 'p' },

+          { "bind", required_argument, 0, 'b' },

+ +        { "quiet", no_argument, 0, 'q' },

+          { "help", no_argument, 0, 'h' },

+          { 0, 0, 0, 0 }

+      };

+ @@ -87,7 +89,7 @@ int main(int c, char **v)

+      while (1) 

+      {

+          int o;

+ -        o = getopt_long (c, v, "p:b:h", longopts, &optindex);

+ +        o = getopt_long (c, v, "p:b:qh", longopts, &optindex);

+          if (o < 0) 

+          {

+              break;

+ @@ -109,6 +111,10 @@ int main(int c, char **v)

+                  config_bind[65535] = '\0';

+                  break;

+  

+ +            case 'q':

+ +                config_quiet = 1;

+ +                break;

+ +

+              case 'h':

+                  usage (v[0]);

+                  break;

+ @@ -182,6 +188,12 @@ static void chmhttp_server(const char *filename)

+          exit(3);

+      }

+  

+ +    /* Display URL for server */

+ +    if (!config_quiet)

+ +    {

+ +        printf("Server running at http://%s:%d/\n", config_bind, config_port);

+ +    }

+ +

+      /* listen for connections */

+      listen(server.socket, 75);

+      addrLen = sizeof(struct sockaddr);

+ -- 

+ 2.21.0

+ 

@@ -0,0 +1,28 @@ 

+ From 107ce67661c517d1c0b63c31ed1dbe34573de445 Mon Sep 17 00:00:00 2001

+ From: "FeRD (Frank Dana)" <ferdnyc@gmail.com>

+ Date: Thu, 11 Jul 2019 21:20:23 -0400

+ Subject: [PATCH] Correct port short-opt to -p (not -n)

+ 

+ The getopt_long arguments specified the short option for `--port` as

+ `-n`, which was not handled by the case statement, making both `-p`

+ (invalid argument) and `-n` (ignored) unusable to set the port.

+ ---

+  src/chm_http.c | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/src/chm_http.c b/src/chm_http.c

+ index 237e85a..6ae00cc 100644

+ --- a/src/chm_http.c

+ +++ b/src/chm_http.c

+ @@ -87,7 +87,7 @@ int main(int c, char **v)

+      while (1) 

+      {

+          int o;

+ -        o = getopt_long (c, v, "n:b:h", longopts, &optindex);

+ +        o = getopt_long (c, v, "p:b:h", longopts, &optindex);

+          if (o < 0) 

+          {

+              break;

+ -- 

+ 2.21.0

+ 

file modified
+13 -1
@@ -1,7 +1,7 @@ 

  Name:		chmlib

  Summary:	Library for dealing with ITSS/CHM format files

  Version:	0.40

- Release:	19%{?dist}

+ Release:	20%{?dist}

  License:	LGPLv2+

  Url:		http://www.jedrea.com/chmlib/

  %if 0%{?el7}%{?fedora}
@@ -12,6 +12,12 @@ 

  Patch1:		chmlib-0001-Patch-to-fix-integer-types-problem-by-Goswin-von-Bre.patch

  # backported from upstream

  Patch2:		chmlib-0002-Fix-for-extract_chmLib-confusing-empty-files-with-di.patch

+ # Submitted upstream https://github.com/jedwing/CHMLib/pull/10

+ Patch3:		chm_http-port-shortopt.patch

+ # Submitted upstream https://github.com/jedwing/CHMLib/pull/11

+ Patch4:		chm_http-bind-localhost.patch

+ # Submitted upstream https://github.com/jedwing/CHMLib/pull/12

+ Patch5:		chm_http-output-server-address.patch

  BuildRequires:	autoconf

  BuildRequires:	automake

  BuildRequires:	libtool
@@ -38,6 +44,9 @@ 

  %setup -q

  %patch1 -p1 -b .types

  %patch2 -p1 -b .files_dirs

+ %patch3 -p1 -b .shortopt

+ %patch4 -p1 -b .localhost

+ %patch5 -p1 -b .printaddr

  rm -f libtool

  mv configure.in configure.ac

  autoreconf -ivf
@@ -72,6 +81,9 @@ 

  

  

  %changelog

+ * Thu Jul 11 2019 FeRD (Frank Dana) <ferdnyc@gmail.com> - 0.40-20

+ - Patch chm_http to fix -p (port) short opt, bind to 127.0.0.1, display URL

+ 

  * Thu Jan 31 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.40-19

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

  

This adds three patches to chm_http which:

  • Correct the short option for --port to -p (from the previous -n, which was ignored).
  • Bind to "127.0.0.1" by default, instead of "0.0.0.0".
  • Display a message (untranslated, sadly) indicating the URL of the runing server, unless the new -q / --quiet option is used.
$ chm_http -p 8888 procexp.chm
Server running at http://127.0.0.1:8888/

All patches have been submitted upstream:

But, since the last commit to that repo was in 2009, I thought I'd submit them here as well.

Pull-Request has been merged by peter

4 years ago