本文整理汇总了Golang中net/textproto.Conn.PrintfLine方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.PrintfLine方法的具体用法?Golang Conn.PrintfLine怎么用?Golang Conn.PrintfLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/textproto.Conn
的用法示例。
在下文中一共展示了Conn.PrintfLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleStreaming
// handle streaming event
// this function should send only
func (self nntpConnection) handleStreaming(daemon NNTPDaemon, reader bool, conn *textproto.Conn) (err error) {
select {
case msgid := <-self.check:
log.Println(self.name, "CHECK", msgid)
err = conn.PrintfLine("CHECK %s", msgid)
case msgid := <-self.take:
// send a file via TAKETHIS
if ValidMessageID(msgid) {
fname := daemon.store.GetFilename(msgid)
if CheckFile(fname) {
f, err := os.Open(fname)
if err == nil {
// time to send
err = conn.PrintfLine("TAKETHIS %s", msgid)
dw := conn.DotWriter()
_, err = io.Copy(dw, f)
err = dw.Close()
f.Close()
}
} else {
log.Println(self.name, "didn't send", msgid, "we don't have it locally")
}
}
}
return
}
示例2: handleStreamEvent
// handle sending 1 stream event
func (self *nntpConnection) handleStreamEvent(ev nntpStreamEvent, daemon *NNTPDaemon, conn *textproto.Conn) (err error) {
if ValidMessageID(ev.MessageID()) {
cmd, msgid := ev.Command(), ev.MessageID()
if cmd == "TAKETHIS" {
// open message for reading
var rc io.ReadCloser
rc, err = daemon.store.OpenMessage(msgid)
if err == nil {
err = conn.PrintfLine("%s", ev)
// time to send
dw := conn.DotWriter()
_, err = io.Copy(dw, rc)
err = dw.Close()
rc.Close()
self.messageSetPendingState(msgid, "sent")
} else {
log.Println(self.name, "didn't send", msgid, err)
self.messageSetProcessed(msgid)
// ignore this error
err = nil
}
} else if cmd == "CHECK" {
conn.PrintfLine("%s", ev)
} else {
log.Println("invalid stream command", ev)
}
}
return
}
示例3: startReader
func (self *nntpConnection) startReader(daemon *NNTPDaemon, conn *textproto.Conn) {
log.Println(self.name, "run reader mode")
for {
var err error
select {
case chnl := <-self.die:
// we were asked to die
// send quit
conn.PrintfLine("QUIT")
chnl <- true
break
case msgid := <-self.article:
// next article to ask for
log.Println(self.name, "obtaining", msgid)
self.messageSetPendingState(msgid, "article")
err = self.requestArticle(daemon, conn, msgid)
self.messageSetProcessed(msgid)
if err != nil {
log.Println(self.name, "error while in reader mode:", err)
break
}
}
}
// close connection
conn.Close()
}
示例4: handleIHave
func handleIHave(args []string, s *session, c *textproto.Conn) error {
if !s.backend.AllowPost() {
return NotWanted
}
// XXX: See if we have it.
article, err := s.backend.GetArticle(nil, args[0])
if article != nil {
return NotWanted
}
c.PrintfLine("335 send it")
article = new(nntp.Article)
article.Header, err = c.ReadMIMEHeader()
if err != nil {
return PostingFailed
}
article.Body = c.DotReader()
err = s.backend.Post(article)
if err != nil {
return err
}
c.PrintfLine("235 article received OK")
return nil
}
示例5: handleStreaming
// handle streaming event
// this function should send only
func (self *nntpConnection) handleStreaming(daemon NNTPDaemon, reader bool, conn *textproto.Conn) (err error) {
for err == nil {
ev := <-self.stream
log.Println(self.name, ev)
if ValidMessageID(ev.MessageID()) {
cmd, msgid := ev.Command(), ev.MessageID()
if cmd == "TAKETHIS" {
fname := daemon.store.GetFilename(msgid)
if CheckFile(fname) {
f, err := os.Open(fname)
if err == nil {
err = conn.PrintfLine("%s", ev)
// time to send
dw := conn.DotWriter()
_, err = io.Copy(dw, f)
err = dw.Close()
f.Close()
}
} else {
log.Println(self.name, "didn't send", msgid, "we don't have it locally")
}
} else if cmd == "CHECK" {
conn.PrintfLine("%s", ev)
} else {
log.Println("invalid stream command", ev)
}
}
}
return
}
示例6: handleList
func handleList(args []string, s *session, c *textproto.Conn) error {
ltype := "active"
if len(args) > 0 {
ltype = strings.ToLower(args[0])
}
if ltype == "overview.fmt" {
dw := c.DotWriter()
defer dw.Close()
return handleListOverviewFmt(dw, c)
}
groups, err := s.backend.ListGroups(-1)
if err != nil {
return err
}
c.PrintfLine("215 list of newsgroups follows")
dw := c.DotWriter()
defer dw.Close()
for _, g := range groups {
switch ltype {
case "active":
fmt.Fprintf(dw, "%s %d %d %v\r\n",
g.Name, g.High, g.Low, g.Posting)
case "newsgroups":
fmt.Fprintf(dw, "%s %s\r\n", g.Name, g.Description)
}
}
return nil
}
示例7: handleMode
func handleMode(args []string, s *session, c *textproto.Conn) error {
if s.backend.AllowPost() {
c.PrintfLine("200 Posting allowed")
} else {
c.PrintfLine("201 Posting prohibited")
}
return nil
}
示例8: outboundHandshake
// outbound setup, check capabilities and set mode
// returns (supports stream, supports reader) + error
func (self nntpConnection) outboundHandshake(conn *textproto.Conn) (stream, reader bool, err error) {
log.Println(self.name, "outbound handshake")
var code int
var line string
for err == nil {
code, line, err = conn.ReadCodeLine(-1)
log.Println(self.name, line)
if err == nil {
if code == 200 {
// send capabilities
log.Println(self.name, "ask for capabilities")
err = conn.PrintfLine("CAPABILITIES")
if err == nil {
// read response
dr := conn.DotReader()
r := bufio.NewReader(dr)
for {
line, err = r.ReadString('\n')
if err == io.EOF {
// we are at the end of the dotreader
// set err back to nil and break out
err = nil
break
} else if err == nil {
// we got a line
if line == "MODE-READER\n" || line == "READER\n" {
log.Println(self.name, "supports READER")
reader = true
} else if line == "STREAMING\n" {
stream = true
log.Println(self.name, "supports STREAMING")
} else if line == "POSTIHAVESTREAMING\n" {
stream = true
reader = false
log.Println(self.name, "is SRNd")
}
} else {
// we got an error
log.Println("error reading capabilities", err)
break
}
}
// return after reading
return
}
} else if code == 201 {
log.Println("feed", self.name, "does not allow posting")
// we don't do auth yet
break
} else {
continue
}
}
}
return
}
示例9: requestArticle
// ask for an article from the remote server
// feed it to the daemon if we get it
func (self *nntpConnection) requestArticle(daemon NNTPDaemon, conn *textproto.Conn, msgid string) (err error) {
log.Println(self.name, "asking for", msgid)
// send command
err = conn.PrintfLine("ARTICLE %s", msgid)
// read response
code, line, err := conn.ReadCodeLine(-1)
if code == 220 {
// awwww yeh we got it
var hdr textproto.MIMEHeader
// read header
hdr, err = conn.ReadMIMEHeader()
if err == nil {
// prepare to read body
dr := conn.DotReader()
// check header and decide if we want this
reason, err := self.checkMIMEHeader(daemon, hdr)
if err == nil {
if len(reason) > 0 {
log.Println(self.name, "discarding", msgid, reason)
// we don't want it, discard
io.Copy(ioutil.Discard, dr)
daemon.database.BanArticle(msgid, reason)
} else {
// yeh we want it open up a file to store it in
f := daemon.store.CreateTempFile(msgid)
if f == nil {
// already being loaded elsewhere
} else {
// write header to file
writeMIMEHeader(f, hdr)
// write article body to file
_, _ = io.Copy(f, dr)
// close file
f.Close()
log.Println(msgid, "obtained via reader from", self.name)
// tell daemon to load article via infeed
daemon.infeed_load <- msgid
}
}
} else {
// error happened while processing
log.Println(self.name, "error happend while processing MIME header", err)
}
} else {
// error happened while reading header
log.Println(self.name, "error happened while reading MIME header", err)
}
} else if code == 430 {
// they don't know it D:
log.Println(msgid, "not known by", self.name)
} else {
// invalid response
log.Println(self.name, "invald response to ARTICLE:", code, line)
}
return
}
示例10: handleBody
func handleBody(args []string, s *session, c *textproto.Conn) error {
article, err := s.getArticle(args)
if err != nil {
return err
}
c.PrintfLine("222 1 %s", article.MessageId())
dw := c.DotWriter()
defer dw.Close()
_, err = io.Copy(dw, article.Body)
return err
}
示例11: handleHead
func handleHead(args []string, s *session, c *textproto.Conn) error {
article, err := s.getArticle(args)
if err != nil {
return err
}
c.PrintfLine("221 1 %s", article.MessageId())
dw := c.DotWriter()
defer dw.Close()
for k, v := range article.Header {
fmt.Fprintf(dw, "%s: %s\r\n", k, v[0])
}
return nil
}
示例12: GetRequest
func GetRequest(request Request, client *textproto.Conn) error {
var err error
defer func() {
if err != nil {
if err == io.EOF {
} else {
log.Println("Conn died with err %s", err)
}
}
}()
requestHeaders, err := client.ReadMIMEHeader()
if err != nil {
return err
}
response := fmt.Sprintf("Hello from Baboon!\nHave I seen you before?"+
"\nI know a bit about you.\n"+
"For example, your User Agent is %s", requestHeaders["User-Agent"])
serverHeaders := map[string]string{}
serverHeaders["Server"] = "Baboon/0.001"
serverHeaders["Content-Type"] = "text/plain"
serverHeaders["Content-Length"] = strconv.Itoa(len(response))
client.PrintfLine("HTTP/1.1 200 OK")
for key, value := range serverHeaders {
client.PrintfLine("%s: %s", key, value)
}
client.PrintfLine("")
client.PrintfLine(response)
return nil
}
示例13: handleListOverviewFmt
func handleListOverviewFmt(dw io.Writer, c *textproto.Conn) error {
err := c.PrintfLine("215 list of newsgroups follows")
if err != nil {
return err
}
_, err = fmt.Fprintln(dw, `Subject:
From:
Date:
Message-ID:
References:
:bytes
:lines`)
return err
}
示例14: requestArticle
// ask for an article from the remote server
// feed it to the daemon if we get it
func (self *nntpConnection) requestArticle(daemon *NNTPDaemon, conn *textproto.Conn, msgid string) (err error) {
// send command
err = conn.PrintfLine("ARTICLE %s", msgid)
// read response
code, line, err := conn.ReadCodeLine(-1)
if code == 220 {
// awwww yeh we got it
var hdr textproto.MIMEHeader
// read header
hdr, err = readMIMEHeader(conn.R)
if err == nil {
// prepare to read body
dr := conn.DotReader()
// check header and decide if we want this
reason, ban, err := self.checkMIMEHeaderNoAuth(daemon, hdr)
if err == nil {
if len(reason) > 0 {
log.Println(self.name, "discarding", msgid, reason)
// we don't want it, discard
io.Copy(ioutil.Discard, dr)
if ban {
daemon.database.BanArticle(msgid, reason)
}
} else {
// yeh we want it open up a file to store it in
err = self.storeMessage(daemon, hdr, dr)
if err != nil {
log.Println(self.name, "failed to obtain article", err)
// probably an invalid signature or format
daemon.database.BanArticle(msgid, err.Error())
}
}
} else {
// error happened while processing
log.Println(self.name, "error happend while processing MIME header", err)
}
} else {
// error happened while reading header
log.Println(self.name, "error happened while reading MIME header", err)
}
} else if code == 430 {
// they don't know it D:
} else {
// invalid response
log.Println(self.name, "invald response to ARTICLE:", code, line)
}
return
}
示例15: handleCap
func handleCap(args []string, s *session, c *textproto.Conn) error {
c.PrintfLine("101 Capability list:")
dw := c.DotWriter()
defer dw.Close()
fmt.Fprintf(dw, "VERSION 2\n")
fmt.Fprintf(dw, "READER\n")
if s.backend.AllowPost() {
fmt.Fprintf(dw, "POST\n")
fmt.Fprintf(dw, "IHAVE\n")
}
fmt.Fprintf(dw, "OVER\n")
fmt.Fprintf(dw, "XOVER\n")
fmt.Fprintf(dw, "LIST ACTIVE NEWSGROUPS OVERVIEW.FMT\n")
return nil
}