//todo: look if we can rewrite this function in c# to be more efficent internal static byte[] imm_formatHTTPUpload(string path, byte[] content) { Random randomGenerator = new Random(); string boundary; string mp_header = "Content-Disposition: form-data; name=\"" + path + "\"; filename=\"api\"\r\n" + "Content-Type: application/octet-stream\r\n" + "Content-Transfer-Encoding: binary\r\n\r\n"; // find a valid boundary do { boundary = string.Format("Zz{0:x6}zZ", randomGenerator.Next(0x1000000)); } while (mp_header.Contains(boundary) && YAPIContext.imm_find_in_bytes(content, YAPI.DefaultEncoding.GetBytes(boundary)) >= 0); //construct header parts string header_start = "Content-Type: multipart/form-data; boundary=" + boundary + "\r\n\r\n--" + boundary + "\r\n" + mp_header; string header_stop = "\r\n--" + boundary + "--\r\n"; byte[] head_body = new byte[header_start.Length + content.Length + header_stop.Length]; int pos = 0; int len = header_start.Length; Array.Copy(YAPI.DefaultEncoding.GetBytes(header_start), 0, head_body, pos, len); pos += len; len = content.Length; Array.Copy(content, 0, head_body, pos, len); pos += len; len = header_stop.Length; Array.Copy(YAPI.DefaultEncoding.GetBytes(header_stop), 0, head_body, pos, len); Array.Copy(YAPI.DefaultEncoding.GetBytes(header_stop), 0, head_body, pos, len); return(head_body); }
private byte[] imm_RemoveHeader(byte[] response) { int hpos = YAPIContext.imm_find_in_bytes(response, rnrn); int ofs = 0; int size = (int)_response_size; if (hpos >= 0) { ofs += hpos + 4; size -= hpos + 4; } byte[] res = new byte[size]; Buffer.BlockCopy(_response, ofs, res, 0, size); return(res); }
private static byte[] imm_verifyHTTPheader(byte[] full_result) { int hpos = YAPIContext.imm_find_in_bytes(full_result, rnrn); int ofs = 0; int size = full_result.Length; if (hpos >= 0) { ofs += hpos + 4; size -= hpos + 4; } byte[] res = new byte[size]; Array.Copy(full_result, ofs, res, 0, size); return(res); }