From 0f37d0e1f2aeee466b3c6179886963354eaa6222 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 24 Sep 2011 20:22:53 +0200 Subject: sockets.recv optimizations; stdlib now supports taint mode --- lib/impure/rdstdin.nim | 8 ++++---- lib/impure/ssl.nim | 6 +++--- lib/impure/web.nim | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'lib/impure') diff --git a/lib/impure/rdstdin.nim b/lib/impure/rdstdin.nim index 003cfa3d1..bc523187a 100755 --- a/lib/impure/rdstdin.nim +++ b/lib/impure/rdstdin.nim @@ -14,7 +14,7 @@ ## wanted functionality. when defined(Windows): - proc ReadLineFromStdin*(prompt: string): string = + proc ReadLineFromStdin*(prompt: string): TaintedString = ## Reads a line from stdin. stdout.write(prompt) result = readLine(stdin) @@ -22,11 +22,11 @@ when defined(Windows): else: import readline, history - proc ReadLineFromStdin*(prompt: string): string = + proc ReadLineFromStdin*(prompt: string): TaintedString = var buffer = readline.readLine(prompt) if isNil(buffer): quit(0) - result = $buffer - if result.len > 0: + result = TaintedString($buffer) + if result.string.len > 0: add_history(buffer) readline.free(buffer) diff --git a/lib/impure/ssl.nim b/lib/impure/ssl.nim index ab53d0538..80e75f726 100755 --- a/lib/impure/ssl.nim +++ b/lib/impure/ssl.nim @@ -50,11 +50,11 @@ proc connect*(sock: var TSecureSocket, address: string, result = SSL_get_verify_result(sock.ssl) -proc recvLine*(sock: TSecureSocket, line: var string): bool = +proc recvLine*(sock: TSecureSocket, line: var TaintedString): bool = ## Acts in a similar fashion to the `recvLine` in the sockets module. ## Returns false when no data is available to be read. ## `Line` must be initialized and not nil! - setLen(line, 0) + setLen(line.string, 0) while True: var c: array[0..0, char] var n = BIO_read(sock.bio, c, c.len) @@ -66,7 +66,7 @@ proc recvLine*(sock: TSecureSocket, line: var string): bool = elif n <= 0: return False elif c[0] == '\L': return True - add(line, c) + add(line.string, c) proc send*(sock: TSecureSocket, data: string) = diff --git a/lib/impure/web.nim b/lib/impure/web.nim index af302cc57..f4009ba80 100755 --- a/lib/impure/web.nim +++ b/lib/impure/web.nim @@ -43,19 +43,19 @@ proc URLretrieveStream*(url: string): PStream = if easy_perform(hCurl) != E_OK: return nil easy_cleanup(hCurl) -proc URLretrieveString*(url: string): string = +proc URLretrieveString*(url: string): TaintedString = ## retrieves the given `url` and returns the contents. Returns nil if an ## error occurs. var stream = newStringStream() var hCurl = easy_init() - if hCurl == nil: return nil - if easy_setopt(hCurl, OPT_URL, url) != E_OK: return nil + if hCurl == nil: return + if easy_setopt(hCurl, OPT_URL, url) != E_OK: return if easy_setopt(hCurl, OPT_WRITEFUNCTION, - curlwrapperWrite) != E_OK: return nil - if easy_setopt(hCurl, OPT_WRITEDATA, stream) != E_OK: return nil - if easy_perform(hCurl) != E_OK: return nil + curlwrapperWrite) != E_OK: return + if easy_setopt(hCurl, OPT_WRITEDATA, stream) != E_OK: return + if easy_perform(hCurl) != E_OK: return easy_cleanup(hCurl) - result = stream.data + result = stream.data.TaintedString when isMainModule: echo URLretrieveString("http://nimrod.ethexor.com/") -- cgit 1.4.1-2-gfad0