Original Post
Hey all, I've been struggling a bit on this. Basically, I'm building an array of bytes in the C program(can contain '\0' chars in it), which i then send to the PHP script using libcurl.
Here's the sending code from C program (I omitted the usual initing stuff of libcurl) :
My data actually gets there, but for some reason, I'm pretty sure I am not handling the data properly on the PHP side of things, and basically, PHP will cut some data because it thinks I am handling strings.
In the example above, here's the content of my char buffer called "data" :
With that information, how can I put the content of $_POST['dataField'] safely in a var on the PHP side, so that i can then iterate over it with a simple FOR loop ? I can normally get the "0018" size to an int without issues, and then I get myUUID, but the rest, I'm not able to parse.
Thanks.
Here's the sending code from C program (I omitted the usual initing stuff of libcurl) :
curl_formadd( &formpost,
&lastptr,
CURLFORM_COPYNAME, "dataField",
CURLFORM_CONTENTSLENGTH, dataSize,
CURLFORM_COPYCONTENTS, data,
CURLFORM_END);
My data actually gets there, but for some reason, I'm pretty sure I am not handling the data properly on the PHP side of things, and basically, PHP will cut some data because it thinks I am handling strings.
In the example above, here's the content of my char buffer called "data" :
data[0] = '0' // length of the data packed in 4 digits for easier parsing
data[1] = '0'
data[2] = '1'
data[3] = '8'
data[4] = '6' // length of the string "myUUID" written next (doing so to remove '\0' in the byte array)
data[5] = 'm' // the actual string
data[6] = 'y'
data[7] = 'U'
data[8] = 'U'
data[9] = 'I'
data[10] = 'D'
data[11] = 'x' // first byte of a 4byte integer (replaced some weird code by 'x')
data[12] = 'x' // second byte of a 4byte integer (replaced some weird code by 'x')
data[13] = 'x' // third byte of a 4byte integer (replaced some weird code by 'x')
data[14] = 'x' // fourth byte of a 4byte integer (replaced some weird code by 'x')
data[15] = '6' // length of the string "myNICK" written next (doing so to remove '\0' in the byte array)
data[16] = 'm' // the actual string
data[17] = 'y'
data[18] = 'N'
data[19] = 'I'
data[20] = 'C'
data[21] = 'K'
With that information, how can I put the content of $_POST['dataField'] safely in a var on the PHP side, so that i can then iterate over it with a simple FOR loop ? I can normally get the "0018" size to an int without issues, and then I get myUUID, but the rest, I'm not able to parse.
Thanks.