2
0

protocol.luadoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ---[[
  2. LuCI http protocol class.
  3. This class contains several functions useful for http message- and content
  4. decoding and to retrive form data from raw http messages.
  5. ]]
  6. module "luci.http.protocol"
  7. ---[[
  8. Decode an urlencoded string - optionally without decoding
  9. the "+" sign to " " - and return the decoded string.
  10. @class function
  11. @name urldecode
  12. @param str Input string in x-www-urlencoded format
  13. @param no_plus Don't decode "+" signs to spaces
  14. @return The decoded string
  15. @see urlencode
  16. ]]
  17. ---[[
  18. Extract and split urlencoded data pairs, separated bei either "&" or ";"
  19. from given url or string. Returns a table with urldecoded values.
  20. Simple parameters are stored as string values associated with the parameter
  21. name within the table. Parameters with multiple values are stored as array
  22. containing the corresponding values.
  23. @class function
  24. @name urldecode_params
  25. @param url The url or string which contains x-www-urlencoded form data
  26. @param tbl Use the given table for storing values (optional)
  27. @return Table containing the urldecoded parameters
  28. @see urlencode_params
  29. ]]
  30. ---[[
  31. Encode given string to x-www-urlencoded format.
  32. @class function
  33. @name urlencode
  34. @param str String to encode
  35. @return String containing the encoded data
  36. @see urldecode
  37. ]]
  38. ---[[
  39. Encode each key-value-pair in given table to x-www-urlencoded format,
  40. separated by "&". Tables are encoded as parameters with multiple values by
  41. repeating the parameter name with each value.
  42. @class function
  43. @name urlencode_params
  44. @param tbl Table with the values
  45. @return String containing encoded values
  46. @see urldecode_params
  47. ]]
  48. ---[[
  49. Creates a ltn12 source from the given socket. The source will return it's
  50. data line by line with the trailing \r\n stripped of.
  51. @class function
  52. @name header_source
  53. @param sock Readable network socket
  54. @return Ltn12 source function
  55. ]]
  56. ---[[
  57. Decode a mime encoded http message body with multipart/form-data
  58. Content-Type. Stores all extracted data associated with its parameter name
  59. in the params table withing the given message object. Multiple parameter
  60. values are stored as tables, ordinary ones as strings.
  61. If an optional file callback function is given then it is feeded with the
  62. file contents chunk by chunk and only the extracted file name is stored
  63. within the params table. The callback function will be called subsequently
  64. with three arguments:
  65. o Table containing decoded (name, file) and raw (headers) mime header data
  66. o String value containing a chunk of the file data
  67. o Boolean which indicates wheather the current chunk is the last one (eof)
  68. @class function
  69. @name mimedecode_message_body
  70. @param src Ltn12 source function
  71. @param msg HTTP message object
  72. @param filecb File callback function (optional)
  73. @return Value indicating successful operation (not nil means "ok")
  74. @return String containing the error if unsuccessful
  75. @see parse_message_header
  76. ]]
  77. ---[[
  78. Decode an urlencoded http message body with application/x-www-urlencoded
  79. Content-Type. Stores all extracted data associated with its parameter name
  80. in the params table withing the given message object. Multiple parameter
  81. values are stored as tables, ordinary ones as strings.
  82. @class function
  83. @name urldecode_message_body
  84. @param src Ltn12 source function
  85. @param msg HTTP message object
  86. @return Value indicating successful operation (not nil means "ok")
  87. @return String containing the error if unsuccessful
  88. @see parse_message_header
  89. ]]
  90. ---[[
  91. Try to extract an http message header including information like protocol
  92. version, message headers and resulting CGI environment variables from the
  93. given ltn12 source.
  94. @class function
  95. @name parse_message_header
  96. @param src Ltn12 source function
  97. @return HTTP message object
  98. @see parse_message_body
  99. ]]
  100. ---[[
  101. Try to extract and decode a http message body from the given ltn12 source.
  102. This function will examine the Content-Type within the given message object
  103. to select the appropriate content decoder.
  104. Currently the application/x-www-urlencoded and application/form-data
  105. mime types are supported. If the encountered content encoding can't be
  106. handled then the whole message body will be stored unaltered as "content"
  107. property within the given message object.
  108. @class function
  109. @name parse_message_body
  110. @param src Ltn12 source function
  111. @param msg HTTP message object
  112. @param filecb File data callback (optional, see mimedecode_message_body())
  113. @return Value indicating successful operation (not nil means "ok")
  114. @return String containing the error if unsuccessful
  115. @see parse_message_header
  116. ]]
  117. ---[[
  118. Table containing human readable messages for several http status codes.
  119. @class table
  120. ]]