request_callback_windows.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //go:build windows
  2. package yu_curl
  3. import (
  4. yu_fast "gogs.qqck.cn/s/tools/fast"
  5. yu_http "gogs.qqck.cn/s/tools/http"
  6. yu_strings "gogs.qqck.cn/s/tools/strings"
  7. "strings"
  8. "syscall"
  9. "unsafe"
  10. )
  11. var callback_PREREQFUNCTION_ptr = syscall.NewCallbackCDecl(func(userdata, conn_primary_ip, conn_local_ip, conn_primary_port, conn_local_port uintptr) uintptr {
  12. t := (*Request)(unsafe.Pointer(userdata))
  13. t.resp_reset()
  14. return PREREQFUNC_OK
  15. })
  16. var callback_WRITEFUNCTION_ptr = syscall.NewCallbackCDecl(func(buffer uintptr, size uintptr, nmemb uintptr, userdata uintptr) uintptr {
  17. t := (*Request)(unsafe.Pointer(userdata))
  18. t.resp_body = append(t.resp_body, yu_fast.P2B(buffer, size*nmemb)...)
  19. return size * nmemb
  20. })
  21. var callback_HEADERFUNCTION_ptr = syscall.NewCallbackCDecl(func(bheader uintptr, size uintptr, nitems uintptr, userdata uintptr) uintptr {
  22. t := (*Request)(unsafe.Pointer(userdata))
  23. j_headers := yu_strings.GbkPtrLenToUtf8(bheader, size*nitems)
  24. t.resp_headers_raw = append(t.resp_headers_raw, j_headers...)
  25. if strings.HasSuffix(j_headers, "\r\n") {
  26. j_headers = j_headers[:len(j_headers)-2]
  27. }
  28. if strings.HasSuffix(j_headers, "\n") {
  29. j_headers = j_headers[:len(j_headers)-1]
  30. }
  31. if j_headers == "" {
  32. return size * nitems
  33. }
  34. j_key, j_value := yu_strings.Left(j_headers, ":"), yu_strings.Empty(yu_strings.Right(j_headers, ":"))
  35. if j_key != "" && j_value != "" {
  36. j_key = yu_http.Normalize(j_key)
  37. if j_key == "Set-Cookie" {
  38. if strings.Index(j_value, ";") > -1 {
  39. j_value = yu_strings.Left(j_value, ";")
  40. }
  41. if strings.Index(j_value, "=") == -1 {
  42. return size * nitems
  43. }
  44. j_key, j_value = yu_strings.Left(j_value, "="), yu_strings.Empty(yu_strings.Right(j_value, "="))
  45. if j_value == "" {
  46. delete(t.resp_cookies, j_key)
  47. } else {
  48. t.resp_cookies[j_key] = j_value
  49. }
  50. if t.cookies_updata {
  51. t.SetCookie(j_key, j_value)
  52. }
  53. } else {
  54. t.resp_headers[j_key] = j_value
  55. }
  56. }
  57. return size * nitems
  58. })