int PutContent(IntPtr h, NormalStruct Data) { int res = 0; Egal.ccn_charbuf Nm = new Egal.ccn_charbuf(); Nm = (Egal.ccn_charbuf)Marshal.PtrToStructure(Data.nm, typeof(Egal.ccn_charbuf)); IntPtr uri = Egal.ccn_charbuf_create(); Egal.ccn_uri_append(uri, Nm.buf, Nm.length, 0); IntPtr name = Egal.SyncCopyName(Data.nm); IntPtr cb = Egal.ccn_charbuf_create(); IntPtr cob = Egal.ccn_charbuf_create(); Egal.ccn_charbuf_append(cb, Data.value, Data.vSize); Egal.ccn_charbuf Cb = new Egal.ccn_charbuf(); Cb = (Egal.ccn_charbuf)Marshal.PtrToStructure(cb, typeof(Egal.ccn_charbuf)); Egal.ccn_signing_params Sp = new Egal.ccn_signing_params(CCN.CCN_API_VERSION); Sp.sp_flags |= SP.signingparameters.CCN_SP_FINAL_BLOCK; IntPtr pSp = Marshal.AllocHGlobal(Marshal.SizeOf(Sp)); Marshal.StructureToPtr(Sp, pSp, true); /* * // test zone * Egal.ccn_signing_params Test = new Egal.ccn_signing_params(CCN.CCN_API_VERSION); * IntPtr pTest = Marshal.AllocHGlobal(Marshal.SizeOf(Test)); * Marshal.StructureToPtr(Test, pTest, true); * IntPtr a = IntPtr.Zero; * IntPtr b = IntPtr.Zero; * IntPtr c = IntPtr.Zero; * res = Egal.ccn_chk_signing_params(h, pSp, pTest, ref a, ref b, ref c); * print ("check result: " + res); * // test zone end */ // Data.ccn, Cb.buf, Data.vSize is correct res |= Egal.ccn_sign_content(h, cob, name, pSp, Cb.buf, Data.vSize); if (res < 0) { print("sign content error."); } Egal.ccn_charbuf Cob = new Egal.ccn_charbuf(); Cob = (Egal.ccn_charbuf)Marshal.PtrToStructure(cob, typeof(Egal.ccn_charbuf)); res |= Egal.ccn_put(Data.ccn, Cob.buf, Cob.length); if (res < 0) { print("ccn_put error."); } // cleanup Egal.ccn_charbuf_destroy(ref uri); Egal.ccn_charbuf_destroy(ref name); Egal.ccn_charbuf_destroy(ref cb); Egal.ccn_charbuf_destroy(ref cob); Marshal.FreeHGlobal(pSp); return(res); }
int PutContent(IntPtr h, NormalStruct Data) { int res = 0; Egal.ccn_charbuf Nm = new Egal.ccn_charbuf(); Nm = (Egal.ccn_charbuf)Marshal.PtrToStructure(Data.nm, typeof(Egal.ccn_charbuf)); IntPtr uri = Egal.ccn_charbuf_create(); Egal.ccn_uri_append(uri, Nm.buf, Nm.length, 0); IntPtr name = Egal.SyncCopyName(Data.nm); // test probe // Egal.ccn_charbuf Name = new Egal.ccn_charbuf(); Name = (Egal.ccn_charbuf)Marshal.PtrToStructure(name, typeof(Egal.ccn_charbuf)); //print("Name length before numeric: " + Name.length); // end test probe // res = Egal.ccn_name_append_numeric(name, Marker.ccn_marker.CCN_MARKER_SEQNUM, 0); // test probe // Name = (Egal.ccn_charbuf)Marshal.PtrToStructure(name, typeof(Egal.ccn_charbuf)); //print("Name length after numeric: " + Name.length); //print ("size of enum type is: " + sizeof(Marker.ccn_marker)); // end test probe // //print("append numeric returns: " + res); //print(Marker.ccn_marker.CCN_MARKER_SEQNUM); IntPtr cb = Egal.ccn_charbuf_create(); Egal.ccn_charbuf_append(cb, Data.value, Data.vSize); Egal.ccn_charbuf Cb = new Egal.ccn_charbuf(); Cb = (Egal.ccn_charbuf)Marshal.PtrToStructure(cb, typeof(Egal.ccn_charbuf)); Egal.ccn_signing_params Sp = new Egal.ccn_signing_params(CCN.CCN_API_VERSION); Sp.sp_flags |= SP.signingparameters.CCN_SP_FINAL_BLOCK; IntPtr pSp = Marshal.AllocHGlobal(Marshal.SizeOf(Sp)); Marshal.StructureToPtr(Sp, pSp, true); // Data.ccn, Cb.buf, Data.vSize is correct IntPtr cob = Egal.ccn_charbuf_create(); res = Egal.ccn_sign_content(h, cob, name, pSp, Cb.buf, Data.vSize); if(res<0) print ("sign content error."); Egal.ccn_charbuf Cob = new Egal.ccn_charbuf(); Cob = (Egal.ccn_charbuf)Marshal.PtrToStructure(cob, typeof(Egal.ccn_charbuf)); res = Egal.ccn_put(Data.ccn, Cob.buf, Cob.length); if (res<0) print ("ccn_put error."); // cleanup Egal.ccn_charbuf_destroy(ref uri); Egal.ccn_charbuf_destroy(ref name); Egal.ccn_charbuf_destroy(ref cb); Egal.ccn_charbuf_destroy(ref cob); Marshal.FreeHGlobal(pSp); return res; }