about summary refs log tree commit diff stats
path: root/adapter/protocol
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-26 19:20:52 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-26 19:21:35 +0200
commit83dae4a87a78190262317eca15cbb5d25989d41b (patch)
tree3b706bd215e05ef8a07a3f102755a94dff2fe115 /adapter/protocol
parent3554f4c3241664d794d656240ccfa43cd99d84df (diff)
downloadchawan-83dae4a87a78190262317eca15cbb5d25989d41b.tar.gz
adapter: update code style
Diffstat (limited to 'adapter/protocol')
-rw-r--r--adapter/protocol/curl.nim44
-rw-r--r--adapter/protocol/curlwrap.nim12
-rw-r--r--adapter/protocol/dirlist.nim20
-rw-r--r--adapter/protocol/file.nim8
-rw-r--r--adapter/protocol/ftp.nim7
-rw-r--r--adapter/protocol/gopher.nim4
-rw-r--r--adapter/protocol/http.nim19
7 files changed, 57 insertions, 57 deletions
diff --git a/adapter/protocol/curl.nim b/adapter/protocol/curl.nim
index 74d24e6a..9e6aeda3 100644
--- a/adapter/protocol/curl.nim
+++ b/adapter/protocol/curl.nim
@@ -377,10 +377,10 @@ type
     CURLUPART_FRAGMENT
     CURLUPART_ZONEID # added in 7.65.0
 
-proc `==`*(a: CURL, b: CURL): bool {.borrow.}
-proc `==`*(a: CURL, b: typeof(nil)): bool {.borrow.}
-proc `==`*(a: CURLM, b: CURLM): bool {.borrow.}
-proc `==`*(a: CURLM, b: typeof(nil)): bool {.borrow.}
+proc `==`*(a: CURL; b: CURL): bool {.borrow.}
+proc `==`*(a: CURL; b: typeof(nil)): bool {.borrow.}
+proc `==`*(a: CURLM; b: CURLM): bool {.borrow.}
+proc `==`*(a: CURLM; b: typeof(nil)): bool {.borrow.}
 
 {.push importc.}
 
@@ -390,41 +390,45 @@ proc curl_free*(p: pointer)
 
 proc curl_easy_init*(): CURL
 proc curl_easy_cleanup*(handle: CURL)
-proc curl_easy_setopt*(handle: CURL, option: CURLoption): CURLcode {.varargs.}
+proc curl_easy_setopt*(handle: CURL; option: CURLoption): CURLcode {.varargs.}
 proc curl_easy_perform*(handle: CURL): CURLcode
-proc curl_easy_getinfo*(handle: CURL, info: CURLINFO): CURLcode {.varargs.}
+proc curl_easy_getinfo*(handle: CURL; info: CURLINFO): CURLcode {.varargs.}
 proc curl_easy_strerror*(errornum: CURLcode): cstring
 
 proc curl_url*(): CURLU
 proc curl_url_cleanup*(handle: CURLU)
 proc curl_url_dup*(inh: CURLU): CURLU
-proc curl_url_get*(handle: CURLU, what: CURLUPart, part: ptr cstring,
+proc curl_url_get*(handle: CURLU; what: CURLUPart; part: ptr cstring;
   flags: cuint): CURLUcode
-proc curl_url_set*(handle: CURLU, what: CURLUPart, part: cstring,
+proc curl_url_set*(handle: CURLU; what: CURLUPart; part: cstring;
   flags: cuint): CURLUcode
 proc curl_url_strerror*(code: CURLUcode): cstring
 
 proc curl_mime_init*(handle: CURL): curl_mime
 proc curl_mime_free*(mime: curl_mime)
 proc curl_mime_addpart*(mime: curl_mime): curl_mimepart
-proc curl_mime_name*(part: curl_mimepart, name: cstring)
-proc curl_mime_data*(part: curl_mimepart, data: pointer, datasize: csize_t)
-proc curl_mime_filename*(part: curl_mimepart, name: cstring)
-proc curl_mime_filedata*(part: curl_mimepart, filename: cstring)
+proc curl_mime_name*(part: curl_mimepart; name: cstring)
+proc curl_mime_data*(part: curl_mimepart; data: pointer; datasize: csize_t)
+proc curl_mime_filename*(part: curl_mimepart; name: cstring)
+proc curl_mime_filedata*(part: curl_mimepart; filename: cstring)
 
-proc curl_slist_append*(slist: curl_slist, str: cstring): curl_slist
+proc curl_slist_append*(slist: curl_slist; str: cstring): curl_slist
 proc curl_slist_free_all*(slist: curl_slist)
 
 proc curl_multi_init*(): CURLM
-proc curl_multi_add_handle*(multi_handle: CURLM, curl_handle: CURL): CURLMcode
-proc curl_multi_remove_handle*(multi_handle: CURLM, curl_handle: CURL): CURLMcode
-proc curl_multi_fdset*(multi_handle: CURLM, read_fd_set, write_fd_set, exc_fd_set: pointer, max_fd: ptr cint): CURLMcode
-proc curl_multi_wait*(multi_handle: CURLM, extra_fds: ptr curl_waitfd, extra_nfds: cuint, timeout_ns: cint, ret: ptr cint): CURLMcode
-proc curl_multi_poll*(multi_handle: CURLM, extra_fds: ptr curl_waitfd, extra_nfds: cuint, timeout_ns: cint, ret: ptr cint): CURLMcode
+proc curl_multi_add_handle*(multi_handle: CURLM; curl_handle: CURL): CURLMcode
+proc curl_multi_remove_handle*(multi_handle: CURLM; curl_handle: CURL): CURLMcode
+proc curl_multi_fdset*(multi_handle: CURLM; read_fd_set, write_fd_set,
+  exc_fd_set: pointer; max_fd: ptr cint): CURLMcode
+proc curl_multi_wait*(multi_handle: CURLM; extra_fds: ptr curl_waitfd;
+  extra_nfds: cuint; timeout_ns: cint; ret: ptr cint): CURLMcode
+proc curl_multi_poll*(multi_handle: CURLM; extra_fds: ptr curl_waitfd;
+  extra_nfds: cuint; timeout_ns: cint; ret: ptr cint): CURLMcode
 proc curl_multi_wakeup*(multi_handle: CURLM): CURLMcode
-proc curl_multi_perform*(multi_handle: CURLM, running_handles: ptr cint): CURLMcode
+proc curl_multi_perform*(multi_handle: CURLM; running_handles: ptr cint):
+  CURLMcode
 proc curl_multi_cleanup*(multi_handle: CURLM): CURLMcode
-proc curl_multi_info_read*(multi_handle: CURLM, msgs_in_queue: ptr cint): CURLMsg
+proc curl_multi_info_read*(multi_handle: CURLM; msgs_in_queue: ptr cint): CURLMsg
 proc curl_multi_strerror*(code: CURLMcode): cstring
 {.pop.}
 
diff --git a/adapter/protocol/curlwrap.nim b/adapter/protocol/curlwrap.nim
index c3c69a68..0f948542 100644
--- a/adapter/protocol/curlwrap.nim
+++ b/adapter/protocol/curlwrap.nim
@@ -1,21 +1,21 @@
 import curl
 
-template setopt*(curl: CURL, opt: CURLoption, arg: typed) =
+template setopt*(curl: CURL; opt: CURLoption; arg: typed) =
   discard curl_easy_setopt(curl, opt, arg)
 
-template setopt*(curl: CURL, opt: CURLoption, arg: string) =
+template setopt*(curl: CURL; opt: CURLoption; arg: string) =
   discard curl_easy_setopt(curl, opt, cstring(arg))
 
-template getinfo*(curl: CURL, info: CURLINFO, arg: typed) =
+template getinfo*(curl: CURL; info: CURLINFO; arg: typed) =
   discard curl_easy_getinfo(curl, info, arg)
 
-template set*(url: CURLU, part: CURLUPart, content: cstring, flags: cuint) =
+template set*(url: CURLU; part: CURLUPart; content: cstring; flags: cuint) =
   discard curl_url_set(url, part, content, flags)
 
-template set*(url: CURLU, part: CURLUPart, content: string, flags: cuint) =
+template set*(url: CURLU; part: CURLUPart; content: string; flags: cuint) =
   url.set(part, cstring(content), flags)
 
-template get*(url: CURLU, part: CURLUPart, flags: cuint): cstring =
+template get*(url: CURLU; part: CURLUPart; flags: cuint): cstring =
   var outs: cstring
   if curl_url_get(url, part, addr outs, flags) == CURLUE_OK:
     outs
diff --git a/adapter/protocol/dirlist.nim b/adapter/protocol/dirlist.nim
index a8623f35..7b284c15 100644
--- a/adapter/protocol/dirlist.nim
+++ b/adapter/protocol/dirlist.nim
@@ -4,17 +4,17 @@ import utils/strwidth
 import utils/twtstr
 
 type DirlistItemType = enum
-  ITEM_FILE, ITEM_LINK, ITEM_DIR
+  ditFile, ditLink, ditDir
 
 type DirlistItem* = object
   name*: string
   modified*: string
   case t*: DirlistItemType
-  of ITEM_LINK:
+  of ditLink:
     linkto*: string
-  of ITEM_FILE:
+  of ditFile:
     nsize*: int
-  of ITEM_DIR:
+  of ditDir:
     discard
 
 type NameWidthTuple = tuple[name: string, width: int, item: ptr DirlistItem]
@@ -24,9 +24,9 @@ func makeDirlist*(items: seq[DirlistItem]): string =
   var maxw = 20
   for item in items:
     var name = item.name
-    if item.t == ITEM_LINK:
+    if item.t == ditLink:
       name &= '@'
-    elif item.t == ITEM_DIR:
+    elif item.t == ditDir:
       name &= '/'
     let w = name.width()
     maxw = max(w, maxw)
@@ -36,11 +36,11 @@ func makeDirlist*(items: seq[DirlistItem]): string =
   for (name, width, itemp) in names.mitems:
     let item = itemp[]
     var path = percentEncode(item.name, PathPercentEncodeSet)
-    if item.t == ITEM_LINK:
+    if item.t == ditLink:
       if item.linkto.len > 0 and item.linkto[^1] == '/':
         # If the target is a directory, treat it as a directory. (For FTP.)
         path &= '/'
-    elif item.t == ITEM_DIR:
+    elif item.t == ditDir:
       path &= '/'
     var line = "<A HREF=\"" & path & "\">" & htmlEscape(name) & "</A>"
     while width <= maxw:
@@ -52,9 +52,9 @@ func makeDirlist*(items: seq[DirlistItem]): string =
     if line[^1] != ' ':
       line &= ' '
     line &= htmlEscape(item.modified)
-    if item.t == ITEM_FILE:
+    if item.t == ditFile:
       line &= ' ' & convertSize(item.nsize)
-    elif item.t == ITEM_LINK:
+    elif item.t == ditLink:
       line &= " -> " & htmlEscape(item.linkto)
     outs &= line & '\n'
   return outs
diff --git a/adapter/protocol/file.nim b/adapter/protocol/file.nim
index b77f725f..bd2c34a2 100644
--- a/adapter/protocol/file.nim
+++ b/adapter/protocol/file.nim
@@ -41,13 +41,13 @@ proc loadDir(path, opath: string) =
     case pc
     of pcDir:
       items.add(DirlistItem(
-        t: ITEM_DIR,
+        t: ditDir,
         name: file,
         modified: modified
       ))
     of pcFile:
       items.add(DirlistItem(
-        t: ITEM_FILE,
+        t: ditFile,
         name: file,
         modified: modified,
         nsize: int(info.size)
@@ -57,7 +57,7 @@ proc loadDir(path, opath: string) =
       if pc == pcLinkToDir:
         target &= '/'
       items.add(DirlistItem(
-        t: ITEM_LINK,
+        t: ditLink,
         name: file,
         modified: modified,
         linkto: target
@@ -71,7 +71,7 @@ proc loadFile(f: File) =
   const BufferSize = 16384
   var buffer {.noinit.}: array[BufferSize, char]
   while true:
-    let n = readBuffer(f, addr buffer[0], BufferSize)
+    let n = f.readBuffer(addr buffer[0], BufferSize)
     if n == 0:
       break
     let n2 = stdout.writeBuffer(addr buffer[0], n)
diff --git a/adapter/protocol/ftp.nim b/adapter/protocol/ftp.nim
index ee571130..4484180f 100644
--- a/adapter/protocol/ftp.nim
+++ b/adapter/protocol/ftp.nim
@@ -38,7 +38,6 @@ proc curlWriteHeader(p: cstring; size, nitems: csize_t; userdata: pointer):
     csize_t {.cdecl.} =
   var line = newString(nitems)
   if nitems > 0:
-    prepareMutation(line)
     copyMem(addr line[0], p, nitems)
   let op = cast[FtpHandle](userdata)
   if not op.statusline:
@@ -132,20 +131,20 @@ proc finish(op: FtpHandle) =
       let linkfrom = name.substr(0, linki - 1)
       let linkto = name.substr(linki + 4) # you?
       items.add(DirlistItem(
-        t: ITEM_LINK,
+        t: ditLink,
         name: linkfrom,
         modified: dates,
         linkto: linkto
       ))
     of 'd': # directory
       items.add(DirlistItem(
-        t: ITEM_DIR,
+        t: ditDir,
         name: name,
         modified: dates
       ))
     else: # file
       items.add(DirlistItem(
-        t: ITEM_FILE,
+        t: ditFile,
         name: name,
         modified: dates,
         nsize: int(nsize)
diff --git a/adapter/protocol/gopher.nim b/adapter/protocol/gopher.nim
index f266e857..8eb89508 100644
--- a/adapter/protocol/gopher.nim
+++ b/adapter/protocol/gopher.nim
@@ -30,7 +30,7 @@ proc onStatusLine(op: GopherHandle) =
   else: ""
   stdout.write(s & "\n")
 
-proc loadSearch(op: GopherHandle, surl: string) =
+proc loadSearch(op: GopherHandle; surl: string) =
   stdout.write("""
 Content-Type: text/html
 
@@ -49,7 +49,7 @@ Content-Type: text/html
 """)
 
 # From the documentation: size is always 1.
-proc curlWriteBody(p: cstring, size, nmemb: csize_t, userdata: pointer):
+proc curlWriteBody(p: cstring; size, nmemb: csize_t; userdata: pointer):
     csize_t {.cdecl.} =
   let op = cast[GopherHandle](userdata)
   if not op.statusline:
diff --git a/adapter/protocol/http.nim b/adapter/protocol/http.nim
index e2e53f22..f5e3249c 100644
--- a/adapter/protocol/http.nim
+++ b/adapter/protocol/http.nim
@@ -14,7 +14,7 @@ import utils/twtstr
 
 type
   EarlyHintState = enum
-    NO_EARLY_HINT, EARLY_HINT_STARTED, EARLY_HINT_DONE
+    ehsNone, ehsStarted, ehsDone
 
   HttpHandle = ref object
     curl: CURL
@@ -26,37 +26,34 @@ type
 proc puts(s: string) =
   discard write(1, unsafeAddr s[0], s.len)
 
-proc curlWriteHeader(p: cstring, size, nitems: csize_t, userdata: pointer):
+proc curlWriteHeader(p: cstring; size, nitems: csize_t; userdata: pointer):
     csize_t {.cdecl.} =
   var line = newString(nitems)
   if nitems > 0:
-    prepareMutation(line)
     copyMem(addr line[0], p, nitems)
-
   let op = cast[HttpHandle](userdata)
   if not op.statusline:
     op.statusline = true
     var status: clong
     op.curl.getinfo(CURLINFO_RESPONSE_CODE, addr status)
-    if status == 103 and op.earlyhint == NO_EARLY_HINT:
-      op.earlyhint = EARLY_HINT_STARTED
+    if status == 103 and op.earlyhint == ehsNone:
+      op.earlyhint = ehsStarted
     else:
       op.connectreport = true
       puts("Status: " & $status & "\nCha-Control: ControlDone\n")
     return nitems
-
   if line == "\r\n" or line == "\n":
     # empty line (last, before body)
-    if op.earlyhint == EARLY_HINT_STARTED:
+    if op.earlyhint == ehsStarted:
       # ignore; we do not have a way to stream headers yet.
-      op.earlyhint = EARLY_HINT_DONE
+      op.earlyhint = ehsDone
       # reset statusline; we are awaiting the next line.
       op.statusline = false
       return nitems
     puts("\r\n")
     return nitems
 
-  if op.earlyhint != EARLY_HINT_STARTED:
+  if op.earlyhint != ehsStarted:
     # Regrettably, we can only write early hint headers after the status
     # code is already known.
     # For now, it seems easiest to just ignore them all.
@@ -73,7 +70,7 @@ proc readFromStdin(p: pointer; size, nitems: csize_t; userdata: pointer):
     csize_t {.cdecl.} =
   return csize_t(read(0, p, int(nitems)))
 
-proc curlPreRequest(clientp: pointer, conn_primary_ip, conn_local_ip: cstring,
+proc curlPreRequest(clientp: pointer; conn_primary_ip, conn_local_ip: cstring;
     conn_primary_port, conn_local_port: cint): cint {.cdecl.} =
   let op = cast[HttpHandle](clientp)
   op.connectreport = true