telnet_server: drop unused options
[fw/openocd] / src / server / telnet_server.c
index 090aa86fdee33b0961b3ad93d9ec66b211d7e39b..7507afea8d688613eeadff39940e22ba743cc911 100644 (file)
@@ -19,9 +19,7 @@
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -32,7 +30,7 @@
 #include <target/target_request.h>
 #include <helper/configuration.h>
 
-static const char *telnet_port;
+static char *telnet_port;
 
 static char *negotiate =
        "\xFF\xFB\x03"                  /* IAC WILL Suppress Go Ahead */
@@ -207,17 +205,23 @@ static void telnet_save_history(struct telnet_connection *t_con)
 
 static int telnet_new_connection(struct connection *connection)
 {
-       struct telnet_connection *telnet_connection = malloc(sizeof(struct telnet_connection));
+       struct telnet_connection *telnet_connection;
        struct telnet_service *telnet_service = connection->service->priv;
        int i;
 
+       telnet_connection = malloc(sizeof(struct telnet_connection));
+
+       if (!telnet_connection) {
+               LOG_ERROR("Failed to allocate telnet connection.");
+               return ERROR_FAIL;
+       }
+
        connection->priv = telnet_connection;
 
        /* initialize telnet connection information */
        telnet_connection->closed = 0;
        telnet_connection->line_size = 0;
        telnet_connection->line_cursor = 0;
-       telnet_connection->option_size = 0;
        telnet_connection->prompt = strdup("> ");
        telnet_connection->state = TELNET_STATE_DATA;
 
@@ -568,7 +572,7 @@ static int telnet_input(struct connection *connection)
                                break;
                        default:
                                LOG_ERROR("unknown telnet state");
-                               exit(-1);
+                               return ERROR_FAIL;
                }
 
                bytes_read--;
@@ -619,17 +623,26 @@ int telnet_init(char *banner)
                return ERROR_OK;
        }
 
-       struct telnet_service *telnet_service = malloc(sizeof(struct telnet_service));
+       struct telnet_service *telnet_service =
+               malloc(sizeof(struct telnet_service));
+
+       if (!telnet_service) {
+               LOG_ERROR("Failed to allocate telnet service.");
+               return ERROR_FAIL;
+       }
 
        telnet_service->banner = banner;
 
-       return add_service("telnet",
-               telnet_port,
-               1,
-               telnet_new_connection,
-               telnet_input,
-               telnet_connection_closed,
+       int ret = add_service("telnet", telnet_port, CONNECTION_LIMIT_UNLIMITED,
+               telnet_new_connection, telnet_input, telnet_connection_closed,
                telnet_service);
+
+       if (ret != ERROR_OK) {
+               free(telnet_service);
+               return ret;
+       }
+
+       return ERROR_OK;
 }
 
 /* daemon configuration command telnet_port */