Fixed recvLine deprecation warnings.

This commit is contained in:
Dominik Picheta 2013-04-14 01:00:38 +01:00
commit e3d097c4e9
6 changed files with 72 additions and 80 deletions

View file

@ -126,7 +126,7 @@ type
handleTask*: proc (s: PAsyncSocket) {.closure.} handleTask*: proc (s: PAsyncSocket) {.closure.}
lineBuffer: TaintedString ## Temporary storage for ``recvLine`` lineBuffer: TaintedString ## Temporary storage for ``readLine``
sendBuffer: string ## Temporary storage for ``send`` sendBuffer: string ## Temporary storage for ``send``
sslNeedAccept: bool sslNeedAccept: bool
proto: TProtocol proto: TProtocol
@ -635,7 +635,7 @@ when isMainModule:
proc testRead(s: PAsyncSocket, no: int) = proc testRead(s: PAsyncSocket, no: int) =
echo("Reading! " & $no) echo("Reading! " & $no)
var data = "" var data = ""
if not s.recvLine(data): if not s.readLine(data):
OSError() OSError()
if data == "": if data == "":
echo("Closing connection. " & $no) echo("Closing connection. " & $no)

View file

@ -124,7 +124,7 @@ template blockingOperation(sock: TSocket, body: stmt) {.immediate.} =
proc expectReply(ftp: PFTPClient): TaintedString = proc expectReply(ftp: PFTPClient): TaintedString =
result = TaintedString"" result = TaintedString""
blockingOperation(ftp.getCSock()): blockingOperation(ftp.getCSock()):
if not ftp.getCSock().recvLine(result): setLen(result.string, 0) ftp.getCSock().readLine(result)
proc send*(ftp: PFTPClient, m: string): TaintedString = proc send*(ftp: PFTPClient, m: string): TaintedString =
## Send a message to the server, and wait for a primary reply. ## Send a message to the server, and wait for a primary reply.
@ -280,19 +280,18 @@ proc getLines(ftp: PFTPClient, async: bool = false): bool =
if ftp.dsockConnected: if ftp.dsockConnected:
var r = TaintedString"" var r = TaintedString""
if ftp.isAsync: if ftp.isAsync:
if ftp.asyncDSock.recvLine(r): if ftp.asyncDSock.readLine(r):
if r.string == "": if r.string == "":
ftp.dsockConnected = false ftp.dsockConnected = false
else: else:
ftp.job.lines.add(r.string & "\n") ftp.job.lines.add(r.string & "\n")
else: else:
assert(not async) assert(not async)
if ftp.dsock.recvLine(r): ftp.dsock.readLine(r)
if r.string == "": if r.string == "":
ftp.dsockConnected = false ftp.dsockConnected = false
else: else:
ftp.job.lines.add(r.string & "\n") ftp.job.lines.add(r.string & "\n")
else: OSError()
if not async: if not async:
var readSocks: seq[TSocket] = @[ftp.getCSock()] var readSocks: seq[TSocket] = @[ftp.getCSock()]

View file

@ -100,27 +100,27 @@ proc parseChunks(s: TSocket, timeout: int): string =
while true: while true:
var chunkSizeStr = "" var chunkSizeStr = ""
var chunkSize = 0 var chunkSize = 0
if s.recvLine(chunkSizeStr, timeout): s.readLine(chunkSizeStr, timeout)
var i = 0 var i = 0
if chunkSizeStr == "": if chunkSizeStr == "":
httpError("Server terminated connection prematurely") httpError("Server terminated connection prematurely")
while true: while true:
case chunkSizeStr[i] case chunkSizeStr[i]
of '0'..'9': of '0'..'9':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('0')) chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('0'))
of 'a'..'f': of 'a'..'f':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('a') + 10) chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('a') + 10)
of 'A'..'F': of 'A'..'F':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('A') + 10) chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('A') + 10)
of '\0': of '\0':
break break
of ';': of ';':
# http://tools.ietf.org/html/rfc2616#section-3.6.1 # http://tools.ietf.org/html/rfc2616#section-3.6.1
# We don't care about chunk-extensions. # We don't care about chunk-extensions.
break break
else: else:
httpError("Invalid chunk size: " & chunkSizeStr) httpError("Invalid chunk size: " & chunkSizeStr)
inc(i) inc(i)
if chunkSize <= 0: break if chunkSize <= 0: break
result.setLen(ri+chunkSize) result.setLen(ri+chunkSize)
var bytesRead = 0 var bytesRead = 0
@ -175,39 +175,38 @@ proc parseResponse(s: TSocket, getBody: bool, timeout: int): TResponse =
while True: while True:
line = "" line = ""
linei = 0 linei = 0
if s.recvLine(line, timeout): s.readLine(line, timeout)
if line == "": break # We've been disconnected. if line == "": break # We've been disconnected.
if line == "\c\L": if line == "\c\L":
fullyRead = true fullyRead = true
break break
if not parsedStatus: if not parsedStatus:
# Parse HTTP version info and status code. # Parse HTTP version info and status code.
var le = skipIgnoreCase(line, "HTTP/", linei) var le = skipIgnoreCase(line, "HTTP/", linei)
if le <= 0: httpError("invalid http version") if le <= 0: httpError("invalid http version")
inc(linei, le) inc(linei, le)
le = skipIgnoreCase(line, "1.1", linei) le = skipIgnoreCase(line, "1.1", linei)
if le > 0: result.version = "1.1" if le > 0: result.version = "1.1"
else:
le = skipIgnoreCase(line, "1.0", linei)
if le <= 0: httpError("unsupported http version")
result.version = "1.0"
inc(linei, le)
# Status code
linei.inc skipWhitespace(line, linei)
result.status = line[linei .. -1]
parsedStatus = true
else: else:
# Parse headers le = skipIgnoreCase(line, "1.0", linei)
var name = "" if le <= 0: httpError("unsupported http version")
var le = parseUntil(line, name, ':', linei) result.version = "1.0"
if le <= 0: httpError("invalid headers") inc(linei, le)
inc(linei, le) # Status code
if line[linei] != ':': httpError("invalid headers") linei.inc skipWhitespace(line, linei)
inc(linei) # Skip : result.status = line[linei .. -1]
linei += skipWhitespace(line, linei) parsedStatus = true
else:
# Parse headers
var name = ""
var le = parseUntil(line, name, ':', linei)
if le <= 0: httpError("invalid headers")
inc(linei, le)
if line[linei] != ':': httpError("invalid headers")
inc(linei) # Skip :
linei += skipWhitespace(line, linei)
result.headers[name] = line[linei.. -1] result.headers[name] = line[linei.. -1]
else: SocketError(s)
if not fullyRead: if not fullyRead:
httpError("Connection was closed before full request has been made") httpError("Connection was closed before full request has been made")
if getBody: if getBody:

View file

@ -345,9 +345,9 @@ proc poll*(irc: PIRC, ev: var TIRCEvent,
var socks = @[irc.sock] var socks = @[irc.sock]
var ret = socks.select(timeout) var ret = socks.select(timeout)
if socks.len() == 0 and ret != 0: if socks.len() == 0 and ret != 0:
if irc.sock.recvLine(line): irc.sock.readLine(line)
ev = irc.processLine(line.string) ev = irc.processLine(line.string)
result = true result = true
if processOther(irc, ev): result = true if processOther(irc, ev): result = true
@ -380,7 +380,7 @@ proc handleConnect(s: PAsyncSocket, irc: PAsyncIRC) =
proc handleRead(s: PAsyncSocket, irc: PAsyncIRC) = proc handleRead(s: PAsyncSocket, irc: PAsyncIRC) =
var line = "".TaintedString var line = "".TaintedString
var ret = s.recvLine(line) var ret = s.readLine(line)
if ret: if ret:
if line == "": if line == "":
var ev: TIRCEvent var ev: TIRCEvent

View file

@ -28,9 +28,6 @@
## For SSL support this module relies on OpenSSL. If you want to ## For SSL support this module relies on OpenSSL. If you want to
## enable SSL, compile with ``-d:ssl``. ## enable SSL, compile with ``-d:ssl``.
when not defined(ssl):
{.error: "The SMTP module should be compiled with SSL support. Compile with -d:ssl."}
import sockets, strutils, strtabs, base64, os import sockets, strutils, strtabs, base64, os
type type
@ -54,16 +51,11 @@ proc debugSend(smtp: TSMTP, cmd: string) =
proc debugRecv(smtp: var TSMTP): TaintedString = proc debugRecv(smtp: var TSMTP): TaintedString =
var line = TaintedString"" var line = TaintedString""
var ret = False smtp.sock.readLine(line)
ret = smtp.sock.recvLine(line)
if ret: if smtp.debug:
if smtp.debug: echo("S:" & line.string)
echo("S:" & line.string) return line
return line
else:
OSError()
return TaintedString""
proc quitExcpt(smtp: TSMTP, msg: string) = proc quitExcpt(smtp: TSMTP, msg: string) =
smtp.debugSend("QUIT") smtp.debugSend("QUIT")

View file

@ -35,6 +35,8 @@ Changes affecting backwards compatibility
----------------------------------------- -----------------------------------------
- ``shared`` is a keyword now. - ``shared`` is a keyword now.
- Deprecated ``sockets.recvLine`` and ``asyncio.recvLine``, added
``readLine`` instead.
Compiler Additions Compiler Additions