<commit_before>package supervisord

import (
	"bufio"
	"errors"
	"fmt"
	"log"
	"net"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/lowstz/xmlrpc"
)

var supervisorURL, _ = url.Parse("http://localhost/RPC2")

func unmarshalStruct(in xmlrpc.Struct, out interface{}) error {
	t := reflect.TypeOf(out)
	if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
		return errors.New("unmarshalStruct: out is not a struct pointer")
	}

	t = t.Elem()
	v := reflect.ValueOf(out).Elem()

	//log.Printf("type of out: %s with %d fields", t.Name(), t.NumField())

	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		fieldName := field.Tag.Get("xmlrpc")
		if fieldName == "" {
			fieldName = field.Name
		} else if fieldName == "-" {
			continue
		}

		//log.Printf("looking for field %s", fieldName)

		if value, ok := in[fieldName]; ok {
			vT := reflect.TypeOf(value)
			if vT.AssignableTo(field.Type) {
				v.Field(i).Set(reflect.ValueOf(value))
			} else {
				log.Println(in)
				return fmt.Errorf("unmarshalStruct: incompatible type for field '%s' (%s != %s)",
					field.Name, field.Type.Name(), vT.Name())
			}
		} else {
			//log.Printf("field %s not found", fieldName)
			//ignore struct fields that are not in the response struct
			return fmt.Errorf("unmarshalStruct: field %s couldn't be found in input struct", fieldName)
		}
	}

	return nil
}

type State struct {
	Statecode int64  `xmlrpc:"statecode"`
	Statename string `xmlrpc:"statename"`
}

type ProcessInfo struct {
	Name          string `xmlrpc:"name"`
	Group         string `xmlrpc:"group"`
	Start         int64  `xmlrpc:"start"`
	Stop          int64  `xmlrpc:"stop"`
	Now           int64  `xmlrpc:"now"`
	State         int64  `xmlrpc:"state"`
	Statename     string `xmlrpc:"statename"`
	StdoutLogfile string `xmlrpc:"stdout_logfile"`
	StderrLogfile string `xmlrpc:"stderr_logfile"`
	SpawnErr      string `xmlrpc:"spawnerr"`
	ExitStatus    int64  `xmlrpc:"exitstatus"`
	Pid           int64  `xmlrpc:"pid"`
}

type Supervisor interface {
	//status and control

	GetAPIVersion() (string, error)
	GetSupervisorVersion() (string, error)
	GetIdentification() (string, error)
	GetState() (State, error)
	GetPID() (int, error)
	ReadLog(offset, length int) (string, error)
	ClearLog() (bool, error)
	Shutdown() (bool, error)
	Restart() (bool, error)<commit_msg>change struct field<commit_after>package supervisord

import (
	"bufio"
	"errors"
	"fmt"
	"log"
	"net"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/lowstz/xmlrpc"
)

var supervisorURL, _ = url.Parse("http://localhost/RPC2")

func unmarshalStruct(in xmlrpc.Struct, out interface{}) error {
	t := reflect.TypeOf(out)
	if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
		return errors.New("unmarshalStruct: out is not a struct pointer")
	}

	t = t.Elem()
	v := reflect.ValueOf(out).Elem()

	//log.Printf("type of out: %s with %d fields", t.Name(), t.NumField())

	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		fieldName := field.Tag.Get("xmlrpc")
		if fieldName == "" {
			fieldName = field.Name
		} else if fieldName == "-" {
			continue
		}

		//log.Printf("looking for field %s", fieldName)

		if value, ok := in[fieldName]; ok {
			vT := reflect.TypeOf(value)
			if vT.AssignableTo(field.Type) {
				v.Field(i).Set(reflect.ValueOf(value))
			} else {
				log.Println(in)
				return fmt.Errorf("unmarshalStruct: incompatible type for field '%s' (%s != %s)",
					field.Name, field.Type.Name(), vT.Name())
			}
		} else {
			//log.Printf("field %s not found", fieldName)
			//ignore struct fields that are not in the response struct
			return fmt.Errorf("unmarshalStruct: field %s couldn't be found in input struct", fieldName)
		}
	}

	return nil
}

type State struct {
	StateCode int64  `xmlrpc:"statecode"`
	StateName string `xmlrpc:"statename"`
}

type ProcessInfo struct {
	Name          string `xmlrpc:"name"`
	Description   string `xmlrpc:"description"`
	Group         string `xmlrpc:"group"`
	Start         int64  `xmlrpc:"start"`
	Stop          int64  `xmlrpc:"stop"`
	Now           int64  `xmlrpc:"now"`
	State         int64  `xmlrpc:"state"`
	StateName     string `xmlrpc:"statename"`
	Logfile       string `xmlrpc:"logfile"`
	StdoutLogfile string `xmlrpc:"stdout_logfile"`
	StderrLogfile string `xmlrpc:"stderr_logfile"`
	SpawnErr      string `xmlrpc:"spawnerr"`
	ExitStatus    int64  `xmlrpc:"exitstatus"`
	Pid           int64  `xmlrpc:"pid"`
}

type Supervisor interface {
	//status and control

	GetAPIVersion() (string, error)
	GetSupervisorVersion() (string, error)
	GetIdentification() (string, error)
	GetState() (State, error)
	GetPID() (int, error)
	ReadLog(offset, length int) (string, error)
	ClearLog() (bool, error)
	Shutdown() (bool, error)
	Restart() (bool, error)
{'fraction_non_alphanumeric': 0.1538784067085954, 'fraction_numerical': 0.0067085953878406705, 'mean_word_length': 3.600771456123433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 36}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4575564', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1669, 'n_words': 425}