├── .gitignore ├── LICENSE ├── README.md ├── src ├── Telegram.au3 └── include │ ├── Base64.au3 │ ├── BinaryCall.au3 │ ├── JSON.au3 │ ├── WinHttp.au3 │ └── WinHttpConstants.au3 └── tests ├── Tests.au3 ├── config.example.ini └── media ├── audio.mp3 ├── image.png ├── sticker.webp ├── text.txt ├── video.mp4 └── voice.ogg /.gitignore: -------------------------------------------------------------------------------- 1 | # Executables 2 | *.exe 3 | 4 | # Test config 5 | tests/config.ini 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [2023] [https://github.com/xLinkOut] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegram Bot UDFs for AutoIt 2 | A collection of user defined functions to seamlessly control your Telegram Bot with AutoIt. 3 | It support [most](https://github.com/xLinkOut/telegram-udf-autoit/wiki/Supported-APIs) of the Telegram Bot API and offer a whole set of useful features to interact with them. 4 | 5 | > [!NOTE] 6 | > This library is listed in the official [AutoIt Script Wiki!](https://www.autoitscript.com/wiki/User_Defined_Functions#Social_Media_and_other_Website_API). Also, refer to the [original forum topic](https://www.autoitscript.com/forum/topic/186381-telegram-bot-udf/) for more details. 7 | 8 | > [!IMPORTANT] 9 | > I've rewritten the library code from scratch after years of inactivity. The aim is to update, optimize it, fix all reported issues accumulated over the years, and support the latest Telegram features. It's still in work in progress and, obviously, there are breaking changes. You can find the development in the dev branch; I appreciate any kind of contribution. Also, in the release section, you can find the previous version for backward compatibility. Thank you for the support! 10 | 11 | ## How to use 12 | The library itself is in the `src/Telegram.au3` file. It need all the dependencies in the `src/include` folder: [WinHttp](https://www.autoitscript.com/forum/topic/84133-winhttp-functions/), [JSON](https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn). 13 | 14 | First, include the library in your script with `#include "path/to/Telegram.au3"`. Then, you can initialize the bot with the `_Telegram_Init` function: it take the bot token as first parameter (given to you by BotFather), and a boolean that validate the token as second parameter. I recommend to always validate your token, so the script fail immediately if it is invalid. 15 | The function return True if everything is ok, or False otherwise, and set `@error` and `@extended` accordingly. 16 | 17 | After this initialization step, you can use all the other functions. Refer to the [wiki](https://github.com/xLinkOut/telegram-udf-autoit/wiki/) for more examples. 18 | 19 | ## What functions return 20 | The main difference from previous version of this library is that every Telegram API call return the response object almost as-is; it check the response status and return the `result` inner object to the caller. If any error occurs during the HTTP request, the function return `Null` and set `@error` and `@extended` flags. 21 | 22 | That said, when you call any Telegram-related functions, expect in return an object as described in the Telegram API documentation. Use the JSON library to retrieve the information you need. 23 | 24 | ## Read incoming messages 25 | If you want to read incoming messages, you can put the bot in polling mode: the script will poll for incoming messages and return them. This state is blocking, therefore your script will wait here until a message is received or it exit. For example, to create a simple echo bot that receive a message and send it back, you can do the following: 26 | ```autoit 27 | ; Retrieve an array of messages from Telegram 28 | $aMessages = _Telegram_Polling() 29 | ; For each message, send it back 30 | For $i = 0 To UBound($aMessages) - 1 31 | $sChatId = Json_Get($aMessages[$i], "[message][chat][id]") 32 | $sMessage = Json_Get($aMessages[$i], "[message][text]") 33 | _Telegram_SendMessage($sChatId, $sMessage) 34 | Next 35 | ``` 36 | 37 | ## License 38 | The license for this project has been updated from GPL to MIT. This means that you are now free to use this work in your projects, with the condition that you acknowledge and cite this library within your own work. Thank you for your support and cooperation. 39 | -------------------------------------------------------------------------------- /src/Telegram.au3: -------------------------------------------------------------------------------- 1 | #cs ------------------------------------------------------------------------------ 2 | About: 3 | Author: Luca (@LinkOut) 4 | Description: Control Telegram Bot with AutoIt 5 | 6 | Documentation: 7 | Telegram API: https://core.telegram.org/bots/api 8 | GitHub Page: https://github.com/xLinkOut/telegram-udf-autoit/ 9 | 10 | Author Information: 11 | GitHub: https://github.com/xLinkOut 12 | 13 | #ce ------------------------------------------------------------------------------ 14 | 15 | #include-once 16 | #include 17 | #include 18 | #include "include/JSON.au3" 19 | #include "include/WinHttp.au3" 20 | 21 | ;@GLOBAL 22 | Global $URL = "" 23 | Global $TOKEN = "" 24 | Global $OFFSET = 0 25 | 26 | ;@CONST 27 | Const $BASE_URL = "https://api.telegram.org/bot" 28 | Const $BOT_CRLF = _Telegram_UrlEncode(@CRLF) 29 | 30 | ;@ERRORS 31 | ; Initialization errors 32 | Const $TG_ERR_INIT = 1 ;@error 33 | Const $TG_ERR_INIT_MISSING_TOKEN = 1 ;@extended 34 | Const $TG_ERR_INIT_INVALID_TOKEN = 2 ;@extended 35 | 36 | ; Telegram API Call errors 37 | Const $TG_ERR_API_CALL = 2 ;@error 38 | Const $TG_ERR_API_CALL_OPEN = 1 ;@extended 39 | Const $TG_ERR_API_CALL_SEND = 2 ;@extended 40 | Const $TG_ERR_API_CALL_HTTP_NOT_SUCCESS = 3 ;@extended 41 | Const $TG_ERR_API_CALL_NOT_DECODED = 4 ;@extended 42 | Const $TG_ERR_API_CALL_INVALID_JSON = 5 ;@extended 43 | Const $TG_ERR_API_CALL_NOT_SUCCESS = 6 ;@extended 44 | 45 | ; Missing or invalid input errors 46 | Const $TG_ERR_BAD_INPUT = 3 ;@error 47 | 48 | #cs ====================================================================================== 49 | Name .......: _Telegram_Init 50 | Description.: Initializes a Telegram connection using the provided token 51 | Parameters..: 52 | $sToken - Token to authenticate with Telegram API 53 | $bValidate - [optional] Boolean flag to indicate whether to validate 54 | the token (Default is False) 55 | Return......: 56 | Success - True upon successful initialization 57 | Failure - False, sets @error to $TG_ERR_INIT and set @extended to: 58 | - $TG_ERR_INIT_MISSING_TOKEN if token is empty 59 | - $TG_ERR_INIT_INVALID_TOKEN if token is invalid 60 | #ce ====================================================================================== 61 | Func _Telegram_Init($sToken, $bValidate = False) 62 | ; Check if provided token is not empty 63 | If ($sToken = "" Or $sToken = Null) Then 64 | Return SetError($TG_ERR_INIT, $TG_ERR_INIT_MISSING_TOKEN, False) 65 | EndIf 66 | 67 | ; Save token 68 | $TOKEN = $sToken 69 | ; Form URL as BASE_URL + TOKEN 70 | $URL = $BASE_URL & $TOKEN 71 | 72 | if ($bValidate) Then 73 | ; Validate token calling GetMe endpoint 74 | Local $aData = _Telegram_GetMe() 75 | ; Double control on error flag and return value 76 | If (@error Or Not Json_IsObject($aData)) Then 77 | Return SetError($TG_ERR_INIT, $TG_ERR_INIT_INVALID_TOKEN, False) 78 | EndIf 79 | EndIf 80 | 81 | Return True 82 | EndFunc ;==> _Telegram_Init 83 | 84 | #Region "API Implementation" 85 | 86 | #cs ====================================================================================== 87 | Name .......: _Telegram_GetMe 88 | Description.: Retrieves information about the current bot using Telegram API 89 | Reference...: https://core.telegram.org/bots/api#getme 90 | Parameters..: None 91 | Return......: 92 | Success - An object with information about the bot 93 | Failure - Null, sets @error/@extended to the encountered error code 94 | #ce ====================================================================================== 95 | Func _Telegram_GetMe() 96 | Local $oResponse = _Telegram_API_Call($URL, "/getMe") 97 | If (@error) Then Return SetError(@error, @extended, Null) 98 | 99 | Return $oResponse 100 | EndFunc ;==>_Telegram_GetMe 101 | 102 | #cs ====================================================================================== 103 | Name .......: _Telegram_GetUpdates 104 | Description.: Retrieves updates from the Telegram API, optionally updating the offset 105 | Reference...: https://core.telegram.org/bots/api#getupdates 106 | Parameters..: 107 | $bUpdateOffset - [optional] Boolean flag indicating whether to update 108 | the offset (Default is True) 109 | Return......: 110 | Success - A list of Message objects. If $bUpdateOffset is True, the 111 | offset might get updated based on the retrieved updates 112 | Failure - Null, sets @error/@extended to the encountered error code 113 | #ce ====================================================================================== 114 | Func _Telegram_GetUpdates($bUpdateOffset = True) 115 | ; Get updates 116 | Local $aMessages = _Telegram_API_Call($URL, "/getUpdates", "GET", "offset=" & $OFFSET) 117 | If (@error) Then Return SetError(@error, @extended, Null) 118 | 119 | If ($bUpdateOffset) Then 120 | ; Get messages count 121 | Local $iMessageCount = UBound($aMessages) 122 | if ($iMessageCount > 0) Then 123 | ; Set offset as last message id + 1 124 | $iUpdateId = Json_Get($aMessages[$iMessageCount - 1], "[update_id]") 125 | $OFFSET = $iUpdateId + 1 126 | EndIf 127 | EndIf 128 | 129 | Return $aMessages 130 | EndFunc ;==> _Telegram_GetUpdates 131 | 132 | #cs ====================================================================================== 133 | Name .......: _Telegram_LogOut 134 | Description.: Logs out from the cloud Bot API server before launching the bot locally 135 | Reference...: https://core.telegram.org/bots/api#logout 136 | Parameters..: None 137 | Return......: 138 | Success - True 139 | Failure - False, sets @error/@extended to the encountered error code 140 | #ce ====================================================================================== 141 | Func _Telegram_LogOut() 142 | Local $oResponse = _Telegram_API_Call($URL, "/logOut", "GET", "") 143 | If (@error) Then Return SetError(@error, @extended, Null) 144 | 145 | Return True 146 | EndFunc ;==> _Telegram_LogOut 147 | 148 | #cs ====================================================================================== 149 | Name .......: _Telegram_Close 150 | Description.: Close the bot instance before moving it from one local server to another 151 | Reference...: https://core.telegram.org/bots/api#close 152 | Parameters..: None 153 | Return......: 154 | Success - True 155 | Failure - False, sets @error/@extended to the encountered error code 156 | #ce ====================================================================================== 157 | Func _Telegram_Close() 158 | Local $oResponse = _Telegram_API_Call($URL, "/close", "GET", "") 159 | If (@error) Then Return SetError(@error, @extended, Null) 160 | Return True 161 | EndFunc ;==> _Telegram_Close 162 | 163 | #cs ====================================================================================== 164 | Name .......: _Telegram_SendMessage 165 | Description.: Sends a message via the Telegram API to a specified chat ID 166 | Reference...: https://core.telegram.org/bots/api#sendmessage 167 | Parameters..: 168 | $sChatId - ID of the chat where the message will be sent 169 | $sText - Text content of the message 170 | $sParseMode - [optional] Parse mode for the message (Default is Null) 171 | $sReplyMarkup - [optional] Reply markup for the message (Default is Null) 172 | $iReplyToMessage - [optional] ID of the message to reply to (Default is Null) 173 | $bDisableWebPreview - [optional] Boolean flag to disable web preview (Default is False) 174 | $bDisableNotification - [optional] Boolean flag to disable notification (Default is False) 175 | Return......: 176 | Success - An object containing information about the sent message 177 | Failure - Null,, sets @error/@extended to the encountered error code 178 | #ce ====================================================================================== 179 | Func _Telegram_SendMessage($sChatId, $sText, $sParseMode = Null, $sReplyMarkup = Null, $iReplyToMessage = Null, $bDisableWebPreview = False, $bDisableNotification = False) 180 | ; TODO: Enum for ParseMode 181 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 182 | If ($sText = "" Or $sText = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 183 | If ($sParseMode <> Null And $sParseMode <> "MarkdownV2" And $sParseMode <> "HTML") Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 184 | 185 | Local $sParams = _Telegram_BuildCommonParams($sChatId, $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification, $bDisableWebPreview) 186 | $sParams &= "&text=" & $sText 187 | 188 | Local $oResponse = _Telegram_API_Call($URL, "/sendMessage", "POST", $sParams) 189 | If (@error) Then Return SetError(@error, @extended, Null) 190 | 191 | Return $oResponse 192 | EndFunc ;==> _Telegram_SendMessage 193 | 194 | #cs ====================================================================================== 195 | Name .......: _Telegram_ForwardMessage 196 | Description.: Forwards a message from one chat to another using the Telegram API 197 | Reference...: https://core.telegram.org/bots/api#forwardmessage 198 | Parameters..: 199 | $sChatId - ID of the chat where the message will be forwarded 200 | $sFromChatId - ID of the chat where the original message is from 201 | $iMessageId - ID of the message to be forwarded 202 | $bDisableNotification - [optional] Boolean flag to disable notification (Default is False) 203 | Return......: 204 | Success - An object containing information about the forwarded message 205 | Failure - Null, sets @error/@extended to the encountered error code 206 | #ce ====================================================================================== 207 | Func _Telegram_ForwardMessage($sChatId, $sFromChatId, $iMessageId, $bDisableNotification = False) 208 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 209 | If ($sFromChatId = "" Or $sFromChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 210 | If ($iMessageId = "" Or $iMessageId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 211 | 212 | Local $sParams = _Telegram_BuildCommonParams($sChatId, Null, Null, Null, $bDisableNotification) 213 | $sParams &= _ 214 | "&from_chat_id=" & $sFromChatId & _ 215 | "&message_id=" & $iMessageId 216 | 217 | Local $oResponse = _Telegram_API_Call($URL, "/forwardMessage", "POST", $sParams) 218 | If (@error) Then Return SetError(@error, @extended, Null) 219 | 220 | Return $oResponse 221 | EndFunc ;==> _Telegram_ForwardMessage 222 | 223 | #cs ====================================================================================== 224 | Name .......: _Telegram_Send 225 | Description.: Sends a via the Telegram API to a specified chat ID 226 | Reference...: https://core.telegram.org/bots/api#sendphoto 227 | Parameters..: 228 | $sChatId - ID of the chat where the will be sent 229 | $ - to be sent, a string representing a local path to a file, 230 | a remote URL or a Telegram File ID. Supported objects are: photo, 231 | audio, document, video, animation, voice, videonote, mediagroup 232 | $sCaption - [optional] Caption for the (Default is "") 233 | $sParseMode - [optional] Parse mode for the caption (Default is "") 234 | $sReplyMarkup - [optional] Reply markup for the (Default is "") 235 | $iReplyToMessage - [optional] ID of the message to reply to (Default is Null) 236 | $bDisableNotification - [optional] Boolean flag to disable notification (Default is False) 237 | Return......: 238 | Success - An object containing information about 239 | the sent 240 | Failure - Null, sets @error/@extended to the encountered error code 241 | #ce ====================================================================================== 242 | Func _Telegram_SendPhoto($sChatId, $sPhoto, $sCaption = "", $sParseMode = "", $sReplyMarkup = "", $iReplyToMessage = Null, $bDisableNotification = False) 243 | Local $oResponse = _Telegram_SendMedia($sChatId, $sPhoto, "photo", $sCaption, $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 244 | If (@error) Then Return SetError(@error, @extended, Null) 245 | Return $oResponse 246 | EndFunc ;==> _Telegram_SendPhoto 247 | 248 | Func _Telegram_SendAudio($sChatId,$sAudio,$sCaption = '', $sParseMode = "", $sReplyMarkup = "",$iReplyToMessage = Null,$bDisableNotification = False) 249 | Local $oResponse = _Telegram_SendMedia($sChatId, $sAudio, "audio", $sCaption, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 250 | If (@error) Then Return SetError(@error, @extended, Null) 251 | Return $oResponse 252 | EndFunc ;==> _Telegram_SendAudio 253 | 254 | Func _Telegram_SendDocument($sChatId,$Document,$sCaption = '',$sParseMode = "", $sReplyMarkup = "",$iReplyToMessage = Null,$bDisableNotification = False) 255 | Local $oResponse = _Telegram_SendMedia($sChatId, $Document, "document", $sCaption, $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 256 | If (@error) Then Return SetError(@error, @extended, Null) 257 | Return $oResponse 258 | EndFunc ;==> _Telegram_SendDocument 259 | 260 | Func _Telegram_SendVideo($sChatId,$Video,$sCaption = '', $sParseMode = "", $sReplyMarkup = "",$iReplyToMessage = Null,$bDisableNotification = False) 261 | Local $oResponse = _Telegram_SendMedia($sChatId, $Video, "video", $sCaption, $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 262 | If (@error) Then Return SetError(@error, @extended, Null) 263 | Return $oResponse 264 | EndFunc ;==> _Telegram_SendVideo 265 | 266 | Func _Telegram_SendAnimation($sChatId,$Animation,$sCaption = '',$sParseMode = "", $sReplyMarkup = "",$iReplyToMessage = Null,$bDisableNotification = False) 267 | Local $oResponse = _Telegram_SendMedia($sChatId, $Animation, "animation", $sCaption, $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 268 | If (@error) Then Return SetError(@error, @extended, Null) 269 | Return $oResponse 270 | EndFunc ;==> _Telegram_SendAnimation 271 | 272 | Func _Telegram_SendVoice($sChatId,$Path,$sCaption = '',$sParseMode = "", $sReplyMarkup = "",$iReplyToMessage = Null,$bDisableNotification = False) 273 | Local $oResponse = _Telegram_SendMedia($sChatId, $Path, "voice", $sCaption, $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 274 | If (@error) Then Return SetError(@error, @extended, Null) 275 | Return $oResponse 276 | EndFunc ;==> _Telegram_SendVoice 277 | 278 | Func _Telegram_SendVideoNote($sChatId,$VideoNote,$sParseMode = "", $sReplyMarkup = "",$iReplyToMessage = Null,$bDisableNotification = False) 279 | Local $oResponse = _Telegram_SendMedia($sChatId, $VideoNote, "video_note", $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 280 | If (@error) Then Return SetError(@error, @extended, Null) 281 | Return $oResponse 282 | EndFunc ;==> _Telegram_SendVideoNote 283 | 284 | Func _Telegram_SendMediaGroup($sChatId,$aMedias,$bDisableNotification = False) 285 | Local $oResponse = _Telegram_SendMedia($sChatId, $aMedias, "media_group", $bDisableNotification) 286 | If (@error) Then Return SetError(@error, @extended, Null) 287 | Return $oResponse 288 | EndFunc 289 | 290 | #cs ====================================================================================== 291 | Name .......: _Telegram_SendLocation 292 | Description.: Sends a location to the specified chat. 293 | Parameters..: 294 | $sChatId - The chat ID. 295 | $fLatitude - The latitude of the location. 296 | $fLongitude - The longitude of the location. 297 | $fHorizontalAccuracy - [optional] The radius of uncertainty for the location, measured in meters. 298 | $iLivePeriod - [optional] Period in seconds for which the location will be updated (for live locations). 299 | $iProximityAlertRadius - [optional] The radius for triggering proximity alerts. 300 | $sReplyMarkup - [optional] Additional interface options. Default is an empty string. 301 | $iReplyToMessage - [optional] ID of the message to reply to. 302 | $bDisableNotification - [optional] Disables notifications if set to True. Default is False. 303 | Return......: 304 | Success - Returns the API response. 305 | Failure - Returns @error flag along with @extended flag if an error occurs. 306 | Possible @error values: 307 | $TG_ERR_BAD_INPUT - Invalid input parameters. 308 | Other errors based on the API response. 309 | #ce ====================================================================================== 310 | Func _Telegram_SendLocation($sChatId,$fLatitude,$fLongitude,$fHorizontalAccuracy = Null, $iLivePeriod = Null,$iProximityAlertRadius = Null, $sReplyMarkup = "",$iReplyToMessage = Null,$bDisableNotification = False) 311 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 312 | If ($fLatitude = "" Or $fLatitude = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 313 | If ($fLongitude = "" Or $fLongitude = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 314 | 315 | Local $sParams = _Telegram_BuildCommonParams($sChatId, Null, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 316 | $sParams &= _ 317 | "&latitude=" & $fLatitude & _ 318 | "&longitude=" & $fLongitude 319 | 320 | If $iLivePeriod <> Null Then $sParams &= "&live_period=" & $iLivePeriod 321 | If $fHorizontalAccuracy <> Null Then $sParams &= "&horizontal_accuracy=" & $fHorizontalAccuracy 322 | If $iProximityAlertRadius <> Null Then $sParams &= "&proximity_alert_radius=" & $iProximityAlertRadius 323 | 324 | Local $oResponse = _Telegram_API_Call($URL, "/sendLocation", "GET", $sParams) 325 | If (@error) Then Return SetError(@error, @extended, Null) 326 | Return $oResponse 327 | 328 | EndFunc ;==> _Telegram_SendLocation 329 | 330 | #cs ====================================================================================== 331 | Name .......: _Telegram_SendVenue 332 | Description.: Sends information about a venue to a specified chat. 333 | Parameters..: 334 | $sChatId - The chat ID. 335 | $fLatitude - Latitude of the venue. 336 | $fLongitude - Longitude of the venue. 337 | $sTitle - Name of the venue. 338 | $sAddress - Address of the venue. 339 | $sFoursquareId - [optional] Foursquare identifier of the venue (Default is ""). 340 | $sFoursquareType - [optional] Foursquare type of the venue (Default is ""). 341 | $sGooglePlaceId - [optional] Google Places identifier of the venue (Default is ""). 342 | $sGooglePlaceType - [optional] Google Places type of the venue (Default is ""). 343 | $sReplyMarkup - [optional] Additional interface options (Default is ""). 344 | $iReplyToMessage - [optional] ID of the message to reply to (Default is Null). 345 | $bDisableNotification - [optional] Disables notifications if set to True (Default is False). 346 | Return......: 347 | Success - Returns the API response. 348 | Failure - Returns @error flag along with @extended flag if an error occurs. 349 | Possible @error values: 350 | $TG_ERR_BAD_INPUT - Invalid input parameters. 351 | Other errors based on the API response. 352 | #ce ====================================================================================== 353 | Func _Telegram_SendVenue($sChatId, $fLatitude, $fLongitude, $sTitle, $sAddress, $sFoursquareId = "", $sFoursquareType = "", $sGooglePlaceId = "", $sGooglePlaceType = "", $sReplyMarkup = "", $iReplyToMessage = Null, $bDisableNotification = False) 354 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 355 | If ($fLatitude = "" Or $fLatitude = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 356 | If ($fLongitude = "" Or $fLongitude = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 357 | If ($sTitle = "" Or $sTitle = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 358 | If ($sAddress = "" Or $sAddress = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 359 | 360 | Local $sParams = _Telegram_BuildCommonParams($sChatId, Null, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 361 | $sParams &= _ 362 | "&latitude=" & $fLatitude & _ 363 | "&longitude=" & $fLongitude & _ 364 | "&title=" & $sTitle & _ 365 | "&address=" & $sAddress 366 | 367 | If $sFoursquareId <> "" Then $sParams &= "&foursquare_id=" & $sFoursquareId 368 | If $sFoursquareType <> "" Then $sParams &= "&foursquare_type=" & $sFoursquareType 369 | If $sGooglePlaceId <> "" Then $sParams &= "&google_place_id=" & $sGooglePlaceId 370 | If $sGooglePlaceType <> "" Then $sParams &= "&google_place_type=" & $sGooglePlaceType 371 | 372 | Local $oResponse = _Telegram_API_Call($URL, "/sendVenue", "POST", $sParams) 373 | If (@error) Then Return SetError(@error, @extended, Null) 374 | Return $oResponse 375 | EndFunc ;==> _Telegram_SendVenue 376 | 377 | #cs ====================================================================================== 378 | Name .......: _Telegram_SendContact 379 | Description.: Sends a contact to the specified chat. 380 | Parameters..: 381 | $sChatId - The chat ID. 382 | $sPhoneNumber - Contact's phone number. 383 | $sFirstName - Contact's first name. 384 | $sLastName - [optional] Contact's last name. Default is an empty string. 385 | $vCard - [optional] Additional data about the contact in the form of a vCard. Default is an empty string. 386 | $sReplyMarkup - [optional] Additional interface options. Default is an empty string. 387 | $iReplyToMessage - [optional] ID of the message to reply to. Default is Null. 388 | $bDisableNotification - [optional] Disables notifications if set to True. Default is False. 389 | Return......: 390 | Success - Returns the API response. 391 | Failure - Returns @error flag along with @extended flag if an error occurs. 392 | Possible @error values: 393 | $TG_ERR_BAD_INPUT - Invalid input parameters. 394 | Other errors based on the API response. 395 | #ce ====================================================================================== 396 | Func _Telegram_SendContact($sChatId, $sPhoneNumber, $sFirstName, $sLastName = "", $vCard = "", $sReplyMarkup = "", $iReplyToMessage = Null, $bDisableNotification = False) 397 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 398 | If ($sPhoneNumber = "" Or $sPhoneNumber = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 399 | If ($sFirstName = "" Or $sFirstName = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 400 | 401 | Local $sParams = _Telegram_BuildCommonParams($sChatId, Null, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 402 | $sParams &= _ 403 | "&phone_number=" & $sPhoneNumber & _ 404 | "&first_name=" & $sFirstName 405 | 406 | If $sLastName <> "" Then $sParams &= "&last_name=" & $sLastName 407 | If $vCard <> "" Then $sParams &= "&vcard=" & $vCard 408 | 409 | Local $oResponse = _Telegram_API_Call($URL, "/sendContact", "GET", $sParams) 410 | If (@error) Then Return SetError(@error, @extended, Null) 411 | Return $oResponse 412 | EndFunc ;==> _Telegram_SendContact 413 | 414 | ; TODO: sendPoll (https://core.telegram.org/bots/api#sendpoll) 415 | 416 | ; TODO: sendDice (https://core.telegram.org/bots/api#senddice) 417 | 418 | #cs ====================================================================================== 419 | Name .......: _Telegram_SendChatAction 420 | Description.: Use this method when you need to tell the user that something is happening on the bot's side 421 | Parameters..: 422 | $sChatId - Unique identifier for the target chat or username of the target channel (in the format @channelusername). 423 | $sAction - Type of action to broadcast. 424 | Choose one, depending on what the user is about to receive: 425 | typing, upload_photo, record_video, upload_video, record_voice, upload_voice, 426 | upload_document, choose_sticker, find_location, record_video_note, upload_video_note. 427 | Return......: 428 | Success - Returns True on success. 429 | Failure - Null and sets @error flag if an error occurs. 430 | Possible @error values: 431 | $TG_ERR_BAD_INPUT - Invalid input parameters. 432 | Other errors based on the API response. 433 | #ce ====================================================================================== 434 | Func _Telegram_SendChatAction($sChatId, $sAction) 435 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 436 | If ($sAction = "" Or $sAction = Null Or StringInStr("typing,upload_photo,record_video,upload_video,record_voice,upload_voice,upload_document,choose_sticker,find_location,record_video_note,upload_video_note", $sAction) = 0) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 437 | 438 | Local $sParams = _Telegram_BuildCommonParams($sChatId) 439 | $sParams &= "&action=" & $sAction 440 | 441 | Local $oResponse = _Telegram_API_Call($URL, "/sendChatAction", "GET", $sParams) 442 | If (@error) Then Return SetError(@error, @extended, Null) 443 | Return $oResponse 444 | EndFunc ;==> _Telegram_SendChatAction 445 | 446 | ; TODO: setMessageReaction (https://core.telegram.org/bots/api#setmessagereaction) 447 | 448 | ; TODO: getUserProfilePhotos (https://core.telegram.org/bots/api#getuserprofilephotos) 449 | 450 | ; TODO: getFile (https://core.telegram.org/bots/api#getfile) 451 | 452 | ; TODO: banChatMember (https://core.telegram.org/bots/api#banchatmember) 453 | 454 | ; TODO: unbanChatMember (https://core.telegram.org/bots/api#unbanchatmember) 455 | 456 | ; TODO: restrictChatMember (https://core.telegram.org/bots/api#restrictchatmember) 457 | 458 | ; TODO: propoteChatMember (https://core.telegram.org/bots/api#promotechatmember) 459 | 460 | ; TODO: setChatAdministratorCustomTitle (https://core.telegram.org/bots/api#setchatadministratorcustomtitle) 461 | 462 | ; TODO: banChatSenderChat (https://core.telegram.org/bots/api#banchatsenderchat) 463 | 464 | ; TODO: unbanChatSenderChat (https://core.telegram.org/bots/api#unbanchatsenderchat) 465 | 466 | ; TODO: setChatPermissions (https://core.telegram.org/bots/api#setchatpermissions) 467 | 468 | ; TODO: exportChatInviteLink (https://core.telegram.org/bots/api#exportchatinvitelink) 469 | 470 | ; TODO: createChatInviteLink (https://core.telegram.org/bots/api#createchatinvitelink) 471 | 472 | ; TODO: editChatInviteLink (https://core.telegram.org/bots/api#editchatinvitelink) 473 | 474 | ; TODO: revokeChatInviteLink (https://core.telegram.org/bots/api#revokechatinvitelink) 475 | 476 | ; TODO: approveChatJoinRequest (https://core.telegram.org/bots/api#approvechatjoinrequest) 477 | 478 | ; TODO: declineChatJoinRequest (https://core.telegram.org/bots/api#declinechatjoinrequest) 479 | 480 | ; TODO: setChatPhoto (https://core.telegram.org/bots/api#setchatphoto) 481 | 482 | ; TODO: deleteChatPhoto (https://core.telegram.org/bots/api#deletechatphoto) 483 | 484 | ; TODO: setChatTitle (https://core.telegram.org/bots/api#setchattitle) 485 | 486 | ; TODO: setChatDescription (https://core.telegram.org/bots/api#setchatdescription) 487 | 488 | ; TODO: pinChatMessage (https://core.telegram.org/bots/api#pinchatmessage) 489 | 490 | ; TODO: unpinChatMessage (https://core.telegram.org/bots/api#unpinchatmessage) 491 | 492 | ; TODO: unpinAllChatMessages (https://core.telegram.org/bots/api#unpinallchatmessages) 493 | 494 | #cs ====================================================================================== 495 | Name .......: _Telegram_LeaveChat 496 | Description.: Use this method for your bot to leave a group, supergroup or channel. 497 | Reference ..: https://core.telegram.org/bots/api#leavechat 498 | Parameters..: 499 | $sChatId - Unique identifier for the target chat 500 | Return......: 501 | Success - A boolean on success, depending on the Telegram response 502 | Failure - Null, sets @error/@extended to the encountered error code 503 | #ce ====================================================================================== 504 | Func _Telegram_LeaveChat($sChatId) 505 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 506 | 507 | Local $sParams = _Telegram_BuildCommonParams($sChatId) 508 | 509 | Local $bResponse = _Telegram_API_Call($URL, "/leaveChat", "GET", $sParams) 510 | If (@error) Then Return SetError(@error, @extended, Null) 511 | 512 | Return $bResponse 513 | EndFunc 514 | 515 | #cs ====================================================================================== 516 | Name .......: _Telegram_GetChat 517 | Description.: Retrieves up-to-date information about a specific chat. 518 | Parameters..: 519 | $sChatId - Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) 520 | Return......: 521 | Success - A Chat object containing information about the chat 522 | Failure - Null, sets @error/@extended to the encountered error code 523 | Possible @error values: 524 | $TG_ERR_BAD_INPUT - Invalid input parameters 525 | Other errors based on the API response 526 | #ce ====================================================================================== 527 | Func _Telegram_GetChat($sChatId) 528 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 529 | 530 | Local $sParams = _Telegram_BuildCommonParams($sChatId) 531 | 532 | Local $oResponse = _Telegram_API_Call($URL, "/getChat", "GET", $sParams) 533 | If (@error) Then Return SetError(@error, @extended, Null) 534 | 535 | Return $oResponse 536 | EndFunc ;==> _Telegram_GetChat 537 | 538 | #cs ====================================================================================== 539 | Name .......: _Telegram_GetChatAdministrators 540 | Description.: Get a list of administrators in a chat. 541 | References..: https://core.telegram.org/bots/api#getchatadministrators 542 | Parameters..: 543 | $sChatId - Unique identifier for the target chat 544 | Return......: 545 | Success - Array of ChatMember objects 546 | Failure - Null, sets @error/@extended to the encountered error code 547 | #ce ====================================================================================== 548 | Func _Telegram_GetChatAdministrators($sChatId) 549 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 550 | 551 | Local $sParams = _Telegram_BuildCommonParams($sChatId) 552 | 553 | Local $aResponse = _Telegram_API_Call($URL, "/getChatAdministrators", "GET", $sParams) 554 | If (@error) Then Return SetError(@error, @extended, Null) 555 | 556 | Return $aResponse 557 | EndFunc 558 | 559 | #cs ====================================================================================== 560 | Name .......: _Telegram_GetChatMemberCount 561 | Description.: Returns the number of members in a chat. 562 | References..: https://core.telegram.org/bots/api#getchatmembercount 563 | Parameters..: 564 | $sChatId - Unique identifier for the target chat 565 | Return......: 566 | Success - Integer number of members in the chat 567 | Failure - Null, sets @error/@extended to the encountered error code 568 | #ce ====================================================================================== 569 | Func _Telegram_GetChatMemberCount($sChatId) 570 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 571 | 572 | Local $sParams = _Telegram_BuildCommonParams($sChatId) 573 | 574 | Local $iResponse = _Telegram_API_Call($URL, "/getChatMemberCount", "GET", $sParams) 575 | If (@error) Then Return SetError(@error, @extended, Null) 576 | 577 | Return $iResponse 578 | EndFunc 579 | 580 | #cs ====================================================================================== 581 | Name .......: _Telegram_GetChatMember 582 | Description.: Returns information about a member of a chat. 583 | References..: https://core.telegram.org/bots/api#getchatmember 584 | Parameters..: 585 | $sChatId - Unique identifier for the target chat 586 | $sUserId - Unique identifier of the target user 587 | Return......: 588 | Success - ChatMember object 589 | Failure - Null, sets @error/@extended to the encountered error code 590 | #ce ====================================================================================== 591 | Func _Telegram_GetChatMember($sChatId, $sUserId) 592 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 593 | If ($sUserId = "" Or $sUserId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 594 | 595 | Local $sParams = _Telegram_BuildCommonParams($sChatId) 596 | $sParams &= "&user_id=" & $sUserId 597 | 598 | Local $oResponse = _Telegram_API_Call($URL, "/getChatMember", "GET", $sParams) 599 | If (@error) Then Return SetError(@error, @extended, Null) 600 | 601 | Return $oResponse 602 | EndFunc 603 | 604 | ; TODO: setChatStickerSet (https://core.telegram.org/bots/api#setchatstickerset) 605 | 606 | ; TODO: deleteChatStickerSet (https://core.telegram.org/bots/api#deletechatstickerset) 607 | 608 | ; TODO: getForumTopicIconSticker (https://core.telegram.org/bots/api#getforumtopiciconsticker) 609 | 610 | ; TODO: createForumTopic (https://core.telegram.org/bots/api#createforumtopic) 611 | 612 | ; TODO: editForumTopic (https://core.telegram.org/bots/api#editforumtopic) 613 | 614 | ; TODO: closeForumTopic (https://core.telegram.org/bots/api#closeforumtopic) 615 | 616 | ; TODO: reopenForumTopic (https://core.telegram.org/bots/api#reopenforumtopic) 617 | 618 | ; TODO: deleteForumTopic (https://core.telegram.org/bots/api#deleteforumtopic) 619 | 620 | ; TODO: unpinAllForumTopicMessages (https://core.telegram.org/bots/api#unpinallforumtopicmessages) 621 | 622 | ; TODO: editGeneralForumTopic (https://core.telegram.org/bots/api#editgeneralforumtopic) 623 | 624 | ; TODO: closeGeneralForumTopic (https://core.telegram.org/bots/api#closegeneralforumtopic) 625 | 626 | ; TODO: reopenGeneralForumTopic (https://core.telegram.org/bots/api#reopengeneralforumtopic) 627 | 628 | ; TODO: hideGeneralForumTopic (https://core.telegram.org/bots/api#hidegeneralforumtopic) 629 | 630 | ; TODO: unhideGeneralForumTopic (https://core.telegram.org/bots/api#unhidegeneralforumtopic) 631 | 632 | ; TODO: unpinAllGeneralForumTopicMessages (https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages) 633 | 634 | ; TODO: answerCallbackQuery (https://core.telegram.org/bots/api#answercallbackquery) 635 | 636 | ; TODO: getUserChatBoosts (https://core.telegram.org/bots/api#getuserchatboosts) 637 | 638 | ; TODO: getBusinessConnection (https://core.telegram.org/bots/api#getbusinessconnection) 639 | 640 | ; TODO: setMyCommands (https://core.telegram.org/bots/api#setmycommands) 641 | 642 | ; TODO: deleteMyCommands (https://core.telegram.org/bots/api#deletemycommands) 643 | 644 | ; TODO: getMyCommands (https://core.telegram.org/bots/api#getmycommands) 645 | 646 | ; TODO: setMyName (https://core.telegram.org/bots/api#setmyname) 647 | 648 | ; TODO: getMyName (https://core.telegram.org/bots/api#getmyname) 649 | 650 | ; TODO: setMyDescription (https://core.telegram.org/bots/api#setmydescription) 651 | 652 | ; TODO: getMyDescription (https://core.telegram.org/bots/api#getmydescription) 653 | 654 | ; TODO: setMyShortDescription (https://core.telegram.org/bots/api#setmyshortdescription) 655 | 656 | ; TODO: getMyShortDescription (https://core.telegram.org/bots/api#getmyshortdescription) 657 | 658 | ; TODO: setChatMenuButton (https://core.telegram.org/bots/api#setchatmenubutton) 659 | 660 | ; TODO: getChatMenuButton (https://core.telegram.org/bots/api#getchatmenubutton) 661 | 662 | ; TODO: setMyDefaultAdministratorRights (https://core.telegram.org/bots/api#setmydefaultadministratorrights) 663 | 664 | ; TODO: getMyDefaultAdministratorRights (https://core.telegram.org/bots/api#getmydefaultadministratorrights) 665 | 666 | ; TODO: editMessageLiveLocation (https://core.telegram.org/bots/api#editmessagelivelocation) 667 | 668 | ; TODO: stopMessageLiveLocation (https://core.telegram.org/bots/api#stopmessagelivelocation) 669 | 670 | ; TODO: editMessageText (https://core.telegram.org/bots/api#editmessagetext) 671 | 672 | ; TODO: editMessageCaption (https://core.telegram.org/bots/api#editmessagecaption) 673 | 674 | ; TODO: editMessageMedia (https://core.telegram.org/bots/api#editmessagemedia) 675 | 676 | ; TODO: editMessageLiveLocation (https://core.telegram.org/bots/api#editmessagelivelocation) 677 | 678 | ; TODO: stopMessageLiveLocation (https://core.telegram.org/bots/api#stopmessagelivelocation) 679 | 680 | ; TODO: editMessageReplyMarkup (https://core.telegram.org/bots/api#editmessagereplymarkup) 681 | 682 | ; TODO: stopPoll (https://core.telegram.org/bots/api#stoppoll) 683 | 684 | #cs ====================================================================================== 685 | Name .......: _Telegram_DeleteMessage 686 | Description.: Deletes a message 687 | Reference...: https://core.telegram.org/bots/api#deletemessage 688 | Parameters..: 689 | $sChatId - Unique identifier for the target chat or username of the target channel 690 | $iMessageId - Identifier of the message to edit 691 | Return......: 692 | Success - An object with information about the edited message 693 | Failure - Null, sets @error/@extended to the encountered error code 694 | #ce ====================================================================================== 695 | Func _Telegram_DeleteMessage($sChatId, $iMessageId) 696 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 697 | If ($iMessageId = "" Or $iMessageId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 698 | 699 | Local $sParams = _Telegram_BuildCommonParams($sChatId) 700 | $sParams &= "&message_id=" & $iMessageId 701 | 702 | Local $oResponse = _Telegram_API_Call($URL, "/deleteMessage", "POST", $sParams) 703 | If (@error) Then Return SetError(@error, @extended, Null) 704 | 705 | Return $oResponse 706 | EndFunc ;==> _Telegram_DeleteMessage 707 | 708 | ; TODO: deleteMessages (https://core.telegram.org/bots/api#deletemessages) 709 | 710 | #EndRegion 711 | 712 | #Region "Extra" 713 | 714 | #cs =============================================================================== 715 | Name .......: _Telegram_Polling 716 | Description.: Wait for incoming messages 717 | Parameters..: 718 | $iSleep - The time to wait in milliseconds between polling requests 719 | (Default is 1000 ms.) 720 | Return......: An array of JSON objects with information about messages 721 | #ce =============================================================================== 722 | Func _Telegram_Polling($iSleep = 1000) 723 | While 1 724 | Sleep($iSleep) ;Wait for $iSleep ms between polling requests 725 | $newMessages = _Telegram_GetUpdates() 726 | If (UBound($newMessages) > 0) Then Return $newMessages 727 | WEnd 728 | EndFunc ;==> _Telegram_Polling 729 | 730 | #cs =============================================================================== 731 | Name .......: _CreateKeyboard 732 | Description.: Create and return a custom keyboard markup 733 | Parameters..: $Keyboard: an array with the keyboard. Use an empty position for line break. 734 | Example: Local $Keyboard[4] = ['Top Left','Top Right','','Second Row'] 735 | $Resize: Set true if you want to resize the buttons of the keyboard 736 | $OneTime: Set true if you want to use the keyboard once 737 | Return......: Return custom markup as string, encoded in JSON 738 | #ce =============================================================================== 739 | Func _Telegram_CreateKeyboard(ByRef $Keyboard,$Resize = False,$OneTime = False) 740 | ;reply_markup={"keyboard":[["Yes","No"],["Maybe"],["1","2","3"]],"one_time_keyboard":true,"resize_keyboard":true} 741 | Local $jsonKeyboard = '{"keyboard":[' 742 | For $i=0 to UBound($Keyboard)-1 743 | If($Keyboard[$i] <> '') Then 744 | If(StringRight($jsonKeyboard,1) = '"') Then 745 | $jsonKeyboard &= ',"'&$Keyboard[$i]&'"' 746 | Else 747 | $jsonKeyboard &= '["'&$Keyboard[$i]&'"' 748 | EndIf 749 | Else 750 | $jsonKeyboard &= '],' 751 | EndIf 752 | Next 753 | $jsonKeyboard &= ']]' 754 | If $Resize = True Then $jsonKeyboard &= ',"resize_keyboard":true' 755 | If $OneTime = True Then $jsonKeyboard &= ',"one_time_keyboard":true' 756 | $jsonKeyboard &= '}' 757 | Return $jsonKeyboard 758 | EndFunc ;==> _Telegram_CreateKeyboard 759 | 760 | #EndRegion 761 | 762 | #cs =============================================================================== 763 | Name .......: _Telegram_CreateInlineKeyboard 764 | Description.: Create and return a custom inline keyboard markup 765 | Parameters..: $Keyboard: an array with the keyboard. Use an empty position for line break. 766 | Example: Local $InlineKeyboard[5] = ['Button1_Text','Button1_Data','','Button2_Text','Button2_Data'] 767 | Return......: Return custom inline markup as string, encoded in JSON 768 | #ce =============================================================================== 769 | Func _Telegram_CreateInlineKeyboard(ByRef $Keyboard) 770 | ;reply_markup={"inline_keyboard":[[['text':'Yes','callback_data':'pressed_yes'],['text':'No','callback_data':'pressed_no']]]} 771 | Local $jsonKeyboard = '{"inline_keyboard":[[' 772 | For $i=0 to UBound($Keyboard)-1 773 | If($Keyboard[$i] <> '') Then 774 | If(StringRight($jsonKeyboard,2) = '[[') Then ;First button 775 | $jsonKeyboard &= '{"text":"' & $Keyboard[$i] & '",' 776 | ElseIf(StringRight($jsonKeyboard,2) = '",') Then ;CallbackData of a button 777 | $jsonKeyboard &= '"callback_data":"' & $Keyboard[$i] & '"}' 778 | ElseIf(StringRight($jsonKeyboard,2) = '"}') Then 779 | $jsonKeyboard &= ',{"text":"' & $Keyboard[$i] & '",' 780 | ElseIf(StringRight($jsonKeyboard,2) = '],') Then 781 | $jsonKeyboard &= '[{"text":"' & $Keyboard[$i] & '",' 782 | EndIf 783 | 784 | Else 785 | $jsonKeyboard &= '],' 786 | EndIf 787 | Next 788 | $jsonKeyboard &= ']]}' 789 | Return $jsonKeyboard 790 | EndFunc 791 | 792 | #EndRegion 793 | 794 | #Region "Internal functions" 795 | 796 | Func _Telegram_BuildCommonParams($sChatId = Null, $sParseMode = Null, $sReplyMarkup = Null, $iReplyToMessage = Null, $bDisableNotification = Null, $bDisableWebPreview = Null) 797 | Local $sParams = "" 798 | 799 | If($sChatId <> Null) Then $sParams = "&chat_id=" & $sChatId 800 | If($sParseMode <> Null) Then $sParams &= "&parse_mode=" & $sParseMode 801 | If($sReplyMarkup <> Null) Then $sParams &= "&reply_markup=" & $sReplyMarkup 802 | If($iReplyToMessage <> Null) Then $sParams &= "&reply_to_message_id=" & $iReplyToMessage 803 | If($bDisableNotification <> Null) Then $sParams &= "&disable_notification=" & $bDisableNotification 804 | If($bDisableWebPreview <> Null) Then $sParams &= "&disable_web_page_preview=" & $bDisableWebPreview 805 | 806 | ; Remove the first "&" character 807 | Return StringTrimLeft($sParams, 1) 808 | EndFunc ;==> _Telegram_BuildCommonParams 809 | 810 | #cs =============================================================================== 811 | Name .......: _Telegram_UrlEncode 812 | Description.: Encode text in url format 813 | Parameters..: $string: Text to encode 814 | Return......: Return the encoded string 815 | #ce =============================================================================== 816 | Func _Telegram_UrlEncode($string) 817 | $string = StringSplit($string, "") 818 | For $i=1 To $string[0] 819 | If AscW($string[$i]) < 48 Or AscW($string[$i]) > 122 Then 820 | $string[$i] = "%"&_StringToHex($string[$i]) 821 | EndIf 822 | Next 823 | $string = _ArrayToString($string, "", 1) 824 | Return $string 825 | EndFunc 826 | 827 | #Region "HTTP Request" 828 | #cs ====================================================================================== 829 | Name .......: _Telegram_API_Call 830 | Description.: Sends a request to the Telegram API based on provided parameters 831 | Parameters..: 832 | $sURL - URL to the Telegram API 833 | $sPath - [optional] Path to the specific API endpoint (Default is "") 834 | $sMethod - [optional] HTTP method for the request (Default is "GET") 835 | $sParams - [optional] Parameters for the request (Default is "") 836 | $vBody - [optional] Body content for the request (Default is Null) 837 | $bValidate - [optional] Boolean flag to validate Telegram response (Default is True) 838 | Return......: 839 | Success - A JSON object with the 'result' field upon 840 | successful API call and validation 841 | Failure - Null and sets @error flag according to encountered errors 842 | #ce ====================================================================================== 843 | Func _Telegram_API_Call($sURL, $sPath = "", $sMethod = "GET", $sParams = "", $vBody = Null, $bValidate = True) 844 | ; Create HTTP request object 845 | Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") 846 | 847 | ; Set parameters, if any, and open request 848 | $oHTTP.Open($sMethod, $sURL & $sPath & ($sParams <> "" ? "?" & $sParams : ""), False) 849 | If (@error) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_OPEN, Null) 850 | 851 | If ($sMethod = "POST") Then 852 | ; Set content type header for POST 853 | $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") 854 | EndIF 855 | 856 | ; Send request with body if any 857 | If ($vBody) Then 858 | $oHTTP.send($vBody) 859 | Else 860 | $oHTTP.send() 861 | EndIf 862 | If (@error) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_SEND, Null) 863 | 864 | ; Check status code 865 | If ($oHTTP.Status < 200 Or $oHTTP.Status > 299) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_HTTP_NOT_SUCCESS, Null) 866 | 867 | ; Decode JSON 868 | Local $oBody = Json_Decode($oHTTP.ResponseText) 869 | 870 | ; Validate Telegram response 871 | If ($bValidate) Then 872 | ; Decoding error 873 | If (@error) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_NOT_DECODED, Null) 874 | ; Invalid JSON 875 | If (Not Json_IsObject($oBody)) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_INVALID_JSON, Null) 876 | ; Unsuccessful response 877 | If (Json_Get($oBody, "[ok]") <> True) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_NOT_SUCCESS, Null) 878 | EndIF 879 | 880 | ; Return 'result' field as JSON object 881 | Return SetError(0, 0, Json_Get($oBody, "[result]")) 882 | EndFunc 883 | 884 | ; TODO: I didn't figure out how to send a media using WinHttpRequest, 885 | ; so I'll continue using _WinHttp and form filling, but I'll try again 886 | ; to drop this dependencies and do everything with the above function. 887 | Func _Telegram_SendMedia($sChatId, $vMedia, $sMediaType, $sCaption = "", $sParseMode = "", $sReplyMarkup = "", $iReplyToMessage = Null, $bDisableNotification = False, $bValidate = True) 888 | ; Mandatory inputs validation 889 | If ($sChatId = "" Or $sChatId = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 890 | If ($vMedia = "" Or $vMedia = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 891 | If ($sMediaType = "" Or $sMediaType = Null) Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 892 | If ($sParseMode <> "" And $sParseMode <> "MarkdownV2" And $sParseMode <> "HTML") Then Return SetError($TG_ERR_BAD_INPUT, 0, Null) 893 | 894 | Local $sParams = _Telegram_BuildCommonParams($sChatId, $sParseMode, $sReplyMarkup, $iReplyToMessage, $bDisableNotification) 895 | $sParams &= "&caption=" & $sCaption 896 | 897 | Local $hOpen = _WinHttpOpen() 898 | If (@error) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_OPEN, Null) 899 | 900 | ; Params as query params and media as form data 901 | $sMediaType = StringLower($sMediaType) 902 | Local $sForm = _ 903 | "
" & _ 904 | "
" 905 | 906 | Local $sResponse = _WinHttpSimpleFormFill($sForm, $hOpen, Default, "name:" & $sMediaType, $vMedia) 907 | If (@error) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_SEND, Null) 908 | 909 | _WinHttpCloseHandle($hOpen) 910 | 911 | Local $oBody = Json_Decode($sResponse) 912 | 913 | ; Validate Telegram response 914 | ; (Same check as above) 915 | If ($bValidate) Then 916 | ; Decoding error 917 | If (@error) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_NOT_DECODED, Null) 918 | ; Invalid JSON 919 | If (Not Json_IsObject($oBody)) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_INVALID_JSON, Null) 920 | ; Unsuccessful response 921 | If (Json_Get($oBody, "[ok]") <> True) Then Return SetError($TG_ERR_API_CALL, $TG_ERR_API_CALL_NOT_SUCCESS, Null) 922 | EndIF 923 | 924 | Return SetError(0, 0, Json_Get($oBody, "[result]")) 925 | EndFunc 926 | 927 | #EndRegion 928 | -------------------------------------------------------------------------------- /src/include/Base64.au3: -------------------------------------------------------------------------------- 1 | Func _Base64Decode($Data) 2 | Local $Opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000" 3 | 4 | Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]") 5 | DllStructSetData($CodeBuffer, 1, $Opcode) 6 | 7 | Local $Ouput = DllStructCreate("byte[" & BinaryLen($Data) & "]") 8 | Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _ 9 | "str", $Data, _ 10 | "ptr", DllStructGetPtr($Ouput), _ 11 | "int", 0, _ 12 | "int", 0) 13 | 14 | Return BinaryMid(DllStructGetData($Ouput, 1), 1, $Ret[0]) 15 | EndFunc 16 | 17 | Func _Base64Encode($Data, $LineBreak = 76) 18 | Local $Opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC04750C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000" 19 | 20 | Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]") 21 | DllStructSetData($CodeBuffer, 1, $Opcode) 22 | 23 | $Data = Binary($Data) 24 | Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]") 25 | DllStructSetData($Input, 1, $Data) 26 | 27 | $LineBreak = Floor($LineBreak / 4) * 4 28 | Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3) 29 | $OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4 30 | 31 | Local $Ouput = DllStructCreate("char[" & $OputputSize & "]") 32 | DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _ 33 | "ptr", DllStructGetPtr($Input), _ 34 | "int", BinaryLen($Data), _ 35 | "ptr", DllStructGetPtr($Ouput), _ 36 | "uint", $LineBreak) 37 | Return DllStructGetData($Ouput, 1) 38 | EndFunc 39 | -------------------------------------------------------------------------------- /src/include/BinaryCall.au3: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; AutoIt BinaryCall UDF (2014.7.24) 3 | ; Purpose: Allocate, Decompress, And Prepare Binary Machine Code 4 | ; Author: Ward 5 | ; ============================================================================= 6 | 7 | #Include-once 8 | 9 | Global $__BinaryCall_Kernel32dll = DllOpen('kernel32.dll') 10 | Global $__BinaryCall_Msvcrtdll = DllOpen('msvcrt.dll') 11 | Global $__BinaryCall_LastError = "" 12 | 13 | Func _BinaryCall_GetProcAddress($Module, $Proc) 14 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, 'ptr', 'GetProcAddress', 'ptr', $Module, 'str', $Proc) 15 | If @Error Or Not $Ret[0] Then Return SetError(1, @Error, 0) 16 | Return $Ret[0] 17 | EndFunc 18 | 19 | Func _BinaryCall_LoadLibrary($Filename) 20 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "handle", "LoadLibraryW", "wstr", $Filename) 21 | If @Error Then Return SetError(1, @Error, 0) 22 | Return $Ret[0] 23 | EndFunc 24 | 25 | Func _BinaryCall_lstrlenA($Ptr) 26 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "int", "lstrlenA", "ptr", $Ptr) 27 | If @Error Then Return SetError(1, @Error, 0) 28 | Return $Ret[0] 29 | EndFunc 30 | 31 | Func _BinaryCall_Alloc($Code, $Padding = 0) 32 | Local $Length = BinaryLen($Code) + $Padding 33 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "ptr", "VirtualAlloc", "ptr", 0, "ulong_ptr", $Length, "dword", 0x1000, "dword", 0x40) 34 | If @Error Or Not $Ret[0] Then Return SetError(1, @Error, 0) 35 | If BinaryLen($Code) Then 36 | Local $Buffer = DllStructCreate("byte[" & $Length & "]", $Ret[0]) 37 | DllStructSetData($Buffer, 1, $Code) 38 | EndIf 39 | Return $Ret[0] 40 | EndFunc 41 | 42 | Func _BinaryCall_RegionSize($Ptr) 43 | Local $Buffer = DllStructCreate("ptr;ptr;dword;uint_ptr;dword;dword;dword") 44 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "int", "VirtualQuery", "ptr", $Ptr, "ptr", DllStructGetPtr($Buffer), "uint_ptr", DllStructGetSize($Buffer)) 45 | If @Error Or $Ret[0] = 0 Then Return SetError(1, @Error, 0) 46 | Return DllStructGetData($Buffer, 4) 47 | EndFunc 48 | 49 | Func _BinaryCall_Free($Ptr) 50 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "bool", "VirtualFree", "ptr", $Ptr, "ulong_ptr", 0, "dword", 0x8000) 51 | If @Error Or $Ret[0] = 0 Then 52 | $Ret = DllCall($__BinaryCall_Kernel32dll, "bool", "GlobalFree", "ptr", $Ptr) 53 | If @Error Or $Ret[0] <> 0 Then Return SetError(1, @Error, False) 54 | EndIf 55 | Return True 56 | EndFunc 57 | 58 | Func _BinaryCall_Release($CodeBase) 59 | Local $Ret = _BinaryCall_Free($CodeBase) 60 | Return SetError(@Error, @Extended, $Ret) 61 | EndFunc 62 | 63 | Func _BinaryCall_MemorySearch($Ptr, $Length, $Binary) 64 | Static $CodeBase 65 | If Not $CodeBase Then 66 | If @AutoItX64 Then 67 | $CodeBase = _BinaryCall_Create('0x4883EC084D85C94889C8742C4C39CA72254C29CA488D141131C9EB0848FFC14C39C97414448A1408453A140874EE48FFC04839D076E231C05AC3', '', 0, True, False) 68 | Else 69 | $CodeBase = _BinaryCall_Create('0x5589E58B4D14578B4508568B550C538B7D1085C9742139CA721B29CA8D341031D2EB054239CA740F8A1C17381C1074F34039F076EA31C05B5E5F5DC3', '', 0, True, False) 70 | EndIf 71 | If Not $CodeBase Then Return SetError(1, 0, 0) 72 | EndIf 73 | 74 | $Binary = Binary($Binary) 75 | Local $Buffer = DllStructCreate("byte[" & BinaryLen($Binary) & "]") 76 | DllStructSetData($Buffer, 1, $Binary) 77 | 78 | Local $Ret = DllCallAddress("ptr:cdecl", $CodeBase, "ptr", $Ptr, "uint", $Length, "ptr", DllStructGetPtr($Buffer), "uint", DllStructGetSize($Buffer)) 79 | Return $Ret[0] 80 | EndFunc 81 | 82 | Func _BinaryCall_Base64Decode($Src) 83 | Static $CodeBase 84 | If Not $CodeBase Then 85 | If @AutoItX64 Then 86 | $CodeBase = _BinaryCall_Create('0x41544989CAB9FF000000555756E8BE000000534881EC000100004889E7F3A44C89D6E98A0000004439C87E0731C0E98D0000000FB66E01440FB626FFC00FB65E020FB62C2C460FB62424408A3C1C0FB65E034189EB41C1E4024183E3308A1C1C41C1FB044509E34080FF634189CC45881C08744C440FB6DFC1E5044489DF4088E883E73CC1FF0209C7418D44240241887C08014883C10380FB63742488D841C1E3064883C60483E03F4409D841884408FF89F389C84429D339D30F8C67FFFFFF4881C4000100005B5E5F5D415CC35EC3E8F9FFFFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000003E0000003F3435363738393A3B3C3D00000063000000000102030405060708090A0B0C0D0E0F101112131415161718190000000000001A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233', '', 132, True, False) 87 | Else 88 | $CodeBase = _BinaryCall_Create('0x55B9FF00000089E531C05756E8F10000005381EC0C0100008B55088DBDF5FEFFFFF3A4E9C00000003B45140F8FC20000000FB65C0A028A9C1DF5FEFFFF889DF3FEFFFF0FB65C0A038A9C1DF5FEFFFF889DF2FEFFFF0FB65C0A018985E8FEFFFF0FB69C1DF5FEFFFF899DECFEFFFF0FB63C0A89DE83E630C1FE040FB6BC3DF5FEFFFFC1E70209FE8B7D1089F3881C074080BDF3FEFFFF63745C0FB6B5F3FEFFFF8BBDECFEFFFF8B9DE8FEFFFF89F083E03CC1E704C1F80209F88B7D1088441F0189D883C00280BDF2FEFFFF6374278A85F2FEFFFFC1E60683C10483E03F09F088441F0289D883C0033B4D0C0F8C37FFFFFFEB0231C081C40C0100005B5E5F5DC35EC3E8F9FFFFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000003E0000003F3435363738393A3B3C3D00000063000000000102030405060708090A0B0C0D0E0F101112131415161718190000000000001A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233', '', 132, True, False) 89 | EndIf 90 | If Not $CodeBase Then Return SetError(1, 0, Binary("")) 91 | EndIf 92 | 93 | $Src = String($Src) 94 | Local $SrcLen = StringLen($Src) 95 | Local $SrcBuf = DllStructCreate("char[" & $SrcLen & "]") 96 | DllStructSetData($SrcBuf, 1, $Src) 97 | 98 | Local $DstLen = Int(($SrcLen + 2) / 4) * 3 + 1 99 | Local $DstBuf = DllStructCreate("byte[" & $DstLen & "]") 100 | 101 | Local $Ret = DllCallAddress("uint:cdecl", $CodeBase, "ptr", DllStructGetPtr($SrcBuf), "uint", $SrcLen, "ptr", DllStructGetPtr($DstBuf), "uint", $DstLen) 102 | If $Ret[0] = 0 Then Return SetError(2, 0, Binary("")) 103 | Return BinaryMid(DllStructGetData($DstBuf, 1), 1, $Ret[0]) 104 | EndFunc 105 | 106 | Func _BinaryCall_Base64Encode($Src) 107 | Static $CodeBase 108 | If Not $CodeBase Then 109 | If @AutoItX64 Then 110 | $CodeBase = _BinaryCall_Create('AwAAAARiAQAAAAAAAAArkuFQDAlvIp0qAgbDnjr76UDZs1EPNIP2K18t9s6SNTbd43IB7HfdyPM8VfD/o36z4AmSW2m2AIsC6Af3fKNsHU4BdQKGd0PQXHxPSX0iNqp1YAKovksqQna06NeKMoOYqryTUX4WgpHjokhp6zY2sEFSIjcL7dW3FDoNVz4bGPyZHRvjFwmqvr7YGlNYKwNoh+SYCXmIgVPVZ63Vz1fbT33/QFpWmWOeBRqs4J+c8Qp6zJFsK345Pjw0I8kMSsnho4F4oNzQ2OsAbmIioaQ6Ma2ziw5NH+M+t4SpEeHDnBdUTTL20sxWZ0yKruFAsBIRoHvM7LYcid2eBV2d5roSjnkwMG0g69LNjs1fHjbI/9iU/hJwpSsgl4fltXdZG659/li13UFY89M7UfckiZ9XOeBM0zadgNsy8r8M3rEAAA==') 111 | Else 112 | $CodeBase = _BinaryCall_Create('AwAAAARVAQAAAAAAAAAqr7blBndrIGnmhhfXD7R1fkOTKhicg1W6MCtStbz+CsneBEg0bbHH1sqTLmLfY7A6LqZl6LYWT5ULVj6MXgugPbBn9wKsSU2ZCcBBPNkx09HVPdUaKnbqghDGj/C5SHoF+A/5g+UgE1C5zJZORjJ8ljs5lt2Y9lA4BsY7jVKX2vmDvHK1NnSR6nVwh7Pb+Po/UpNcy5sObVWDKkYSCCtCIjKIYqOe3c6k8Xsp4eritCUprXEVvCFi7K5Z6HFXdm3nZsFcE+eSJ1WkRnVQbWcmpjGMGka61C68+CI7tsQ13UnCFWNSpDrCbzUejMZh8HdPgEc5vCg3pKMKin/NavNpB6+87Y9y7HIxmKsPdjDT30u9hUKWnYiRe3nrwKyVDsiYpKU/Nse368jHag5B5or3UKA+nb2+eY8JwzgA') 113 | EndIf 114 | If Not $CodeBase Then Return SetError(1, 0, Binary("")) 115 | EndIf 116 | 117 | $Src = Binary($Src) 118 | Local $SrcLen = BinaryLen($Src) 119 | Local $SrcBuf = DllStructCreate("byte[" & $SrcLen & "]") 120 | DllStructSetData($SrcBuf, 1, $Src) 121 | 122 | Local $DstLen = Int(($SrcLen + 2) / 3) * 4 + 1 123 | Local $DstBuf = DllStructCreate("char[" & $DstLen & "]") 124 | 125 | Local $Ret = DllCallAddress("uint:cdecl", $CodeBase, "ptr", DllStructGetPtr($SrcBuf), "uint", $SrcLen, "ptr", DllStructGetPtr($DstBuf), "uint", $DstLen) 126 | If $Ret[0] = 0 Then Return Binary("") 127 | Return StringMid(DllStructGetData($DstBuf, 1), 1, $Ret[0]) 128 | EndFunc 129 | 130 | Func _BinaryCall_LzmaDecompress($Src) 131 | Static $CodeBase 132 | If Not $CodeBase Then 133 | If @AutoItX64 Then 134 | $CodeBase = _BinaryCall_Create(_BinaryCall_Base64Decode('QVcxwEFWQVVBVFVXSInXVkiJzlMx20iB7OgAAABEiiFBgPzgdgnpyQAAAEGD7C1BiMf/wEGA/Cx38THA6wRBg+wJQYjG/8BBgPwId/GLRglEi24FQQ+2zkyJRCQoRQ+2/0HB5xBBiQFBD7bEAcG4AAMAANPgjYQAcA4AAEhjyOjIBAAATInpSInF6L0EAABIicMxwEyJ8kSI4EyLRCQoiNQl//8A/0QJ+EiF24lFAHQoTYXtdCNIjVfzSI1MJDhIg8YNTIkEJE2J6UmJ2EiJ7+g2AAAAicbrBb4BAAAASInp6IQEAACF9nQKSInZMdvodgQAAEiJ2EiBxOgAAABbXl9dQVxBXUFeQV/DVVNBV0FWQVVBVEFQTQHBQVFNicVRVkgB8lJIieX8SYn0iwdMjX8Eik8Cg8r/0+L30olV6Ijhg8r/0+L30olV5ADBiUXsuAEAAACJReCJRdyJRdhIiUXQRSnJKfaDy/8A0bgAAwAA0+BIjYg2BwAAuAAEAARMif/R6fOrvwUAAADoUAMAAP/PdfdEie9EicgrfSDB4ARBifpEI1XoRAHQTY0cR+hAAwAAD4WTAAAAik3sI33k0+eA6Qj22dPuAfe4AQAAAEiNPH++AAEAAMHnCEGD+QdNjbR/bA4AAHI0TInvSCt90A+2P9HnQYnzIf5BAfNPjRxe6O8CAACJwcHuCIPhATnOvgABAAB1DjnGd9jrDE2J8+jQAgAAOfBy9EyJ76pEiclBg/kEcg65AwAAAEGD+QpyA4PBA0EpyelDAgAAT42cT4ABAADomgIAAHUsi0XcQYP5B4lF4BnAi1XY99CLTdCD4AOJVdxBicGJTdhNjbdkBgAA6akAAABPjZxPmAEAAOhfAgAAdUZEicjB4AREAdBNjZxH4AEAAOhHAgAAdWpBg/kHuQkAAAByA4PBAkGJyUyJ70grfdBIO30gD4L9AQAAigdIA33QqumzAQAAT42cT7ABAADoCgIAAIt12HQhT42cT8gBAADo+AEAAIt13HQJi03ci3XgiU3gi03YiU3ci03QiU3YiXXQQYP5B7kIAAAAcgODwQNBiclNjbdoCgAATYnz6LsBAAB1FESJ0CnJweADvggAAABJjXxGBOs2TY1eAuicAQAAdRpEidC5CAAAAMHgA74IAAAASY28RgQBAADrEUmNvgQCAAC5EAAAAL4AAQAAiU3MuAEAAABJifvoYQEAAInCKfJy8gNVzEGD+QSJVcwPg7kAAABBg8EHuQMAAAA50XICidHB4Qa4AQAAAEmNvE9gAwAAvkAAAABJifvoHwEAAEGJwkEp8nLwQYP6BHJ4RInWRIlV0NHug2XQAf/Og03QAkGD+g5zFYnx0mXQi0XQRCnQTY20R14FAADrLIPuBOi6AAAA0evRZdBBOdhyBv9F0EEp2P/OdedNjbdEBgAAwWXQBL4EAAAAvwEAAACJ+E2J8+ioAAAAqAF0Awl90NHn/8516+sERIlV0P9F0EyJ74tNzEiJ+IPBAkgrRSBIOUXQd1RIif5IK3XQSItVGKyqSDnXcwT/yXX1SYn9D7bwTDttGA+C9fz//+gwAAAAKcBIi1UQTCtlCESJIkiLVWBMK20gRIkqSIPEKEFcQV1BXUFfW13DXli4AQAAAOvSgfsAAAABcgHDweMITDtlAHPmQcHgCEWKBCRJg8QBwynATY0cQ4H7AAAAAXMVweMITDtlAHPBQcHgCEWKBCRJg8QBidlBD7cTwekLD6/KQTnIcxOJy7kACAAAKdHB6QVmQQELAcDDKcvB6gVBKchmQSkTAcCDwAHDSLj////////////gbXN2Y3J0LmRsbHxtYWxsb2MASLj////////////gZnJlZQA=')) 135 | Else 136 | $CodeBase = _BinaryCall_Create(_BinaryCall_Base64Decode('VYnlVzH/VlOD7EyLXQiKC4D54A+HxQAAADHA6wWD6S2I0ID5LI1QAXfziEXmMcDrBYPpCYjQgPkIjVABd/OIReWLRRSITeSLUwkPtsmLcwWJEA+2ReUBwbgAAwAA0+CNhABwDgAAiQQk6EcEAACJNCSJRdToPAQAAItV1InHi0Xkhf+JArgBAAAAdDaF9nQyi0UQg8MNiRQkiXQkFIl8JBCJRCQYjUXgiUQkDItFDIlcJASD6A2JRCQI6CkAAACLVdSJRdSJFCToAQQAAItF1IXAdAqJPCQx/+jwAwAAg8RMifhbXl9dw1dWU1WJ5YtFJAFFKFD8i3UYAXUcVot1FK2SUopO/oPI/9Pg99BQiPGDyP/T4PfQUADRifeD7AwpwEBQUFBQUFcp9laDy/+4AAMAANPgjYg2BwAAuAAEAATR6fOragVZ6MoCAADi+Yt9/ItF8Ct9JCH4iUXosADoywIAAA+FhQAAAIpN9CN97NPngOkI9tnT7lgB916NPH/B5wg8B1qNjH5sDgAAUVa+AAEAAFCwAXI0i338K33cD7Y/i23M0eeJ8SH+AfGNbE0A6JgCAACJwcHuCIPhATnOvgABAAB1DjnwctfrDIttzOh5AgAAOfBy9FqD+gSJ0XIJg/oKsQNyArEGKcpS60mwwOhJAgAAdRRYX1pZWln/NCRRUrpkBgAAsQDrb7DM6CwCAAB1LLDw6BMCAAB1U1g8B7AJcgKwC1CLdfwrddw7dSQPgs8BAACsi338qumOAQAAsNjo9wEAAIt12HQbsOTo6wEAAIt11HQJi3XQi03UiU3Qi03YiU3Ui03ciU3YiXXcWF9ZumgKAACxCAH6Ulc8B4jIcgIEA1CLbczovAEAAHUUi0Xoi33MweADKclqCF6NfEcE6zWLbcyDxQLomwEAAHUYi0Xoi33MweADaghZaghejbxHBAEAAOsQvwQCAAADfcxqEFm+AAEAAIlN5CnAQIn96GYBAACJwSnxcvMBTeSDfcQED4OwAAAAg0XEB4tN5IP5BHIDagNZi33IweEGKcBAakBejbxPYAMAAIn96CoBAACJwSnxcvOJTeiJTdyD+QRyc4nOg2XcAdHug03cAk6D+Q5zGbivAgAAKciJ8dJl3ANF3NHgA0XIiUXM6y2D7gToowAAANHr0WXcOV3gcgb/RdwpXeBOdei4RAYAAANFyIlFzMFl3ARqBF4p/0eJ+IttzOi0AAAAqAF0Awl93NHnTnXs6wD/RdyLTeSDwQKLffyJ+CtFJDlF3HdIif4rddyLVSisqjnXcwNJdfeJffwPtvA7fSgPgnH9///oKAAAACnAjWwkPItVIIt1+Ct1GIkyi1Usi338K30kiTrJW15fw15YKcBA69qB+wAAAAFyAcPB4whWi3X4O3Ucc+SLReDB4AisiUXgiXX4XsOLTcQPtsDB4QQDRegByOsGD7bAA0XEi23IjWxFACnAjWxFAIH7AAAAAXMci0wkOMFkJCAIO0wkXHOcihH/RCQ4weMIiFQkIInZD7dVAMHpCw+vyjlMJCBzF4nLuQAIAAAp0cHpBWYBTQABwI1sJEDDweoFKUwkICnLZilVAAHAg8ABjWwkQMO4///////gbXN2Y3J0LmRsbHxtYWxsb2MAuP//////4GZyZWUA')) 137 | EndIf 138 | If Not $CodeBase Then Return SetError(1, 0, Binary("")) 139 | EndIf 140 | 141 | $Src = Binary($Src) 142 | Local $SrcLen = BinaryLen($Src) 143 | Local $SrcBuf = DllStructCreate("byte[" & $SrcLen & "]") 144 | DllStructSetData($SrcBuf, 1, $Src) 145 | 146 | Local $Ret = DllCallAddress("ptr:cdecl", $CodeBase, "ptr", DllStructGetPtr($SrcBuf), "uint_ptr", $SrcLen, "uint_ptr*", 0, "uint*", 0) 147 | If $Ret[0] Then 148 | Local $DstBuf = DllStructCreate("byte[" & $Ret[3] & "]", $Ret[0]) 149 | Local $Output = DllStructGetData($DstBuf, 1) 150 | DllCall($__BinaryCall_Msvcrtdll, "none:cdecl", "free", "ptr", $Ret[0]) 151 | 152 | Return $Output 153 | EndIf 154 | Return SetError(2, 0, Binary("")) 155 | EndFunc 156 | 157 | Func _BinaryCall_Relocation($Base, $Reloc) 158 | Local $Size = Int(BinaryMid($Reloc, 1, 2)) 159 | 160 | For $i = 3 To BinaryLen($Reloc) Step $Size 161 | Local $Offset = Int(BinaryMid($Reloc, $i, $Size)) 162 | Local $Ptr = $Base + $Offset 163 | DllStructSetData(DllStructCreate("ptr", $Ptr), 1, DllStructGetData(DllStructCreate("ptr", $Ptr), 1) + $Base) 164 | Next 165 | EndFunc 166 | 167 | Func _BinaryCall_ImportLibrary($Base, $Length) 168 | Local $JmpBin, $JmpOff, $JmpLen, $DllName, $ProcName 169 | If @AutoItX64 Then 170 | $JmpBin = Binary("0x48B8FFFFFFFFFFFFFFFFFFE0") 171 | $JmpOff = 2 172 | Else 173 | $JmpBin = Binary("0xB8FFFFFFFFFFE0") 174 | $JmpOff = 1 175 | EndIf 176 | $JmpLen = BinaryLen($JmpBin) 177 | 178 | Do 179 | Local $Ptr = _BinaryCall_MemorySearch($Base, $Length, $JmpBin) 180 | If $Ptr = 0 Then ExitLoop 181 | 182 | Local $StringPtr = $Ptr + $JmpLen 183 | Local $StringLen = _BinaryCall_lstrlenA($StringPtr) 184 | Local $String = DllStructGetData(DllStructCreate("char[" & $StringLen & "]", $StringPtr), 1) 185 | Local $Split = StringSplit($String, "|") 186 | 187 | If $Split[0] = 1 Then 188 | $ProcName = $Split[1] 189 | ElseIf $Split[0] = 2 Then 190 | If $Split[1] Then $DllName = $Split[1] 191 | $ProcName = $Split[2] 192 | EndIf 193 | 194 | If $DllName And $ProcName Then 195 | Local $Handle = _BinaryCall_LoadLibrary($DllName) 196 | If Not $Handle Then 197 | $__BinaryCall_LastError = "LoadLibrary fail on " & $DllName 198 | Return SetError(1, 0, False) 199 | EndIf 200 | 201 | Local $Proc = _BinaryCall_GetProcAddress($Handle, $ProcName) 202 | If Not $Proc Then 203 | $__BinaryCall_LastError = "GetProcAddress failed on " & $ProcName 204 | Return SetError(2, 0, False) 205 | EndIf 206 | 207 | DllStructSetData(DllStructCreate("ptr", $Ptr + $JmpOff), 1, $Proc) 208 | EndIf 209 | 210 | Local $Diff = Int($Ptr - $Base + $JmpLen + $StringLen + 1) 211 | $Base += $Diff 212 | $Length -= $Diff 213 | 214 | Until $Length <= $JmpLen 215 | Return True 216 | EndFunc 217 | 218 | Func _BinaryCall_CodePrepare($Code) 219 | If Not $Code Then Return "" 220 | If IsBinary($Code) Then Return $Code 221 | 222 | $Code = String($Code) 223 | If StringLeft($Code, 2) = "0x" Then Return Binary($Code) 224 | If StringIsXDigit($Code) Then Return Binary("0x" & $Code) 225 | 226 | Return _BinaryCall_LzmaDecompress(_BinaryCall_Base64Decode($Code)) 227 | EndFunc 228 | 229 | Func _BinaryCall_SymbolFind($CodeBase, $Identify, $Length = Default) 230 | $Identify = Binary($Identify) 231 | 232 | If IsKeyword($Length) Then 233 | $Length = _BinaryCall_RegionSize($CodeBase) 234 | EndIf 235 | 236 | Local $Ptr = _BinaryCall_MemorySearch($CodeBase, $Length, $Identify) 237 | If $Ptr = 0 Then Return SetError(1, 0, 0) 238 | 239 | Return $Ptr + BinaryLen($Identify) 240 | EndFunc 241 | 242 | Func _BinaryCall_SymbolList($CodeBase, $Symbol) 243 | If Not IsArray($Symbol) Or $CodeBase = 0 Then Return SetError(1, 0, 0) 244 | 245 | Local $Tag = "" 246 | For $i = 0 To UBound($Symbol) - 1 247 | $Tag &= "ptr " & $Symbol[$i] & ";" 248 | Next 249 | 250 | Local $SymbolList = DllStructCreate($Tag) 251 | If @Error Then Return SetError(1, 0, 0) 252 | 253 | For $i = 0 To UBound($Symbol) - 1 254 | $CodeBase = _BinaryCall_SymbolFind($CodeBase, $Symbol[$i]) 255 | DllStructSetData($SymbolList, $Symbol[$i], $CodeBase) 256 | Next 257 | Return $SymbolList 258 | EndFunc 259 | 260 | Func _BinaryCall_Create($Code, $Reloc = '', $Padding = 0, $ReleaseOnExit = True, $LibraryImport = True) 261 | Local $BinaryCode = _BinaryCall_CodePrepare($Code) 262 | If Not $BinaryCode Then Return SetError(1, 0, 0) 263 | 264 | Local $BinaryCodeLen = BinaryLen($BinaryCode) 265 | Local $TotalCodeLen = $BinaryCodeLen + $Padding 266 | 267 | Local $CodeBase = _BinaryCall_Alloc($BinaryCode, $Padding) 268 | If Not $CodeBase Then Return SetError(2, 0, 0) 269 | 270 | If $Reloc Then 271 | $Reloc = _BinaryCall_CodePrepare($Reloc) 272 | If Not $Reloc Then Return SetError(3, 0, 0) 273 | _BinaryCall_Relocation($CodeBase, $Reloc) 274 | EndIf 275 | 276 | If $LibraryImport Then 277 | If Not _BinaryCall_ImportLibrary($CodeBase, $BinaryCodeLen) Then 278 | _BinaryCall_Free($CodeBase) 279 | Return SetError(4, 0, 0) 280 | EndIf 281 | EndIf 282 | 283 | If $ReleaseOnExit Then 284 | _BinaryCall_ReleaseOnExit($CodeBase) 285 | EndIf 286 | 287 | Return SetError(0, $TotalCodeLen, $CodeBase) 288 | EndFunc 289 | 290 | Func _BinaryCall_CommandLineToArgv($CommandLine, ByRef $Argc, $IsUnicode = False) 291 | Static $SymbolList 292 | If Not IsDllStruct($SymbolList) Then 293 | Local $Code 294 | If @AutoItX64 Then 295 | $Code = 'AwAAAASuAgAAAAAAAAAkL48ClEB9jTEOeYv4yYTosNjFNgf81Ag4vS2VP4y4wxFa+4yMI7GDB7CG+xn4JE3cdEVvk8cMp4oIuS3DgTxlcKHGVIg94tvzG/256bizZfGtAETQUCPQjW5+JSx2C/Y4C0VNJMKTlSCHiV5AzXRZ5gw3WFghbtkCCFxWOX+RDSI2oH/vROEOnqc0jfKTo17EBjqX+dW3QxrUe45xsbyYTZ9ccIGySgcOAxetbRiSxQnz8BOMbJyfrbZbuVJyGpKrXFLh/5MlBZ09Cim9qgflbGzmkrGStT9QL1f+O2krzyOzgaWWqhWL6S+y0G32RWVi0uMLR/JOGLEW/+Yg/4bzkeC0lKELT+RmWAatNa38BRfaitROMN12moRDHM6LYD1lzPLnaiefSQRVti561sxni/AFkYoCb5Lkuyw4RIn/r/flRiUg5w48YkqBBd9rXkaXrEoKwPg6rmOvOCZadu//B6HN4+Ipq5aYNuZMxSJXmxwXVRSQZVpSfLS2ATZMd9/Y7kLqrKy1H4V76SgI/d9OKApfKSbQ8ZaKIHBCsoluEip3UDOB82Z21zd933UH5l0laGWLIrTz7xVGkecjo0NQzR7LyhhoV3xszlIuw2v8q0Q/S9LxB5G6tYbOXo7lLjNIZc0derZz7DNeeeJ9dQE9hp8unubaTBpulPxTNtRjog==' 296 | Else 297 | $Code = 'AwAAAAR6AgAAAAAAAABcQfD553vjya/3DmalU0BKqABevUb/60GZ55rMwmzpQfPSRUlIl04lEiS8RDrXpS0EoBUe+uzDgZd37nVu9wsJ4fykqYvLoMz3ApxQbTBKleOIRSla6I0V8dNP3P7rHeUfjH0jCho0RvhhVpf0o4ht/iZptauxaoy1zQ19TkPZ/vf5Im8ecY6qEdHNzjo2H60jVwiOJ+1J47TmQRwxJ+yKLakq8QNxtKkRIB9B9ugfo3NAL0QslDxbyU0dSgw2aOPxV+uttLzYNnWbLBZVQbchcKgLRjC/32U3Op576sOYFolB1Nj4/33c7MRgtGLjlZfTB/4yNvd4/E+u3U6/Q4MYApCfWF4R/d9CAdiwgIjCYUkGDExKjFtHbAWXfWh9kQ7Q/GWUjsfF9BtHO6924Cy1Ou+BUKksqsxmIKP4dBjvvmz9OHc1FdtR9I63XKyYtlUnqVRtKwlNrYAZVCSFsyAefMbteq1ihU33sCsLkAnp1LRZ2wofgT1/JtT8+GO2s/n52D18wM70RH2n5uJJv8tlxQc1lwbmo4XQvcbcE91U2j9glvt2wC1pkP0hF23Nr/iiIEZHIPAOAHvhervlHE830LSHyUx8yh5Tjojr0gdLvQ==' 298 | EndIf 299 | Local $CodeBase = _BinaryCall_Create($Code) 300 | If @Error Then Return SetError(1, 0, 0) 301 | 302 | Local $Symbol[] = ["ToArgvW","ToArgvA"] 303 | $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) 304 | If @Error Then Return SetError(1, 0, 0) 305 | EndIf 306 | 307 | Local $Ret 308 | If $IsUnicode Then 309 | $Ret = DllCallAddress("ptr:cdecl", DllStructGetData($SymbolList, "ToArgvW"), "wstr", $CommandLine, "int*", 0) 310 | Else 311 | $Ret = DllCallAddress("ptr:cdecl", DllStructGetData($SymbolList, "ToArgvA"), "str", $CommandLine, "int*", 0) 312 | EndIf 313 | 314 | If Not @Error And $Ret[0] <> 0 Then 315 | _BinaryCall_ReleaseOnExit($Ret[0]) 316 | $Argc = $Ret[2] 317 | Return $Ret[0] 318 | Else 319 | Return SetError(2, 0, 0) 320 | EndIf 321 | EndFunc 322 | 323 | Func _BinaryCall_StdioRedirect($Filename = "CON", $Flag = 1 + 2 + 4) 324 | Static $SymbolList 325 | If Not IsDllStruct($SymbolList) Then 326 | Local $Code, $Reloc 327 | If @AutoItX64 Then 328 | $Code = 'AwAAAASjAQAAAAAAAAAkL48ClEB9jTEOeYv4yYTosNjFM1rLNdMULriZUDxTj+ZdkQ01F5zKL+WDCScfQKKLn66EDmcA+gXIkPcZV4lyz8VPw8BPZlNB5KymydM15kCA+uqvmBc1V0NJfzgsF0Amhn0JhM/ZIguYCHxywMQ1SgKxUb05dxDg8WlX/2aPfSolcX47+4/72lPDNTeT7d7XRdm0ND+eCauuQcRH2YOahare9ASxuU4IMHCh2rbZYHwmTNRiQUB/8dLGtph93yhmwdHtyMPLX2x5n6sdA1mxua9htLsLTulE05LLmXbRYXylDz0A' 329 | $Reloc = 'AwAAAAQIAAAAAAAAAAABAB7T+CzGn9ScQAC=' 330 | Else 331 | $Code = 'AwAAAASVAQAAAAAAAABcQfD553vjya/3DmalU0BKqABaUcndypZ3mTYUkHxlLV/lKZPrXYWXgNATjyiowkUQGDVYUy5THQwK4zYdU7xuGf7qfVDELc1SNbiW3NgD4D6N6ZM7auI1jPaThsPfA/ouBcx2aVQX36fjmViTZ8ZLzafjJeR7d5OG5s9sAoIzFLTZsqrFlkIJedqDAOfhA/0mMrkavTWnsio6yTbic1dER0DcEsXpLn0vBNErKHoagLzAgofHNLeFRw5yHWz5owR5CYL7rgiv2k51neHBWGx97A==' 332 | $Reloc = 'AwAAAAQgAAAAAAAAAAABABfyHS/VRkdjBBzbtGPD6vtmVH/IsGHYvPsTv2lGuqJxGlAA' 333 | EndIf 334 | 335 | Local $CodeBase = _BinaryCall_Create($Code, $Reloc) 336 | If @Error Then Return SetError(1, 0, 0) 337 | 338 | Local $Symbol[] = ["StdinRedirect","StdoutRedirect","StderrRedirect"] 339 | $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) 340 | If @Error Then Return SetError(1, 0, 0) 341 | EndIf 342 | 343 | If BitAND($Flag, 1) Then DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "StdinRedirect"), "str", $Filename) 344 | If BitAND($Flag, 2) Then DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "StdoutRedirect"), "str", $Filename) 345 | If BitAND($Flag, 4) Then DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "StderrRedirect"), "str", $Filename) 346 | EndFunc 347 | 348 | Func _BinaryCall_StdinRedirect($Filename = "CON") 349 | Local $Ret = _BinaryCall_StdioRedirect($Filename, 1) 350 | Return SetError(@Error, @Extended, $Ret) 351 | EndFunc 352 | 353 | Func _BinaryCall_StdoutRedirect($Filename = "CON") 354 | Local $Ret = _BinaryCall_StdioRedirect($Filename, 2) 355 | Return SetError(@Error, @Extended, $Ret) 356 | EndFunc 357 | 358 | Func _BinaryCall_StderrRedirect($Filename = "CON") 359 | Local $Ret = _BinaryCall_StdioRedirect($Filename, 4) 360 | Return SetError(@Error, @Extended, $Ret) 361 | EndFunc 362 | 363 | Func _BinaryCall_ReleaseOnExit($Ptr) 364 | OnAutoItExitRegister('__BinaryCall_DoRelease') 365 | __BinaryCall_ReleaseOnExit_Handle($Ptr) 366 | EndFunc 367 | 368 | Func __BinaryCall_DoRelease() 369 | __BinaryCall_ReleaseOnExit_Handle() 370 | EndFunc 371 | 372 | Func __BinaryCall_ReleaseOnExit_Handle($Ptr = Default) 373 | Static $PtrList 374 | 375 | If @NumParams = 0 Then 376 | If IsArray($PtrList) Then 377 | For $i = 1 To $PtrList[0] 378 | _BinaryCall_Free($PtrList[$i]) 379 | Next 380 | EndIf 381 | Else 382 | If Not IsArray($PtrList) Then 383 | Local $InitArray[1] = [0] 384 | $PtrList = $InitArray 385 | EndIf 386 | 387 | If IsPtr($Ptr) Then 388 | Local $Array = $PtrList 389 | Local $Size = UBound($Array) 390 | ReDim $Array[$Size + 1] 391 | $Array[$Size] = $Ptr 392 | $Array[0] += 1 393 | $PtrList = $Array 394 | EndIf 395 | EndIf 396 | EndFunc 397 | -------------------------------------------------------------------------------- /src/include/JSON.au3: -------------------------------------------------------------------------------- 1 | ; ============================================================================================================================ 2 | ; File : Json.au3 (2021.11.20) 3 | ; Purpose : A Non-Strict JavaScript Object Notation (JSON) Parser UDF 4 | ; Author : Ward 5 | ; Dependency: BinaryCall.au3 6 | ; Website : http://www.json.org/index.html 7 | ; 8 | ; Source : jsmn.c 9 | ; Author : zserge 10 | ; Website : http://zserge.com/jsmn.html 11 | ; 12 | ; Source : json_string_encode.c, json_string_decode.c 13 | ; Author : Ward 14 | ; Jos - Added Json_Dump() 15 | ; TheXMan - Json_ObjGetItems and some Json_Dump Fixes. 16 | ; Jos - Changed Json_ObjGet() and Json_ObjExists() to allow for multilevel object in string. 17 | ; ============================================================================================================================ 18 | 19 | ; ============================================================================================================================ 20 | ; Public Functions: 21 | ; Json_StringEncode($String, $Option = 0) 22 | ; Json_StringDecode($String) 23 | ; Json_IsObject(ByRef $Object) 24 | ; Json_IsNull(ByRef $Null) 25 | ; Json_Encode($Data, $Option = 0, $Indent = Default, $ArraySep = Default, $ObjectSep = Default, $ColonSep = Default) 26 | ; Json_Decode($Json, $InitTokenCount = 1000) 27 | ; Json_ObjCreate() 28 | ; Json_ObjPut(ByRef $Object, $Key, $Value) 29 | ; Json_ObjGet(ByRef $Object, $Key) 30 | ; Json_ObjDelete(ByRef $Object, $Key) 31 | ; Json_ObjExists(ByRef $Object, $Key) 32 | ; Json_ObjGetCount(ByRef $Object) 33 | ; Json_ObjGetKeys(ByRef $Object) 34 | ; Json_ObjGetItems(ByRef $Object) 35 | ; Json_ObjClear(ByRef $Object) 36 | ; Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) 37 | ; Json_Get(ByRef $Var, $Notation) 38 | ; Json_Dump($String) 39 | ; ============================================================================================================================ 40 | 41 | #include-once 42 | #include "BinaryCall.au3" 43 | 44 | ; The following constants can be combined to form options for Json_Encode() 45 | Global Const $JSON_UNESCAPED_UNICODE = 1 ; Encode multibyte Unicode characters literally 46 | Global Const $JSON_UNESCAPED_SLASHES = 2 ; Don't escape / 47 | Global Const $JSON_HEX_TAG = 4 ; All < and > are converted to \u003C and \u003E 48 | Global Const $JSON_HEX_AMP = 8 ; All &s are converted to \u0026 49 | Global Const $JSON_HEX_APOS = 16 ; All ' are converted to \u0027 50 | Global Const $JSON_HEX_QUOT = 32 ; All " are converted to \u0022 51 | Global Const $JSON_UNESCAPED_ASCII = 64 ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) 52 | Global Const $JSON_PRETTY_PRINT = 128 ; Use whitespace in returned data to format it 53 | Global Const $JSON_STRICT_PRINT = 256 ; Make sure returned JSON string is RFC4627 compliant 54 | Global Const $JSON_UNQUOTED_STRING = 512 ; Output unquoted string if possible (conflicting with $Json_STRICT_PRINT) 55 | 56 | ; Error value returnd by Json_Decode() 57 | Global Const $JSMN_ERROR_NOMEM = -1 ; Not enough tokens were provided 58 | Global Const $JSMN_ERROR_INVAL = -2 ; Invalid character inside JSON string 59 | Global Const $JSMN_ERROR_PART = -3 ; The string is not a full JSON packet, more bytes expected 60 | Global $Total_JSON_DUMP_Output = "" 61 | 62 | Func __Jsmn_RuntimeLoader($ProcName = "") 63 | Static $SymbolList 64 | If Not IsDllStruct($SymbolList) Then 65 | Local $Code 66 | If @AutoItX64 Then 67 | $Code = 'AwAAAAQfCAAAAAAAAAA1HbEvgTNrvX54gCiWSTVmt5v7RCdoFJ/zhkKmwcm8yVqZPjJBoVhNHHAIzrHWKbZh1J0QAUaHB5zyQTilTmWa9O0OKeLrk/Jg+o7CmMzjEk74uPongdHv37nwYXvg97fiHvjP2bBzI9gxSkKq9Cqh/GxSHIlZPYyW76pXUt//25Aqs2Icfpyay/NFd50rW7eMliH5ynkrp16HM1afithVrO+LpSaz/IojowApmXnBHUncHliDqbkx6/AODUkyDm1hj+AiEZ9Me1Jy+hBQ1/wC/YnuuYSJvNAKp6XDnyc8Nwr54Uqx5SbUW2CezwQQ7aXX/HFiHSKpQcFW/gi8oSx5nsoxUXVjxeNI/L7z6GF2mfu3Tnpt7hliWEdA2r2VB+TIM7Pgwl9X3Ge0T3KJQUaRtLJZcPvVtOuKXr2Q9wy7hl80hVRrt9zYrbjBHXLrRx/HeIMkZwxhmKo/dD/vvaNgE+BdU8eeJqFBJK2alrK2rh2WkRynftyepm1WrdKrz/5KhQPp/4PqH+9IADDjoGBbfvJQXdT+yiO8DtfrVnd+JOEKsKEsdgeM3UXx5r6tEHO9rYWbzbnyEiX7WozZemry+vBZMMtHn1aA63+RcDQED73xOsnj00/9E5Z6hszM5Hi8vi6Hw3iOgf3cHwcXG44aau0JpuA2DlrUvnJOYkNnY+bECeSdAR1UQkFNyqRoH2xm4Y7gYMCPsFtPBlwwleEKI27SsUq1ZHVQvFCoef7DXgf/GwPCAvwDMIQfb3hJtIVubOkASRQZVNIJ/y4KPrn/gcASV7fvMjE34loltTVlyqprUWxpI51tN6vhTOLAp+CHseKxWaf9g1wdbVs0e/5xAiqgJbmKNi9OYbhV/blpp3SL63XKxGiHdxhK1aR+4rUY4eckNbaHfW7ob+q7aBoHSs6LVX9lWakb/xWxwQdwcX/7/C+TcQSOOg6rLoWZ8wur9qp+QwzoCbXkf04OYpvD5kqgEiwQnB90kLtcA+2XSbDRu+aq02eNNCzgkZujeL/HjVISjf2EuQKSsZkBhS15eiXoRgPaUoQ5586VS7t7rhM8ng5LiVzoUQIZ0pNKxWWqD+gXRBvOMIXY2yd0Ei4sE5KFIEhbs3u8vwP7nFLIpZ/RembPTuc0ZlguGJgJ2F5iApfia+C2tRYRNjVCqECCveWw6P2Btfaq9gw7cWWmJflIQbjxtccDqsn52cftLqXSna9zk05mYdJSV8z2W7vM1YJ5Rd82v0j3kau710A/kQrN41bdaxmKjL+gvSRlOLB1bpvkCtf9+h+eVA4XIkIXKFydr1OjMZ8wq2FIxPJXskAe4YMgwQmeWZXMK1KBbLB3yQR1YOYaaHk1fNea9KsXgs5YLbiP/noAusz76oEDo/DJh1aw7cUwdhboVPg1bNq88mRb5RGa13KDK9uEET7OA02KbSL+Q4HOtyasLUoVrZzVyd8iZPoGrV36vHnj+yvG4fq6F/fkug/sBRp186yVZQVmdAgFd+WiRLnUjxHUKJ6xBbpt4FTP42E/PzPw3JlDb0UQtXTDnIL0CWqbns2E7rZ5PBwrwQYwvBn/gaEeLVGDSh84DfW4zknIneGnYDXdVEHC+ITzejAnNxb1duB+w2aVTk64iXsKHETq53GMH6DuFi0oUeEFb/xp0HsRyNC8vBjOq3Kk7NZHxCQLh7UATFttG7sH+VIqGjjNwmraGJ0C92XhpQwSgfAb3KHucCHGTTti0sn6cgS3vb36BkjGKsRhXVuoQCFH96bvTYtl8paQQW9ufRfvxPqmU0sALdR0fIvZwd7Z8z0UoEec6b1Sul4e60REj/H4scb6N2ryHBR9ua5N1YxJu1uwgoLXUL2wT9ZPBjPjySUzeqXikUIKKYgNlWy+VlNIiWWTPtKpCTr508logA==' 68 | Else 69 | $Code = 'AwAAAASFBwAAAAAAAAA1HbEvgTNrvX54gCiqsa1mt5v7RCdoAFjCfVE40DZbE5UfabA9UKuHrjqOMbvjSoB2zBJTEYEQejBREnPrXL3VwpVOW+L9SSfo0rTfA8U2W+Veqo1uy0dOsPhl7vAHbBHrvJNfEUe8TT0q2eaTX2LeWpyrFEm4I3mhDJY/E9cpWf0A78e+y4c7NxewvcVvAakIHE8Xb8fgtqCTVQj3Q1eso7n1fKQj5YsQ20A86Gy9fz8dky78raeZnhYayn0b1riSUKxGVnWja2i02OvAVM3tCCvXwcbSkHTRjuIAbMu2mXF1UpKci3i/GzPmbxo9n/3aX/jpR6UvxMZuaEDEij4yzfZv7EyK9WCNBXxMmtTp3Uv6MZsK+nopXO3C0xFzZA/zQObwP3zhJ4sdatzMhFi9GAM70R4kgMzsxQDNArueXj+UFzbCCFZ89zXs22F7Ixi0FyFTk3jhH56dBaN65S+gtPztNGzEUmtk4M8IanhQSw8xCXr0x0MPDpDFDZs3aN5TtTPYmyk3psk7OrmofCQGG5cRcqEt9902qtxQDOHumfuCPMvU+oMjzLzBVEDnBbj+tY3y1jvgGbmEJguAgfB04tSeAt/2618ksnJJK+dbBkDLxjB4xrFr3uIFFadJQWUckl5vfh4MVXbsFA1hG49lqWDa7uSuPCnOhv8Yql376I4U4gfcF8LcgorkxS+64urv2nMUq6AkBEMQ8bdkI64oKLFfO7fGxh5iMNZuLoutDn2ll3nq4rPi4kOyAtfhW0UPyjvqNtXJ/h0Wik5Mi8z7BVxaURTDk81TP8y9+tzjySB/uGfHFAzjF8DUY1vqJCgn0GQ8ANtiiElX/+Wnc9HWi2bEEXItbm4yv97QrEPvJG9nPRBKWGiAQsIA5J+WryX5NrfEfRPk0QQwyl16lpHlw6l0UMuk7S21xjQgyWo0MywfzoBWW7+t4HH9sqavvP4dYAw81BxXqVHQhefUOS23en4bFUPWE98pAN6bul+kS767vDK34yTC3lA2a8wLrBEilmFhdB74fxbAl+db91PivhwF/CR4Igxr35uLdof7+jAYyACopQzmsbHpvAAwT2lapLix8H03nztAC3fBqFSPBVdIv12lsrrDw4dfhJEzq7AbL/Y7L/nIcBsQ/3UyVnZk4kZP1KzyPCBLLIQNpCVgOLJzQuyaQ6k2QCBy0eJ0ppUyfp54LjwVg0X7bwncYbAomG4ZcFwTQnC2AX3oYG5n6Bz4SLLjxrFsY+v/SVa+GqH8uePBh1TPkHVNmzjXXymEf5jROlnd+EjfQdRyitkjPrg2HiQxxDcVhCh5J2L5+6CY9eIaYgrbd8zJnzAD8KnowHwh2bi4JLgmt7ktJ1XGizox7cWf3/Dod56KAcaIrSVw9XzYybdJCf0YRA6yrwPWXbwnzc/4+UDkmegi+AoCEMoue+cC7vnYVdmlbq/YLE/DWJX383oz2Ryq8anFrZ8jYvdoh8WI+dIugYL2SwRjmBoSwn56XIaot/QpMo3pYJIa4o8aZIZrjvB7BXO5aCDeMuZdUMT6AXGAGF1AeAWxFd2XIo1coR+OplMNDuYia8YAtnSTJ9JwGYWi2dJz3xrxsTQpBONf3yn8LVf8eH+o5eXc7lzCtHlDB+YyI8V9PyMsUPOeyvpB3rr9fDfNy263Zx33zTi5jldgP2OetUqGfbwl+0+zNYnrg64bluyIN/Awt1doDCQkCKpKXxuPaem/SyCHrKjg' 70 | EndIf 71 | 72 | Local $Symbol[] = ["jsmn_parse", "jsmn_init", "json_string_decode", "json_string_encode"] 73 | Local $CodeBase = _BinaryCall_Create($Code) 74 | If @error Then Exit MsgBox(16, "Json", "Startup Failure!") 75 | 76 | $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) 77 | If @error Then Exit MsgBox(16, "Json", "Startup Failure!") 78 | EndIf 79 | If $ProcName Then Return DllStructGetData($SymbolList, $ProcName) 80 | EndFunc ;==>__Jsmn_RuntimeLoader 81 | 82 | Func Json_StringEncode($String, $Option = 0) 83 | Static $Json_StringEncode = __Jsmn_RuntimeLoader("json_string_encode") 84 | Local $Length = StringLen($String) * 6 + 1 85 | Local $Buffer = DllStructCreate("wchar[" & $Length & "]") 86 | Local $Ret = DllCallAddress("int:cdecl", $Json_StringEncode, "wstr", $String, "ptr", DllStructGetPtr($Buffer), "uint", $Length, "int", $Option) 87 | Return SetError($Ret[0], 0, DllStructGetData($Buffer, 1)) 88 | EndFunc ;==>Json_StringEncode 89 | 90 | Func Json_StringDecode($String) 91 | Static $Json_StringDecode = __Jsmn_RuntimeLoader("json_string_decode") 92 | Local $Length = StringLen($String) + 1 93 | Local $Buffer = DllStructCreate("wchar[" & $Length & "]") 94 | Local $Ret = DllCallAddress("int:cdecl", $Json_StringDecode, "wstr", $String, "ptr", DllStructGetPtr($Buffer), "uint", $Length) 95 | Return SetError($Ret[0], 0, DllStructGetData($Buffer, 1)) 96 | EndFunc ;==>Json_StringDecode 97 | 98 | Func Json_Decode($Json, $InitTokenCount = 1000) 99 | Static $Jsmn_Init = __Jsmn_RuntimeLoader("jsmn_init"), $Jsmn_Parse = __Jsmn_RuntimeLoader("jsmn_parse") 100 | If $Json = "" Then $Json = '""' 101 | Local $TokenList, $Ret 102 | Local $Parser = DllStructCreate("uint pos;int toknext;int toksuper") 103 | Do 104 | DllCallAddress("none:cdecl", $Jsmn_Init, "ptr", DllStructGetPtr($Parser)) 105 | $TokenList = DllStructCreate("byte[" & ($InitTokenCount * 20) & "]") 106 | $Ret = DllCallAddress("int:cdecl", $Jsmn_Parse, "ptr", DllStructGetPtr($Parser), "wstr", $Json, "ptr", DllStructGetPtr($TokenList), "uint", $InitTokenCount) 107 | $InitTokenCount *= 2 108 | Until $Ret[0] <> $JSMN_ERROR_NOMEM 109 | 110 | Local $Next = 0 111 | Return SetError($Ret[0], 0, _Json_Token($Json, DllStructGetPtr($TokenList), $Next)) 112 | EndFunc ;==>Json_Decode 113 | 114 | Func _Json_Token(ByRef $Json, $Ptr, ByRef $Next) 115 | If $Next = -1 Then Return Null 116 | 117 | Local $Token = DllStructCreate("int;int;int;int", $Ptr + ($Next * 20)) 118 | Local $Type = DllStructGetData($Token, 1) 119 | Local $Start = DllStructGetData($Token, 2) 120 | Local $End = DllStructGetData($Token, 3) 121 | Local $Size = DllStructGetData($Token, 4) 122 | $Next += 1 123 | 124 | If $Type = 0 And $Start = 0 And $End = 0 And $Size = 0 Then ; Null Item 125 | $Next = -1 126 | Return Null 127 | EndIf 128 | 129 | Switch $Type 130 | Case 0 ; Json_PRIMITIVE 131 | Local $Primitive = StringMid($Json, $Start + 1, $End - $Start) 132 | Switch $Primitive 133 | Case "true" 134 | Return True 135 | Case "false" 136 | Return False 137 | Case "null" 138 | Return Null 139 | Case Else 140 | If StringRegExp($Primitive, "^[+\-0-9]") Then 141 | Return Number($Primitive) 142 | Else 143 | Return Json_StringDecode($Primitive) 144 | EndIf 145 | EndSwitch 146 | 147 | Case 1 ; Json_OBJECT 148 | Local $Object = Json_ObjCreate() 149 | For $i = 0 To $Size - 1 Step 2 150 | Local $Key = _Json_Token($Json, $Ptr, $Next) 151 | Local $Value = _Json_Token($Json, $Ptr, $Next) 152 | If Not IsString($Key) Then $Key = Json_Encode($Key) 153 | 154 | If $Object.Exists($Key) Then $Object.Remove($Key) 155 | $Object.Add($Key, $Value) 156 | Next 157 | Return $Object 158 | 159 | Case 2 ; Json_ARRAY 160 | Local $Array[$Size] 161 | For $i = 0 To $Size - 1 162 | $Array[$i] = _Json_Token($Json, $Ptr, $Next) 163 | Next 164 | Return $Array 165 | 166 | Case 3 ; Json_STRING 167 | Return Json_StringDecode(StringMid($Json, $Start + 1, $End - $Start)) 168 | EndSwitch 169 | EndFunc ;==>_Json_Token 170 | 171 | Func Json_IsObject(ByRef $Object) 172 | Return (IsObj($Object) And ObjName($Object) = "Dictionary") 173 | EndFunc ;==>Json_IsObject 174 | 175 | Func Json_IsNull(ByRef $Null) 176 | Return IsKeyword($Null) Or (Not IsObj($Null) And VarGetType($Null) = "Object") 177 | EndFunc ;==>Json_IsNull 178 | 179 | Func Json_Encode_Compact($Data, $Option = 0) 180 | Local $Json = "" 181 | 182 | Select 183 | Case IsString($Data) 184 | Return '"' & Json_StringEncode($Data, $Option) & '"' 185 | 186 | Case IsNumber($Data) 187 | Return $Data 188 | 189 | Case IsArray($Data) And UBound($Data, 0) = 1 190 | $Json = "[" 191 | For $i = 0 To UBound($Data) - 1 192 | $Json &= Json_Encode_Compact($Data[$i], $Option) & "," 193 | Next 194 | If StringRight($Json, 1) = "," Then $Json = StringTrimRight($Json, 1) 195 | Return $Json & "]" 196 | 197 | Case Json_IsObject($Data) 198 | $Json = "{" 199 | Local $Keys = $Data.Keys() 200 | For $i = 0 To UBound($Keys) - 1 201 | $Json &= '"' & Json_StringEncode($Keys[$i], $Option) & '":' & Json_Encode_Compact($Data.Item($Keys[$i]), $Option) & "," 202 | Next 203 | If StringRight($Json, 1) = "," Then $Json = StringTrimRight($Json, 1) 204 | Return $Json & "}" 205 | 206 | Case IsBool($Data) 207 | Return StringLower($Data) 208 | 209 | Case IsPtr($Data) 210 | Return Number($Data) 211 | 212 | Case IsBinary($Data) 213 | Return '"' & Json_StringEncode(BinaryToString($Data, 4), $Option) & '"' 214 | 215 | Case Else ; Keyword, DllStruct, Object 216 | Return "null" 217 | EndSelect 218 | EndFunc ;==>Json_Encode_Compact 219 | 220 | Func Json_Encode_Pretty($Data, $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep, $ArrayCRLF = Default, $ObjectCRLF = Default, $NextIdent = "") 221 | Local $ThisIdent = $NextIdent, $Json = "", $String = "", $Match = "", $Keys = "" 222 | Local $Length = 0 223 | 224 | Select 225 | Case IsString($Data) 226 | $String = Json_StringEncode($Data, $Option) 227 | If BitAND($Option, $JSON_UNQUOTED_STRING) And Not BitAND($Option, $JSON_STRICT_PRINT) And Not StringRegExp($String, "[\s,:]") And Not StringRegExp($String, "^[+\-0-9]") Then 228 | Return $String 229 | Else 230 | Return '"' & $String & '"' 231 | EndIf 232 | 233 | Case IsArray($Data) And UBound($Data, 0) = 1 234 | If UBound($Data) = 0 Then Return "[]" 235 | If IsKeyword($ArrayCRLF) Then 236 | $ArrayCRLF = "" 237 | $Match = StringRegExp($ArraySep, "[\r\n]+$", 3) 238 | If IsArray($Match) Then $ArrayCRLF = $Match[0] 239 | EndIf 240 | 241 | If $ArrayCRLF Then $NextIdent &= $Indent 242 | $Length = UBound($Data) - 1 243 | For $i = 0 To $Length 244 | If $ArrayCRLF Then $Json &= $NextIdent 245 | $Json &= Json_Encode_Pretty($Data[$i], $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep, $ArrayCRLF, $ObjectCRLF, $NextIdent) 246 | If $i < $Length Then $Json &= $ArraySep 247 | Next 248 | 249 | If $ArrayCRLF Then Return "[" & $ArrayCRLF & $Json & $ArrayCRLF & $ThisIdent & "]" 250 | Return "[" & $Json & "]" 251 | 252 | Case Json_IsObject($Data) 253 | If $Data.Count = 0 Then Return "{}" 254 | If IsKeyword($ObjectCRLF) Then 255 | $ObjectCRLF = "" 256 | $Match = StringRegExp($ObjectSep, "[\r\n]+$", 3) 257 | If IsArray($Match) Then $ObjectCRLF = $Match[0] 258 | EndIf 259 | 260 | If $ObjectCRLF Then $NextIdent &= $Indent 261 | $Keys = $Data.Keys() 262 | $Length = UBound($Keys) - 1 263 | For $i = 0 To $Length 264 | If $ObjectCRLF Then $Json &= $NextIdent 265 | $Json &= Json_Encode_Pretty(String($Keys[$i]), $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep) & $ColonSep _ 266 | & Json_Encode_Pretty($Data.Item($Keys[$i]), $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep, $ArrayCRLF, $ObjectCRLF, $NextIdent) 267 | If $i < $Length Then $Json &= $ObjectSep 268 | Next 269 | 270 | If $ObjectCRLF Then Return "{" & $ObjectCRLF & $Json & $ObjectCRLF & $ThisIdent & "}" 271 | Return "{" & $Json & "}" 272 | 273 | Case Else 274 | Return Json_Encode_Compact($Data, $Option) 275 | 276 | EndSelect 277 | EndFunc ;==>Json_Encode_Pretty 278 | 279 | Func Json_Encode($Data, $Option = 0, $Indent = Default, $ArraySep = Default, $ObjectSep = Default, $ColonSep = Default) 280 | If BitAND($Option, $JSON_PRETTY_PRINT) Then 281 | Local $Strict = BitAND($Option, $JSON_STRICT_PRINT) 282 | 283 | If IsKeyword($Indent) Then 284 | $Indent = @TAB 285 | Else 286 | $Indent = Json_StringDecode($Indent) 287 | If StringRegExp($Indent, "[^\t ]") Then $Indent = @TAB 288 | EndIf 289 | 290 | If IsKeyword($ArraySep) Then 291 | $ArraySep = "," & @CRLF 292 | Else 293 | $ArraySep = Json_StringDecode($ArraySep) 294 | If $ArraySep = "" Or StringRegExp($ArraySep, "[^\s,]|,.*,") Or ($Strict And Not StringRegExp($ArraySep, ",")) Then $ArraySep = "," & @CRLF 295 | EndIf 296 | 297 | If IsKeyword($ObjectSep) Then 298 | $ObjectSep = "," & @CRLF 299 | Else 300 | $ObjectSep = Json_StringDecode($ObjectSep) 301 | If $ObjectSep = "" Or StringRegExp($ObjectSep, "[^\s,]|,.*,") Or ($Strict And Not StringRegExp($ObjectSep, ",")) Then $ObjectSep = "," & @CRLF 302 | EndIf 303 | 304 | If IsKeyword($ColonSep) Then 305 | $ColonSep = ": " 306 | Else 307 | $ColonSep = Json_StringDecode($ColonSep) 308 | If $ColonSep = "" Or StringRegExp($ColonSep, "[^\s,:]|[,:].*[,:]") Or ($Strict And (StringRegExp($ColonSep, ",") Or Not StringRegExp($ColonSep, ":"))) Then $ColonSep = ": " 309 | EndIf 310 | 311 | Return Json_Encode_Pretty($Data, $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep) 312 | 313 | ElseIf BitAND($Option, $JSON_UNQUOTED_STRING) Then 314 | Return Json_Encode_Pretty($Data, $Option, "", ",", ",", ":") 315 | Else 316 | Return Json_Encode_Compact($Data, $Option) 317 | EndIf 318 | EndFunc ;==>Json_Encode 319 | 320 | Func Json_ObjCreate() 321 | Local $Object = ObjCreate('Scripting.Dictionary') 322 | $Object.CompareMode = 0 323 | Return $Object 324 | EndFunc ;==>Json_ObjCreate 325 | 326 | Func Json_ObjPut(ByRef $Object, $Key, $Value) 327 | $Key = String($Key) 328 | If $Object.Exists($Key) Then $Object.Remove($Key) 329 | $Object.Add($Key, $Value) 330 | EndFunc ;==>Json_ObjPut 331 | 332 | Func Json_ObjGet(ByRef $Object, $Key) 333 | Local $DynObject = $Object 334 | Local $Keys = StringSplit($Key, ".") 335 | For $x = 1 To $Keys[0] 336 | If $DynObject.Exists($Keys[$x]) Then 337 | If $x = $Keys[0] Then 338 | Return $DynObject.Item($Keys[$x]) 339 | Else 340 | $DynObject = Json_ObjGet($DynObject, $Keys[$x]) 341 | EndIf 342 | EndIf 343 | Next 344 | Return SetError(1, 0, '') 345 | EndFunc ;==>Json_ObjGet 346 | 347 | Func Json_ObjDelete(ByRef $Object, $Key) 348 | $Key = String($Key) 349 | If $Object.Exists($Key) Then $Object.Remove($Key) 350 | EndFunc ;==>Json_ObjDelete 351 | 352 | Func Json_ObjExists(ByRef $Object, $Key) 353 | Local $DynObject = $Object 354 | Local $Keys = StringSplit($Key, ".") 355 | For $x = 1 To $Keys[0] 356 | If $DynObject.Exists($Keys[$x]) Then 357 | If $x = $Keys[0] Then 358 | Return True 359 | Else 360 | $DynObject = Json_ObjGet($DynObject, $Keys[$x]) 361 | EndIf 362 | Else 363 | Return False 364 | EndIf 365 | Next 366 | Return False 367 | EndFunc ;==>Json_ObjExists 368 | 369 | Func Json_ObjGetCount(ByRef $Object) 370 | Return $Object.Count 371 | EndFunc ;==>Json_ObjGetCount 372 | 373 | Func Json_ObjGetKeys(ByRef $Object) 374 | Return $Object.Keys() 375 | EndFunc ;==>Json_ObjGetKeys 376 | 377 | Func Json_ObjGetItems(ByRef $Object) 378 | Return $Object.Items() 379 | EndFunc ;==>Json_ObjGetItems 380 | 381 | Func Json_ObjClear(ByRef $Object) 382 | Return $Object.RemoveAll() 383 | EndFunc ;==>Json_ObjClear 384 | 385 | ; Both dot notation and square bracket notation can be supported 386 | Func Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) 387 | ;Dot-notation and bracket-notation regular expressions 388 | Const $REGEX_DOT_WITH_STRING = '^\.("[^"]+")', _ 389 | $REGEX_DOT_WITH_LITERAL = '^\.([^.[]+)', _ 390 | $REGEX_BRACKET_WITH_STRING = '^\[("[^"]+")]', _ 391 | $REGEX_BRACKET_WITH_LITERAL = '^\[([^]]+)]' 392 | 393 | Local $Ret = 0, $Item = "", $Error = 0 394 | Local $Match = "" 395 | 396 | ;Set regular expression based on identified notation type. 397 | ;Note: The order below matters. Check "string" notations 398 | ;before their "literal" counterpart. 399 | Local $Regex = "" 400 | Select 401 | Case StringRegExp($Notation, $REGEX_DOT_WITH_STRING) 402 | $Regex = $REGEX_DOT_WITH_STRING 403 | Case StringRegExp($Notation, $REGEX_DOT_WITH_LITERAL) 404 | $Regex = $REGEX_DOT_WITH_LITERAL 405 | Case StringRegExp($Notation, $REGEX_BRACKET_WITH_STRING) 406 | $Regex = $REGEX_BRACKET_WITH_STRING 407 | Case StringRegExp($Notation, $REGEX_BRACKET_WITH_LITERAL) 408 | $Regex = $REGEX_BRACKET_WITH_LITERAL 409 | Case Else 410 | Return SetError(2, 0, "") ; invalid notation 411 | EndSelect 412 | 413 | ;Parse leading notation 414 | $Match = StringRegExp($Notation, $Regex, 2) 415 | If IsArray($Match) Then 416 | Local $Index 417 | If StringLeft($Match[0], 1) = "." Then 418 | $Index = String(Json_Decode($Match[1])) ;only string using dot-notation 419 | Else 420 | $Index = Json_Decode($Match[1]) 421 | EndIf 422 | $Notation = StringTrimLeft($Notation, StringLen($Match[0])) ;trim leading notation 423 | 424 | If IsString($Index) Then 425 | If $CheckExists And (Not Json_IsObject($Var) Or Not Json_ObjExists($Var, $Index)) Then 426 | Return SetError(1, 0, False) ; no specific object 427 | EndIf 428 | 429 | If Not Json_IsObject($Var) Then $Var = Json_ObjCreate() 430 | If $Notation Then 431 | $Item = Json_ObjGet($Var, $Index) 432 | $Ret = Json_Put($Item, $Notation, $Data, $CheckExists) 433 | $Error = @error 434 | If Not $Error Then Json_ObjPut($Var, $Index, $Item) 435 | Return SetError($Error, 0, $Ret) 436 | Else 437 | Json_ObjPut($Var, $Index, $Data) 438 | Return True 439 | EndIf 440 | 441 | ElseIf IsInt($Index) Then 442 | If $Index < 0 Or ($CheckExists And (Not IsArray($Var) Or UBound($Var, 0) <> 1 Or $Index >= UBound($Var))) Then 443 | Return SetError(1, 0, False) ; no specific object 444 | EndIf 445 | 446 | If Not IsArray($Var) Or UBound($Var, 0) <> 1 Then 447 | Dim $Var[$Index + 1] 448 | ElseIf $Index >= UBound($Var) Then 449 | ReDim $Var[$Index + 1] 450 | EndIf 451 | 452 | If $Notation Then 453 | $Ret = Json_Put($Var[$Index], $Notation, $Data, $CheckExists) 454 | Return SetError(@error, 0, $Ret) 455 | Else 456 | $Var[$Index] = $Data 457 | Return True 458 | EndIf 459 | 460 | EndIf 461 | EndIf 462 | Return SetError(2, 0, False) ; invalid notation 463 | EndFunc ;==>Json_Put 464 | 465 | ; Both dot notation and square bracket notation can be supported 466 | Func Json_Get(ByRef $Var, $Notation) 467 | ;Dot-notation and bracket-notation regular expressions 468 | Const $REGEX_DOT_WITH_STRING = '^\.("[^"]+")', _ 469 | $REGEX_DOT_WITH_LITERAL = '^\.([^.[]+)', _ 470 | $REGEX_BRACKET_WITH_STRING = '^\[("[^"]+")]', _ 471 | $REGEX_BRACKET_WITH_LITERAL = '^\[([^]]+)]' 472 | 473 | ;Set regular expression based on identified notation type. 474 | ;Note: The order below matters. Check "string" notations 475 | ;before their "literal" counterpart. 476 | Local $Regex = "" 477 | Select 478 | Case StringRegExp($Notation, $REGEX_DOT_WITH_STRING) 479 | $Regex = $REGEX_DOT_WITH_STRING 480 | Case StringRegExp($Notation, $REGEX_DOT_WITH_LITERAL) 481 | $Regex = $REGEX_DOT_WITH_LITERAL 482 | Case StringRegExp($Notation, $REGEX_BRACKET_WITH_STRING) 483 | $Regex = $REGEX_BRACKET_WITH_STRING 484 | Case StringRegExp($Notation, $REGEX_BRACKET_WITH_LITERAL) 485 | $Regex = $REGEX_BRACKET_WITH_LITERAL 486 | Case Else 487 | Return SetError(2, 0, "") ; invalid notation 488 | EndSelect 489 | 490 | ;Parse leading notation 491 | Local $Match = StringRegExp($Notation, $Regex, 2) 492 | If IsArray($Match) Then 493 | Local $Index 494 | If StringLeft($Match[0], 1) = "." Then 495 | $Index = String(Json_Decode($Match[1])) ;only string using dot-notation 496 | Else 497 | $Index = Json_Decode($Match[1]) 498 | EndIf 499 | $Notation = StringTrimLeft($Notation, StringLen($Match[0])) ;trim leading notation 500 | 501 | Local $Item 502 | If IsString($Index) And Json_IsObject($Var) And Json_ObjExists($Var, $Index) Then 503 | $Item = Json_ObjGet($Var, $Index) 504 | ElseIf IsInt($Index) And IsArray($Var) And UBound($Var, 0) = 1 And $Index >= 0 And $Index < UBound($Var) Then 505 | $Item = $Var[$Index] 506 | Else 507 | Return SetError(1, 0, "") ; no specific object 508 | EndIf 509 | 510 | If Not $Notation Then Return $Item 511 | 512 | Local $Ret = Json_Get($Item, $Notation) 513 | Return SetError(@error, 0, $Ret) 514 | EndIf 515 | EndFunc ;==>Json_Get 516 | 517 | ; List all JSON keys and their value to the Console 518 | Func Json_Dump($Json, $InitTokenCount = 1000) 519 | Static $Jsmn_Init = __Jsmn_RuntimeLoader("jsmn_init"), $Jsmn_Parse = __Jsmn_RuntimeLoader("jsmn_parse") 520 | If $Json = "" Then $Json = '""' 521 | Local $TokenList, $Ret 522 | $Total_JSON_DUMP_Output = "" ; reset totaldump variable at the start of the dump process (Use for testing) 523 | Local $Parser = DllStructCreate("uint pos;int toknext;int toksuper") 524 | Do 525 | DllCallAddress("none:cdecl", $Jsmn_Init, "ptr", DllStructGetPtr($Parser)) 526 | $TokenList = DllStructCreate("byte[" & ($InitTokenCount * 20) & "]") 527 | $Ret = DllCallAddress("int:cdecl", $Jsmn_Parse, "ptr", DllStructGetPtr($Parser), "wstr", $Json, "ptr", DllStructGetPtr($TokenList), "uint", $InitTokenCount) 528 | $InitTokenCount *= 2 529 | Until $Ret[0] <> $JSMN_ERROR_NOMEM 530 | 531 | Local $Next = 0 532 | _Json_TokenDump($Json, DllStructGetPtr($TokenList), $Next) 533 | EndFunc ;==>Json_Dump 534 | 535 | Func _Json_TokenDump(ByRef $Json, $Ptr, ByRef $Next, $ObjPath = "") 536 | If $Next = -1 Then Return Null 537 | 538 | Local $Token = DllStructCreate("int;int;int;int", $Ptr + ($Next * 20)) 539 | Local $Type = DllStructGetData($Token, 1) 540 | Local $Start = DllStructGetData($Token, 2) 541 | Local $End = DllStructGetData($Token, 3) 542 | Local $Size = DllStructGetData($Token, 4) 543 | Local $Value 544 | $Next += 1 545 | 546 | If $Type = 0 And $Start = 0 And $End = 0 And $Size = 0 Then ; Null Item 547 | $Next = -1 548 | Return Null 549 | EndIf 550 | 551 | Switch $Type 552 | Case 0 ; Json_PRIMITIVE 553 | Local $Primitive = StringMid($Json, $Start + 1, $End - $Start) 554 | Switch $Primitive 555 | Case "true" 556 | Return "True" 557 | Case "false" 558 | Return "False" 559 | Case "null" 560 | Return "Null" 561 | Case Else 562 | If StringRegExp($Primitive, "^[+\-0-9]") Then 563 | Return Number($Primitive) 564 | Else 565 | Return Json_StringDecode($Primitive) 566 | EndIf 567 | EndSwitch 568 | 569 | Case 1 ; Json_OBJECT 570 | For $i = 0 To $Size - 1 Step 2 571 | Local $Key = _Json_TokenDump($Json, $Ptr, $Next) 572 | Local $cObjPath = $ObjPath & "." & $Key 573 | $Value = _Json_TokenDump($Json, $Ptr, $Next, $ObjPath & "." & $Key) 574 | If Not (IsBool($Value) And $Value = False) Then 575 | If Not IsString($Key) Then 576 | $Key = Json_Encode($Key) 577 | EndIf 578 | ; show the key and its value 579 | ConsoleWrite("+-> " & $cObjPath & ' =' & $Value & @CRLF) 580 | $Total_JSON_DUMP_Output &= "+-> " & $cObjPath & ' =' & $Value & @CRLF 581 | EndIf 582 | Next 583 | Return False 584 | Case 2 ; Json_ARRAY 585 | Local $sObjPath = $ObjPath 586 | For $i = 0 To $Size - 1 587 | $sObjPath = $ObjPath & "[" & $i & "]" 588 | $Value = _Json_TokenDump($Json, $Ptr, $Next, $sObjPath) 589 | If Not (IsBool($Value) And $Value = False) Then ;XC - Changed line 590 | ; show the key and its value 591 | ConsoleWrite("+=> " & $sObjPath & "=>" & $Value & @CRLF) 592 | $Total_JSON_DUMP_Output &= "+=> " & $sObjPath & "=>" & $Value & @CRLF 593 | EndIf 594 | Next 595 | $ObjPath = $sObjPath 596 | Return False 597 | 598 | Case 3 ; Json_STRING 599 | Local $LastKey = Json_StringDecode(StringMid($Json, $Start + 1, $End - $Start)) 600 | Return $LastKey 601 | EndSwitch 602 | EndFunc ;==>_Json_TokenDump 603 | -------------------------------------------------------------------------------- /src/include/WinHttpConstants.au3: -------------------------------------------------------------------------------- 1 | 2 | ; For those who would fear the license - don't. I tried to license it as liberal as possible. 3 | ; It really means you can do what ever you want with this. 4 | ; Donations are wellcome and will be accepted via PayPal address: trancexx at yahoo dot com 5 | ; Thank you for the shiny stuff :kiss: 6 | 7 | #comments-start 8 | Copyright 2013 Dragana R. 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #comments-end 22 | 23 | #include-once 24 | 25 | Global Const $INTERNET_DEFAULT_PORT = 0 26 | Global Const $INTERNET_DEFAULT_HTTP_PORT = 80 27 | Global Const $INTERNET_DEFAULT_HTTPS_PORT = 443 28 | 29 | Global Const $INTERNET_SCHEME_HTTP = 1 30 | Global Const $INTERNET_SCHEME_HTTPS = 2 31 | Global Const $INTERNET_SCHEME_FTP = 3 32 | 33 | Global Const $ICU_ESCAPE = 0x80000000 34 | 35 | ; For WinHttpOpen 36 | Global Const $WINHTTP_FLAG_ASYNC = 0x10000000 37 | 38 | ; For WinHttpOpenRequest ; 39 | Global Const $WINHTTP_FLAG_ESCAPE_PERCENT = 0x00000004 40 | Global Const $WINHTTP_FLAG_NULL_CODEPAGE = 0x00000008 41 | Global Const $WINHTTP_FLAG_ESCAPE_DISABLE = 0x00000040 42 | Global Const $WINHTTP_FLAG_ESCAPE_DISABLE_QUERY = 0x00000080 43 | Global Const $WINHTTP_FLAG_BYPASS_PROXY_CACHE = 0x00000100 44 | Global Const $WINHTTP_FLAG_REFRESH = $WINHTTP_FLAG_BYPASS_PROXY_CACHE 45 | Global Const $WINHTTP_FLAG_SECURE = 0x00800000 46 | 47 | Global Const $WINHTTP_ACCESS_TYPE_DEFAULT_PROXY = 0 48 | Global Const $WINHTTP_ACCESS_TYPE_NO_PROXY = 1 49 | Global Const $WINHTTP_ACCESS_TYPE_NAMED_PROXY = 3 50 | 51 | Global Const $WINHTTP_NO_PROXY_NAME = "" 52 | Global Const $WINHTTP_NO_PROXY_BYPASS = "" 53 | 54 | Global Const $WINHTTP_NO_REFERER = "" 55 | Global Const $WINHTTP_DEFAULT_ACCEPT_TYPES = 0 56 | 57 | Global Const $WINHTTP_NO_ADDITIONAL_HEADERS = "" 58 | Global Const $WINHTTP_NO_REQUEST_DATA = "" 59 | 60 | Global Const $WINHTTP_HEADER_NAME_BY_INDEX = "" 61 | Global Const $WINHTTP_NO_OUTPUT_BUFFER = 0 62 | Global Const $WINHTTP_NO_HEADER_INDEX = 0 63 | 64 | Global Const $WINHTTP_ADDREQ_INDEX_MASK = 0x0000FFFF 65 | Global Const $WINHTTP_ADDREQ_FLAGS_MASK = 0xFFFF0000 66 | Global Const $WINHTTP_ADDREQ_FLAG_ADD_IF_NEW = 0x10000000 67 | Global Const $WINHTTP_ADDREQ_FLAG_ADD = 0x20000000 68 | Global Const $WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA = 0x40000000 69 | Global Const $WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON = 0x01000000 70 | Global Const $WINHTTP_ADDREQ_FLAG_COALESCE = $WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA 71 | Global Const $WINHTTP_ADDREQ_FLAG_REPLACE = 0x80000000 72 | 73 | Global Const $WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH = 0 74 | 75 | ; For WinHttp{Set and Query} Options ; 76 | Global Const $WINHTTP_OPTION_CALLBACK = 1 77 | Global Const $WINHTTP_FIRST_OPTION = $WINHTTP_OPTION_CALLBACK 78 | Global Const $WINHTTP_OPTION_RESOLVE_TIMEOUT = 2 79 | Global Const $WINHTTP_OPTION_CONNECT_TIMEOUT = 3 80 | Global Const $WINHTTP_OPTION_CONNECT_RETRIES = 4 81 | Global Const $WINHTTP_OPTION_SEND_TIMEOUT = 5 82 | Global Const $WINHTTP_OPTION_RECEIVE_TIMEOUT = 6 83 | Global Const $WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT = 7 84 | Global Const $WINHTTP_OPTION_HANDLE_TYPE = 9 85 | Global Const $WINHTTP_OPTION_READ_BUFFER_SIZE = 12 86 | Global Const $WINHTTP_OPTION_WRITE_BUFFER_SIZE = 13 87 | Global Const $WINHTTP_OPTION_PARENT_HANDLE = 21 88 | Global Const $WINHTTP_OPTION_EXTENDED_ERROR = 24 89 | Global Const $WINHTTP_OPTION_SECURITY_FLAGS = 31 90 | Global Const $WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT = 32 91 | Global Const $WINHTTP_OPTION_URL = 34 92 | Global Const $WINHTTP_OPTION_SECURITY_KEY_BITNESS = 36 93 | Global Const $WINHTTP_OPTION_PROXY = 38 94 | Global Const $WINHTTP_OPTION_USER_AGENT = 41 95 | Global Const $WINHTTP_OPTION_CONTEXT_VALUE = 45 96 | Global Const $WINHTTP_OPTION_CLIENT_CERT_CONTEXT = 47 97 | Global Const $WINHTTP_OPTION_REQUEST_PRIORITY = 58 98 | Global Const $WINHTTP_OPTION_HTTP_VERSION = 59 99 | Global Const $WINHTTP_OPTION_DISABLE_FEATURE = 63 100 | Global Const $WINHTTP_OPTION_CODEPAGE = 68 101 | Global Const $WINHTTP_OPTION_MAX_CONNS_PER_SERVER = 73 102 | Global Const $WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER = 74 103 | Global Const $WINHTTP_OPTION_AUTOLOGON_POLICY = 77 104 | Global Const $WINHTTP_OPTION_SERVER_CERT_CONTEXT = 78 105 | Global Const $WINHTTP_OPTION_ENABLE_FEATURE = 79 106 | Global Const $WINHTTP_OPTION_WORKER_THREAD_COUNT = 80 107 | Global Const $WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT = 81 108 | Global Const $WINHTTP_OPTION_PASSPORT_COBRANDING_URL = 82 109 | Global Const $WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH = 83 110 | Global Const $WINHTTP_OPTION_SECURE_PROTOCOLS = 84 111 | Global Const $WINHTTP_OPTION_ENABLETRACING = 85 112 | Global Const $WINHTTP_OPTION_PASSPORT_SIGN_OUT = 86 113 | Global Const $WINHTTP_OPTION_PASSPORT_RETURN_URL = 87 114 | Global Const $WINHTTP_OPTION_REDIRECT_POLICY = 88 115 | Global Const $WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS = 89 116 | Global Const $WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE = 90 117 | Global Const $WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE = 91 118 | Global Const $WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE = 92 119 | Global Const $WINHTTP_OPTION_CONNECTION_INFO = 93 120 | Global Const $WINHTTP_OPTION_CLIENT_CERT_ISSUER_LIST = 94 121 | Global Const $WINHTTP_OPTION_SPN = 96 122 | Global Const $WINHTTP_OPTION_GLOBAL_PROXY_CREDS = 97 123 | Global Const $WINHTTP_OPTION_GLOBAL_SERVER_CREDS = 98 124 | Global Const $WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT = 99 125 | Global Const $WINHTTP_OPTION_REJECT_USERPWD_IN_URL = 100 126 | Global Const $WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS = 101 127 | Global Const $WINHTTP_OPTION_RECEIVE_PROXY_CONNECT_RESPONSE = 103 128 | Global Const $WINHTTP_OPTION_IS_PROXY_CONNECT_RESPONSE = 104 129 | Global Const $WINHTTP_OPTION_SERVER_SPN_USED = 106 130 | Global Const $WINHTTP_OPTION_PROXY_SPN_USED = 107 131 | Global Const $WINHTTP_OPTION_SERVER_CBT = 108 132 | Global Const $WINHTTP_OPTION_UNSAFE_HEADER_PARSING = 110 133 | Global Const $WINHTTP_OPTION_DECOMPRESSION = 118 134 | Global Const $WINHTTP_LAST_OPTION = $WINHTTP_OPTION_DECOMPRESSION 135 | 136 | Global Const $WINHTTP_OPTION_USERNAME = 0x1000 137 | Global Const $WINHTTP_OPTION_PASSWORD = 0x1001 138 | Global Const $WINHTTP_OPTION_PROXY_USERNAME = 0x1002 139 | Global Const $WINHTTP_OPTION_PROXY_PASSWORD = 0x1003 140 | 141 | Global Const $WINHTTP_CONNS_PER_SERVER_UNLIMITED = 0xFFFFFFFF 142 | 143 | ; For WINHTTP_OPTION_DECOMPRESSION 144 | Global Const $WINHTTP_DECOMPRESSION_FLAG_GZIP = 0x00000001 145 | Global Const $WINHTTP_DECOMPRESSION_FLAG_DEFLATE = 0x00000002 146 | Global Const $WINHTTP_DECOMPRESSION_FLAG_ALL = 0x00000003 147 | 148 | Global Const $WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM = 0 149 | Global Const $WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW = 1 150 | Global Const $WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH = 2 151 | Global Const $WINHTTP_AUTOLOGON_SECURITY_LEVEL_DEFAULT = $WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM 152 | 153 | Global Const $WINHTTP_OPTION_REDIRECT_POLICY_NEVER = 0 154 | Global Const $WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP = 1 155 | Global Const $WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS = 2 156 | Global Const $WINHTTP_OPTION_REDIRECT_POLICY_LAST = $WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS 157 | Global Const $WINHTTP_OPTION_REDIRECT_POLICY_DEFAULT = $WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP 158 | 159 | Global Const $WINHTTP_DISABLE_PASSPORT_AUTH = 0x00000000 160 | Global Const $WINHTTP_ENABLE_PASSPORT_AUTH = 0x10000000 161 | Global Const $WINHTTP_DISABLE_PASSPORT_KEYRING = 0x20000000 162 | Global Const $WINHTTP_ENABLE_PASSPORT_KEYRING = 0x40000000 163 | 164 | Global Const $WINHTTP_DISABLE_COOKIES = 0x00000001 165 | Global Const $WINHTTP_DISABLE_REDIRECTS = 0x00000002 166 | Global Const $WINHTTP_DISABLE_AUTHENTICATION = 0x00000004 167 | Global Const $WINHTTP_DISABLE_KEEP_ALIVE = 0x00000008 168 | Global Const $WINHTTP_ENABLE_SSL_REVOCATION = 0x00000001 169 | Global Const $WINHTTP_ENABLE_SSL_REVERT_IMPERSONATION = 0x00000002 170 | Global Const $WINHTTP_DISABLE_SPN_SERVER_PORT = 0x00000000 171 | Global Const $WINHTTP_ENABLE_SPN_SERVER_PORT = 0x00000001 172 | Global Const $WINHTTP_OPTION_SPN_MASK = $WINHTTP_ENABLE_SPN_SERVER_PORT 173 | 174 | ; WinHTTP error codes ; 175 | Global Const $WINHTTP_ERROR_BASE = 12000 176 | Global Const $ERROR_WINHTTP_OUT_OF_HANDLES = 12001 177 | Global Const $ERROR_WINHTTP_TIMEOUT = 12002 178 | Global Const $ERROR_WINHTTP_INTERNAL_ERROR = 12004 179 | Global Const $ERROR_WINHTTP_INVALID_URL = 12005 180 | Global Const $ERROR_WINHTTP_UNRECOGNIZED_SCHEME = 12006 181 | Global Const $ERROR_WINHTTP_NAME_NOT_RESOLVED = 12007 182 | Global Const $ERROR_WINHTTP_INVALID_OPTION = 12009 183 | Global Const $ERROR_WINHTTP_OPTION_NOT_SETTABLE = 12011 184 | Global Const $ERROR_WINHTTP_SHUTDOWN = 12012 185 | Global Const $ERROR_WINHTTP_LOGIN_FAILURE = 12015 186 | Global Const $ERROR_WINHTTP_OPERATION_CANCELLED = 12017 187 | Global Const $ERROR_WINHTTP_INCORRECT_HANDLE_TYPE = 12018 188 | Global Const $ERROR_WINHTTP_INCORRECT_HANDLE_STATE = 12019 189 | Global Const $ERROR_WINHTTP_CANNOT_CONNECT = 12029 190 | Global Const $ERROR_WINHTTP_CONNECTION_ERROR = 12030 191 | Global Const $ERROR_WINHTTP_RESEND_REQUEST = 12032 192 | Global Const $ERROR_WINHTTP_SECURE_CERT_DATE_INVALID = 12037 193 | Global Const $ERROR_WINHTTP_SECURE_CERT_CN_INVALID = 12038 194 | Global Const $ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED = 12044 195 | Global Const $ERROR_WINHTTP_SECURE_INVALID_CA = 12045 196 | Global Const $ERROR_WINHTTP_SECURE_CERT_REV_FAILED = 12057 197 | Global Const $ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN = 12100 198 | Global Const $ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND = 12101 199 | Global Const $ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND = 12102 200 | Global Const $ERROR_WINHTTP_CANNOT_CALL_AFTER_OPEN = 12103 201 | Global Const $ERROR_WINHTTP_HEADER_NOT_FOUND = 12150 202 | Global Const $ERROR_WINHTTP_INVALID_SERVER_RESPONSE = 12152 203 | Global Const $ERROR_WINHTTP_INVALID_HEADER = 12153 204 | Global Const $ERROR_WINHTTP_INVALID_QUERY_REQUEST = 12154 205 | Global Const $ERROR_WINHTTP_HEADER_ALREADY_EXISTS = 12155 206 | Global Const $ERROR_WINHTTP_REDIRECT_FAILED = 12156 207 | Global Const $ERROR_WINHTTP_SECURE_CHANNEL_ERROR = 12157 208 | Global Const $ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT = 12166 209 | Global Const $ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT = 12167 210 | Global Const $ERROR_WINHTTP_SECURE_INVALID_CERT = 12169 211 | Global Const $ERROR_WINHTTP_SECURE_CERT_REVOKED = 12170 212 | Global Const $ERROR_WINHTTP_NOT_INITIALIZED = 12172 213 | Global Const $ERROR_WINHTTP_SECURE_FAILURE = 12175 214 | Global Const $ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR = 12178 215 | Global Const $ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE = 12179 216 | Global Const $ERROR_WINHTTP_AUTODETECTION_FAILED = 12180 217 | Global Const $ERROR_WINHTTP_HEADER_COUNT_EXCEEDED = 12181 218 | Global Const $ERROR_WINHTTP_HEADER_SIZE_OVERFLOW = 12182 219 | Global Const $ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW = 12183 220 | Global Const $ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW = 12184 221 | Global Const $ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY = 12185 222 | Global Const $ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY = 12186 223 | Global Const $WINHTTP_ERROR_LAST = 12186 224 | 225 | ; WinHttp status codes ; 226 | Global Const $HTTP_STATUS_CONTINUE = 100 227 | Global Const $HTTP_STATUS_SWITCH_PROTOCOLS = 101 228 | Global Const $HTTP_STATUS_OK = 200 229 | Global Const $HTTP_STATUS_CREATED = 201 230 | Global Const $HTTP_STATUS_ACCEPTED = 202 231 | Global Const $HTTP_STATUS_PARTIAL = 203 232 | Global Const $HTTP_STATUS_NO_CONTENT = 204 233 | Global Const $HTTP_STATUS_RESET_CONTENT = 205 234 | Global Const $HTTP_STATUS_PARTIAL_CONTENT = 206 235 | Global Const $HTTP_STATUS_WEBDAV_MULTI_STATUS = 207 236 | Global Const $HTTP_STATUS_AMBIGUOUS = 300 237 | Global Const $HTTP_STATUS_MOVED = 301 238 | Global Const $HTTP_STATUS_REDIRECT = 302 239 | Global Const $HTTP_STATUS_REDIRECT_METHOD = 303 240 | Global Const $HTTP_STATUS_NOT_MODIFIED = 304 241 | Global Const $HTTP_STATUS_USE_PROXY = 305 242 | Global Const $HTTP_STATUS_REDIRECT_KEEP_VERB = 307 243 | Global Const $HTTP_STATUS_BAD_REQUEST = 400 244 | Global Const $HTTP_STATUS_DENIED = 401 245 | Global Const $HTTP_STATUS_PAYMENT_REQ = 402 246 | Global Const $HTTP_STATUS_FORBIDDEN = 403 247 | Global Const $HTTP_STATUS_NOT_FOUND = 404 248 | Global Const $HTTP_STATUS_BAD_METHOD = 405 249 | Global Const $HTTP_STATUS_NONE_ACCEPTABLE = 406 250 | Global Const $HTTP_STATUS_PROXY_AUTH_REQ = 407 251 | Global Const $HTTP_STATUS_REQUEST_TIMEOUT = 408 252 | Global Const $HTTP_STATUS_CONFLICT = 409 253 | Global Const $HTTP_STATUS_GONE = 410 254 | Global Const $HTTP_STATUS_LENGTH_REQUIRED = 411 255 | Global Const $HTTP_STATUS_PRECOND_FAILED = 412 256 | Global Const $HTTP_STATUS_REQUEST_TOO_LARGE = 413 257 | Global Const $HTTP_STATUS_URI_TOO_LONG = 414 258 | Global Const $HTTP_STATUS_UNSUPPORTED_MEDIA = 415 259 | Global Const $HTTP_STATUS_RETRY_WITH = 449 260 | Global Const $HTTP_STATUS_SERVER_ERROR = 500 261 | Global Const $HTTP_STATUS_NOT_SUPPORTED = 501 262 | Global Const $HTTP_STATUS_BAD_GATEWAY = 502 263 | Global Const $HTTP_STATUS_SERVICE_UNAVAIL = 503 264 | Global Const $HTTP_STATUS_GATEWAY_TIMEOUT = 504 265 | Global Const $HTTP_STATUS_VERSION_NOT_SUP = 505 266 | Global Const $HTTP_STATUS_FIRST = $HTTP_STATUS_CONTINUE 267 | Global Const $HTTP_STATUS_LAST = $HTTP_STATUS_VERSION_NOT_SUP 268 | 269 | Global Const $SECURITY_FLAG_IGNORE_UNKNOWN_CA = 0x00000100 270 | Global Const $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000 271 | Global Const $SECURITY_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000 272 | Global Const $SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE = 0x00000200 273 | Global Const $SECURITY_FLAG_SECURE = 0x00000001 274 | Global Const $SECURITY_FLAG_STRENGTH_WEAK = 0x10000000 275 | Global Const $SECURITY_FLAG_STRENGTH_MEDIUM = 0x40000000 276 | Global Const $SECURITY_FLAG_STRENGTH_STRONG = 0x20000000 277 | 278 | Global Const $ICU_NO_ENCODE = 0x20000000 279 | Global Const $ICU_DECODE = 0x10000000 280 | Global Const $ICU_NO_META = 0x08000000 281 | Global Const $ICU_ENCODE_SPACES_ONLY = 0x04000000 282 | Global Const $ICU_BROWSER_MODE = 0x02000000 283 | Global Const $ICU_ENCODE_PERCENT = 0x00001000 284 | 285 | ; Query flags ; 286 | Global Const $WINHTTP_QUERY_MIME_VERSION = 0 287 | Global Const $WINHTTP_QUERY_CONTENT_TYPE = 1 288 | Global Const $WINHTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2 289 | Global Const $WINHTTP_QUERY_CONTENT_ID = 3 290 | Global Const $WINHTTP_QUERY_CONTENT_DESCRIPTION = 4 291 | Global Const $WINHTTP_QUERY_CONTENT_LENGTH = 5 292 | Global Const $WINHTTP_QUERY_CONTENT_LANGUAGE = 6 293 | Global Const $WINHTTP_QUERY_ALLOW = 7 294 | Global Const $WINHTTP_QUERY_PUBLIC = 8 295 | Global Const $WINHTTP_QUERY_DATE = 9 296 | Global Const $WINHTTP_QUERY_EXPIRES = 10 297 | Global Const $WINHTTP_QUERY_LAST_MODIFIED = 11 298 | Global Const $WINHTTP_QUERY_MESSAGE_ID = 12 299 | Global Const $WINHTTP_QUERY_URI = 13 300 | Global Const $WINHTTP_QUERY_DERIVED_FROM = 14 301 | Global Const $WINHTTP_QUERY_COST = 15 302 | Global Const $WINHTTP_QUERY_LINK = 16 303 | Global Const $WINHTTP_QUERY_PRAGMA = 17 304 | Global Const $WINHTTP_QUERY_VERSION = 18 305 | Global Const $WINHTTP_QUERY_STATUS_CODE = 19 306 | Global Const $WINHTTP_QUERY_STATUS_TEXT = 20 307 | Global Const $WINHTTP_QUERY_RAW_HEADERS = 21 308 | Global Const $WINHTTP_QUERY_RAW_HEADERS_CRLF = 22 309 | Global Const $WINHTTP_QUERY_CONNECTION = 23 310 | Global Const $WINHTTP_QUERY_ACCEPT = 24 311 | Global Const $WINHTTP_QUERY_ACCEPT_CHARSET = 25 312 | Global Const $WINHTTP_QUERY_ACCEPT_ENCODING = 26 313 | Global Const $WINHTTP_QUERY_ACCEPT_LANGUAGE = 27 314 | Global Const $WINHTTP_QUERY_AUTHORIZATION = 28 315 | Global Const $WINHTTP_QUERY_CONTENT_ENCODING = 29 316 | Global Const $WINHTTP_QUERY_FORWARDED = 30 317 | Global Const $WINHTTP_QUERY_FROM = 31 318 | Global Const $WINHTTP_QUERY_IF_MODIFIED_SINCE = 32 319 | Global Const $WINHTTP_QUERY_LOCATION = 33 320 | Global Const $WINHTTP_QUERY_ORIG_URI = 34 321 | Global Const $WINHTTP_QUERY_REFERER = 35 322 | Global Const $WINHTTP_QUERY_RETRY_AFTER = 36 323 | Global Const $WINHTTP_QUERY_SERVER = 37 324 | Global Const $WINHTTP_QUERY_TITLE = 38 325 | Global Const $WINHTTP_QUERY_USER_AGENT = 39 326 | Global Const $WINHTTP_QUERY_WWW_AUTHENTICATE = 40 327 | Global Const $WINHTTP_QUERY_PROXY_AUTHENTICATE = 41 328 | Global Const $WINHTTP_QUERY_ACCEPT_RANGES = 42 329 | Global Const $WINHTTP_QUERY_SET_COOKIE = 43 330 | Global Const $WINHTTP_QUERY_COOKIE = 44 331 | Global Const $WINHTTP_QUERY_REQUEST_METHOD = 45 332 | Global Const $WINHTTP_QUERY_REFRESH = 46 333 | Global Const $WINHTTP_QUERY_CONTENT_DISPOSITION = 47 334 | Global Const $WINHTTP_QUERY_AGE = 48 335 | Global Const $WINHTTP_QUERY_CACHE_CONTROL = 49 336 | Global Const $WINHTTP_QUERY_CONTENT_BASE = 50 337 | Global Const $WINHTTP_QUERY_CONTENT_LOCATION = 51 338 | Global Const $WINHTTP_QUERY_CONTENT_MD5 = 52 339 | Global Const $WINHTTP_QUERY_CONTENT_RANGE = 53 340 | Global Const $WINHTTP_QUERY_ETAG = 54 341 | Global Const $WINHTTP_QUERY_HOST = 55 342 | Global Const $WINHTTP_QUERY_IF_MATCH = 56 343 | Global Const $WINHTTP_QUERY_IF_NONE_MATCH = 57 344 | Global Const $WINHTTP_QUERY_IF_RANGE = 58 345 | Global Const $WINHTTP_QUERY_IF_UNMODIFIED_SINCE = 59 346 | Global Const $WINHTTP_QUERY_MAX_FORWARDS = 60 347 | Global Const $WINHTTP_QUERY_PROXY_AUTHORIZATION = 61 348 | Global Const $WINHTTP_QUERY_RANGE = 62 349 | Global Const $WINHTTP_QUERY_TRANSFER_ENCODING = 63 350 | Global Const $WINHTTP_QUERY_UPGRADE = 64 351 | Global Const $WINHTTP_QUERY_VARY = 65 352 | Global Const $WINHTTP_QUERY_VIA = 66 353 | Global Const $WINHTTP_QUERY_WARNING = 67 354 | Global Const $WINHTTP_QUERY_EXPECT = 68 355 | Global Const $WINHTTP_QUERY_PROXY_CONNECTION = 69 356 | Global Const $WINHTTP_QUERY_UNLESS_MODIFIED_SINCE = 70 357 | Global Const $WINHTTP_QUERY_PROXY_SUPPORT = 75 358 | Global Const $WINHTTP_QUERY_AUTHENTICATION_INFO = 76 359 | Global Const $WINHTTP_QUERY_PASSPORT_URLS = 77 360 | Global Const $WINHTTP_QUERY_PASSPORT_CONFIG = 78 361 | Global Const $WINHTTP_QUERY_MAX = 78 362 | Global Const $WINHTTP_QUERY_CUSTOM = 65535 363 | Global Const $WINHTTP_QUERY_FLAG_REQUEST_HEADERS = 0x80000000 364 | Global Const $WINHTTP_QUERY_FLAG_SYSTEMTIME = 0x40000000 365 | Global Const $WINHTTP_QUERY_FLAG_NUMBER = 0x20000000 366 | 367 | ; Callback options ; 368 | Global Const $WINHTTP_CALLBACK_STATUS_RESOLVING_NAME = 0x00000001 369 | Global Const $WINHTTP_CALLBACK_STATUS_NAME_RESOLVED = 0x00000002 370 | Global Const $WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER = 0x00000004 371 | Global Const $WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER = 0x00000008 372 | Global Const $WINHTTP_CALLBACK_STATUS_SENDING_REQUEST = 0x00000010 373 | Global Const $WINHTTP_CALLBACK_STATUS_REQUEST_SENT = 0x00000020 374 | Global Const $WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE = 0x00000040 375 | Global Const $WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED = 0x00000080 376 | Global Const $WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION = 0x00000100 377 | Global Const $WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED = 0x00000200 378 | Global Const $WINHTTP_CALLBACK_STATUS_HANDLE_CREATED = 0x00000400 379 | Global Const $WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING = 0x00000800 380 | Global Const $WINHTTP_CALLBACK_STATUS_DETECTING_PROXY = 0x00001000 381 | Global Const $WINHTTP_CALLBACK_STATUS_REDIRECT = 0x00004000 382 | Global Const $WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE = 0x00008000 383 | Global Const $WINHTTP_CALLBACK_STATUS_SECURE_FAILURE = 0x00010000 384 | Global Const $WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE = 0x00020000 385 | Global Const $WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE = 0x00040000 386 | Global Const $WINHTTP_CALLBACK_STATUS_READ_COMPLETE = 0x00080000 387 | Global Const $WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE = 0x00100000 388 | Global Const $WINHTTP_CALLBACK_STATUS_REQUEST_ERROR = 0x00200000 389 | Global Const $WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE = 0x00400000 390 | Global Const $WINHTTP_CALLBACK_FLAG_RESOLVE_NAME = 0x00000003 391 | Global Const $WINHTTP_CALLBACK_FLAG_CONNECT_TO_SERVER = 0x0000000C 392 | Global Const $WINHTTP_CALLBACK_FLAG_SEND_REQUEST = 0x00000030 393 | Global Const $WINHTTP_CALLBACK_FLAG_RECEIVE_RESPONSE = 0x000000C0 394 | Global Const $WINHTTP_CALLBACK_FLAG_CLOSE_CONNECTION = 0x00000300 395 | Global Const $WINHTTP_CALLBACK_FLAG_HANDLES = 0x00000C00 396 | Global Const $WINHTTP_CALLBACK_FLAG_DETECTING_PROXY = $WINHTTP_CALLBACK_STATUS_DETECTING_PROXY 397 | Global Const $WINHTTP_CALLBACK_FLAG_REDIRECT = $WINHTTP_CALLBACK_STATUS_REDIRECT 398 | Global Const $WINHTTP_CALLBACK_FLAG_INTERMEDIATE_RESPONSE = $WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE 399 | Global Const $WINHTTP_CALLBACK_FLAG_SECURE_FAILURE = $WINHTTP_CALLBACK_STATUS_SECURE_FAILURE 400 | Global Const $WINHTTP_CALLBACK_FLAG_SENDREQUEST_COMPLETE = $WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE 401 | Global Const $WINHTTP_CALLBACK_FLAG_HEADERS_AVAILABLE = $WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE 402 | Global Const $WINHTTP_CALLBACK_FLAG_DATA_AVAILABLE = $WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE 403 | Global Const $WINHTTP_CALLBACK_FLAG_READ_COMPLETE = $WINHTTP_CALLBACK_STATUS_READ_COMPLETE 404 | Global Const $WINHTTP_CALLBACK_FLAG_WRITE_COMPLETE = $WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE 405 | Global Const $WINHTTP_CALLBACK_FLAG_REQUEST_ERROR = $WINHTTP_CALLBACK_STATUS_REQUEST_ERROR 406 | Global Const $WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS = 0x007E0000 407 | Global Const $WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS = 0xFFFFFFFF 408 | 409 | Global Const $API_RECEIVE_RESPONSE = 1 410 | Global Const $API_QUERY_DATA_AVAILABLE = 2 411 | Global Const $API_READ_DATA = 3 412 | Global Const $API_WRITE_DATA = 4 413 | Global Const $API_SEND_REQUEST = 5 414 | 415 | Global Const $WINHTTP_HANDLE_TYPE_SESSION = 1 416 | Global Const $WINHTTP_HANDLE_TYPE_CONNECT = 2 417 | Global Const $WINHTTP_HANDLE_TYPE_REQUEST = 3 418 | 419 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED = 0x00000001 420 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT = 0x00000002 421 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED = 0x00000004 422 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA = 0x00000008 423 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID = 0x00000010 424 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID = 0x00000020 425 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE = 0x00000040 426 | Global Const $WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR = 0x80000000 427 | 428 | Global Const $WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 = 0x00000008 429 | Global Const $WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 = 0x00000020 430 | Global Const $WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 = 0x00000080 431 | Global Const $WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 = 0x00000200 432 | Global Const $WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 = 0x00000800 433 | Global Const $WINHTTP_FLAG_SECURE_PROTOCOL_ALL = 0x000000A8 434 | 435 | Global Const $WINHTTP_AUTH_SCHEME_BASIC = 0x00000001 436 | Global Const $WINHTTP_AUTH_SCHEME_NTLM = 0x00000002 437 | Global Const $WINHTTP_AUTH_SCHEME_PASSPORT = 0x00000004 438 | Global Const $WINHTTP_AUTH_SCHEME_DIGEST = 0x00000008 439 | Global Const $WINHTTP_AUTH_SCHEME_NEGOTIATE = 0x00000010 440 | 441 | Global Const $WINHTTP_AUTH_TARGET_SERVER = 0x00000000 442 | Global Const $WINHTTP_AUTH_TARGET_PROXY = 0x00000001 443 | 444 | 445 | Global Const $WINHTTP_AUTOPROXY_AUTO_DETECT = 0x00000001 446 | Global Const $WINHTTP_AUTOPROXY_CONFIG_URL = 0x00000002 447 | Global Const $WINHTTP_AUTOPROXY_RUN_INPROCESS = 0x00010000 448 | Global Const $WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY = 0x00020000 449 | Global Const $WINHTTP_AUTO_DETECT_TYPE_DHCP = 0x00000001 450 | Global Const $WINHTTP_AUTO_DETECT_TYPE_DNS_A = 0x00000002 -------------------------------------------------------------------------------- /tests/Tests.au3: -------------------------------------------------------------------------------- 1 | #include "../src/Telegram.au3" 2 | 3 | Const $sConfigFilePath = @ScriptDir & "\config.ini" 4 | ConsoleWrite("Using config file located at " & $sConfigFilePath & @CRLF) 5 | 6 | Global Const $sValidToken = IniRead($sConfigFilePath, "Init", "ValidToken", "") 7 | Global Const $sInvalidToken = IniRead($sConfigFilePath, "Init", "InvalidToken", "") 8 | Global Const $sChatId = IniRead($sConfigFilePath, "Init", "ChatId", "") 9 | 10 | ; Check if the config file read was successful 11 | If @error Then 12 | ConsoleWrite("An error occurred while reading the config file" & @CRLF) 13 | Exit 1 14 | EndIf 15 | 16 | ; Check if the config file is missing required parameters 17 | If $sValidToken = "" Or $sChatId = "" Then 18 | ConsoleWrite("The config file is missing required parameters" & @CRLF) 19 | Exit 2 20 | EndIf 21 | 22 | Func UTAssert(Const $bResult, Const $sMsg = "Assert Failure", Const $iError = @error, Const $iExtended = @extended, Const $iSln = @ScriptLineNumber) 23 | ConsoleWrite("(" & $iSln & ") " & ($bResult ? "Passed" : "Failed (" & $iError & "/" & $iExtended & ")") & ": " & $sMsg & @LF) 24 | Return $bResult 25 | EndFunc ;==>UTAssert 26 | 27 | Func _Validate_Telegram_Response($oResponse, Const $iError = @error) 28 | Return (Not @error And $oResponse <> Null And Json_IsObject($oResponse)) 29 | EndFunc 30 | 31 | Func _Test_Telegram_Init() 32 | Local $bResult 33 | 34 | ; Test with valid token without validation 35 | $bResult = _Telegram_Init($sValidToken) 36 | UTAssert($bResult = True, "Init with valid token, no validate") 37 | 38 | ; Test with valid token with validation 39 | $bResult = _Telegram_Init($sValidToken, True) 40 | UTAssert($bResult = True, "Init with valid token, validate") 41 | 42 | ; Test with invalid token without validation 43 | $bResult = _Telegram_Init($sInvalidToken) 44 | UTAssert($bResult = True, "Init with invalid token, no validate") 45 | 46 | ; Test with invalid token with validation 47 | $bResult = _Telegram_Init($sInvalidToken, True) 48 | UTAssert($bResult = False And @error = $TG_ERR_INIT, "Init with invalid token, validate") 49 | 50 | ; Test with empty token without validation 51 | $bResult = _Telegram_Init("") 52 | UTAssert($bResult = False And @error = $TG_ERR_INIT, "Init with empty token, no validate") 53 | 54 | ; Test with null token without validation 55 | $bResult = _Telegram_Init(Null) 56 | UTAssert($bResult = False And @error = $TG_ERR_INIT, "Init with null token, no validate") 57 | EndFunc ;==> _Test_Telegram_Init 58 | 59 | Func _Test_Telegram_GetMe() 60 | ; Get information about the bot 61 | Local $oMe = _Telegram_GetMe() 62 | 63 | ; Test if there are no errors during the call 64 | UTAssert(_Validate_Telegram_Response($oMe), "Test_GetMe: Validate Telegram response") 65 | 66 | ; Test if the 'is_bot' field is set to true 67 | UTAssert(Json_Get($oMe, "[is_bot]") = True, "Test_GetMe: Bot status is 'is_bot'") 68 | 69 | ; Test if the 'id' field is an integer value 70 | UTAssert(IsInt(Json_Get($oMe, "[id]")), "Test_GetMe: 'id' field is an integer") 71 | 72 | ; Test if the 'username' field is not empty 73 | UTAssert(Json_Get($oMe, "[username]") <> Null, "Test_GetMe: 'username' field is not empty") 74 | 75 | ; Test if the 'first_name' field is not empty 76 | UTAssert(Json_Get($oMe, "[first_name]") <> Null, "Test_GetMe: 'first_name' field is not empty") 77 | EndFunc ;==> _Test_Telegram_GetMe 78 | 79 | Func _Test_Telegram_SendMessage() 80 | ; Test if the message is successfully sent 81 | Local $oMessage = _Telegram_SendMessage($sChatId, "Test message") 82 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_SendMessage: valid response") 83 | UTAssert(IsInt(Json_Get($oMessage, "[message_id]")), "Test_SendMessage: message id") 84 | 85 | ; Test with Parse Mode 86 | $oMessage = _Telegram_SendMessage($sChatId, "*Test* _message_", "MarkdownV2") 87 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_SendMessage: valid response with Parse Mode") 88 | UTAssert(UBound(Json_Get($oMessage, "[entities]")) = 2, "Test_SendMessage: entities") 89 | 90 | ; Test with Keyboard Markup 91 | Local $sKeyboardMarkup = '{"keyboard":[["Button 1"],["Button 2"]],"one_time_keyboard":true}' 92 | $oMessage = _Telegram_SendMessage($sChatId, "Test with Keyboard Markup", Null, $sKeyboardMarkup) 93 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_SendMessage: valid response with Keyboard Markup") 94 | 95 | ; Test with Inline Keyboard Markup 96 | Local $sInlineKeyboardMarkup = '{"inline_keyboard":[[{"text":"Button 1","callback_data":"data_1"}],[{"text":"Button 2","callback_data":"data_2"}]]}' 97 | $oMessage = _Telegram_SendMessage($sChatId, "Test with Inline Keyboard Markup", Null, $sInlineKeyboardMarkup) 98 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_SendMessage: valid response with Inline Keyboard Markup") 99 | 100 | ; Test with Reply To Message 101 | Local $iPreviousMesssageId = Json_Get($oMessage, "[message_id]") 102 | $oMessage = _Telegram_SendMessage($sChatId, "Test with Reply To Message", Null, Null, $iPreviousMesssageId) 103 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_SendMessage: valid response with Reply To Message") 104 | 105 | ; Test with Disable Web Preview 106 | $oMessage = _Telegram_SendMessage($sChatId, "Test with Disable Web Preview (https://github.com)", Null, Null, Null, True) 107 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_SendMessage: valid response with Disable Web Preview") 108 | 109 | ; Test with Disable Notification 110 | $oMessage = _Telegram_SendMessage($sChatId, "Test with Disable Notification", Null, Null, Null, False, True) 111 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_SendMessage: valid response with Disable Notification") 112 | EndFunc ;==> _Test_Telegram_SendMessage 113 | 114 | Func _Test_Telegram_ForwardMessage() 115 | ; Sending a test message 116 | Local $oMessage = _Telegram_SendMessage($sChatId, "Test message for forwarding") 117 | ; Check if message was sent successfully 118 | UTAssert(_Validate_Telegram_Response($oMessage), "Test_ForwardMessage: Sent message successfully") 119 | ; Forwarding the sent message 120 | Local $oForwardedMessage = _Telegram_ForwardMessage($sChatId, $sChatId, Json_Get($oMessage, "[message_id]")) 121 | ; Check if message was forwarded successfully 122 | UTAssert(_Validate_Telegram_Response($oForwardedMessage), "Test_ForwardMessage: Forwarded message successfully") 123 | EndFunc ;==> _Test_Telegram_ForwardMessage 124 | 125 | Func _Test_Telegram_SendPhoto() 126 | Local Const $sLocalMedia = "media/image.png" 127 | Local Const $sRemoteMedia = "https://picsum.photos/200" 128 | 129 | ; Sending a local photo 130 | Local $oLocalPhotoMessage = _Telegram_SendPhoto($sChatId, $sLocalMedia, "Test caption") 131 | ; Check if the local photo was sent successfully 132 | UTAssert(_Validate_Telegram_Response($oLocalPhotoMessage), "Test_SendPhoto: Sent local photo successfully") 133 | 134 | ; Sending a photo from a URL 135 | Local $oRemotePhotoMessage = _Telegram_SendPhoto($sChatId, $sRemoteMedia, "Test caption") 136 | ; Check if the photo from URL was sent successfully 137 | UTAssert(_Validate_Telegram_Response($oRemotePhotoMessage), "Test_SendPhoto: Sent photo from URL successfully") 138 | 139 | ; Get File ID of the last sent photo 140 | Local $sFileID = Json_Get($oLocalPhotoMessage, "[photo][0][file_id]") 141 | ; Resend the photo using the File ID 142 | Local $oRecentPhotoMessage = _Telegram_SendPhoto($sChatId, $sFileID, "Test caption") 143 | ; Check if the photo sent via File ID was successful 144 | UTAssert(_Validate_Telegram_Response($oRecentPhotoMessage), "Test_SendPhoto: Sent photo via File ID successfully") 145 | EndFunc ;==> _Test_Telegram_SendPhoto 146 | 147 | Func _Test_Telegram_SendVenue() 148 | Local Const $fLatitude = 40.7128 149 | Local Const $fLongitude = -74.0060 150 | Local Const $sTitle = "Central Park" 151 | Local Const $sAddress = "New York City, NY, USA" 152 | 153 | Local $oResponse = _Telegram_SendVenue($sChatId, $fLatitude, $fLongitude, $sTitle, $sAddress) 154 | 155 | UTAssert(_Validate_Telegram_Response($oResponse), "Test_SendVenue: Sending venue") 156 | EndFunc ;==> _Test_Telegram_SendVenue 157 | 158 | Func _Test_Telegram_SendContact() 159 | Const $sPhoneNumber = "123456789" 160 | Const $sFirstName = "John" 161 | Const $sLastName = "Doe" 162 | 163 | Local $oResponse = _Telegram_SendContact($sChatId, $sPhoneNumber, $sFirstName, $sLastName) 164 | 165 | UTAssert(_Validate_Telegram_Response($oResponse), "Test_SendContact: Sending contact") 166 | EndFunc ;==> _Test_Telegram_SendContact 167 | 168 | Func _Test_Telegram_SendChatAction() 169 | Const $sTestAction = "typing" 170 | 171 | UTAssert(_Telegram_SendChatAction($sChatId, $sTestAction) = True, "Test_SendChatAction: sending action") 172 | UTAssert(_Telegram_SendChatAction("", $sTestAction) = Null And @error = $TG_ERR_BAD_INPUT, "Test_SendChatAction: empty chat ID") 173 | UTAssert(_Telegram_SendChatAction($sChatId, "") = Null And @error = $TG_ERR_BAD_INPUT, "Test_SendChatAction: empty action") 174 | 175 | ; Invalid action 176 | UTAssert(_Telegram_SendChatAction($sChatId, "invalid_action") = Null And @error = $TG_ERR_BAD_INPUT, "Test_SendChatAction: invalid action") 177 | EndFunc ;==> _Test_Telegram_SendChatAction 178 | 179 | Func _Test_Telegram_GetChat() 180 | ; Valid parameters 181 | UTAssert(_Telegram_GetChat($sChatId), "Test_GetChat: valid parameters") 182 | 183 | ; Invalid parameters 184 | UTAssert(Not _Telegram_GetChat(""), "Test_GetChat: empty chat ID") 185 | EndFunc ;==> _Test_Telegram_GetChat 186 | 187 | Func _Test_Telegram_DeleteMessage() 188 | Local $sText = "Test message for deletion" 189 | 190 | ; Sending a test message to be deleted 191 | Local $oMessage = _Telegram_SendMessage($sChatId, $sText) 192 | UTAssert(Not @error, "Test_DeleteMessage: message sent successfully") 193 | Local $iMessageId = Json_Get($oMessage, "[message_id]") 194 | 195 | ; Deleting the sent message 196 | Local $oResponse = _Telegram_DeleteMessage($sChatId, $iMessageId) 197 | UTAssert(Not @error, "Test_DeleteMessage: message deleted successfully") 198 | EndFunc ;==> _Test_Telegram_DeleteMessage 199 | 200 | Func _Test_Telegram_CreateKeyboard() 201 | 202 | ; Keyboard with one row 203 | Local $aKeyboard = ['Option 1', 'Option 2', 'Option 3'] 204 | Local $sKeyboardExpectedResult = '{"keyboard":[["Option 1","Option 2","Option 3"]]}' 205 | UTAssert(_Telegram_CreateKeyboard($aKeyboard) = $sKeyboardExpectedResult, "Test_CreateKeyboard: one row") 206 | 207 | ; Keyboard with two rows 208 | Local $aKeyboard = ['Button1', 'Button2', '', 'Button3'] 209 | Local $sKeyboardExpectedResult = '{"keyboard":[["Button1","Button2"],["Button3"]]}' 210 | UTAssert(_Telegram_CreateKeyboard($aKeyboard) = $sKeyboardExpectedResult, "Test_CreateKeyboard: two rows") 211 | 212 | ; Keyboard with two rows and empty spaces 213 | Local $aKeyboard = ['Button A', '', 'Button B', 'Button C', ''] 214 | Local $sKeyboardExpectedResult = '{"keyboard":[["Button A"],["Button B","Button C"]]}' 215 | UTAssert(_Telegram_CreateKeyboard($aKeyboard) = $sKeyboardExpectedResult, "Test_CreateKeyboard: two rows and empty spaces") 216 | 217 | ; Keyboard with only one row and resize 218 | Local $aKeyboard = ['First Button', 'Second Button', 'Third Button'] 219 | Local $sKeyboardExpectedResult = '{"keyboard":[["First Button","Second Button","Third Button"]],"resize_keyboard":true}' 220 | UTAssert(_Telegram_CreateKeyboard($aKeyboard, True) = $sKeyboardExpectedResult, "Test_CreateKeyboard: one row and resize") 221 | 222 | ; Keyboard with only one row and one-time 223 | Local $aKeyboard = ['First Button', 'Second Button', 'Third Button'] 224 | Local $sKeyboardExpectedResult = '{"keyboard":[["First Button","Second Button","Third Button"]],"one_time_keyboard":true}' 225 | UTAssert(_Telegram_CreateKeyboard($aKeyboard, False, True) = $sKeyboardExpectedResult, "Test_CreateKeyboard: one row and one-time") 226 | 227 | ; Keyboard with only one row and resize and one-time 228 | Local $aKeyboard = ['First Button', 'Second Button', 'Third Button'] 229 | Local $sKeyboardExpectedResult = '{"keyboard":[["First Button","Second Button","Third Button"]],"resize_keyboard":true,"one_time_keyboard":true}' 230 | UTAssert(_Telegram_CreateKeyboard($aKeyboard, True, True) = $sKeyboardExpectedResult, "Test_CreateKeyboard: one row and resize and one-time") 231 | 232 | ; Keyboard with no buttons 233 | Local $aKeyboard = [] 234 | Local $sKeyboardExpectedResult = '{"keyboard":[]}' 235 | UTAssert(_Telegram_CreateKeyboard($aKeyboard) = $sKeyboardExpectedResult, "Test_CreateKeyboard: empty keyboard") 236 | 237 | EndFunc ;==> _Test_Telegram_CreateKeyboard 238 | 239 | #Region "Test runner" 240 | #cs ====================================================================================== 241 | Name .........: __GetTestFunctions 242 | Description...: Retrieves the names of the test functions present in the current script. 243 | Syntax .......: __GetTestFunctions() 244 | Parameters....: None 245 | Return values.: 246 | Success - Returns an array containing the names of test functions 247 | based on the specified prefix. 248 | Failure - Returns an empty array if no test functions are found. 249 | #ce ====================================================================================== 250 | Func __GetTestFunctions() 251 | Local $sTestPrefix = "_Test_Telegram_" 252 | Local $aFunctions = StringRegExp(FileRead(@ScriptFullPath), "(?i)(?s)Func\s+" & $sTestPrefix &"(\w+)\s*\(", 3) 253 | 254 | For $i = 0 To UBound($aFunctions) - 1 255 | $aFunctions[$i] = $sTestPrefix & $aFunctions[$i] 256 | Next 257 | 258 | Return $aFunctions 259 | EndFunc ;==> __GetTestFunctions 260 | 261 | #cs ====================================================================================== 262 | Name .........: _RunAllTests 263 | Description...: Executes all test functions found in the current script. 264 | Syntax .......: _RunAllTests() 265 | Parameters....: None 266 | Return values.: 267 | Success - Executes all test functions present in the script. 268 | Failure - None. 269 | #ce ====================================================================================== 270 | Func _RunAllTests() 271 | Local $aTestFunctions = __GetTestFunctions() 272 | For $i = 0 To UBound($aTestFunctions) - 1 273 | ; Like a beforeEach, initialize the bot with a valid token 274 | _Telegram_Init($sValidToken) 275 | ; Execute the test 276 | Call($aTestFunctions[$i]) 277 | Next 278 | EndFunc ;==> _RunAllTests 279 | 280 | #EndRegion 281 | 282 | _RunAllTests() 283 | 284 | ; Here for debug purposes (run tests manually) 285 | ;~ _Telegram_Init($sValidToken) 286 | ;~ _Test_Telegram_CreateKeyboard() 287 | -------------------------------------------------------------------------------- /tests/config.example.ini: -------------------------------------------------------------------------------- 1 | [Init] 2 | ValidToken= 3 | InvalidToken=123456789:ABCDEFGH 4 | ChatId= 5 | -------------------------------------------------------------------------------- /tests/media/audio.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xLinkOut/telegram-udf-autoit/d820eea646265a8270c418ca624b2495f8fb0d7d/tests/media/audio.mp3 -------------------------------------------------------------------------------- /tests/media/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xLinkOut/telegram-udf-autoit/d820eea646265a8270c418ca624b2495f8fb0d7d/tests/media/image.png -------------------------------------------------------------------------------- /tests/media/sticker.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xLinkOut/telegram-udf-autoit/d820eea646265a8270c418ca624b2495f8fb0d7d/tests/media/sticker.webp -------------------------------------------------------------------------------- /tests/media/text.txt: -------------------------------------------------------------------------------- 1 | https://github.com/xLinkOut -------------------------------------------------------------------------------- /tests/media/video.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xLinkOut/telegram-udf-autoit/d820eea646265a8270c418ca624b2495f8fb0d7d/tests/media/video.mp4 -------------------------------------------------------------------------------- /tests/media/voice.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xLinkOut/telegram-udf-autoit/d820eea646265a8270c418ca624b2495f8fb0d7d/tests/media/voice.ogg --------------------------------------------------------------------------------