Small fixes for http/telnet/tcp codepath
authorHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Fri, 18 Aug 2017 11:03:49 +0000 (13:03 +0200)
committerHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Fri, 18 Aug 2017 11:03:49 +0000 (13:03 +0200)
src-plugins/subsystems/oonf_http.c
src-plugins/subsystems/oonf_stream_socket.c
src-plugins/subsystems/oonf_stream_socket.h
src-plugins/subsystems/oonf_telnet.c
src-plugins/subsystems/oonf_telnet.h

index 454e6ff..c3ee71b 100644 (file)
@@ -389,6 +389,8 @@ _cb_receive_data(struct oonf_stream_session *session) {
   }
 
   header.decoded_request_uri = uri;
+  header.remote = &session->remote_address;
+
   handler = _get_site_handler(uri);
   if (handler == NULL) {
     OONF_DEBUG(LOG_HTTP, "No HTTP handler for site: %s", uri);
@@ -503,6 +505,7 @@ _cb_create_error(struct oonf_stream_session *session,
 static void
 _create_http_error(struct oonf_stream_session *session,
     enum oonf_http_result error) {
+  abuf_clear(&session->out);
   abuf_appendf(&session->out, "<html><head><title>%s %s http server</title></head>"
       "<body><h1>HTTP error %d: %s</h1></body></html>",
       oonf_log_get_appdata()->app_name, oonf_log_get_libdata()->version,
index daf6e36..063a123 100644 (file)
@@ -456,10 +456,6 @@ oonf_stream_copy_managed_config(struct oonf_stream_managed_config *dst,
  */
 static void
 _stream_close(struct oonf_stream_session *session) {
-  if (!list_is_node_added(&session->node)) {
-    return;
-  }
-
   if (session->stream_socket->config.cleanup) {
     session->stream_socket->config.cleanup(session);
   }
@@ -469,6 +465,7 @@ _stream_close(struct oonf_stream_session *session) {
   session->stream_socket->session_counter--;
   list_remove(&session->node);
 
+
   oonf_socket_remove(&session->scheduler_entry);
   os_fd_close(&session->scheduler_entry.fd);
 
index 9f6adaf..ed38374 100644 (file)
@@ -64,6 +64,9 @@
  * TCP session states
  */
 enum oonf_stream_session_state {
+  /*! tcp session has not been initialized */
+  STREAM_SESSION_INACTIVE,
+
   /*! tcp session is active */
   STREAM_SESSION_ACTIVE,
 
index 06d5bc5..b36a7f9 100644 (file)
@@ -251,18 +251,31 @@ oonf_telnet_stop(struct oonf_telnet_data *data, bool print_prompt) {
 enum oonf_telnet_result
 oonf_telnet_execute(const char *cmd, const char *para,
     struct autobuf *out, struct netaddr *remote) {
-  struct oonf_telnet_data data;
+  struct oonf_telnet_cleanup *handler, *it;
+  struct oonf_telnet_session session;
   enum oonf_telnet_result result;
 
-  memset(&data, 0, sizeof(data));
-  data.command = cmd;
-  data.parameter = para;
-  data.out = out;
-  data.remote = remote;
+  memset(&session, 0, sizeof(session));
+  session.data.command = cmd;
+  session.data.parameter = para;
+  session.data.out = out;
+  session.data.remote = remote;
+
+  list_init_head(&session.data.cleanup_list);
+
+  result = _telnet_handle_command(&session.data);
+  _call_stop_handler(&session.data);
+
+  /* call all cleanup handlers */
+  list_for_each_element_safe(&session.data.cleanup_list, handler, node, it) {
+    /* remove from list first */
+    oonf_telnet_remove_cleanup(handler);
+
+    /* after this command the handler pointer might not be valid anymore */
+    handler->cleanup_handler(handler);
+  }
 
-  result = _telnet_handle_command(&data);
-  _call_stop_handler(&data);
-  return abuf_has_failed(data.out) ? TELNET_RESULT_INTERNAL_ERROR : result;
+  return abuf_has_failed(session.data.out) ? TELNET_RESULT_INTERNAL_ERROR : result;
 }
 
 /**
index b9e37eb..8efe69d 100644 (file)
@@ -233,7 +233,10 @@ oonf_telnet_flush_session(struct oonf_telnet_data *data) {
   struct oonf_telnet_session *session;
 
   session = container_of(data, struct oonf_telnet_session, data);
-  oonf_stream_flush(&session->session);
+  if (session->session.state != STREAM_SESSION_INACTIVE
+      && session->session.state != STREAM_SESSION_CLEANUP) {
+    oonf_stream_flush(&session->session);
+  }
 }
 
 #endif /* OONF_TELNET_H_ */