Reformat tftp_server.c using astylerc

This commit is contained in:
Dirk Ziegelmeier 2017-09-17 18:08:43 +02:00
parent 2ab73ad572
commit 6e7fe4520a

View File

@ -92,7 +92,7 @@ struct tftp_state {
static struct tftp_state tftp_state;
static void tftp_tmr(void* arg);
static void tftp_tmr(void *arg);
static void
close_handle(void)
@ -100,7 +100,7 @@ close_handle(void)
tftp_state.port = 0;
ip_addr_set_any(0, &tftp_state.addr);
if(tftp_state.last_data != NULL) {
if (tftp_state.last_data != NULL) {
pbuf_free(tftp_state.last_data);
tftp_state.last_data = NULL;
}
@ -118,15 +118,15 @@ static void
send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char *str)
{
int str_length = strlen(str);
struct pbuf* p;
u16_t* payload;
struct pbuf *p;
u16_t *payload;
p = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(TFTP_HEADER_LENGTH + str_length + 1), PBUF_RAM);
if(p == NULL) {
if (p == NULL) {
return;
}
payload = (u16_t*) p->payload;
payload = (u16_t *) p->payload;
payload[0] = PP_HTONS(TFTP_ERROR);
payload[1] = lwip_htons(code);
MEMCPY(&payload[2], str, str_length + 1);
@ -138,14 +138,14 @@ send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char *
static void
send_ack(u16_t blknum)
{
struct pbuf* p;
u16_t* payload;
struct pbuf *p;
u16_t *payload;
p = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH, PBUF_RAM);
if(p == NULL) {
if (p == NULL) {
return;
}
payload = (u16_t*) p->payload;
payload = (u16_t *) p->payload;
payload[0] = PP_HTONS(TFTP_ACK);
payload[1] = lwip_htons(blknum);
@ -157,11 +157,11 @@ static void
resend_data(void)
{
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, tftp_state.last_data->len, PBUF_RAM);
if(p == NULL) {
if (p == NULL) {
return;
}
if(pbuf_copy(p, tftp_state.last_data) != ERR_OK) {
if (pbuf_copy(p, tftp_state.last_data) != ERR_OK) {
pbuf_free(p);
return;
}
@ -176,12 +176,12 @@ send_data(void)
u16_t *payload;
int ret;
if(tftp_state.last_data != NULL) {
if (tftp_state.last_data != NULL) {
pbuf_free(tftp_state.last_data);
}
tftp_state.last_data = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH + TFTP_MAX_PAYLOAD_SIZE, PBUF_RAM);
if(tftp_state.last_data == NULL) {
if (tftp_state.last_data == NULL) {
return;
}
@ -223,15 +223,14 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
switch (opcode) {
case PP_HTONS(TFTP_RRQ): /* fall through */
case PP_HTONS(TFTP_WRQ):
{
case PP_HTONS(TFTP_WRQ): {
const char tftp_null = 0;
char filename[TFTP_MAX_FILENAME_LEN+1];
char mode[TFTP_MAX_MODE_LEN+1];
char filename[TFTP_MAX_FILENAME_LEN + 1];
char mode[TFTP_MAX_MODE_LEN + 1];
u16_t filename_end_offset;
u16_t mode_end_offset;
if(tftp_state.handle != NULL) {
if (tftp_state.handle != NULL) {
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
break;
}
@ -240,19 +239,19 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
/* find \0 in pbuf -> end of filename string */
filename_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), 2);
if((u16_t)(filename_end_offset-1) > sizeof(filename)) {
if ((u16_t)(filename_end_offset - 1) > sizeof(filename)) {
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated");
break;
}
pbuf_copy_partial(p, filename, filename_end_offset-1, 2);
pbuf_copy_partial(p, filename, filename_end_offset - 1, 2);
/* find \0 in pbuf -> end of mode string */
mode_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), filename_end_offset+1);
if((u16_t)(mode_end_offset-filename_end_offset) > sizeof(mode)) {
mode_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), filename_end_offset + 1);
if ((u16_t)(mode_end_offset - filename_end_offset) > sizeof(mode)) {
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated");
break;
}
pbuf_copy_partial(p, mode, mode_end_offset-filename_end_offset, filename_end_offset+1);
pbuf_copy_partial(p, mode, mode_end_offset - filename_end_offset, filename_end_offset + 1);
tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(TFTP_WRQ));
tftp_state.blknum = 1;
@ -280,8 +279,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
break;
}
case PP_HTONS(TFTP_DATA):
{
case PP_HTONS(TFTP_DATA): {
int ret;
u16_t blknum;
@ -312,8 +310,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
break;
}
case PP_HTONS(TFTP_ACK):
{
case PP_HTONS(TFTP_ACK): {
u16_t blknum;
int lastpkt;
@ -358,7 +355,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
}
static void
tftp_tmr(void* arg)
tftp_tmr(void *arg)
{
LWIP_UNUSED_ARG(arg);