diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2018-05-21 14:26:20 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2018-05-21 14:26:20 +0200 |
commit | 4f5c7c8b68a93a47f0fea8831ba0c59669cef54f (patch) | |
tree | 197fe5dfd93e6693b64d84925e27bdf9e0f34a5c /doc/en/weechat_plugin_api.en.adoc | |
parent | 3b82e8ef1e977d6d0dc1e813e34289efb73931cf (diff) | |
download | weechat-4f5c7c8b68a93a47f0fea8831ba0c59669cef54f.zip |
doc: add example of URL with custom HTTP headers in function hook_process_hashtable (plugin API reference)
Diffstat (limited to 'doc/en/weechat_plugin_api.en.adoc')
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 498fb95fa..c374b0ff9 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -8797,22 +8797,40 @@ my_process_cb (const void *pointer, void *data, const char *command, } /* example 1: download URL */ -struct t_hashtable *options = weechat_hashtable_new (8, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); -if (options) +struct t_hashtable *options_url1 = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); +if (options_url1) { weechat_hashtable_set (options, "file_out", "/tmp/weechat.org.html"); struct t_hook *my_process_hook = weechat_hook_process_hashtable ("url:https://weechat.org/", - options, + options_url1, 20000, &my_process_cb, NULL, NULL); - weechat_hashtable_free (options); + weechat_hashtable_free (options_url1); } -/* example 2: execute a notify program with a message from someone */ +/* example 2: open URL with custom HTTP headers */ +struct t_hashtable *options_url2 = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); +if (options_url2) +{ + weechat_hashtable_set (options, "httpheader", + "Header1: value1\n" + "Header2: value2"); + struct t_hook *my_process_hook = weechat_hook_process_hashtable ("url:http://localhost:8080/", + options_url2, + 20000, + &my_process_cb, NULL, NULL); + weechat_hashtable_free (options_url2); +} + +/* example 3: execute a notify program with a message from someone */ struct t_hashtable *options_cmd1 = weechat_hashtable_new (8, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, @@ -8831,7 +8849,7 @@ if (options_cmd1) weechat_hashtable_free (options_cmd1); } -/* example 3: call shell to execute a command (command must be SAFE) */ +/* example 4: call shell to execute a command (command must be SAFE) */ struct t_hashtable *options_cmd2 = weechat_hashtable_new (8, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, @@ -8874,16 +8892,27 @@ hook1 = weechat.hook_process_hashtable("url:https://weechat.org/", {"file_out": "/tmp/weechat.org.html"}, 20000, "my_process_cb", "") -# example 2: execute a notify program with a message from someone -hook2 = weechat.hook_process_hashtable("my-notify-command", +# example 2: open URL with custom HTTP headers +options = { + "httpheader": "\n".join([ + "Header1: value1", + "Header2: value2", + ]), +} +hook2 = weechat.hook_process_hashtable("url:http://localhost:8080/", + options, + 20000, "my_process_cb", "") + +# example 3: execute a notify program with a message from someone +hook3 = weechat.hook_process_hashtable("my-notify-command", {"arg1": "-from", "arg2": nick, "arg3": "-msg", "arg4": message}, # untrusted argument 20000, "my_process_cb", "") -# example 3: call shell to execute a command (command must be SAFE) -hook3 = weechat.hook_process_hashtable("sh", +# example 4: call shell to execute a command (command must be SAFE) +hook4 = weechat.hook_process_hashtable("sh", {"arg1": "-c", "arg2": "ls -l /tmp | grep something"}, 20000, "my_process_cb", "") |