Пример #1
0
func req(conn *client.Conn) {
	conn.Send("200 StoreD")
	for {
		tok, e := conn.ReadLine()
		if e != nil {
			fmt.Println(fmt.Sprintf("WARN: C(%s): %s", conn.RemoteAddr(), e.Error()))
			break
		}

		cmd := strings.ToUpper(tok[0])
		if cmd == "QUIT" {
			Quit(conn, tok)
			break
		} else if cmd == "ARTICLE" {
			Article(conn, tok)
		} else if cmd == "HEAD" {
			Head(conn, tok)
		} else if cmd == "BODY" {
			Body(conn, tok)
		} else if cmd == "STAT" {
			Stat(conn, tok)
		} else if cmd == "AUTHINFO" {
			sub := strings.ToUpper(tok[1])
			if sub == "USER" {
				conn.User = tok[2]
				conn.Send("381 Need more.")
			} else if sub == "PASS" {
				if tok[2] == "test" {
					conn.Send("281 Authentication accepted.")
				}
			}
		} else if cmd == "GROUP" {
			Group(conn, tok)
		} else if cmd == "NOOP" {
			conn.Send("500 Unsupported.")
		} else if cmd == "IHAVE" {
			PostArticle(conn, tok)
		} else if cmd == "POST" {
			if e := conn.Send("340 Start posting."); e != nil {
				conn.Send("437 Start failed.")
			}
			br := bufio.NewReader(conn.GetReader())
			if _, e := io.Copy(ioutil.Discard, dotreader.New(br)); e != nil {
				conn.Send("437 Failed reading body")
				return
			}
			if e := conn.Send("240 Posted "); e != nil {
				conn.Send("437 Failed storing.")
			}
		} else if cmd == "XOVER" {
			Xover(conn, tok)
		} else if cmd == "XHDR" {
			Xhdr(conn, tok)
		} else if cmd == "LIST" {
			List(conn, tok)
		} else if cmd == "DATE" {
			Date(conn, tok)
		} else {
			Unsupported(conn, tok)
			break
		}
	}

	conn.Close()
	if config.Verbose {
		fmt.Println(fmt.Sprintf("C(%s) Closed", conn.RemoteAddr()))
	}
}
Пример #2
0
func Unsupported(conn *client.Conn, tok []string) {
	fmt.Println(fmt.Sprintf("WARN: C(%s): Unsupported cmd %s", conn.RemoteAddr(), tok[0]))
	conn.Send("500 Unsupported.")
}