]> Cypherpunks.ru repositories - nncp.git/commitdiff
nncp-pkt can decompress the data
authorSergey Matveev <stargrave@stargrave.org>
Mon, 16 Jan 2017 08:56:13 +0000 (11:56 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 16 Jan 2017 08:56:39 +0000 (11:56 +0300)
doc/cmds.texi
doc/news.texi
src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go

index 1061cc273352224029ed19eb223e76a8c4ce3a00..54348c832cf67ea0bbc0e38a6087ea63119a3e34 100644 (file)
@@ -185,7 +185,7 @@ operating system.
 
 @verbatim
 % nncp-pkt [options] < pkt
-% nncp-pkt [options] -dump < pkt > payload
+% nncp-pkt [options] [-decompress] -dump < pkt > payload
 @end verbatim
 
 Low level packet parser. Normally it should not be used, but can help in
@@ -215,7 +215,9 @@ Path: stargrave@stargrave.org
 @end verbatim
 
 And with the @option{-dump} option it will give you the actual payload
-(the whole file, mail message, and so on).
+(the whole file, mail message, and so on). @option{-decompress} option
+tries to zlib-decompress the data from plain packet (useful for mail
+packets).
 
 @node nncp-stat
 @section nncp-stat
index 405cd1589c44ba3a00871b562d9edf2150558395..d72250f6d4e229e26c981b5074a8da1eeff40778 100644 (file)
@@ -18,4 +18,5 @@ could be used to keep connection alive for a long time.
 @item @option{-maxonlinetime} option gives ability to set maximal
 allowable online connection alive time.
 @item @ref{nncp-caller} command appeared: cron-ed TCP daemon caller.
+@item @ref{nncp-pkt} command can decompress the data.
 @end itemize
index 535c7d25ae7c670ea621f4d23b12ac074e3dddc5..82bcffbd5d0fe444e0908fc5e15106a9fa46ae1f 100644 (file)
@@ -22,6 +22,7 @@ package main
 import (
        "bufio"
        "bytes"
+       "compress/zlib"
        "flag"
        "fmt"
        "io"
@@ -44,10 +45,11 @@ func usage() {
 
 func main() {
        var (
-               dump     = flag.Bool("dump", false, "Write decrypted/parsed payload to stdout")
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               dump       = flag.Bool("dump", false, "Write decrypted/parsed payload to stdout")
+               decompress = flag.Bool("decompress", false, "Try to zlib decompress dumped data")
+               cfgPath    = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               version    = flag.Bool("version", false, "Print version information")
+               warranty   = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -70,7 +72,16 @@ func main() {
        if err == nil && pkt.Magic == nncp.MagicNNCPPv1 {
                if *dump {
                        bufW := bufio.NewWriter(os.Stdout)
-                       if _, err = io.Copy(bufW, bufio.NewReader(os.Stdin)); err != nil {
+                       var r io.Reader
+                       r = bufio.NewReader(os.Stdin)
+                       if *decompress {
+                               decompressor, err := zlib.NewReader(r)
+                               if err != nil {
+                                       log.Fatalln(err)
+                               }
+                               r = decompressor
+                       }
+                       if _, err = io.Copy(bufW, r); err != nil {
                                log.Fatalln(err)
                        }
                        if err = bufW.Flush(); err != nil {