[PATCH 4/5] Allow client version to be specified.
Thadeu Lima de Souza Cascardo
cascardo en cascardo.eti.br
Jue Abr 20 11:40:46 UTC 2017
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 | 13 ++++++++++++-
t-parse.c | 2 +-
4 files changed, 20 insertions(+), 6 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 en minaslivre.org>
+ * Copyright (C) 2013-2017 Thadeu Lima de Souza Cascardo <cascardo en minaslivre.org>
* Copyright (C) 2014 Alexandre Oliva <lxoliva en 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");
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..29de38a 100644
--- a/rnetclient.c
+++ b/rnetclient.c
@@ -70,6 +70,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 +89,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 +114,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 +537,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
Más información sobre la lista de distribución Softwares-impostos