Proper trimming at CR/LF for RF>IS IGate.

This commit is contained in:
WB2OSZ 2017-04-01 10:36:36 -04:00
parent 2fec597581
commit 7f77b29e89
3 changed files with 58 additions and 16 deletions

View File

@ -1578,9 +1578,9 @@ int ax25_get_rr (packet_t this_p, int n)
*
* Purpose: Obtain Information part of current packet.
*
* Inputs: None.
* Inputs: this_p - Packet object pointer.
*
* Outputs: paddr - Starting address is returned here.
* Outputs: paddr - Starting address of information part is returned here.
*
* Assumption: ax25_from_text or ax25_from_frame was called first.
*
@ -1621,6 +1621,56 @@ int ax25_get_info (packet_t this_p, unsigned char **paddr)
*paddr = info_ptr;
return (info_len);
} /* end ax25_get_info */
/*------------------------------------------------------------------------------
*
* Name: ax25_cut_at_crlf
*
* Purpose: Truncate the information part at the first CR or LF.
* This is used for the RF>IS IGate function.
* CR/LF is used as record separator so we must remove it
* before packaging up packet to sending to server.
*
* Inputs: this_p - Packet object pointer.
*
* Outputs: Packet is modified in place.
*
* Returns: Number of characters removed from the end.
* 0 if not changed.
*
* Assumption: ax25_from_text or ax25_from_frame was called first.
*
*------------------------------------------------------------------------------*/
int ax25_cut_at_crlf (packet_t this_p)
{
unsigned char *info_ptr;
int info_len;
int j;
assert (this_p->magic1 == MAGIC);
assert (this_p->magic2 == MAGIC);
info_len = ax25_get_info (this_p, &info_ptr);
// Can't use strchr because there is potential of nul character.
for (j = 0; j < info_len; j++) {
if (info_ptr[j] == '\r' || info_ptr[j] == '\n') {
int chop = info_len - j;
this_p->frame_len -= chop;
return (chop);
}
}
return (0);
}

View File

@ -397,6 +397,7 @@ extern int ax25_get_first_not_repeated(packet_t pp);
extern int ax25_get_rr (packet_t this_p, int n);
extern int ax25_get_info (packet_t pp, unsigned char **paddr);
extern int ax25_cut_at_crlf (packet_t this_p);
extern void ax25_set_nextp (packet_t this_p, packet_t next_p);

19
igate.c
View File

@ -870,7 +870,6 @@ void igate_send_rec_packet (int chan, packet_t recv_pp)
packet_t pp;
int n;
unsigned char *pinfo;
char *p;
int info_len;
@ -995,33 +994,25 @@ void igate_send_rec_packet (int chan, packet_t recv_pp)
/*
* Cut the information part at the first CR or LF.
* This is required because CR/LF is used as record separator when sending to server.
* Do NOT trim trailing spaces.
* Starting in 1.4 we preserve any nul characters in the information part.
*/
info_len = ax25_get_info (pp, &pinfo);
(void)(info_len);
if ((p = strchr ((char*)pinfo, '\r')) != NULL) {
if (ax25_cut_at_crlf (pp) > 0) {
if (s_debug >= 1) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("Rx IGate: Truncated information part at CR.\n");
}
*p = '\0';
}
if ((p = strchr ((char*)pinfo, '\n')) != NULL) {
if (s_debug >= 1) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("Rx IGate: Truncated information part at LF.\n");
}
*p = '\0';
}
info_len = ax25_get_info (pp, &pinfo);
/*
* Someone around here occasionally sends a packet with no information part.
*/
if (strlen((char*)pinfo) == 0) {
if (info_len == 0) {
if (s_debug >= 1) {
text_color_set(DW_COLOR_DEBUG);