🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #90725

Re: A C library for the NNTP protocol?

#90725
From: Billy G. (go-while)
Date: Tue, 05 Sep 2023 21:01
124 lines
4155 bytes
On 05.09.23 17:06, Johann 'Myrkraverk' Oskarsson wrote:
> Are there still extant C libraries that implement NNTP
I'm not a C guy but as C is old as nntp i bet you'll find something?

> and are useful for creating Usenet clients? 
What kind of client?
a reader or a binary downloader?


 > 1) how would I start experimenting on my own?

https://datatracker.ietf.org/doc/html/rfc3977

 > Do Usenet providers frown upon practice clients, such as Eternal 
September?

Paid providers mostly don't care. private ones may do better in banning 
you for doing stupid stuff.
please try only with your localhost. inn is enough.

 > practicing all the intricacies of SSL verification

SSL(-lib) is only a wrapped around layer to a tcp connection which in 
case of NNTP sends/receives commands and data via text or 
'line1\r\nline2\r\n.'

why use C?
try GO and have a working ssl/tcp connection with a textproto wrapper

easy like this:

the returned 'srvtp *textproto.Conn': https://pkg.go.dev/net/textproto

the returnd 'conn net.Conn' is either the tcp or ssl conn which can be 
closed via conn.Close() -> https://pkg.go.dev/net#Conn .

import (
   "crypto/tls"
   "net"
   "net/textproto"
)


type PEER struct {
   Hostname       string
   Port           int
   Addr4          string
   Addr6          string
   R_SSL          bool
   R_SSL_Insecure bool
} // end type PEER

func main() {
  peer := &PEER{
    Hostname: "myServer",
    Addr4: "localhost",
    Port: 119, R_SSL: true
  }
  srvtp, rconn, err := RCONN(1, 1, peer)
  if err != nil {
    log.Printf("Error RCONN err='%v'", err)
    return
  }
  for {
     line, err := s.srvtp.ReadLine()
     if err != nil {
       log.Printf("Error ReadLine err='%v'", err)
       return false
     }
     log.Printf("srvtp.Readline='%s'", line)
  }
}


func RCONN(num int, wid int, peer *PEER) (*textproto.Conn, net.Conn, 
error) {
	log.Printf("New RCONN num=%d wid=%d peer=%s", num, wid, peer.Hostname)
	var conn net.Conn
	var err error
	ssl_conf := &tls.Config{
		InsecureSkipVerify: true,
	}
	addrs := []string{peer.Hostname, peer.Addr4, peer.Addr6}
	port := 119
	if peer.Port > 0 && peer.Port < 65535 {
		port = peer.Port
	}
connect_peer:
	for _, addr := range addrs {
		if addr == "" {
			continue connect_peer
		}

		peer_url := fmt.Sprintf("peer.Hostname:%d", port)
		if peer.R_SSL {
			conn, err = tls.Dial(peer_url, "tcp", ssl_conf)
		} else {
			conn, err = net.Dial(peer_url, "tcp")
		}
		if err != nil {
			log.Printf("ERROR CONN Dial peer=%s peer_url='%s' err='%v'", 
peer.Hostname, peer_url, err)
			time.Sleep(time.Second * 3)
			continue connect_peer
		}
		break connect_peer
	} // end for loop_connect
	if conn == nil || err != nil {
		return nil, nil, fmt.Errorf("ERROR CONN conn=nil peer=%s err='%v'", 
peer.Hostname, err)
	}
	srvtp := textproto.NewConn(conn)
	code, msg, err := srvtp.ReadCodeLine(20)
	if err != nil || (code != 200 && code != 201) {
		log.Printf("ERROR RCONN code=%d msg='%s' peer=%s err='%v'", code, msg, 
peer.Hostname, err)
		return nil, nil, err
	}
	log.Printf("RCONN ESTABLISHED peer=%s", peer.Hostname)
	return srvtp, conn, err
} // end func RCONN


MIT license.
Technical Details
Message-ID: <BGMJM.1820980$Y1R7.419554@fx04.ams4>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
References: <cuHJM.1091805$6Li6.85230@fx12.ams4>

Show Full Headers
Complete Article Headers
Message-ID: <BGMJM.1820980$Y1R7.419554@fx04.ams4>
Subject: Re: A C library for the NNTP protocol?
Date: Tue, 5 Sep 2023 23:01:29 +0200
From: "Billy G. (go-while)" <no-reply@no.spam>
References: <cuHJM.1091805$6Li6.85230@fx12.ams4>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
Mime-Version: 1.0
User-Agent: NoZilla/3.11 (Hackint; Unicorn; rv:0.8.15) go-while/19720229 NewsRW/4.2.0
Newsgroups: news.software.nntp
Content-Language: en-US
Organization: github.com/go-while
In-Reply-To: <cuHJM.1091805$6Li6.85230@fx12.ams4>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 125
X-Complaints-To: abuse@blocknews.net
Nntp-Posting-Date: Tue, 05 Sep 2023 21:01:21 UTC