Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7974c76
commit 8ec434f
Showing
12 changed files
with
329 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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,87 @@ | ||
PROGRAM | ||
|
||
OMIT('***') | ||
* Created with Clarion 10.0 | ||
* User: Mike | ||
* Date: 22.01.2019 | ||
* Time: 15:59 | ||
*** | ||
|
||
PRAGMA('project(#pragma link(libcurl.lib))') | ||
INCLUDE('libcurl.inc') | ||
|
||
MAP | ||
GetUrlPart(CURLUPart what, UNSIGNED flags = 0), STRING | ||
PrintUrlParts() | ||
END | ||
|
||
|
||
uapi TCurlUrlApiClass | ||
url STRING('https://example.com:449/foo/bar?name=moo') | ||
rc CURLUcode, AUTO | ||
|
||
|
||
|
||
CODE | ||
!Create a handle that holds URL info and resources. | ||
uapi.Init() | ||
|
||
!If successful, this stores the URL in its individual parts within the handle. | ||
rc = uapi.SetPart(CURLUPART_URL, url, 0) | ||
IF rc = CURLUE_OK | ||
PrintUrlParts() | ||
|
||
!Redirect to a relative URL. | ||
!When the handle already has parsed a URL, setting a relative URL will make it "redirect" to adapt to it. | ||
uapi.SetPart(CURLUPART_URL, '../test?another', 0) | ||
curl::DebugInfo('Redirected URL: '& GetUrlPart(CURLUPART_URL)) | ||
|
||
!Set individual URL parts. | ||
!A user can opt to set individual parts, either after having parsed a full URL or instead of parsing such. | ||
uapi.SetPart(CURLUPART_USER, 'john', 0) | ||
uapi.SetPart(CURLUPART_PASSWORD, 'doe', 0) | ||
uapi.SetPart(CURLUPART_PATH, '/index.html', 0) | ||
uapi.SetPart(CURLUPART_FRAGMENT, 'anchor', 0) | ||
curl::DebugInfo('Modified URL: '& GetUrlPart(CURLUPART_URL)) | ||
|
||
!Append to the query. | ||
!An application can append a string to the right end of the query part with the CURLU_APPENDQUERY flag. | ||
uapi.SetPart(CURLUPART_QUERY, 'hat=1', CURLU_APPENDQUERY) | ||
uapi.SetPart(CURLUPART_QUERY, 'shoes=2', CURLU_APPENDQUERY) | ||
curl::DebugInfo('Appended URL: '& GetUrlPart(CURLUPART_URL)) | ||
|
||
!The appended string can of course also get URL encoded on add, and if asked, the encoding will skip the '=' character. | ||
!For example, append candy=M&M to what we already have, and URL encode it to deal with the ampersand in the data: | ||
uapi.SetPart(CURLUPART_QUERY, 'candy=M&M', CURLU_APPENDQUERY+CURLU_URLENCODE) | ||
curl::DebugInfo('Encoded URL: '& GetUrlPart(CURLUPART_URL)) | ||
ELSE | ||
MESSAGE('Parse failed, error '& rc) | ||
END | ||
|
||
!When done with it, clean it up | ||
uapi.Cleanup() !-- not required, automatically called by destructor | ||
|
||
MESSAGE('Done!') | ||
|
||
GetUrlPart PROCEDURE(CURLUPart what, UNSIGNED flags = 0) | ||
part STRING(256) | ||
CODE | ||
uapi.GetPart(what, part, flags) | ||
RETURN CLIP(part) | ||
|
||
PrintUrlParts PROCEDURE() | ||
CODE | ||
!Get individual URL parts. | ||
!When a URL has been parsed or parts have been set, you can extract those pieces from the handle at any time. | ||
!Extracted parts are not URL decoded unless the user asks for it with the CURLU_URLDECODE flag. | ||
|
||
curl::DebugInfo('URL: '& GetUrlPart(CURLUPART_URL)) | ||
curl::DebugInfo('Scheme: '& GetUrlPart(CURLUPART_SCHEME)) | ||
curl::DebugInfo('User: '& GetUrlPart(CURLUPART_USER)) | ||
curl::DebugInfo('Password: '& GetUrlPart(CURLUPART_PASSWORD)) | ||
curl::DebugInfo('Options: '& GetUrlPart(CURLUPART_OPTIONS)) | ||
curl::DebugInfo('Host: '& GetUrlPart(CURLUPART_HOST)) | ||
curl::DebugInfo('Port: '& GetUrlPart(CURLUPART_PORT)) | ||
curl::DebugInfo('Path: '& GetUrlPart(CURLUPART_PATH)) | ||
curl::DebugInfo('Query: '& GetUrlPart(CURLUPART_QUERY)) | ||
curl::DebugInfo('Fragment: '& GetUrlPart(CURLUPART_FRAGMENT)) |
This file contains 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 @@ | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ProjectGuid>{D6CF98E5-1E14-4E55-A958-52DA5091208A}</ProjectGuid> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">Win32</Platform> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>urlapi</RootNamespace> | ||
<AssemblyName>urlapi</AssemblyName> | ||
<OutputName>urlapi</OutputName> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<DebugSymbols>True</DebugSymbols> | ||
<DebugType>Full</DebugType> | ||
<vid>full</vid> | ||
<check_stack>True</check_stack> | ||
<check_index>True</check_index> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DebugSymbols>False</DebugSymbols> | ||
<DebugType>None</DebugType> | ||
<vid>off</vid> | ||
<check_stack>False</check_stack> | ||
<check_index>False</check_index> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="urlapi.clw" /> | ||
</ItemGroup> | ||
<Import Project="$(ClarionBinPath)\SoftVelocity.Build.Clarion.targets" /> | ||
</Project> |
This file contains 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
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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,98 @@ | ||
!** libcurl for Clarion v1.42 | ||
!** 22.01.2019 | ||
!** mikeduglas66@gmail.com | ||
|
||
MEMBER | ||
|
||
INCLUDE('libcurl.inc') | ||
|
||
MAP | ||
MODULE('URL API') | ||
!/* | ||
! * curl_url() creates a new CURLU handle and returns a pointer to it. | ||
! * Must be freed with curl_url_cleanup(). | ||
! */ | ||
!CURL_EXTERN CURLU *curl_url(void); | ||
curl_url(), CURLU, C, NAME('curl_url') | ||
|
||
!/* | ||
! * curl_url_cleanup() frees the CURLU handle and related resources used for | ||
! * the URL parsing. It will not free strings previously returned with the URL | ||
! * API. | ||
! */ | ||
!CURL_EXTERN void curl_url_cleanup(CURLU *handle); | ||
curl_url_cleanup(CURLU handle), C, NAME('curl_url_cleanup') | ||
|
||
!/* | ||
! * curl_url_dup() duplicates a CURLU handle and returns a new copy. The new | ||
! * handle must also be freed with curl_url_cleanup(). | ||
! */ | ||
!CURL_EXTERN CURLU *curl_url_dup(CURLU *in); | ||
curl_url_dup(CURLU in), CURLU, C, NAME('curl_url_dup') | ||
|
||
!/* | ||
! * curl_url_get() extracts a specific part of the URL from a CURLU | ||
! * handle. Returns error code. The returned pointer MUST be freed with | ||
! * curl_free() afterwards. | ||
! */ | ||
!CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what, | ||
! char **part, unsigned int flags); | ||
curl_url_get(CURLU handle, CURLUPart what, LONG part, UNSIGNED flags), CURLUcode, C, NAME('curl_url_get') | ||
|
||
!/* | ||
! * curl_url_set() sets a specific part of the URL in a CURLU handle. Returns | ||
! * error code. The passed in string will be copied. Passing a NULL instead of | ||
! * a part string, clears that part. | ||
! */ | ||
!CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what, | ||
! const char *part, unsigned int flags); | ||
curl_url_set(CURLU handle, CURLUPart what, *CSTRING part, UNSIGNED flags), CURLUcode, C, RAW, NAME('curl_url_set') | ||
END | ||
END | ||
|
||
!!! region TCurlUrlApiClass | ||
TCurlUrlApiClass.Construct PROCEDURE() | ||
CODE | ||
SELF.urlp = 0 | ||
|
||
TCurlUrlApiClass.Destruct PROCEDURE() | ||
CODE | ||
SELF.Cleanup() | ||
|
||
TCurlUrlApiClass.Init PROCEDURE() | ||
CODE | ||
SELF.Cleanup() | ||
SELF.urlp = curl_url() | ||
|
||
TCurlUrlApiClass.Cleanup PROCEDURE() | ||
CODE | ||
IF SELF.urlp <> 0 | ||
curl_url_cleanup(SELF.urlp) | ||
SELF.urlp = 0 | ||
END | ||
|
||
TCurlUrlApiClass.Dup PROCEDURE(TCurlUrlApiClass src) | ||
CODE | ||
SELF.Cleanup() | ||
SELF.urlp = curl_url_dup(src.urlp) | ||
|
||
TCurlUrlApiClass.GetPart PROCEDURE(CURLUPart what, *STRING part, UNSIGNED flags = 0) | ||
rc CURLUcode, AUTO | ||
lppart LONG, AUTO | ||
szpart &CSTRING | ||
CODE | ||
rc = curl_url_get(SELF.urlp, what, ADDRESS(lppart), flags) | ||
IF rc = CURLUE_OK | ||
szpart &= (lppart) | ||
part = szpart | ||
curl::free(lppart) | ||
END | ||
|
||
RETURN rc | ||
|
||
TCurlUrlApiClass.SetPart PROCEDURE(CURLUPart what, STRING part, UNSIGNED flags = 0) | ||
szpart CSTRING(LEN(CLIP(part)) + 1) | ||
CODE | ||
szpart = CLIP(part) | ||
RETURN curl_url_set(SELF.urlp, what, szpart, flags) | ||
!!!endregion |
This file contains 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