Parsing text file without storing (tftp)

242 Views Asked by At

I need to parse a text file stream after downloading and without saving the text file to harddisk or sdcard using tftp protocol. I've the data in payload. Please help.

struct pbuf {

    struct pbuf *next;
    void *payload;
    u16_t tot_len;
    u16_t len;  
    u8_t  type;
    u8_t flags;
    u16_t ref;

};

The following code assigns the opcode and filename. But how to get the contents of the file?

/* Extract the opcode from a TFTP message in a buffer */
tftp_opcode tftp_decode_op(char *buf)
{
  return (tftp_opcode)(buf[1]);
}

void tftp_extract_filename(char *fname, char *buf)
{
  strcpy(fname, buf + 2);
}
2

There are 2 best solutions below

0
On

In the TFTP protocol, you first get a write request packet (opcode WRQ), and then the data in separate data packets (opcode DATA). You will need to do something whenever a data packet is received in order to process the contents of the file. I'd recommend reading up a bit on the TFTP protocol if you haven't done that yet. An overview is at http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol#Protocol_walkthrough and the spec (which is very readable) is at https://www.rfc-editor.org/rfc/rfc1350 .

0
On

If your text file not more then some KB then why you not use static buffer to store content of it.In TFTP protocol you must know at which (in source point of view ) point the packet received.So you get packet buffer and size of the packet.So simply copy that received packet buffer in above static buffer and increase offest of static buffer and so on....So at last you will get whole text file content in static buffer.