[Libwebsockets] libwebsocket problem

Wei, Catherine catherine.wei at commscope.com
Thu May 16 10:12:55 CEST 2019


Thanks for the API, since the number of the parameters are also unknow, so I didn't use the API. I added a patch to keep the parameters to the url, so I can easily get the request url with parameters with current interface. Still thanks. By the way, if there is any unproper place in my patch, please let me know.

Index: libwebsockets-3.0.1/lib/roles/http/server/parsers.c
===================================================================
--- libwebsockets-3.0.1.orig/lib/roles/http/server/parsers.c
+++ libwebsockets-3.0.1/lib/roles/http/server/parsers.c
@@ -743,7 +743,8 @@ lws_parse_urldecode(struct lws *wsi, uin
 	case URIPS_SEEN_SLASH_DOT_DOT:
 
 		/* /../ or /..[End of URI] --> backup to last / */
-		if (c == '/' || c == '?') {
+		//if (c == '/' || c == '?') {
+		if (c == '/') {
 			/*
 			 * back up one dir level if possible
 			 * safe against header fragmentation because
@@ -774,28 +775,30 @@ lws_parse_urldecode(struct lws *wsi, uin
 		break;
 	}
 
-	if (c == '?' && !enc &&
-	    !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) { /* start of URI args */
-		if (ah->ues != URIES_IDLE)
-			goto forbid;
+    // Following lines are commented out so that we can keep the parameters to request path,
+    // we can remove the parameters if we don't want it in our stb platform
+	//if (c == '?' && !enc &&
+	  //  !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) { /* start of URI args */
+		//if (ah->ues != URIES_IDLE)
+		//	goto forbid;
 
 		/* seal off uri header */
-		if (issue_char(wsi, '\0') < 0)
-			return -1;
+		//if (issue_char(wsi, '\0') < 0)
+		//	return -1;
 
 		/* move to using WSI_TOKEN_HTTP_URI_ARGS */
-		ah->nfrag++;
-		if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags))
-			goto excessive;
-		ah->frags[ah->nfrag].offset = ++ah->pos;
-		ah->frags[ah->nfrag].len = 0;
-		ah->frags[ah->nfrag].nfrag = 0;
-
-		ah->post_literal_equal = 0;
-		ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] = ah->nfrag;
-		ah->ups = URIPS_IDLE;
-		goto swallow;
-	}
+		//ah->nfrag++;
+		//if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags))
+		//	goto excessive;
+		//ah->frags[ah->nfrag].offset = ++ah->pos;
+		//ah->frags[ah->nfrag].len = 0;
+		//ah->frags[ah->nfrag].nfrag = 0;
+
+	//	ah->post_literal_equal = 0;
+	//	ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] = ah->nfrag;
+	//	ah->ups = URIPS_IDLE;
+	//	goto swallow;
+	//}
 
 	return LPUR_CONTINUE;

Best regards,
Catherine

-----Original Message-----
From: Andy Green <andy at warmcat.com> 
Sent: 2019年5月16日 14:02
To: Wei, Catherine <catherine.wei at commscope.com>; libwebsockets at ml.libwebsockets.org
Subject: RE: [Libwebsockets] libwebsocket problem

Email Security Warning:

The following message was sent from an external e-mail address. Exercise caution when opening attachments, clicking links, or exchanging information.


On May 16, 2019 6:19:25 AM GMT+01:00, "Wei, Catherine" <catherine.wei at commscope.com> wrote:
>Thanks for your reply. However, I don't know the parameters, so using 
>the lws_get_urlarg_by_name is not useful for me. Do you know how can I 
>add a patch to it so that I can in any way get the complete url. Which 
>file to patch? Very appreciate for your help.

This api should be enough

https://secure-web.cisco.com/1Fb3gMvFs0ZWvPx-uA5uTd1hEaz8CGreF8RgJcnxB2SzwYi92pZMf9UhxlVfFGrtC_waX1bbz-RjWkGbtl8kVtc5taXLt0T5eHevHsl-sFNGgpkHwXTpj4E7LX3guiCQUQkPV8JFsG5S1ShA4xCC04FsVsO6Ou_EcsECUQJhKIvYD1O_5ZJDt_HX-AtD9_vgv761WUlaVRlCnqF6Z85GN70ypTIBnnjSHJpbvfP6o7XRIhJsWcIKKOFsZ1LTUiQxMtFmXlCsR9ZE_pMd2LHWtIY45g_wcJRFuMjyBtoJ0TRCTPOqPVDsAAGkM_q0So1wA/https%3A%2F%2Flibwebsockets.org%2Fgit%2Flibwebsockets%2Ftree%2Finclude%2Flibwebsockets%2Flws-http.h#n388-407

-Andy

>Best regards,
>Catheriene
>
>-----Original Message-----
>From: Andy Green <andy at warmcat.com>
>Sent: 2019年5月16日 12:35
>To: Wei, Catherine <catherine.wei at commscope.com>; 
>libwebsockets at ml.libwebsockets.org
>Subject: Re: [Libwebsockets] libwebsocket problem
>
>Email Security Warning:
>
>The following message was sent from an external e-mail address.
>Exercise caution when opening attachments, clicking links, or 
>exchanging information.
>
>
>On 5/16/19 4:34 AM, Wei, Catherine wrote:
>
>> Hi, I’m using libwebsocket 3.0.1 in my code. I can only get the url 
>> without query parameters. Is there any interface or any way to get
>the
>> complete url of the client connection?
>
>Query parameters get parsed out of the url string so they and the path 
>part are available separately... you can get hold of them using:
>
>/**
>  * lws_get_urlarg_by_name() - return pointer to arg value if present
>  * \param wsi: the connection to check
>  * \param name: the arg name, like "token="
>* \param buf: the buffer to receive the urlarg (including the name=
>part)
>  * \param len: the length of the buffer to receive the urlarg
>  *
>*     Returns NULL if not found or a pointer inside buf to just after
>the
>  *     name= part.
>  */
>LWS_VISIBLE LWS_EXTERN const char *
>lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, 
>int len);
>
>https://secure-web.cisco.com/1Og4rW6xLT3Cev5v3yL71L1nPpFWaQB0DBuHWjmrq1
>1p6hiT6_Ez8wfEntjroxhtT1HeKeLbmKOWZ36I6I3n2VSu2AJovhTv74rgjHRqt-GwNl0Xk
>dpoX7Fd4vUV4UA8ILTNAEwNgEolIUdmfPUU98olAzBhhno6BvHweum_mVMVe87-VkKfm9lP
>BGWwToa6ADy7k0UVICyq7NmTNxuKIkBFR-7m-tHbu4gkxeeML4u7BhAxImSio9uOmT38-Iu
>q1laBq6TeUGF-izIxAJ9bW25dtmdpvItKOxRuI9LFgjHB_GDBCfvrvG_jX2co3nqGx/http
>s%3A%2F%2Flibwebsockets.org%2Fgit%2Flibwebsockets%2Ftree%2Flib%2Flibweb
>sockets.h%3Fid%3Dfb31602ff9aeb88267fb8132d48df31195782ae5#n4161-4172
>
>Notice the query string includes the '='.
>
>-Andy
>
>> Thanks.
>> 
>> Best regards,
>> 
>> Catherine
>> 
>> 
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>>
>https://secure-web.cisco.com/1PIY-al4ld2y8PkT2pFAoxGddOzFzURz907jhnINd
>>
>VN1F7lvUWHZZWVFr1umRhwNuSFKmQ7tVQSERMxgV414F-PjAwJahM_P_YDRgMOT6Q8g0WI
>>
>2v_iNqBVsW9rIcFipJBOzVMvTcCcCSCp1fAWzZ94jKILXOBf-YnDIM8fIbhWJzLa2yv3u1
>>
>j5qgNRezrk0FR3UWStcMPCYo7G7vUYSzIxcJvNJJHshk5wMME-FsPDDByR5JKfD3Tbw4y6
>>
>Zc-anf92SLViSMIorC3dlahweUkQx_N8WtJHs580fzfJlDrLkI3mSLMyNZhy60vFzF08Tf
>> /https%3A%2F%2Flibwebsockets.org%2Fmailman%2Flistinfo%2Flibwebsockets
>> 


More information about the Libwebsockets mailing list