Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various cmake issues #54

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -6,6 +6,9 @@ on:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
Build:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,2 +1,2 @@
build/
.vscode/
/build/
/.vscode/
14 changes: 13 additions & 1 deletion CMakeLists.txt
@@ -1,11 +1,16 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? I'm tentative to bump the minimum required here without a really good reason.

project(libtelnet
VERSION 0.30.0
LANGUAGES C
)
set(PROJECT_DESCRIPTION "TELNET protocol handling library")
set(PROJECT_HOMEPAGE_URL https://github.com/seanmiddleditch/libtelne)

# Enable CMAKE Policy
if(${CMAKE_VERSION} VERSION_LESS 3.10)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()

if (MSVC)
add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS)
if (LIBTELNET_STRICT)
Expand All @@ -27,6 +32,13 @@ target_include_directories(libtelnet
${CMAKE_CURRENT_SOURCE_DIR}
)

find_package(ZLIB)
if(${ZLIB_FOUND})
target_compile_definitions(libtelnet PUBLIC HAVE_ZLIB)
target_include_directories(libtelnet PRIVATE ${ZLIB_INCLUDE_DIRS})
target_link_libraries(libtelnet PRIVATE ${ZLIB_LIBRARIES})
endif()

add_subdirectory(util)
add_subdirectory(doc)
add_subdirectory(test)
Expand Down
4 changes: 2 additions & 2 deletions doc/CMakeLists.txt
@@ -1,8 +1,8 @@
find_package(Doxygen)

add_subdirectory(man)

if (DOXYGEN_FOUND)
add_subdirectory(man)

configure_file(Doxyfile.in Doxyfile)
add_custom_target(doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
Expand Down
33 changes: 16 additions & 17 deletions libtelnet.c
Expand Up @@ -407,7 +407,6 @@ static void _negotiate(telnet_t *telnet, unsigned char telopt) {
break;
case Q_WANTNO_OP:
_set_rfc1143(telnet, telopt, Q_US(q), Q_YES);
NEGOTIATE_EVENT(telnet, TELNET_EV_WILL, telopt);
_error(telnet, __LINE__, __func__, TELNET_EPROTOCOL, 0,
"DONT answered by WILL");
break;
Expand Down Expand Up @@ -437,7 +436,8 @@ static void _negotiate(telnet_t *telnet, unsigned char telopt) {
break;
case Q_WANTNO_OP:
_set_rfc1143(telnet, telopt, Q_US(q), Q_WANTYES);
NEGOTIATE_EVENT(telnet, TELNET_EV_DO, telopt);
_send_negotiate(telnet, TELNET_DO, telopt);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This don't seem to be related to the CMake issues; can you split these out to a separate PR? (Although I believe these are already addressed by another open PR.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#57
I don't know why my PR mix into your PR.

NEGOTIATE_EVENT(telnet, TELNET_EV_WONT, telopt);
break;
case Q_WANTYES:
case Q_WANTYES_OP:
Expand Down Expand Up @@ -465,7 +465,6 @@ static void _negotiate(telnet_t *telnet, unsigned char telopt) {
break;
case Q_WANTNO_OP:
_set_rfc1143(telnet, telopt, Q_YES, Q_HIM(q));
NEGOTIATE_EVENT(telnet, TELNET_EV_DO, telopt);
_error(telnet, __LINE__, __func__, TELNET_EPROTOCOL, 0,
"WONT answered by DO");
break;
Expand All @@ -491,12 +490,12 @@ static void _negotiate(telnet_t *telnet, unsigned char telopt) {
break;
case Q_WANTNO:
_set_rfc1143(telnet, telopt, Q_NO, Q_HIM(q));
NEGOTIATE_EVENT(telnet, TELNET_EV_WONT, telopt);
NEGOTIATE_EVENT(telnet, TELNET_EV_DONT, telopt);
break;
case Q_WANTNO_OP:
_set_rfc1143(telnet, telopt, Q_WANTYES, Q_HIM(q));
_send_negotiate(telnet, TELNET_WILL, telopt);
NEGOTIATE_EVENT(telnet, TELNET_EV_WILL, telopt);
NEGOTIATE_EVENT(telnet, TELNET_EV_DONT, telopt);
break;
case Q_WANTYES:
case Q_WANTYES_OP:
Expand Down Expand Up @@ -553,7 +552,7 @@ static int _environ_telnet(telnet_t *telnet, unsigned char type,
ev.type = TELNET_EV_ENVIRON;
telnet->eh(telnet, &ev, telnet->ud);

return 1;
return 0;
}

/* very second byte must be VAR or USERVAR, if present */
Expand Down Expand Up @@ -657,7 +656,7 @@ static int _environ_telnet(telnet_t *telnet, unsigned char type,

/* clean up */
free(values);
return 1;
return 0;
}

/* process an MSSP subnegotiation buffer */
Expand Down Expand Up @@ -849,17 +848,14 @@ static int _subnegotiate(telnet_t *telnet) {
* start handling the compressed stream if it's not already.
*/
case TELNET_TELOPT_COMPRESS2:
if (telnet->sb_telopt == TELNET_TELOPT_COMPRESS2) {
if (_init_zlib(telnet, 0, 1) != TELNET_EOK)
return 0;
if (_init_zlib(telnet, 0, 1) != TELNET_EOK)
return 0;

/* notify app that compression was enabled */
ev.type = TELNET_EV_COMPRESS;
ev.compress.state = 1;
telnet->eh(telnet, &ev, telnet->ud);
return 1;
}
return 0;
/* notify app that compression was enabled */
ev.type = TELNET_EV_COMPRESS;
ev.compress.state = 1;
telnet->eh(telnet, &ev, telnet->ud);
return 1;
#endif /* defined(HAVE_ZLIB) */

/* specially handled subnegotiation telopt types */
Expand Down Expand Up @@ -1613,6 +1609,9 @@ void telnet_ttype_send(telnet_t *telnet) {
void telnet_ttype_is(telnet_t *telnet, const char* ttype) {
static const unsigned char IS[] = { TELNET_IAC, TELNET_SB,
TELNET_TELOPT_TTYPE, TELNET_TTYPE_IS };
if (!ttype) {
ttype = "NVT";
}
_sendu(telnet, IS, sizeof(IS));
_send(telnet, ttype, strlen(ttype));
telnet_finish_sb(telnet);
Expand Down
10 changes: 5 additions & 5 deletions util/telnet-chatd.c
Expand Up @@ -167,6 +167,7 @@ static void _online(const char *line, size_t overflow, void *ud) {
_message(user->name, "** HAS QUIT **");
free(user->name);
user->name = 0;
telnet_free(user->telnet);
return;
}

Expand All @@ -177,7 +178,7 @@ static void _online(const char *line, size_t overflow, void *ud) {
static void _input(struct user_t *user, const char *buffer,
size_t size) {
unsigned int i;
for (i = 0; i != size; ++i)
for (i = 0; user->sock != -1 && i != size; ++i)
linebuffer_push(user->linebuf, sizeof(user->linebuf), &user->linepos,
(char)buffer[i], _online, user);
}
Expand Down Expand Up @@ -307,7 +308,7 @@ int main(int argc, char **argv) {
}

/* new connection */
if (pfd[MAX_USERS].revents & POLLIN) {
if (pfd[MAX_USERS].revents & (POLLIN | POLLERR | POLLHUP)) {
/* acept the sock */
addrlen = sizeof(addr);
if ((client_sock = accept(listen_sock, (struct sockaddr *)&addr,
Expand Down Expand Up @@ -345,20 +346,19 @@ int main(int argc, char **argv) {
if (users[i].sock == -1)
continue;

if (pfd[i].revents & POLLIN) {
if (pfd[i].revents & (POLLIN | POLLERR | POLLHUP)) {
if ((rs = recv(users[i].sock, buffer, sizeof(buffer), 0)) > 0) {
telnet_recv(users[i].telnet, buffer, rs);
} else if (rs == 0) {
printf("Connection closed.\n");
close(users[i].sock);
users[i].sock = -1;
if (users[i].name != 0) {
_message(users[i].name, "** HAS DISCONNECTED **");
free(users[i].name);
users[i].name = 0;
}
telnet_free(users[i].telnet);
users[i].sock = -1;
break;
} else if (errno != EINTR) {
fprintf(stderr, "recv(client) failed: %s\n",
strerror(errno));
Expand Down
4 changes: 2 additions & 2 deletions util/telnet-client.c
Expand Up @@ -225,7 +225,7 @@ int main(int argc, char **argv) {
/* loop while both connections are open */
while (poll(pfd, 2, -1) != -1) {
/* read from stdin */
if (pfd[0].revents & POLLIN) {
if (pfd[0].revents & (POLLIN | POLLERR | POLLHUP)) {
if ((rs = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) {
_input(buffer, rs);
} else if (rs == 0) {
Expand All @@ -238,7 +238,7 @@ int main(int argc, char **argv) {
}

/* read from client */
if (pfd[1].revents & POLLIN) {
if (pfd[1].revents & (POLLIN | POLLERR | POLLHUP)) {
if ((rs = recv(sock, buffer, sizeof(buffer), 0)) > 0) {
telnet_recv(telnet, buffer, rs);
} else if (rs == 0) {
Expand Down
4 changes: 2 additions & 2 deletions util/telnet-proxy.c
Expand Up @@ -464,7 +464,7 @@ int main(int argc, char **argv) {
/* loop while both connections are open */
while (poll(pfd, 2, -1) != -1) {
/* read from server */
if (pfd[0].revents & POLLIN) {
if (pfd[0].revents & (POLLIN | POLLERR | POLLHUP)) {
if ((rs = recv(server.sock, buffer, sizeof(buffer), 0)) > 0) {
telnet_recv(server.telnet, buffer, rs);
} else if (rs == 0) {
Expand All @@ -480,7 +480,7 @@ int main(int argc, char **argv) {
}

/* read from client */
if (pfd[1].revents & POLLIN) {
if (pfd[1].revents & (POLLIN | POLLERR | POLLHUP)) {
if ((rs = recv(client.sock, buffer, sizeof(buffer), 0)) > 0) {
telnet_recv(client.telnet, buffer, rs);
} else if (rs == 0) {
Expand Down