test getting patch sets

This commit is contained in:
Jeff Carr 2024-12-14 13:12:23 -06:00
parent 797edb1d5c
commit 019d2961e5
2 changed files with 69 additions and 21 deletions

View File

@ -2,7 +2,6 @@ package main
/*
this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/

89
http.go
View File

@ -2,11 +2,15 @@ package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"time"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
)
@ -17,12 +21,19 @@ func cleanURL(url string) string {
}
func okHandler(w http.ResponseWriter, r *http.Request) {
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil {
log.Info("ioutil.ReadAll() error =", err)
return
}
log.Info("ioutil.ReadAll() msg =", len(msg))
fmt.Fprintln(w, "ioutil.ReadAll() msg =", len(msg))
// dumpClient(accessf, clientf, r)
var tmp string
var route string
// tmp = r.URL.String()
tmp = cleanURL(r.URL.Path)
parts := strings.Split(tmp, "?")
log.Info("client sent url =", tmp)
route = cleanURL(r.URL.Path)
parts := strings.Split(route, "?")
log.Info("client sent url =", route)
log.Info("parts are:", parts)
requrl := parts[0]
@ -32,7 +43,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
repoHTML(w, url, repourl)
return
}
if tmp == "/" {
if route == "/" {
indexHeader(w)
indexBodyStart(w)
indexBodyScanConfig(w)
@ -48,11 +59,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
indexBodyEnd(w)
return
}
if tmp == "/install.sh" {
if route == "/install.sh" {
writeFile(w, "install.sh")
return
}
if tmp == "/me" {
if route == "/me" {
j, err := dumpJsonClient(r)
if err != nil {
fmt.Fprintln(w, "BAD ZOOT")
@ -61,7 +72,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, j)
return
}
if tmp == "/register" {
if route == "/register" {
fname := filepath.Join(LIBDIR, "regfile.log")
regfile, _ := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if registerClient(regfile, r) {
@ -71,26 +82,71 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
return
}
if tmp == "/goReference.svg" {
if route == "/machine" {
var m *zoopb.Machine
m = new(zoopb.Machine)
if err := m.Unmarshal(msg); err != nil {
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
log.Info("error =", err)
return
}
log.Info("GOT patchset:", len(msg))
fmt.Fprintln(w, "GOT patchset:", len(msg))
return
}
if route == "/patchset" {
log.Info("proto.Unmarshal() try message len", len(msg))
var m *forgepb.Patchs
m = new(forgepb.Patchs)
if err := m.Unmarshal(msg); err != nil {
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
log.Info("error =", err)
return
}
log.Info("GOT patchset:", len(msg))
fmt.Fprintln(w, "GOT patchset:", len(msg))
all := m.SortByFilename()
for all.Scan() {
repo := all.Next()
log.Info("filename:", repo.Filename)
fmt.Fprintln(w, "filename:", repo.Filename)
}
now := time.Now()
// timestamp := now.Format("2022.07.18.190545") // 50yr shout out to K&R
timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
filename := filepath.Join(LIBDIR, "patchset/", timestamp+".submitted.pb")
regfile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
log.Info("filename open error:", filename, err)
fmt.Fprintln(w, "filename open error:", filename, err)
return
}
fmt.Fprint(regfile, msg)
regfile.Close()
return
}
if route == "/goReference.svg" {
writeFile(w, "goReference.svg")
return
}
if tmp == "/skeleton.v2.css" {
if route == "/skeleton.v2.css" {
writeFile(w, "skeleton.v2.css")
return
}
if tmp == "/favicon.ico" {
if route == "/favicon.ico" {
writeFile(w, "ipv6.png")
return
}
// used for uptime monitor checking
if tmp == "/uptime" {
if route == "/uptime" {
writeFile(w, "uptime.html")
return
}
log.Warn("BAD URL =", url, "REPO URL =", repourl)
badurl(w, r.URL.String())
// fmt.Fprintln(w, "BAD", tmp)
}
func writeFile(w http.ResponseWriter, filename string) {
@ -110,13 +166,6 @@ func writeFile(w http.ResponseWriter, filename string) {
}
fmt.Fprintln(w, repohtml)
log.Println("writeFile() found internal file:", filename)
// w.Close()
/*
filename = "/tmp/" + name + ".so"
log.Error(err, "write out file here", name, filename, len(pfile))
f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
f.Close()
*/
}
func badurl(w http.ResponseWriter, badurl string) {