<commit_before>// Copyright (C) 2016 <NAME>. All rights reserved.
// This software may be modified and distributed under the terms
// of the MIT license.  See the LICENSE file for details

// +build ignore

package main

import (
	"database/sql"
	"io/ioutil"
	"log"

	_ "github.com/mattn/go-sqlite3"
	"github.com/vcabbage/trivialt"
)

func main() {
	// Create or open a sqlite database
	db, err := sql.Open("sqlite3", "tftp.db")
	if err != nil {
		log.Fatal(err)
	}

	// Create a simple table to hold the ip and sent log data from
	// the client.
	_, err = db.Exec(`CREATE TABLE IF NOT EXISTS tftplogs (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        ip TEXT,
        log TEXT
    );`)
	if err != nil {
		log.Fatal(err)
	}

	// Create a new server listening on port 6900, all interfaces
	server, err := trivialt.NewServer(":6900")
	if err != nil {
		log.Fatal(err)
	}

	// Set the server's write handler, read requests will be rejeccted
	server.WriteHandler(&tftpDB{db})

	// Start the server, if it fails error will be printed by log.Fatal
	log.Fatal(server.ListenAndServe())
}

// tftpDB embeds a *sql.DB and implements the trivialt.ReadHandler
// interface.
type tftpDB struct {
	*sql.DB
}

func (db *tftpDB) ReceiveTFTP(w trivialt.WriteRequest) {
	// Get the file size
	size, err := w.Size()

	// We're choosing to only store logs that are less than 1MB.
	// An error indicates no size was recieved.<commit_msg>Correct spelling mistake in database example<commit_after>// Copyright (C) 2016 <NAME>. All rights reserved.
// This software may be modified and distributed under the terms
// of the MIT license.  See the LICENSE file for details

// +build ignore

package main

import (
	"database/sql"
	"io/ioutil"
	"log"

	_ "github.com/mattn/go-sqlite3"
	"github.com/vcabbage/trivialt"
)

func main() {
	// Create or open a sqlite database
	db, err := sql.Open("sqlite3", "tftp.db")
	if err != nil {
		log.Fatal(err)
	}

	// Create a simple table to hold the ip and sent log data from
	// the client.
	_, err = db.Exec(`CREATE TABLE IF NOT EXISTS tftplogs (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        ip TEXT,
        log TEXT
    );`)
	if err != nil {
		log.Fatal(err)
	}

	// Create a new server listening on port 6900, all interfaces
	server, err := trivialt.NewServer(":6900")
	if err != nil {
		log.Fatal(err)
	}

	// Set the server's write handler, read requests will be rejeccted
	server.WriteHandler(&tftpDB{db})

	// Start the server, if it fails error will be printed by log.Fatal
	log.Fatal(server.ListenAndServe())
}

// tftpDB embeds a *sql.DB and implements the trivialt.ReadHandler
// interface.
type tftpDB struct {
	*sql.DB
}

func (db *tftpDB) ReceiveTFTP(w trivialt.WriteRequest) {
	// Get the file size
	size, err := w.Size()

	// We're choosing to only store logs that are less than 1MB.
	// An error indicates no size was received.
{'fraction_non_alphanumeric': 0.11269565217391304, 'fraction_numerical': 0.010434782608695653, 'mean_word_length': 3.1203438395415475, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2463067', 'n_tokens_mistral': 1037, 'n_tokens_neox': 960, 'n_words': 350}