Several changes (#18)
Show help if no argument is provided In case someone calls `xmppc` assume that he doesn't know how to use it. Which means he might even not be aware of `-h`. So let's print the help in case no argument is provided instead of connecting, then discoverin that no mode is selected and disconnecting again. Fix segfault when not roster subcommand is provided _roster_parse_command() segfaults since it assumes there is an argv[0]. Let's test the number of arguments. Since we are already connected xmpp_connect_client() will wait for a disconnect. So I introduce a teardown function that is called in both the error case and the succesful case. Now _roster_send_query() doesn't disconnect anymore. Set to development by default Only set to release when a new release is tagged. Like this not every developer needs to change the code. And it's git aka development anyways. Don't mix german and english Co-authored-by: Michael Vetter <jubalh@iodoru.org> Reviewed-on: https://codeberg.org/Anoxinon_e.V./xmppc/pulls/18
This commit is contained in:
		| @@ -19,8 +19,8 @@ AS_CASE([$host_os], | |||||||
|     [cygwin], [PLATFORM="cygwin"], |     [cygwin], [PLATFORM="cygwin"], | ||||||
|     [PLATFORM="nix"]) |     [PLATFORM="nix"]) | ||||||
|  |  | ||||||
| #PACKAGE_STATUS="development" | PACKAGE_STATUS="development" | ||||||
| PACKAGE_STATUS="release" | #PACKAGE_STATUS="release" | ||||||
|  |  | ||||||
| AM_CFLAGS="-Wall -Wno-deprecated-declarations -pedantic -std=c11" | AM_CFLAGS="-Wall -Wno-deprecated-declarations -pedantic -std=c11" | ||||||
| AS_IF([test "x$PACKAGE_STATUS" = xdevelopment], | AS_IF([test "x$PACKAGE_STATUS" = xdevelopment], | ||||||
|   | |||||||
| @@ -358,6 +358,13 @@ int main(int argc, char *argv[]) { | |||||||
|       {"mode", required_argument, 0, 'm'}, |       {"mode", required_argument, 0, 'm'}, | ||||||
|       {"file", required_argument, 0, 'f'}, |       {"file", required_argument, 0, 'f'}, | ||||||
|       {0, 0, 0, 0}}; |       {0, 0, 0, 0}}; | ||||||
|  |  | ||||||
|  |   // No arguments provided | ||||||
|  |   if (argc == 1) { | ||||||
|  |         _show_help(); | ||||||
|  |         return EXIT_SUCCESS; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   while (c > -1) { |   while (c > -1) { | ||||||
|     int option_index = 0; |     int option_index = 0; | ||||||
|  |  | ||||||
| @@ -484,7 +491,7 @@ int main(int argc, char *argv[]) { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|   if( handler == NULL ) { |   if( handler == NULL ) { | ||||||
|     logError(&xmppc, "Unbekannter mode\n"); |     logError(&xmppc, "Unknown mode\n"); | ||||||
|     return -1; |     return -1; | ||||||
|   }  |   }  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -59,11 +59,20 @@ static void _roster_send_query(xmppc_t *xmppc,command_t *command); | |||||||
| static int _handle_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, | static int _handle_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, | ||||||
|                   void *const userdata); |                   void *const userdata); | ||||||
|  |  | ||||||
|  | static void _teardown(xmppc_t *xmppc); | ||||||
|  |  | ||||||
| void roster_execute_command(xmppc_t *xmppc, int argc, char *argv[]) { | void roster_execute_command(xmppc_t *xmppc, int argc, char *argv[]) { | ||||||
|   command_t *command = malloc(sizeof(command_t));  |   command_t *command = malloc(sizeof(command_t));  | ||||||
|   command->type = UNKOWN; |   command->type = UNKOWN; | ||||||
|   _roster_parse_command(command, argc, argv); |  | ||||||
|   _roster_send_query(xmppc, command); |   if (argc == 0) { | ||||||
|  |     logError(xmppc, "No subcommand provided\n"); | ||||||
|  |   } else { | ||||||
|  |     _roster_parse_command(command, argc, argv); | ||||||
|  |     _roster_send_query(xmppc, command); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   _teardown(xmppc); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void _roster_parse_command(command_t *command, int argc, char *argv[]) { | static void _roster_parse_command(command_t *command, int argc, char *argv[]) { | ||||||
| @@ -115,7 +124,11 @@ int _handle_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   xmpp_disconnect(conn); |  | ||||||
|   xmpp_stop(xmpp_conn_get_context(conn)); |  | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static void _teardown(xmppc_t *xmppc) { | ||||||
|  |   xmpp_conn_t *conn = xmppc->conn; | ||||||
|  |   xmpp_disconnect(conn); | ||||||
|  |   xmpp_stop(xmpp_conn_get_context(conn)); | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jubalh
					jubalh