forked fromamcewen/HttpClient
- Notifications
You must be signed in to change notification settings - Fork171
Added Url parser#173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
andreagilardoni merged 9 commits intoarduino-libraries:masterfromandreagilardoni:url-parserMar 21, 2024
Uh oh!
There was an error while loading.Please reload this page.
Merged
Added Url parser#173
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
cf741b0
Imported Url parser from src/http/ngx_http_parse.c from NGINX
andreagilardoni6159db9
Removed functionalities not related to URL parsing from the imported …
andreagilardonie5db3b5
imported wrapper class for url parsing
andreagilardonia1a79a5
added example for url parsing
andreagilardoni8d44059
Update examples/ParseURL/ParseURL.ino
andreagilardonidbe65d6
added include preprocessor for boards compatibility
andreagilardoni734f5b5
fixing codespell ci for imported url lib
andreagilardoni482e088
added README for imported library
andreagilardoni9ea6ace
moving http_parser from utility to utility/URLParser
andreagilardoniFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion.codespellrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,4 +4,4 @@ | ||
ignore-words-list = , | ||
check-filenames = | ||
check-hidden = | ||
skip = ./.git,./src/utility/URLParser |
29 changes: 29 additions & 0 deletionsexamples/ParseURL/ParseURL.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "URLParser.h" | ||
void setup() { | ||
Serial.begin(9600); | ||
while(!Serial); | ||
Serial.println("starting"); | ||
ParsedUrl url( | ||
"https://www.google.com/search?q=arduino" | ||
); | ||
Serial.print("parsed URL schema: \""); | ||
Serial.print(url.schema()); | ||
Serial.print("\"\nparsed URL host: \""); | ||
Serial.print(url.host()); | ||
Serial.print("\"\nparsed URL path: \""); | ||
Serial.print(url.path()); | ||
Serial.print("\"\nparsed URL query: \""); | ||
Serial.print(url.query()); | ||
Serial.print("\"\nparsed URL userinfo: \""); | ||
Serial.print(url.userinfo()); | ||
Serial.println("\""); | ||
} | ||
void loop() { } |
108 changes: 108 additions & 0 deletionssrc/URLParser.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* PackageLicenseDeclared: Apache-2.0 | ||
* Copyright (c) 2017 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* | ||
* The following class is defined in mbed libraries, in case of STM32H7 include the original library | ||
*/ | ||
#if defined __has_include | ||
# if __has_include(<utility/http_parsed_url.h>) | ||
# include <utility/http_parsed_url.h> | ||
# else | ||
# define NO_HTTP_PARSED | ||
# endif | ||
#endif | ||
#ifdef NO_HTTP_PARSED | ||
#ifndef _MBED_HTTP_PARSED_URL_H_ | ||
#define _MBED_HTTP_PARSED_URL_H_ | ||
#include "utility/URLParser/http_parser.h" | ||
class ParsedUrl { | ||
public: | ||
ParsedUrl(const char* url) { | ||
struct http_parser_url parsed_url; | ||
http_parser_parse_url(url, strlen(url), false, &parsed_url); | ||
for (size_t ix = 0; ix < UF_MAX; ix++) { | ||
char* value; | ||
if (parsed_url.field_set & (1 << ix)) { | ||
value = (char*)calloc(parsed_url.field_data[ix].len + 1, 1); | ||
memcpy(value, url + parsed_url.field_data[ix].off, | ||
parsed_url.field_data[ix].len); | ||
} | ||
else { | ||
value = (char*)calloc(1, 1); | ||
} | ||
switch ((http_parser_url_fields)ix) { | ||
case UF_SCHEMA: _schema = value; break; | ||
case UF_HOST: _host = value; break; | ||
case UF_PATH: _path = value; break; | ||
case UF_QUERY: _query = value; break; | ||
case UF_USERINFO: _userinfo = value; break; | ||
default: | ||
// PORT is already parsed, FRAGMENT is not relevant for HTTP requests | ||
free(value); | ||
break; | ||
} | ||
} | ||
_port = parsed_url.port; | ||
if (!_port) { | ||
if (strcmp(_schema, "https") == 0 || strcmp(_schema, "wss") == 0) { | ||
_port = 443; | ||
} | ||
else { | ||
_port = 80; | ||
} | ||
} | ||
if (strcmp(_path, "") == 0) { | ||
free(_path); | ||
_path = (char*)calloc(2, 1); | ||
_path[0] = '/'; | ||
} | ||
} | ||
~ParsedUrl() { | ||
if (_schema) free(_schema); | ||
if (_host) free(_host); | ||
if (_path) free(_path); | ||
if (_query) free(_query); | ||
if (_userinfo) free(_userinfo); | ||
} | ||
uint16_t port() const { return _port; } | ||
char* schema() const { return _schema; } | ||
char* host() const { return _host; } | ||
char* path() const { return _path; } | ||
char* query() const { return _query; } | ||
char* userinfo() const { return _userinfo; } | ||
private: | ||
uint16_t _port; | ||
char* _schema; | ||
char* _host; | ||
char* _path; | ||
char* _query; | ||
char* _userinfo; | ||
}; | ||
#endif // _MBED_HTTP_PARSED_URL_H_ | ||
#endif // NO_HTTP_PARSED | ||
#undef NO_HTTP_PARSED |
23 changes: 23 additions & 0 deletionssrc/utility/URLParser/LICENSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright | ||
Igor Sysoev. | ||
Additional changes are licensed under the same terms as NGINX and | ||
copyright Joyent, Inc. and other Node contributors. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to | ||
deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
IN THE SOFTWARE. |
5 changes: 5 additions & 0 deletionssrc/utility/URLParser/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# http_parser library | ||
This code is imported from: https://github.com/arduino/ArduinoCore-mbed/tree/4.1.1/libraries/SocketWrapper/src/utility/http_parser | ||
The code is shrinked in size by deleting all the unrelated code to url parse. |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.