From b91c231096c726d0d8ecdc4c88e19a229feb615b Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Mon, 16 Jan 2012 19:52:08 +0100 Subject: [PATCH] core: add URL transfer (using libcurl), add function hook_process_hashtable in plugin API, add support of URL in hook_process/hook_process_hashtable (task #10247) --- ChangeLog | 5 +- configure.in | 15 + debian/control | 2 +- doc/de/autogen/plugin_api/infolists.txt | 2 + doc/de/autogen/plugin_api/url_options.txt | 91 +++ doc/de/weechat_user.de.txt | 2 + doc/docgen.py | 31 + doc/en/autogen/plugin_api/infolists.txt | 2 + doc/en/autogen/plugin_api/url_options.txt | 91 +++ doc/en/weechat_plugin_api.en.txt | 128 +++- doc/en/weechat_user.en.txt | 1 + doc/fr/autogen/plugin_api/infolists.txt | 2 + doc/fr/autogen/plugin_api/url_options.txt | 91 +++ doc/fr/weechat_plugin_api.fr.txt | 135 +++- doc/fr/weechat_user.fr.txt | 1 + doc/it/autogen/plugin_api/infolists.txt | 2 + doc/it/autogen/plugin_api/url_options.txt | 91 +++ doc/it/weechat_plugin_api.it.txt | 134 +++- doc/it/weechat_user.it.txt | 2 + po/POTFILES.in | 2 + po/cs.po | 16 +- po/de.po | 16 +- po/es.po | 16 +- po/fr.po | 16 +- po/hu.po | 16 +- po/it.po | 16 +- po/pl.po | 16 +- po/pt_BR.po | 16 +- po/ru.po | 16 +- po/srcfiles.cmake | 2 + po/weechat.pot | 14 +- src/CMakeLists.txt | 3 + src/core/CMakeLists.txt | 3 + src/core/Makefile.am | 4 +- src/core/wee-hook.c | 70 +- src/core/wee-hook.h | 7 + src/core/wee-url.c | 628 ++++++++++++++++++ src/core/wee-url.h | 59 ++ src/gui/curses/CMakeLists.txt | 2 + src/gui/curses/Makefile.am | 1 + src/gui/gtk/CMakeLists.txt | 2 + src/gui/gtk/Makefile.am | 3 +- src/plugins/plugin-api.c | 23 +- src/plugins/plugin.c | 1 + src/plugins/scripts/lua/weechat-lua-api.c | 40 ++ src/plugins/scripts/perl/weechat-perl-api.c | 36 + .../scripts/python/weechat-python-api.c | 41 ++ src/plugins/scripts/ruby/weechat-ruby-api.c | 49 ++ src/plugins/scripts/script-api.c | 70 +- src/plugins/scripts/script-api.h | 12 + src/plugins/scripts/tcl/weechat-tcl-api.c | 44 ++ src/plugins/weechat-plugin.h | 17 +- 52 files changed, 2049 insertions(+), 56 deletions(-) create mode 100644 doc/de/autogen/plugin_api/url_options.txt create mode 100644 doc/en/autogen/plugin_api/url_options.txt create mode 100644 doc/fr/autogen/plugin_api/url_options.txt create mode 100644 doc/it/autogen/plugin_api/url_options.txt create mode 100644 src/core/wee-url.c create mode 100644 src/core/wee-url.h diff --git a/ChangeLog b/ChangeLog index 3a40b9407..3a21f66d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,9 +41,10 @@ Version 0.3.7 (under dev!) * core: fix compilation error with "pid_t" on Mac OS X (bug #34639) * core: enable background process under Cygwin to connect to servers, fix reconnection problem (bug #34626) +* api: add support of URL in hook_process/hook_process_hashtable (task #10247) * api: add new functions strcasecmp_range, strncasecmp_range, - hashtable_map_string, hdata_check_pointer, hdata_char, hdata_hashtable and - nicklist_get_next_item + hashtable_map_string, hook_process_hashtable, hdata_check_pointer, hdata_char, + hdata_hashtable and nicklist_get_next_item * alias: add default alias umode => /mode $nick * irc: use low priority for MODE sent automatically by WeeChat (when joining channel) diff --git a/configure.in b/configure.in index 46f0ab779..60ffacac6 100644 --- a/configure.in +++ b/configure.in @@ -929,6 +929,21 @@ else not_asked="$not_asked zlib" fi +# ------------------------------------------------------------------------------ +# curl +# ------------------------------------------------------------------------------ + +AC_PATH_PROG(CURL_CONFIG, curl-config) +if test "x$CURL_CONFIG" = "x" ; then + AC_MSG_ERROR([ +*** "curl-config" couldn't be found on your system. +*** Try to install libcurl-dev with your software package manager.]) +fi +CURL_CFLAGS=`$CURL_CONFIG --cflags` +CURL_LFLAGS=`$CURL_CONFIG --libs` +AC_SUBST(CURL_CFLAGS) +AC_SUBST(CURL_LFLAGS) + # ------------------------------------------------------------------------------ # documentation # ------------------------------------------------------------------------------ diff --git a/debian/control b/debian/control index 1e7766de7..328112c10 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ Build-Depends-Indep: asciidoc (>= 8.5), source-highlight Build-Depends: debhelper (>= 7.0.50), cmake, libncursesw5-dev, ruby1.9.1, ruby1.9.1-dev, libperl-dev, python-dev, libaspell-dev, liblua5.1-0-dev, tcl8.5-dev, guile-1.8-dev, libgcrypt11-dev, libgnutls-dev, zlib1g-dev, - dpkg-dev (>= 1.13.19), pkg-config + libcurl-dev, dpkg-dev (>= 1.13.19), pkg-config Standards-Version: 3.9.2 Homepage: http://weechat.org/ Vcs-Git: git://git.debian.org/users/kolter/weechat.git diff --git a/doc/de/autogen/plugin_api/infolists.txt b/doc/de/autogen/plugin_api/infolists.txt index 55519cd4f..e2042f839 100644 --- a/doc/de/autogen/plugin_api/infolists.txt +++ b/doc/de/autogen/plugin_api/infolists.txt @@ -58,6 +58,8 @@ | weechat | plugin | Auflistung der Erweiterungen | Pointer der Erweiterung (optional) | Name einer Erweiterung (darf mit einem "*" als Platzhalter beginnen oder enden) (optional) +| weechat | url_options | options for URL | - | - + | weechat | window | Auflistung der Windows | Fenster Pointer (optional) | "current" für aktuelles Fenster oder die Nummer eines Fensters (optional) | xfer | xfer | Transfer-Liste | Transfer-Pointer (optional) | - diff --git a/doc/de/autogen/plugin_api/url_options.txt b/doc/de/autogen/plugin_api/url_options.txt new file mode 100644 index 000000000..497bf884f --- /dev/null +++ b/doc/de/autogen/plugin_api/url_options.txt @@ -0,0 +1,91 @@ +[width="100%",cols="2,^1,7",options="header"] +|======================================== +| Option | Type | Constants ^(1)^ + +| header | long | + +| wildcardmatch | long | + +| failonerror | long | + +| protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| redir_protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| proxy | string | + +| proxyport | long | + +| proxytype | long | http, http_1_0, socks4, socks5, socks4a, socks5_hostname + +| noproxy | string | + +| httpproxytunnel | long | + +| socks5_gssapi_service | string | + +| socks5_gssapi_nec | long | + +| interface | string | + +| localport | long | + +| localportrange | long | + +| dns_cache_timeout | long | + +| buffersize | long | + +| port | long | + +| tcp_nodelay | long | + +| address_scope | long | + +| netrc | long | ignored, optional, required + +| netrc_file | string | + +| userpwd | string | + +| proxyuserpwd | string | + +| username | string | + +| password | string | + +| proxyusername | string | + +| proxypassword | string | + +| httpauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| tlsauth_type | mask | none, srp + +| tlsauth_username | string | + +| tlsauth_password | string | + +| proxyauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| autoreferer | long | + +| accept_encoding | string | + +| transfer_encoding | long | + +| followlocation | long | + +| unrestricted_auth | long | + +| maxredirs | long | + +| postredir | mask | post_301, post_302 + +| post | long | + +| postfields | string | + +| postfieldsize | long | + +|======================================== diff --git a/doc/de/weechat_user.de.txt b/doc/de/weechat_user.de.txt index 2eff14460..4d8186172 100644 --- a/doc/de/weechat_user.de.txt +++ b/doc/de/weechat_user.de.txt @@ -90,6 +90,8 @@ welche Pakete optional genutzt werden können. | Paket ^(1)^ | Version | benötigt | Funktion | cmake | | *ja* | zum kompilieren (autotools ist möglich. cmake wird aber empfohlen) | libncursesw5-dev ^(2)^ | | *ja* | ncurses Oberfläche +// TRANSLATION MISSING +| libcurl4-xxxxx-dev | | *ja* | URL transfer | gettext | | | Internationalisierung (Übersetzung der Mitteilungen; Hauptsprache ist englisch) | libgcrypt11-dev | | | SASL Authentifikation am IRC Server mittels DH-BLOWFISH Methode | libgnutls-dev | ≥ 2.2.0 | | SSL Verbindung zu einem IRC Server diff --git a/doc/docgen.py b/doc/docgen.py index 1131752b1..4f60bc333 100644 --- a/doc/docgen.py +++ b/doc/docgen.py @@ -250,6 +250,18 @@ def get_completions(): weechat.infolist_free(infolist) return completions +def get_url_options(): + """Get list of completions hooked by plugins in a dict with 3 indexes: plugin, item, xxx.""" + url_options = [] + infolist = weechat.infolist_get('url_options', '', '') + while weechat.infolist_next(infolist): + url_options.append({ 'name': weechat.infolist_string(infolist, 'name').lower(), + 'option': weechat.infolist_integer(infolist, 'option'), + 'type': weechat.infolist_string(infolist, 'type'), + 'constants': weechat.infolist_string(infolist, 'constants').lower().replace(',', ', ') }) + weechat.infolist_free(infolist) + return url_options + def update_file(oldfile, newfile, num_files, num_files_updated, obj): """Update a doc file.""" try: @@ -288,6 +300,7 @@ def docgen_cmd_cb(data, buffer, args): infolists = get_infolists() hdata = get_hdata() completions = get_completions() + url_options = get_url_options() # get path and replace ~ by home if needed path = weechat.config_get_plugin('path') @@ -497,6 +510,24 @@ def docgen_cmd_cb(data, buffer, args): f.close() update_file(filename, tmpfilename, num_files, num_files_updated, 'completions') + # write url options + filename = '%s/plugin_api/url_options.txt' % directory + tmpfilename = '%s.tmp' % filename + f = open(tmpfilename, 'w') + f.write('[width="100%",cols="2,^1,7",options="header"]\n') + f.write('|========================================\n') + f.write('| %s | %s | %s\n\n' % (_('Option'), _('Type'), _('Constants') + ' ^(1)^')) + for option in url_options: + constants = option['constants'] + if constants: + constants = ' ' + constants + f.write('| %s | %s |%s\n\n' % (escape(option['name']), + escape(option['type']), + escape(constants))) + f.write('|========================================\n') + f.close() + update_file(filename, tmpfilename, num_files, num_files_updated, 'url_options') + # write counters weechat.prnt('', 'docgen: %s: %3d files (%2d cmd, %2d opt, %2d infos, ' diff --git a/doc/en/autogen/plugin_api/infolists.txt b/doc/en/autogen/plugin_api/infolists.txt index 7397122ff..9b6b937fd 100644 --- a/doc/en/autogen/plugin_api/infolists.txt +++ b/doc/en/autogen/plugin_api/infolists.txt @@ -58,6 +58,8 @@ | weechat | plugin | list of plugins | plugin pointer (optional) | plugin name (can start or end with "*" as wildcard) (optional) +| weechat | url_options | options for URL | - | - + | weechat | window | list of windows | window pointer (optional) | "current" for current window or a window number (optional) | xfer | xfer | list of xfer | xfer pointer (optional) | - diff --git a/doc/en/autogen/plugin_api/url_options.txt b/doc/en/autogen/plugin_api/url_options.txt new file mode 100644 index 000000000..497bf884f --- /dev/null +++ b/doc/en/autogen/plugin_api/url_options.txt @@ -0,0 +1,91 @@ +[width="100%",cols="2,^1,7",options="header"] +|======================================== +| Option | Type | Constants ^(1)^ + +| header | long | + +| wildcardmatch | long | + +| failonerror | long | + +| protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| redir_protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| proxy | string | + +| proxyport | long | + +| proxytype | long | http, http_1_0, socks4, socks5, socks4a, socks5_hostname + +| noproxy | string | + +| httpproxytunnel | long | + +| socks5_gssapi_service | string | + +| socks5_gssapi_nec | long | + +| interface | string | + +| localport | long | + +| localportrange | long | + +| dns_cache_timeout | long | + +| buffersize | long | + +| port | long | + +| tcp_nodelay | long | + +| address_scope | long | + +| netrc | long | ignored, optional, required + +| netrc_file | string | + +| userpwd | string | + +| proxyuserpwd | string | + +| username | string | + +| password | string | + +| proxyusername | string | + +| proxypassword | string | + +| httpauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| tlsauth_type | mask | none, srp + +| tlsauth_username | string | + +| tlsauth_password | string | + +| proxyauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| autoreferer | long | + +| accept_encoding | string | + +| transfer_encoding | long | + +| followlocation | long | + +| unrestricted_auth | long | + +| maxredirs | long | + +| postredir | mask | post_301, post_302 + +| post | long | + +| postfields | string | + +| postfieldsize | long | + +|======================================== diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index 40f2918e4..987e4e794 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -6706,7 +6706,8 @@ struct t_hook *weechat_hook_process (const char *command, Arguments: -* 'command': command to launch in child process +* 'command': command to launch in child process or URL (_new in version 0.3.7_), + see below * 'timeout': timeout for command (in milliseconds): after this timeout, child process is killed (0 means no timeout) * 'callback': function called when data from child is available, or when child @@ -6731,6 +6732,10 @@ Return value: When command has ended, or if timeout is reached, WeeChat will automatically unhook (and kill process if it is still running). +The command can be an URL with format: "url:http://www.example.com", to download +content of URL (_new in version 0.3.7_). Options are possible for URL with +function <<_weechat_hook_process_hashtable,weechat_hook_process_hashtable>>. + [NOTE] Buffer size for sending data to callback is 64KB (there are 2 buffers: one for stdout and one for stderr). @@ -6801,6 +6806,127 @@ def my_process_cb(data, command, return_code, out, err): hook = weechat.hook_process("ls", 5000, "my_process_cb", "") ---------------------------------------- +weechat_hook_process_hashtable +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +_New in version 0.3.7._ + +Hook a process (launched with fork) using options in a hashtable, and catch +output. + +Prototype: + +[source,C] +---------------------------------------- +struct t_hook *weechat_hook_process_hashtable (const char *command, + struct t_hashtable *options, + int timeout, + int (*callback)(void *data, + const char *command, + int return_code, + const char *out, + const char *err), + void *callback_data); +---------------------------------------- + +Arguments are the same as function <<_weechat_hook_process,weechat_hook_process>>, +with an extra argument: + +* 'options': options for command executed (see table below); the hashtable is + duplicated in function, so it's safe to free it after this call + +For command "url:...", following options are available (see +`man curl_easy_setopt` for a description of each option): + +include::autogen/plugin_api/url_options.txt[] + +[NOTE] +^(1)^ When constants are available they must be used as value for option. For +options with type "mask", format is: "value1+value2+value3". + +For URL, two extra options (strings) are allowed for input/output file: + +* 'file_in': file to read and send with URLs (post file) +* 'file_out': write downloaded URL/file in this file (instead of standard + output) + +Return value: + +* pointer to new hook, NULL if error occurred + +C example: + +[source,C] +---------------------------------------- +int +my_process_cb (void *data, const char *command, int return_code, + const char *out, const char *err) +{ + if (return_code == WEECHAT_HOOK_PROCESS_ERROR) + { + weechat_printf (NULL, "Error with command '%s'", command); + return WEECHAT_RC_OK; + } + + if (return_code >= 0) + { + weechat_printf (NULL, "return_code = %d", return_code); + } + + if (out) + { + weechat_printf (NULL, "stdout: %s", out); + } + + if (err) + { + weechat_printf (NULL, "stderr: %s", err); + } + + return WEECHAT_RC_OK; +} + +struct t_hashtable *options = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); +if (hashtable) +{ + weechat_hashtable_set (options, "file_out", "/tmp/weechat.org.html"); + struct t_hook *my_process_hook = weechat_hook_process_hashtable ("url:http://www.weechat.org/", + options, + 20000, + &my_process_cb, NULL); + weechat_hashtable_free (options); +} +---------------------------------------- + +Script (Python): + +[source,python] +---------------------------------------- +# prototype +hook = weechat.hook_process_hashtable(command, options, timeout, callback, callback_data) + +# example +def my_process_cb(data, command, return_code, out, err): + if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: + weechat.prnt("", "Error with command '%s'" % command) + return weechat.WEECHAT_RC_OK + if return_code >= 0: + weechat.prnt("", "return_code = %d" % return_code) + if out != "": + weechat.prnt("", "stdout: %s" % out) + if err != "": + weechat.prnt("", "stderr: %s" % err) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_process_hashtable("url:http://www.weechat.org/", + { "file_out": "/tmp/weechat.org.html" }, + 20000, "my_process_cb", "") +---------------------------------------- + weechat_hook_connect ^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/en/weechat_user.en.txt b/doc/en/weechat_user.en.txt index 1738449a9..9d1c942e9 100644 --- a/doc/en/weechat_user.en.txt +++ b/doc/en/weechat_user.en.txt @@ -90,6 +90,7 @@ compile WeeChat. | Package ^(1)^ | Version | Required | Feature | cmake | | *yes* | build (autotools still possible, but cmake is recommended) | libncursesw5-dev ^(2)^ | | *yes* | ncurses interface +| libcurl4-xxxxx-dev | | *yes* | URL transfer | gettext | | | internationalization (translation of messages; base language is english) | libgcrypt11-dev | | | SASL authentication with IRC server using DH-BLOWFISH mechanism | libgnutls-dev | ≥ 2.2.0 | | SSL connection to IRC server diff --git a/doc/fr/autogen/plugin_api/infolists.txt b/doc/fr/autogen/plugin_api/infolists.txt index fc05a383e..a1d372e57 100644 --- a/doc/fr/autogen/plugin_api/infolists.txt +++ b/doc/fr/autogen/plugin_api/infolists.txt @@ -58,6 +58,8 @@ | weechat | plugin | liste des extensions | pointeur vers l'extension (optionnel) | nom d'extension (peut démarrer ou se terminer par "*" comme joker) (optionnel) +| weechat | url_options | options pour l'URL | - | - + | weechat | window | liste des fenêtres | pointeur vers la fenêtre (optionnel) | "current" pour la fenêtre courante ou un numéro de fenêtre (optionnel) | xfer | xfer | liste des xfer | pointeur vers le xfer (optionnel) | - diff --git a/doc/fr/autogen/plugin_api/url_options.txt b/doc/fr/autogen/plugin_api/url_options.txt new file mode 100644 index 000000000..f7cab2e55 --- /dev/null +++ b/doc/fr/autogen/plugin_api/url_options.txt @@ -0,0 +1,91 @@ +[width="100%",cols="2,^1,7",options="header"] +|======================================== +| Option | Type | Constantes ^(1)^ + +| header | long | + +| wildcardmatch | long | + +| failonerror | long | + +| protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| redir_protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| proxy | string | + +| proxyport | long | + +| proxytype | long | http, http_1_0, socks4, socks5, socks4a, socks5_hostname + +| noproxy | string | + +| httpproxytunnel | long | + +| socks5_gssapi_service | string | + +| socks5_gssapi_nec | long | + +| interface | string | + +| localport | long | + +| localportrange | long | + +| dns_cache_timeout | long | + +| buffersize | long | + +| port | long | + +| tcp_nodelay | long | + +| address_scope | long | + +| netrc | long | ignored, optional, required + +| netrc_file | string | + +| userpwd | string | + +| proxyuserpwd | string | + +| username | string | + +| password | string | + +| proxyusername | string | + +| proxypassword | string | + +| httpauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| tlsauth_type | mask | none, srp + +| tlsauth_username | string | + +| tlsauth_password | string | + +| proxyauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| autoreferer | long | + +| accept_encoding | string | + +| transfer_encoding | long | + +| followlocation | long | + +| unrestricted_auth | long | + +| maxredirs | long | + +| postredir | mask | post_301, post_302 + +| post | long | + +| postfields | string | + +| postfieldsize | long | + +|======================================== diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index 3aafce46e..ddd94a8ed 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -6795,7 +6795,8 @@ struct t_hook *weechat_hook_process (const char *command, Paramètres : -* 'command' : commande à lancer dans le processus fils +* 'command' : commande à lancer dans le processus fils ou URL + (_nouveau dans la version 0.3.7_), voir ci-dessous * 'timeout' : timeout pour la commande (en millisecondes) : après ce délai, le processus fils est tué (0 signifie pas de limite) * 'callback' : function appelée quand des données du fils sont disponibles, or @@ -6823,6 +6824,11 @@ Lorsque la commande est terminée, ou si le timeout est atteint, WeeChat supprimera automatiquement le "hook" (et tuera le processus s'il tourne toujours). +La commande peut être une URL avec le format : "url:http://www.example.com", +pour télécharger le contenu de l'URL (_nouveau dans la version 0.3.7_). +Des options pour l'URL sont possibles avec la fonction +<<_weechat_hook_process_hashtable,weechat_hook_process_hashtable>>. + [NOTE] La taille du tampon pour l'envoi des données au "callback" est de 64 Ko (il y a 2 tampons : un pour stdout et un pour stderr). @@ -6894,6 +6900,131 @@ def my_process_cb(data, command, return_code, out, err): hook = weechat.hook_process("ls", 5000, "my_process_cb", "") ---------------------------------------- +weechat_hook_process_hashtable +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +_Nouveau dans la version 0.3.7._ + +Accroche un processus (lancé par un fork) en utilisant des options dans une +hashtable, et intercepter sa sortie. + +Prototype : + +[source,C] +---------------------------------------- +struct t_hook *weechat_hook_process_hashtable (const char *command, + struct t_hashtable *options, + int timeout, + int (*callback)(void *data, + const char *command, + int return_code, + const char *out, + const char *err), + void *callback_data); +---------------------------------------- + +Les paramètres sont les mêmes que ceux de la fonction +<<_weechat_hook_process,weechat_hook_process>>, avec un paramètre +supplémentaire : + +* 'options' : options pour la commande exécutée (voir le tableau ci-dessous); + la hashtable est dupliquée dans la fonction, donc il est possible de la + supprimer après cet appel + +Pour la commande "url:...", les options suivantes sont disponibles (voir +`man curl_easy_setopt` pour une description de chaque option) : + +include::autogen/plugin_api/url_options.txt[] + +[NOTE] +^(1)^ Lorsque des constantes sont disponibles, elles doivent être utilisées +comme valeur pour l'option. Pour les options avec le type "mask", le format est : +"valeur1+valeur2+valeur3". + +Pour l'URL, deux options supplémentaires (chaînes) sont autorisées, pour le +fichier en entrée/sortie : + +* 'file_in' : fichier à lire pour envoyer avec l'URL (envoi de fichier "post") +* 'file_out' : écrire l'URL/fichier dans ce fichier (au lieu de la sortie + standard) + +Valeur de retour : + +* pointeur vers le nouveau "hook", NULL en cas d'erreur + +Exemple en C : + +[source,C] +---------------------------------------- +int +my_process_cb (void *data, const char *command, int return_code, + const char *out, const char *err) +{ + if (return_code == WEECHAT_HOOK_PROCESS_ERROR) + { + weechat_printf (NULL, "Erreur avec la commande '%s'", command); + return WEECHAT_RC_OK; + } + + if (return_code >= 0) + { + weechat_printf (NULL, "return_code = %d", return_code); + } + + if (out) + { + weechat_printf (NULL, "stdout : %s", out); + } + + if (err) + { + weechat_printf (NULL, "stderr : %s", err); + } + + return WEECHAT_RC_OK; +} + +struct t_hashtable *options = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); +if (hashtable) +{ + weechat_hashtable_set (options, "file_out", "/tmp/weechat.org.html"); + struct t_hook *my_process_hook = weechat_hook_process_hashtable ("url:http://www.weechat.org/", + options, + 20000, + &my_process_cb, NULL); + weechat_hashtable_free (options); +} +---------------------------------------- + +Script (Python): + +[source,python] +---------------------------------------- +# prototype +hook = weechat.hook_process_hashtable(command, options, timeout, callback, callback_data) + +# exemple +def my_process_cb(data, command, return_code, out, err): + if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: + weechat.prnt("", "Erreur avec la commande '%s'" % command) + return weechat.WEECHAT_RC_OK + if return_code >= 0: + weechat.prnt("", "return_code = %d" % return_code) + if out != "": + weechat.prnt("", "stdout: %s" % out) + if err != "": + weechat.prnt("", "stderr: %s" % err) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_process_hashtable("url:http://www.weechat.org/", + { "file_out": "/tmp/weechat.org.html" }, + 20000, "my_process_cb", "") +---------------------------------------- + weechat_hook_connect ^^^^^^^^^^^^^^^^^^^^ @@ -13326,7 +13457,7 @@ Script (Python) : # prototype hashtable = weechat.hdata_hashtable(hdata, pointer, name) -# example +# exemple hdata = weechat.hdata_get("buffer") buffer = weechat.buffer_search_main() hash = weechat.hdata_hashtable(hdata, buffer, "local_variables") diff --git a/doc/fr/weechat_user.fr.txt b/doc/fr/weechat_user.fr.txt index 61ea45694..c1fa747af 100644 --- a/doc/fr/weechat_user.fr.txt +++ b/doc/fr/weechat_user.fr.txt @@ -92,6 +92,7 @@ compiler WeeChat. | Paquet ^(1)^ | Version | Requis | Fonctionnalité | cmake | | *oui* | construction (autotools toujours possible, mais cmake est recommandé) | libncursesw5-dev ^(2)^ | | *oui* | interface ncurses +| libcurl4-xxxxx-dev | | *oui* | transfert d'URL | gettext | | | internationalisation (traduction des messages; la langue de base est l'anglais) | libgcrypt11-dev | | | authentification SASL avec le serveur IRC, en utilisant le mécanisme DH-BLOWFISH | libgnutls-dev | ≥ 2.2.0 | | connexion SSL au serveur IRC diff --git a/doc/it/autogen/plugin_api/infolists.txt b/doc/it/autogen/plugin_api/infolists.txt index 7dcf002ef..8ef37a236 100644 --- a/doc/it/autogen/plugin_api/infolists.txt +++ b/doc/it/autogen/plugin_api/infolists.txt @@ -58,6 +58,8 @@ | weechat | plugin | elenco dei plugin | puntatore al plugin (opzionale) | nome plugin (può iniziare o terminare con "*" come carattere jolly) (opzionale) +| weechat | url_options | options for URL | - | - + | weechat | window | elenco delle finestre | puntatore alla finestra (opzionale) | "current" per la finestra corrente o un numero della finestra (opzionale) | xfer | xfer | lista di xfer | puntatore a xfer (opzionale) | - diff --git a/doc/it/autogen/plugin_api/url_options.txt b/doc/it/autogen/plugin_api/url_options.txt new file mode 100644 index 000000000..497bf884f --- /dev/null +++ b/doc/it/autogen/plugin_api/url_options.txt @@ -0,0 +1,91 @@ +[width="100%",cols="2,^1,7",options="header"] +|======================================== +| Option | Type | Constants ^(1)^ + +| header | long | + +| wildcardmatch | long | + +| failonerror | long | + +| protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| redir_protocols | mask | http, https, ftp, ftps, scp, sftp, telnet, ldap, ldaps, dict, file, tftp, imap, imaps, pop3, pop3s, smtp, smtps, rtsp, rtmp, rtmpt, rtmpe, rtmpte, rtmps, rtmpts, gopher, all + +| proxy | string | + +| proxyport | long | + +| proxytype | long | http, http_1_0, socks4, socks5, socks4a, socks5_hostname + +| noproxy | string | + +| httpproxytunnel | long | + +| socks5_gssapi_service | string | + +| socks5_gssapi_nec | long | + +| interface | string | + +| localport | long | + +| localportrange | long | + +| dns_cache_timeout | long | + +| buffersize | long | + +| port | long | + +| tcp_nodelay | long | + +| address_scope | long | + +| netrc | long | ignored, optional, required + +| netrc_file | string | + +| userpwd | string | + +| proxyuserpwd | string | + +| username | string | + +| password | string | + +| proxyusername | string | + +| proxypassword | string | + +| httpauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| tlsauth_type | mask | none, srp + +| tlsauth_username | string | + +| tlsauth_password | string | + +| proxyauth | mask | none, basic, digest, gssnegotiate, ntlm, digest_ie, ntlm_wb, only, any, anysafe + +| autoreferer | long | + +| accept_encoding | string | + +| transfer_encoding | long | + +| followlocation | long | + +| unrestricted_auth | long | + +| maxredirs | long | + +| postredir | mask | post_301, post_302 + +| post | long | + +| postfields | string | + +| postfieldsize | long | + +|======================================== diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index 3e93c21d6..370766a5d 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -6731,7 +6731,9 @@ struct t_hook *weechat_hook_process (const char *command, Argomenti: -* 'command': comando da avviare nel processo figlio +// TRANSLATION MISSING +* 'command': comando da avviare nel processo figlio or URL + (_novità nella versione 0.3.7_), see below * 'timeout': timeout per il comando (in millisecondi): dopo questo timeout, il processo figlio viene terminato (0 vuol dire nessun timeout) * 'callback': funzione chiamata quando i dati dal processo figlio sono disponibili, @@ -6757,6 +6759,11 @@ Valore restituito: Quando il comando ha terminato, o se viene raggiunto il timeout, WeeChat effettua automaticamente l'unhook (e termina il processo se ancora in esecuzione). +// TRANSLATION MISSING +The command can be an URL with format: "url:http://www.example.com", to download +content of URL (_new in version 0.3.7_). Options are possible for URL with +function <<_weechat_hook_process_hashtable,weechat_hook_process_hashtable>>. + [NOTE] La dimensione del buffer per l'invio dei dati alla callback è di 64KB (ci sono 2 buffer: uno per stdout ed uno per stderr). @@ -6828,6 +6835,131 @@ def my_process_cb(data, command, return_code, out, err): hook = weechat.hook_process("ls", 5000, "my_process_cb", "") ---------------------------------------- +weechat_hook_process_hashtable +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +_Novità nella versione 0.3.7._ + +// TRANSLATION MISSING +Hook a process (launched with fork) using options in a hashtable, and catch +output. + +Prototipo: + +[source,C] +---------------------------------------- +struct t_hook *weechat_hook_process_hashtable (const char *command, + struct t_hashtable *options, + int timeout, + int (*callback)(void *data, + const char *command, + int return_code, + const char *out, + const char *err), + void *callback_data); +---------------------------------------- + +// TRANSLATION MISSING +Arguments are the same as function <<_weechat_hook_process,weechat_hook_process>>, +with an extra argument: + +* 'options': options for command executed (see table below); the hashtable is + duplicated in function, so it's safe to free it after this call + +// TRANSLATION MISSING +For command "url:...", following options are available (see +`man curl_easy_setopt` for a description of each option): + +include::autogen/plugin_api/url_options.txt[] + +// TRANSLATION MISSING +[NOTE] +^(1)^ When constants are available they must be used as value for option. For +options with type "mask", format is: "value1+value2+value3". + +For URL, two extra options (strings) are allowed for input/output file: + +* 'file_in': file to read and send with URLs (post file) +* 'file_out': write downloaded URL/file in this file (instead of standard + output) + +Valore restituito: + +* puntatore al nuovo hook, NULL in caso di errore + +Esempio in C: + +[source,C] +---------------------------------------- +int +my_process_cb (void *data, const char *command, int return_code, + const char *out, const char *err) +{ + if (return_code == WEECHAT_HOOK_PROCESS_ERROR) + { + weechat_printf (NULL, "Error with command '%s'", command); + return WEECHAT_RC_OK; + } + + if (return_code >= 0) + { + weechat_printf (NULL, "return_code = %d", return_code); + } + + if (out) + { + weechat_printf (NULL, "stdout: %s", out); + } + + if (err) + { + weechat_printf (NULL, "stderr: %s", err); + } + + return WEECHAT_RC_OK; +} + +struct t_hashtable *options = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); +if (hashtable) +{ + weechat_hashtable_set (options, "file_out", "/tmp/weechat.org.html"); + struct t_hook *my_process_hook = weechat_hook_process_hashtable ("url:http://www.weechat.org/", + options, + 20000, + &my_process_cb, NULL); + weechat_hashtable_free (options); +} +---------------------------------------- + +Script (Python): + +[source,python] +---------------------------------------- +# prototipo +hook = weechat.hook_process_hashtable(command, options, timeout, callback, callback_data) + +# esempio +def my_process_cb(data, command, return_code, out, err): + if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: + weechat.prnt("", "Error with command '%s'" % command) + return weechat.WEECHAT_RC_OK + if return_code >= 0: + weechat.prnt("", "return_code = %d" % return_code) + if out != "": + weechat.prnt("", "stdout: %s" % out) + if err != "": + weechat.prnt("", "stderr: %s" % err) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_process_hashtable("url:http://www.weechat.org/", + { "file_out": "/tmp/weechat.org.html" }, + 20000, "my_process_cb", "") +---------------------------------------- + weechat_hook_connect ^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/it/weechat_user.it.txt b/doc/it/weechat_user.it.txt index 6cd6688e9..068e09d7d 100644 --- a/doc/it/weechat_user.it.txt +++ b/doc/it/weechat_user.it.txt @@ -94,6 +94,8 @@ compilare WeeChat. | Pacchetto ^(1)^ | Versione | Richiesto | Caratteristica | cmake | | *sì* | compilazione (ancora possibile con autotools, ma si raccomanda cmake) | libncursesw5-dev ^(2)^ | | *sì* | interfaccia ncurses +// TRANSLATION MISSING +| libcurl4-xxxxx-dev | | *sì* | URL transfer | gettext | | | internazionalizzazione (traduzione dei messaggi; la lingua base è l'inglese) | libgcrypt11-dev | | | autenticazione SASL per i server IRC che utilizzano il meccanismo DH-BLOWFISH | libgnutls-dev | ≥ 2.2.0 | | connessione SSL al server IRC diff --git a/po/POTFILES.in b/po/POTFILES.in index bdb52ea39..1275c4837 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -32,6 +32,8 @@ ./src/core/wee-upgrade.h ./src/core/wee-upgrade-file.c ./src/core/wee-upgrade-file.h +./src/core/wee-url.c +./src/core/wee-url.h ./src/core/wee-utf8.c ./src/core/wee-utf8.h ./src/core/wee-util.c diff --git a/po/cs.po b/po/cs.po index 59abfc0d5..635394963 100644 --- a/po/cs.po +++ b/po/cs.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2012-01-08 12:03+0100\n" +"POT-Creation-Date: 2012-01-15 09:29+0100\n" "PO-Revision-Date: 2011-12-25 22:56+0100\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -6996,6 +6996,10 @@ msgstr "" "jméno pluginu (může začínat nebo končit \"*\" jako zástupným znakem) " "(volitelné)" +#, fuzzy +msgid "options for URL" +msgstr "volby pro pole" + msgid "list of windows" msgstr "seznam oken" @@ -8197,3 +8201,13 @@ msgstr "" msgid "Lists" msgstr "" + +#, fuzzy +msgid "Option" +msgstr "" + +msgid "Type" +msgstr "" + +msgid "Constants" +msgstr "" diff --git a/po/de.po b/po/de.po index 946c041b1..258afab5a 100644 --- a/po/de.po +++ b/po/de.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2012-01-08 12:03+0100\n" +"POT-Creation-Date: 2012-01-15 09:29+0100\n" "PO-Revision-Date: 2011-12-25 22:56+0100\n" "Last-Translator: Nils Görs \n" "Language-Team: weechat-dev \n" @@ -7431,6 +7431,10 @@ msgstr "" "Name einer Erweiterung (darf mit einem \"*\" als Platzhalter beginnen oder " "enden) (optional)" +#, fuzzy +msgid "options for URL" +msgstr "Optionen für Infobars" + msgid "list of windows" msgstr "Auflistung der Windows" @@ -8658,3 +8662,13 @@ msgstr "Variablen" msgid "Lists" msgstr "Listen" + +#, fuzzy +msgid "Option" +msgstr "