[PATCH 4/5] Allow client version to be specified.
Sergio Durigan Junior
sergiodj en sergiodj.net
Lun Abr 24 13:32:59 UTC 2017
On Thursday, April 20 2017, Thadeu Lima de Souza Cascardo wrote:
> In case the server from Receita Federal requires an updated version in
> the future, the user will be able to use a different version for the
> client without any need to rebuild or update rnetclient.
> ---
> rnet_encode.c | 9 ++++++---
> rnet_encode.h | 2 +-
> rnetclient.c | 16 ++++++++++++++--
> t-parse.c | 2 +-
> 4 files changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/rnet_encode.c b/rnet_encode.c
> index 3b522c3..7a744ae 100644
> --- a/rnet_encode.c
> +++ b/rnet_encode.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2013-2014 Thadeu Lima de Souza Cascardo <cascardo em minaslivre.org>
> + * Copyright (C) 2013-2017 Thadeu Lima de Souza Cascardo <cascardo em minaslivre.org>
> * Copyright (C) 2014 Alexandre Oliva <lxoliva em fsfla.org>
> *
> * This program is free software; you can redistribute it and/or modify
> @@ -27,7 +27,7 @@
> #include "rnet_message.h"
> #include "decfile.h"
>
> -int rnet_encode(struct rnet_decfile *decfile, struct rnet_message **msg)
> +int rnet_encode(struct rnet_decfile *decfile, struct rnet_message **msg, char *client)
> {
> int r = -EIO;
>
> @@ -96,7 +96,10 @@ int rnet_encode(struct rnet_decfile *decfile, struct rnet_message **msg)
> r = rnet_message_add_ascii(msg, "versao_java", "1.5.0-gij;Free Software rnetclient pretending to be GNU Interpreter for Java");
> r = rnet_message_add_ascii(msg, "origem", "JA2R");
> r = rnet_message_add_ascii(msg, "so", "GNU");
> - r = rnet_message_add_ascii(msg, "cliente", "201704");
> + if (client)
> + r = rnet_message_add_ascii(msg, "cliente", client);
> + else
> + r = rnet_message_add_ascii(msg, "cliente", "201704");
Corrija-me se eu estiver falando besteira, mas o "client version" pode
ser igual à versão do rnetclient, certo? Nesse caso, acho que
compensaria usar PACKAGE_VERSION ao invés de "201704". Evitaria ter que
ficar atualizando esse valor todo ano.
> r = rnet_message_add_buffer(msg, "dados_val",
> header + header_head,
> header_size - header_tail - header_head);
> diff --git a/rnet_encode.h b/rnet_encode.h
> index 4186642..beade73 100644
> --- a/rnet_encode.h
> +++ b/rnet_encode.h
> @@ -22,6 +22,6 @@
> #include "rnet_message.h"
> #include "decfile.h"
>
> -int rnet_encode(struct rnet_decfile *decfile, struct rnet_message **msg);
> +int rnet_encode(struct rnet_decfile *decfile, struct rnet_message **msg, char *client);
>
> #endif
> diff --git a/rnetclient.c b/rnetclient.c
> index dad3901..4e41a34 100644
> --- a/rnetclient.c
> +++ b/rnetclient.c
> @@ -51,7 +51,8 @@ static const char rnetclient_doc[] =
> "Tax Authority";
> static const char rnetclient_args_doc[] =
> "[-d|--declaration] FILE [-o|--output-dir DIRECTORY]"
> - " [-s|--server-name SERVER]";
> + " [-s|--server-name SERVER]"
> + " [-c|--client-version CLIENT]";
>
> #define RNET_ADDRESS "receitanet.receita.fazenda.gov.br"
>
> @@ -70,6 +71,10 @@ static const struct argp_option rnetclient_options_desc[] = {
> "The server to connect to. Default is " RNET_ADDRESS ".",
> 0 },
>
> + { "client-version", 'c', "CLIENT", 0,
> + "The client version to be used.",
> + 0 },
> +
> { NULL },
> };
>
> @@ -85,6 +90,9 @@ struct rnetclient_args {
>
> /* Server to connect to. */
> char *server_name;
> +
> + /* Client version to use. */
> + char *client_version;
> };
>
> /* Parser for command line arguments. */
> @@ -107,6 +115,10 @@ static error_t rnetclient_parse_opt(int key, char *arg, struct argp_state *state
> a->server_name = arg;
> break;
>
> + case 'c':
> + a->client_version = arg;
> + break;
> +
> case ARGP_KEY_ARG:
> /* The user has possibly provided a filename without
> using any switches (e.g., by running './rnetclient
> @@ -526,7 +538,7 @@ int main(int argc, char **argv)
> goto out_handshake;
> }
>
> - r = rnet_encode(decfile, &message);
> + r = rnet_encode(decfile, &message, rnet_args.client_version);
> if (r < 0) {
> fprintf(stderr, "error encoding message, file not supported?\n");
> r = 1;
> diff --git a/t-parse.c b/t-parse.c
> index 827dcec..ac735de 100644
> --- a/t-parse.c
> +++ b/t-parse.c
> @@ -41,7 +41,7 @@ int main(void)
> return -1;
> }
>
> - r = rnet_encode(decfile, &message);
> + r = rnet_encode(decfile, &message, NULL);
> if (r < 0) {
> fprintf(stderr, "Error encoding message\n");
> return -1;
> --
> 2.11.0
O patch está OK. Eu ainda me preocupo com a falta de documentação, mas
isso é assunto pra outra hora.
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
Más información sobre la lista de distribución Softwares-impostos