From e3d097c4e996616147166f3eb213813b89ec3f9f Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sun, 14 Apr 2013 01:00:38 +0100 Subject: Fixed recvLine deprecation warnings. --- lib/pure/asyncio.nim | 4 +- lib/pure/ftpclient.nim | 15 ++++--- lib/pure/httpclient.nim | 105 ++++++++++++++++++++++++------------------------ lib/pure/irc.nim | 10 ++--- lib/pure/smtp.nim | 18 +++------ 5 files changed, 71 insertions(+), 81 deletions(-) (limited to 'lib') diff --git a/lib/pure/asyncio.nim b/lib/pure/asyncio.nim index c5c1f5696..88e3e848f 100644 --- a/lib/pure/asyncio.nim +++ b/lib/pure/asyncio.nim @@ -126,7 +126,7 @@ type handleTask*: proc (s: PAsyncSocket) {.closure.} - lineBuffer: TaintedString ## Temporary storage for ``recvLine`` + lineBuffer: TaintedString ## Temporary storage for ``readLine`` sendBuffer: string ## Temporary storage for ``send`` sslNeedAccept: bool proto: TProtocol @@ -635,7 +635,7 @@ when isMainModule: proc testRead(s: PAsyncSocket, no: int) = echo("Reading! " & $no) var data = "" - if not s.recvLine(data): + if not s.readLine(data): OSError() if data == "": echo("Closing connection. " & $no) diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index b61793866..7893eafa0 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -124,7 +124,7 @@ template blockingOperation(sock: TSocket, body: stmt) {.immediate.} = proc expectReply(ftp: PFTPClient): TaintedString = result = TaintedString"" blockingOperation(ftp.getCSock()): - if not ftp.getCSock().recvLine(result): setLen(result.string, 0) + ftp.getCSock().readLine(result) proc send*(ftp: PFTPClient, m: string): TaintedString = ## 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: var r = TaintedString"" if ftp.isAsync: - if ftp.asyncDSock.recvLine(r): + if ftp.asyncDSock.readLine(r): if r.string == "": ftp.dsockConnected = false else: ftp.job.lines.add(r.string & "\n") else: assert(not async) - if ftp.dsock.recvLine(r): - if r.string == "": - ftp.dsockConnected = false - else: - ftp.job.lines.add(r.string & "\n") - else: OSError() + ftp.dsock.readLine(r) + if r.string == "": + ftp.dsockConnected = false + else: + ftp.job.lines.add(r.string & "\n") if not async: var readSocks: seq[TSocket] = @[ftp.getCSock()] diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index cc0129b45..ab6cb04a9 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -100,27 +100,27 @@ proc parseChunks(s: TSocket, timeout: int): string = while true: var chunkSizeStr = "" var chunkSize = 0 - if s.recvLine(chunkSizeStr, timeout): - var i = 0 - if chunkSizeStr == "": - httpError("Server terminated connection prematurely") - while true: - case chunkSizeStr[i] - of '0'..'9': - chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('0')) - of 'a'..'f': - chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('a') + 10) - of 'A'..'F': - chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('A') + 10) - of '\0': - break - of ';': - # http://tools.ietf.org/html/rfc2616#section-3.6.1 - # We don't care about chunk-extensions. - break - else: - httpError("Invalid chunk size: " & chunkSizeStr) - inc(i) + s.readLine(chunkSizeStr, timeout) + var i = 0 + if chunkSizeStr == "": + httpError("Server terminated connection prematurely") + while true: + case chunkSizeStr[i] + of '0'..'9': + chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('0')) + of 'a'..'f': + chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('a') + 10) + of 'A'..'F': + chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('A') + 10) + of '\0': + break + of ';': + # http://tools.ietf.org/html/rfc2616#section-3.6.1 + # We don't care about chunk-extensions. + break + else: + httpError("Invalid chunk size: " & chunkSizeStr) + inc(i) if chunkSize <= 0: break result.setLen(ri+chunkSize) var bytesRead = 0 @@ -175,39 +175,38 @@ proc parseResponse(s: TSocket, getBody: bool, timeout: int): TResponse = while True: line = "" linei = 0 - if s.recvLine(line, timeout): - if line == "": break # We've been disconnected. - if line == "\c\L": - fullyRead = true - break - if not parsedStatus: - # Parse HTTP version info and status code. - var le = skipIgnoreCase(line, "HTTP/", linei) - if le <= 0: httpError("invalid http version") - inc(linei, le) - le = skipIgnoreCase(line, "1.1", linei) - 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 + s.readLine(line, timeout) + if line == "": break # We've been disconnected. + if line == "\c\L": + fullyRead = true + break + if not parsedStatus: + # Parse HTTP version info and status code. + var le = skipIgnoreCase(line, "HTTP/", linei) + if le <= 0: httpError("invalid http version") + inc(linei, le) + le = skipIgnoreCase(line, "1.1", linei) + if le > 0: result.version = "1.1" 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] - else: SocketError(s) + 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: + # 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] if not fullyRead: httpError("Connection was closed before full request has been made") if getBody: diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim index aa4e2d557..74ad7e26a 100644 --- a/lib/pure/irc.nim +++ b/lib/pure/irc.nim @@ -345,10 +345,10 @@ proc poll*(irc: PIRC, ev: var TIRCEvent, var socks = @[irc.sock] var ret = socks.select(timeout) if socks.len() == 0 and ret != 0: - if irc.sock.recvLine(line): - ev = irc.processLine(line.string) - result = true - + irc.sock.readLine(line) + ev = irc.processLine(line.string) + result = true + if processOther(irc, ev): result = true proc getLag*(irc: PIRC): float = @@ -380,7 +380,7 @@ proc handleConnect(s: PAsyncSocket, irc: PAsyncIRC) = proc handleRead(s: PAsyncSocket, irc: PAsyncIRC) = var line = "".TaintedString - var ret = s.recvLine(line) + var ret = s.readLine(line) if ret: if line == "": var ev: TIRCEvent diff --git a/lib/pure/smtp.nim b/lib/pure/smtp.nim index abf268942..6a3f65279 100644 --- a/lib/pure/smtp.nim +++ b/lib/pure/smtp.nim @@ -28,9 +28,6 @@ ## For SSL support this module relies on OpenSSL. If you want to ## 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 type @@ -54,16 +51,11 @@ proc debugSend(smtp: TSMTP, cmd: string) = proc debugRecv(smtp: var TSMTP): TaintedString = var line = TaintedString"" - var ret = False - ret = smtp.sock.recvLine(line) - - if ret: - if smtp.debug: - echo("S:" & line.string) - return line - else: - OSError() - return TaintedString"" + smtp.sock.readLine(line) + + if smtp.debug: + echo("S:" & line.string) + return line proc quitExcpt(smtp: TSMTP, msg: string) = smtp.debugSend("QUIT") -- cgit 1.4.1-2-gfad0