GW2RegisterLicenceMemory
GW2RegisterLicenceMemory ใช้ลงทะเบียนไฟล์ licence ที่เก็บอยู่ในหน่วยความจำให้กับเซสชัน
หากไม่มีการลงทะเบียนทั้ง GW2RegisterLicenceFile หรือ GW2RegisterLicenceMemory กับเซสชัน Editor จะพยายามค้นหา licence ในตำแหน่งเริ่มต้น โดยเป็นไฟล์ชื่อ gwkey.lic ที่อยู่ในโฟลเดอร์เดียวกับไลบรารีของ Editor หากไม่พบ ไลบรารีจะถือว่าไม่มี licence และบางกระบวนการอาจล้มเหลวเนื่องจากปัญหา licence หมดอายุ
- C++
- C#
- Java
- Python
- JavaScript
สรุป
สำหรับเซสชัน session ฟังก์ชัน GW2RegisterLicenceMemory จะลงทะเบียน licence ที่ Glasswall จะใช้เมื่อประมวลผลไฟล์ licenceContents คือพอยน์เตอร์ไปยังข้อมูล licence และ licenceLength ระบุขนาดของข้อมูล licence เป็นไบต์
#include "glasswall.core2.api.h"
int GW2RegisterLicenceMemory(Session session,
const char *licenceContents,
size_t licenceLength);
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงล้มเหลว
ตัวอย่าง
#include "glasswall.core2.api.h"
Session session = GW2OpenSession();
char *licence = NULL;
size_t size = 0;
if (!session)
/* deal with error */
else
{
/* ... load 'licence' with a pointer to the licence content ... */
if (GW2RegisterLicenceMemory(session, licence, size) < 0)
/* deal with error */
else
/* continue processing */
}
. . .
/* later */
if (GW2CloseSession(session) < 0)
/* error closing session */
สรุป
สำหรับเซสชัน session เมธอด RegisterLicenceMemory จะลงทะเบียน licence ที่ Glasswall จะใช้เมื่อประมวลผลไฟล์
/// <summary>
/// Provide a licence to use for the session.
/// </summary>
/// <param name="session">Current open Glasswall session</param>
/// <param name="licence">Byte content of the licence</param>
public int RegisterLicenceMemory(int session, byte[] licence)
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงล้มเหลว
สรุป
import com.glasswall.core2javabridge.*;
public int GW2RegisterLicenceMemory(int session, byte[] licenceBuffer) throws GlasswallException, NullPointerException
public int GW2RegisterLicenceMemory(int session, byte[] licenceBuffer, int licenceLength) throws GlasswallException, NullPointerException
หมายเหตุ
สามารถระบุ length ของ licenceBuffer ได้ตามต้องการ
ส่งกลับ
ฟังก์ชัน GW2RegisterLicenceMemory จะส่งคืนค่า enumeration GW2_RetStatus ที่แปลงเป็น int ค่าเป็นลบหมายความว่าเกิดข้อผิดพลาด 0 หมายถึงสำเร็จ โปรดดูรายละเอียดใน API Overview/Return types
ระบบจะโยนข้อยกเว้น GlasswallException หาก session ไม่ถูกต้อง
ระบบจะโยนข้อยกเว้น NullPointerException หากบัฟเฟอร์ licenceBuffer เป็น null หรือว่างเปล่า
การลงทะเบียน licence สำหรับแต่ละเซสชันจะถูกจัดการโดยอัตโนมัติใน Python wrapper และผู้ใช้ไม่จำเป็นต้องเรียก GW2RegisterLicenceFile หรือ GW2RegisterLicenceMemory ด้วยตนเอง
โดยค่าเริ่มต้น คลาส Editor คาดว่าจะมีไฟล์ licence ที่ถูกต้องอยู่ในไดเรกทอรีเดียวกับ library_path คุณยังสามารถระบุพาธอื่นไปยังไฟล์ licence gwkey.lic ได้โดยใช้ argument licence
import glasswall
# Load the Glasswall Editor library with a specified licence file
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0", licence=r"C:\gwpw\licence\gwkey.lic")
อีกทางเลือกหนึ่ง คุณสามารถส่งข้อมูล licence ในหน่วยความจำเป็นออบเจ็กต์ bytes, bytearray หรือ io.BytesIO ได้
import glasswall
# Alternatively, load the licence from in-memory bytes or bytearray
with open(r"C:\gwpw\licence\gwkey.lic", "rb") as f:
licence_data = f.read()
editor = glasswall.Editor(
r"C:\gwpw\libraries\10.0",
licence=licence_data # In-memory licence data
)
สรุป
สำหรับเซสชัน session ฟังก์ชัน GW2RegisterLicenceMemory จะลงทะเบียน licence ที่ Glasswall จะใช้เมื่อประมวลผลไฟล์ licenceContents คือพอยน์เตอร์ไปยังข้อมูล licence และ licenceLength ระบุขนาดของข้อมูล licence เป็นไบต์
/**
* Provides the contents of the licence file that will be used for this session.
* @param {number} session The ID of the session.
* @param {string} licenceContents A pointer to the licence data buffer.
* @param {number} licenceLength Length of the data in the licence buffer.
* @returns {number} Status of the operation; 0 for success, non-zero for failure.
*/
GW2RegisterLicenceMemory(session, licenceContents, licenceLength)
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงล้มเหลว