\hypertarget{group__form-parsing}{}\section{Form Parsing}
\label{group__form-parsing}\index{Form Parsing@{Form Parsing}}
\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef int($\ast$ \hyperlink{group__form-parsing_ga5a70527c0861c2ffa3d29333a6aa7f8e}{lws\+\_\+spa\+\_\+fileupload\+\_\+cb}) (void $\ast$data, const char $\ast$name, const char $\ast$filename, char $\ast$buf, int len, enum \hyperlink{group__form-parsing_ga41a74a822771d3dce89751aa3bce28ae}{lws\+\_\+spa\+\_\+fileupload\+\_\+states} state)
\end{DoxyCompactItemize}
\subsection*{Enumerations}
\begin{DoxyCompactItemize}
\item 
enum \hyperlink{group__form-parsing_ga41a74a822771d3dce89751aa3bce28ae}{lws\+\_\+spa\+\_\+fileupload\+\_\+states} \{ \hyperlink{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aead3a958e7719ac273c3ba4f684f00c87f}{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+C\+O\+N\+T\+E\+NT}, 
\hyperlink{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea6ce2a55a4c3695cdb640c893d95bd3a7}{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+F\+I\+N\+A\+L\+\_\+\+C\+O\+N\+T\+E\+NT}, 
\hyperlink{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea2d25de44865bd44e5a3903a2bab9ca83}{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+O\+P\+EN}
 \}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN struct lws\+\_\+spa $\ast$ \hyperlink{group__form-parsing_ga162f86762173a2bc8c28497941d74815}{lws\+\_\+spa\+\_\+create} (struct lws $\ast$wsi, const char $\ast$const $\ast$param\+\_\+names, int count\+\_\+params, int max\+\_\+storage, \hyperlink{group__form-parsing_ga5a70527c0861c2ffa3d29333a6aa7f8e}{lws\+\_\+spa\+\_\+fileupload\+\_\+cb} opt\+\_\+cb, void $\ast$opt\+\_\+data)
\item 
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int \hyperlink{group__form-parsing_ga9ad9ebf5ea1a7108415ed7e04cb231d2}{lws\+\_\+spa\+\_\+process} (struct lws\+\_\+spa $\ast$spa, const char $\ast$in, int len)
\item 
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int \hyperlink{group__form-parsing_ga83835bf250ee3d4a60f36a182f2b8d24}{lws\+\_\+spa\+\_\+finalize} (struct lws\+\_\+spa $\ast$spa)
\item 
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int \hyperlink{group__form-parsing_ga3fbe378632f85ec9a14cc2c1687bf05f}{lws\+\_\+spa\+\_\+get\+\_\+length} (struct lws\+\_\+spa $\ast$spa, int n)
\item 
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN const char $\ast$ \hyperlink{group__form-parsing_ga2da476217166da02704b90d3a8d4f3cd}{lws\+\_\+spa\+\_\+get\+\_\+string} (struct lws\+\_\+spa $\ast$spa, int n)
\item 
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int \hyperlink{group__form-parsing_gaaa482f07dad3f04b391cccf0a814e13b}{lws\+\_\+spa\+\_\+destroy} (struct lws\+\_\+spa $\ast$spa)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
\subsubsection*{P\+O\+S\+Ted form parsing functions}

These lws\+\_\+spa (stateful post arguments) apis let you parse and urldecode P\+O\+S\+Ted form arguments, both using simple urlencoded and multipart transfer encoding.

It\textquotesingle{}s capable of handling file uploads as well a named input parsing, and the apis are the same for both form upload styles.

You feed it a list of parameter names and it creates pointers to the urldecoded arguments\+: file upload parameters pass the file data in chunks to a user-\/supplied callback as they come.

Since it\textquotesingle{}s stateful, it handles the incoming data needing more than one P\+O\+S\+T\+\_\+\+B\+O\+DY callback and has no limit on uploaded file size. 

\subsection{Typedef Documentation}
\index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+fileupload\+\_\+cb@{lws\+\_\+spa\+\_\+fileupload\+\_\+cb}}
\index{lws\+\_\+spa\+\_\+fileupload\+\_\+cb@{lws\+\_\+spa\+\_\+fileupload\+\_\+cb}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+fileupload\+\_\+cb}{lws\_spa\_fileupload\_cb}}]{\setlength{\rightskip}{0pt plus 5cm}typedef int($\ast$ lws\+\_\+spa\+\_\+fileupload\+\_\+cb) (void $\ast$data, const char $\ast$name, const char $\ast$filename, char $\ast$buf, int len, enum {\bf lws\+\_\+spa\+\_\+fileupload\+\_\+states} state)}\hypertarget{group__form-parsing_ga5a70527c0861c2ffa3d29333a6aa7f8e}{}\label{group__form-parsing_ga5a70527c0861c2ffa3d29333a6aa7f8e}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

\hyperlink{group__form-parsing_ga5a70527c0861c2ffa3d29333a6aa7f8e}{lws\+\_\+spa\+\_\+fileupload\+\_\+cb()} -\/ callback to receive file upload data


\begin{DoxyParams}{Parameters}
{\em data} & opt\+\_\+data pointer set in lws\+\_\+spa\+\_\+create \\
\hline
{\em name} & name of the form field being uploaded \\
\hline
{\em filename} & original filename from client \\
\hline
{\em buf} & start of data to receive \\
\hline
{\em len} & length of data to receive \\
\hline
{\em state} & information about how this call relates to file\\
\hline
\end{DoxyParams}
Notice name and filename shouldn\textquotesingle{}t be trusted, as they are passed from H\+T\+TP provided by the client. 

\subsection{Enumeration Type Documentation}
\index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+fileupload\+\_\+states@{lws\+\_\+spa\+\_\+fileupload\+\_\+states}}
\index{lws\+\_\+spa\+\_\+fileupload\+\_\+states@{lws\+\_\+spa\+\_\+fileupload\+\_\+states}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+fileupload\+\_\+states}{lws\_spa\_fileupload\_states}}]{\setlength{\rightskip}{0pt plus 5cm}enum {\bf lws\+\_\+spa\+\_\+fileupload\+\_\+states}}\hypertarget{group__form-parsing_ga41a74a822771d3dce89751aa3bce28ae}{}\label{group__form-parsing_ga41a74a822771d3dce89751aa3bce28ae}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

enum lws\+\_\+spa\+\_\+fileupload\+\_\+states \begin{Desc}
\item[Enumerator]\par
\begin{description}
\index{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+C\+O\+N\+T\+E\+NT@{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+C\+O\+N\+T\+E\+NT}!Form Parsing@{Form Parsing}}\index{Form Parsing@{Form Parsing}!L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+C\+O\+N\+T\+E\+NT@{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+C\+O\+N\+T\+E\+NT}}\item[{\em 
L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+C\+O\+N\+T\+E\+NT\hypertarget{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aead3a958e7719ac273c3ba4f684f00c87f}{}\label{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aead3a958e7719ac273c3ba4f684f00c87f}
}]a chunk of file content has arrived \index{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+F\+I\+N\+A\+L\+\_\+\+C\+O\+N\+T\+E\+NT@{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+F\+I\+N\+A\+L\+\_\+\+C\+O\+N\+T\+E\+NT}!Form Parsing@{Form Parsing}}\index{Form Parsing@{Form Parsing}!L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+F\+I\+N\+A\+L\+\_\+\+C\+O\+N\+T\+E\+NT@{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+F\+I\+N\+A\+L\+\_\+\+C\+O\+N\+T\+E\+NT}}\item[{\em 
L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+F\+I\+N\+A\+L\+\_\+\+C\+O\+N\+T\+E\+NT\hypertarget{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea6ce2a55a4c3695cdb640c893d95bd3a7}{}\label{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea6ce2a55a4c3695cdb640c893d95bd3a7}
}]the last chunk (possibly zero length) of file content has arrived \index{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+O\+P\+EN@{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+O\+P\+EN}!Form Parsing@{Form Parsing}}\index{Form Parsing@{Form Parsing}!L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+O\+P\+EN@{L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+O\+P\+EN}}\item[{\em 
L\+W\+S\+\_\+\+U\+F\+S\+\_\+\+O\+P\+EN\hypertarget{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea2d25de44865bd44e5a3903a2bab9ca83}{}\label{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea2d25de44865bd44e5a3903a2bab9ca83}
}]a new file is starting to arrive \end{description}
\end{Desc}

\begin{DoxyCode}
2552                                \{
2553         \hyperlink{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aead3a958e7719ac273c3ba4f684f00c87f}{LWS\_UFS\_CONTENT},
2555         \hyperlink{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea6ce2a55a4c3695cdb640c893d95bd3a7}{LWS\_UFS\_FINAL\_CONTENT},
2557         \hyperlink{group__form-parsing_gga41a74a822771d3dce89751aa3bce28aea2d25de44865bd44e5a3903a2bab9ca83}{LWS\_UFS\_OPEN}
2559 \};
\end{DoxyCode}


\subsection{Function Documentation}
\index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+create@{lws\+\_\+spa\+\_\+create}}
\index{lws\+\_\+spa\+\_\+create@{lws\+\_\+spa\+\_\+create}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+create(struct lws $\ast$wsi, const char $\ast$const $\ast$param\+\_\+names, int count\+\_\+params, int max\+\_\+storage, lws\+\_\+spa\+\_\+fileupload\+\_\+cb opt\+\_\+cb, void $\ast$opt\+\_\+data)}{lws\_spa\_create(struct lws *wsi, const char *const *param\_names, int count\_params, int max\_storage, lws\_spa\_fileupload\_cb opt\_cb, void *opt\_data)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN struct lws\+\_\+spa$\ast$ lws\+\_\+spa\+\_\+create (
\begin{DoxyParamCaption}
\item[{struct lws $\ast$}]{wsi, }
\item[{const char $\ast$const $\ast$}]{param\+\_\+names, }
\item[{int}]{count\+\_\+params, }
\item[{int}]{max\+\_\+storage, }
\item[{{\bf lws\+\_\+spa\+\_\+fileupload\+\_\+cb}}]{opt\+\_\+cb, }
\item[{void $\ast$}]{opt\+\_\+data}
\end{DoxyParamCaption}
)}\hypertarget{group__form-parsing_ga162f86762173a2bc8c28497941d74815}{}\label{group__form-parsing_ga162f86762173a2bc8c28497941d74815}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

\hyperlink{group__form-parsing_ga162f86762173a2bc8c28497941d74815}{lws\+\_\+spa\+\_\+create()} -\/ create urldecode parser


\begin{DoxyParams}{Parameters}
{\em wsi} & lws connection (used to find Content Type) \\
\hline
{\em param\+\_\+names} & array of form parameter names, like \char`\"{}username\char`\"{} \\
\hline
{\em count\+\_\+params} & count of param\+\_\+names \\
\hline
{\em max\+\_\+storage} & total amount of form parameter values we can store \\
\hline
{\em opt\+\_\+cb} & N\+U\+LL, or callback to receive file upload data. \\
\hline
{\em opt\+\_\+data} & N\+U\+LL, or user pointer provided to opt\+\_\+cb.\\
\hline
\end{DoxyParams}
Creates a urldecode parser and initializes it.

opt\+\_\+cb can be N\+U\+LL if you just want normal name=value parsing, however if one or more entries in your form are bulk data (file transfer), you can provide this callback and filter on the name callback parameter to treat that urldecoded data separately. The callback should return -\/1 in case of fatal error, and 0 if OK. \index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+destroy@{lws\+\_\+spa\+\_\+destroy}}
\index{lws\+\_\+spa\+\_\+destroy@{lws\+\_\+spa\+\_\+destroy}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+destroy(struct lws\+\_\+spa $\ast$spa)}{lws\_spa\_destroy(struct lws\_spa *spa)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int lws\+\_\+spa\+\_\+destroy (
\begin{DoxyParamCaption}
\item[{struct lws\+\_\+spa $\ast$}]{spa}
\end{DoxyParamCaption}
)}\hypertarget{group__form-parsing_gaaa482f07dad3f04b391cccf0a814e13b}{}\label{group__form-parsing_gaaa482f07dad3f04b391cccf0a814e13b}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

\hyperlink{group__form-parsing_gaaa482f07dad3f04b391cccf0a814e13b}{lws\+\_\+spa\+\_\+destroy()} -\/ destroy parser object


\begin{DoxyParams}{Parameters}
{\em spa} & the parser object previously created \\
\hline
\end{DoxyParams}
\index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+finalize@{lws\+\_\+spa\+\_\+finalize}}
\index{lws\+\_\+spa\+\_\+finalize@{lws\+\_\+spa\+\_\+finalize}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+finalize(struct lws\+\_\+spa $\ast$spa)}{lws\_spa\_finalize(struct lws\_spa *spa)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int lws\+\_\+spa\+\_\+finalize (
\begin{DoxyParamCaption}
\item[{struct lws\+\_\+spa $\ast$}]{spa}
\end{DoxyParamCaption}
)}\hypertarget{group__form-parsing_ga83835bf250ee3d4a60f36a182f2b8d24}{}\label{group__form-parsing_ga83835bf250ee3d4a60f36a182f2b8d24}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

\hyperlink{group__form-parsing_ga83835bf250ee3d4a60f36a182f2b8d24}{lws\+\_\+spa\+\_\+finalize()} -\/ indicate incoming data completed


\begin{DoxyParams}{Parameters}
{\em spa} & the parser object previously created \\
\hline
\end{DoxyParams}
\index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+get\+\_\+length@{lws\+\_\+spa\+\_\+get\+\_\+length}}
\index{lws\+\_\+spa\+\_\+get\+\_\+length@{lws\+\_\+spa\+\_\+get\+\_\+length}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+get\+\_\+length(struct lws\+\_\+spa $\ast$spa, int n)}{lws\_spa\_get\_length(struct lws\_spa *spa, int n)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int lws\+\_\+spa\+\_\+get\+\_\+length (
\begin{DoxyParamCaption}
\item[{struct lws\+\_\+spa $\ast$}]{spa, }
\item[{int}]{n}
\end{DoxyParamCaption}
)}\hypertarget{group__form-parsing_ga3fbe378632f85ec9a14cc2c1687bf05f}{}\label{group__form-parsing_ga3fbe378632f85ec9a14cc2c1687bf05f}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

\hyperlink{group__form-parsing_ga3fbe378632f85ec9a14cc2c1687bf05f}{lws\+\_\+spa\+\_\+get\+\_\+length()} -\/ return length of parameter value


\begin{DoxyParams}{Parameters}
{\em spa} & the parser object previously created \\
\hline
{\em n} & parameter ordinal to return length of value for \\
\hline
\end{DoxyParams}
\index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+get\+\_\+string@{lws\+\_\+spa\+\_\+get\+\_\+string}}
\index{lws\+\_\+spa\+\_\+get\+\_\+string@{lws\+\_\+spa\+\_\+get\+\_\+string}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+get\+\_\+string(struct lws\+\_\+spa $\ast$spa, int n)}{lws\_spa\_get\_string(struct lws\_spa *spa, int n)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN const char$\ast$ lws\+\_\+spa\+\_\+get\+\_\+string (
\begin{DoxyParamCaption}
\item[{struct lws\+\_\+spa $\ast$}]{spa, }
\item[{int}]{n}
\end{DoxyParamCaption}
)}\hypertarget{group__form-parsing_ga2da476217166da02704b90d3a8d4f3cd}{}\label{group__form-parsing_ga2da476217166da02704b90d3a8d4f3cd}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

\hyperlink{group__form-parsing_ga2da476217166da02704b90d3a8d4f3cd}{lws\+\_\+spa\+\_\+get\+\_\+string()} -\/ return pointer to parameter value 
\begin{DoxyParams}{Parameters}
{\em spa} & the parser object previously created \\
\hline
{\em n} & parameter ordinal to return pointer to value for \\
\hline
\end{DoxyParams}
\index{Form Parsing@{Form Parsing}!lws\+\_\+spa\+\_\+process@{lws\+\_\+spa\+\_\+process}}
\index{lws\+\_\+spa\+\_\+process@{lws\+\_\+spa\+\_\+process}!Form Parsing@{Form Parsing}}
\subsubsection[{\texorpdfstring{lws\+\_\+spa\+\_\+process(struct lws\+\_\+spa $\ast$spa, const char $\ast$in, int len)}{lws\_spa\_process(struct lws\_spa *spa, const char *in, int len)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN int lws\+\_\+spa\+\_\+process (
\begin{DoxyParamCaption}
\item[{struct lws\+\_\+spa $\ast$}]{spa, }
\item[{const char $\ast$}]{in, }
\item[{int}]{len}
\end{DoxyParamCaption}
)}\hypertarget{group__form-parsing_ga9ad9ebf5ea1a7108415ed7e04cb231d2}{}\label{group__form-parsing_ga9ad9ebf5ea1a7108415ed7e04cb231d2}


{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}

\hyperlink{group__form-parsing_ga9ad9ebf5ea1a7108415ed7e04cb231d2}{lws\+\_\+spa\+\_\+process()} -\/ parses a chunk of input data


\begin{DoxyParams}{Parameters}
{\em spa} & the parser object previously created \\
\hline
{\em in} & incoming, urlencoded data \\
\hline
{\em len} & count of bytes valid at \\
\hline
{\em in} & \\
\hline
\end{DoxyParams}
