detailed function comments only in .h file
This commit is contained in:
parent
89b8716985
commit
676e16a477
3 changed files with 15 additions and 70 deletions
24
client.c
24
client.c
|
@ -1,12 +1,7 @@
|
||||||
#include "moxerver.h"
|
#include "moxerver.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* Closes client connection. */
|
||||||
* Closes client connection.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* 0 always, but internally tries closing again if it fails.
|
|
||||||
*/
|
|
||||||
int client_close(struct client_t *client) {
|
int client_close(struct client_t *client) {
|
||||||
/* force closing in case of error */
|
/* force closing in case of error */
|
||||||
if (close(client->socket) == -1) {
|
if (close(client->socket) == -1) {
|
||||||
|
@ -17,14 +12,7 @@ int client_close(struct client_t *client) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Reads data from client into client data buffer. Returns number of read bytes. */
|
||||||
* Reads data from client into client data buffer.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* - number of read bytes on success,
|
|
||||||
* - negative ENODATA value (-ENODATA) if client disconnected,
|
|
||||||
* - negative errno value set appropriately by error in reading
|
|
||||||
*/
|
|
||||||
int client_read(struct client_t *client) {
|
int client_read(struct client_t *client) {
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
|
@ -58,13 +46,7 @@ int client_read(struct client_t *client) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Sends data from a buffer to client. Returns number of sent bytes. */
|
||||||
* Sends data from a buffer to client.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* - number of sent bytes on success,
|
|
||||||
* - negative errno value set appropriately by error in sending
|
|
||||||
*/
|
|
||||||
int client_write(struct client_t *client, char *databuf, int datalen) {
|
int client_write(struct client_t *client, char *databuf, int datalen) {
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
|
|
30
server.c
30
server.c
|
@ -1,13 +1,7 @@
|
||||||
#include "moxerver.h"
|
#include "moxerver.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* Sets up the server on specific port, binds to a socket and listens for client connections. */
|
||||||
* Sets up the server on specific port, binds to a socket and listens for client connections.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* - 0 on success,
|
|
||||||
* - negative errno value set appropriately by error in setup process
|
|
||||||
*/
|
|
||||||
int server_setup(struct server_t *server, unsigned int port) {
|
int server_setup(struct server_t *server, unsigned int port) {
|
||||||
|
|
||||||
int namelen, opt;
|
int namelen, opt;
|
||||||
|
@ -69,12 +63,7 @@ int server_setup(struct server_t *server, unsigned int port) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Closes the server socket. */
|
||||||
* Closes the server socket.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* 0 always, but internally tries closing again if it fails.
|
|
||||||
*/
|
|
||||||
int server_close(struct server_t *server) {
|
int server_close(struct server_t *server) {
|
||||||
/* force closing in case of error */
|
/* force closing in case of error */
|
||||||
if (close(server->socket) == -1) {
|
if (close(server->socket) == -1) {
|
||||||
|
@ -84,13 +73,7 @@ int server_close(struct server_t *server) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Accepts incoming client connection. */
|
||||||
* Accepts incoming client connection.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* - 0 on success,
|
|
||||||
* - negative errno value set appropriately by error in setup process
|
|
||||||
*/
|
|
||||||
int server_accept(struct server_t *server, struct client_t *accepted_client) {
|
int server_accept(struct server_t *server, struct client_t *accepted_client) {
|
||||||
|
|
||||||
int namelen;
|
int namelen;
|
||||||
|
@ -119,12 +102,7 @@ int server_accept(struct server_t *server, struct client_t *accepted_client) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Rejects incoming client connection. Errors with rejected client are ignored. */
|
||||||
* Rejects incoming client connection.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* 0 always, errors with rejected client are ignored
|
|
||||||
*/
|
|
||||||
int server_reject(struct server_t *server) {
|
int server_reject(struct server_t *server) {
|
||||||
|
|
||||||
int namelen;
|
int namelen;
|
||||||
|
|
31
telnet.c
31
telnet.c
|
@ -39,7 +39,7 @@ static char telnet_option_value(const char* name) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sends telnet option command. */
|
/* Sends telnet option command. Returns 0 on success, -1 on failure. */
|
||||||
static int telnet_send_command(struct client_t *client, const char* option, const char* command) {
|
static int telnet_send_command(struct client_t *client, const char* option, const char* command) {
|
||||||
|
|
||||||
char data[3];
|
char data[3];
|
||||||
|
@ -59,9 +59,10 @@ static int telnet_send_command(struct client_t *client, const char* option, cons
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handles received telnet option command. */
|
/* Handles received telnet option command. Always returns 0.*/
|
||||||
static int telnet_handle_command(char *databuf, int datalen) {
|
static int telnet_handle_command(char *databuf, int datalen) {
|
||||||
|
|
||||||
|
/* currently just print received commands because we set the client, we don't adapt to client commands */
|
||||||
if (databuf[0] == telnet_option_value("IAC")) {
|
if (databuf[0] == telnet_option_value("IAC")) {
|
||||||
fprintf(stderr, "[%s] received %s %s\n", __func__,
|
fprintf(stderr, "[%s] received %s %s\n", __func__,
|
||||||
telnet_option_name(databuf[1]), telnet_option_name(databuf[2]));
|
telnet_option_name(databuf[1]), telnet_option_name(databuf[2]));
|
||||||
|
@ -70,13 +71,7 @@ static int telnet_handle_command(char *databuf, int datalen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Tells client to go into "character" mode. */
|
||||||
* Tells client to go into "character" mode.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* - 0 on success
|
|
||||||
* - negative value if error occurred
|
|
||||||
*/
|
|
||||||
int telnet_set_character_mode(struct client_t *client) {
|
int telnet_set_character_mode(struct client_t *client) {
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -91,13 +86,8 @@ int telnet_set_character_mode(struct client_t *client) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Handles special characters in data buffer after receiving them from client.
|
||||||
* Handles special characters in data buffer after receiving them from client.
|
* Used to filter out handshake commands of telnet protocol. */
|
||||||
* Used to filter out handshake commands of telnet protocol.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* 0 always
|
|
||||||
*/
|
|
||||||
int telnet_handle_client_read(char *databuf, int *datalen) {
|
int telnet_handle_client_read(char *databuf, int *datalen) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
@ -123,13 +113,8 @@ int telnet_handle_client_read(char *databuf, int *datalen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Handles special characters in data buffer before sending to client.
|
||||||
* Handles special characters in data buffer before sending to client.
|
* Used for echoing characters correctly to telnet client. */
|
||||||
* Used for echoing characters correctly to telnet client.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* 0 always
|
|
||||||
*/
|
|
||||||
int telnet_handle_client_write(char *databuf, int *datalen) {
|
int telnet_handle_client_write(char *databuf, int *datalen) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue