diff --git a/src/varnishapi.py b/src/varnishapi.py index e6d2abb..4d24d05 100644 --- a/src/varnishapi.py +++ b/src/varnishapi.py @@ -270,10 +270,36 @@ def __init__(self, lib): self.VSM_Error = lib.VSM_Error self.VSM_Error.restype = c_char_p + self.VSM_Error.argtypes = [c_void_p] + + self.VSM_New = lib.VSM_New + self.VSM_New.restype = c_void_p + + self.VSM_ResetError = lib.VSM_ResetError + self.VSM_ResetError.argtypes = [c_void_p] + + self.VSM_Delete = lib.VSM_Delete + self.VSM_Delete.argtypes = [c_void_p] + + self.VSM_Open = lib.VSM_Open + self.VSM_Open.restype = c_int + self.VSM_Open.argtypes = [c_void_p] + + self.VSM_n_Arg = lib.VSM_n_Arg + self.VSM_n_Arg.restype = c_int + self.VSM_n_Arg.argtypes = [c_void_p, c_char_p] + + self.VSM_N_Arg = lib.VSM_N_Arg + self.VSM_N_Arg.restype = c_int + self.VSM_N_Arg.argtypes = [c_void_p, c_char_p] self.VSM_Name = lib.VSM_Name self.VSM_Name.restype = c_char_p + self.VSM_Name.argtypes = [c_void_p] + self.VSC_Iter = lib.VSC_Iter + self.VSC_Iter.argtypes = [c_void_p, c_void_p, VSC_iter_f, c_void_p] + self.VSLQ_New = lib.VSLQ_New self.VSLQ_New.restype = c_void_p self.VSLQ_New.argtypes = [c_void_p, POINTER(c_void_p), c_int, c_char_p] @@ -409,7 +435,8 @@ def __init__(self, sopath='libvarnishapi.so.1'): self.lva = LIBVARNISHAPI13(self.lib) self.defi = VarnishAPIDefine40() self._cb = None - self.vsm = self.lib.VSM_New() + self.vsm = self.lva.VSM_New() + print "vsm", self.vsm self.d_opt = 0 VSLTAGS = c_char_p * 256 @@ -440,15 +467,15 @@ def __init__(self, sopath='libvarnishapi.so.1'): def ArgDefault(self, op, arg): if op == "n": # Set Varnish instance name. - i = self.lib.VSM_n_Arg(self.vsm, arg) + i = self.lva.VSM_n_Arg(self.vsm, arg) if i <= 0: - self.error = "%s" % self.lib.VSM_Error(self.vsm).rstrip() + self.error = "%s" % self.lva.VSM_Error(self.vsm).rstrip() return(i) elif op == "N": # Set VSM file. - i = self.lib.VSM_N_Arg(self.vsm, arg) + i = self.lva.VSM_N_Arg(self.vsm, arg) if i <= 0: - self.error = "%s" % self.lib.VSM_Error(self.vsm).rstrip() + self.error = "%s" % self.lva.VSM_Error(self.vsm).rstrip() return(i) self.d_opt = 1 return(None) @@ -461,8 +488,8 @@ def __init__(self, opt='', sopath='libvarnishapi.so.1'): self.name = '' if len(opt) > 0: self.__setArg(opt) - if self.lib.VSM_Open(self.vsm): - self.error = "Can't open VSM file (%s)" % self.lib.VSM_Error( + if self.lva.VSM_Open(self.vsm): + self.error = "Can't open VSM file (%s)" % self.lva.VSM_Error( self.vsm).rstrip() else: self.name = self.lva.VSM_Name(self.vsm) @@ -473,7 +500,7 @@ def __setArg(self, opt): for o in opts: op = o[0].lstrip('-') arg = o[1] - self.__Arg(op, arg) + self.__Arg(op, arg.encode("utf8", "replace")) if error: self.error = error @@ -509,12 +536,12 @@ def _getstat(self, priv, pt): def getStats(self): self._buf = {} - self.lib.VSC_Iter(self.vsm, None, VSC_iter_f(self._getstat), None) + self.lva.VSC_Iter(self.vsm, None, VSC_iter_f(self._getstat), None) return self._buf def Fini(self): if self.vsm: - self.lib.VSM_Delete(self.vsm) + self.lva.VSM_Delete(self.vsm) self.vsm = 0 @@ -590,8 +617,8 @@ def __Setup(self): if self.__r_arg: c = self.lva.VSL_CursorFile(self.vsl, self.__r_arg, 0) else: - if self.lib.VSM_Open(self.vsm): - self.error = "Can't open VSM file (%s)" % self.lib.VSM_Error( + if self.lva.VSM_Open(self.vsm): + self.error = "Can't open VSM file (%s)" % self.lva.VSM_Error( self.vsm).decode("utf8", "replace").rstrip() return(0) self.name = self.lva.VSM_Name(self.vsm) @@ -623,15 +650,15 @@ def __cbMain(self, cb, priv=None): if not self.vslq: # Reconnect VSM time.sleep(0.1) - if self.lib.VSM_Open(self.vsm): - self.lib.VSM_ResetError(self.vsm) + if self.lva.VSM_Open(self.vsm): + self.lva.VSM_ResetError(self.vsm) return(1) c = self.lva.VSL_CursorVSM( self.vsl, self.vsm, self.defi.VSL_COPT_TAIL | self.defi.VSL_COPT_BATCH) if not c: - self.lib.VSM_ResetError(self.vsm) - self.lib.VSM_Close(self.vsm) + self.lva.VSM_ResetError(self.vsm) + self.lva.VSM_Close(self.vsm) return(1) z = cast(c, c_void_p) self.vslq = self.lva.VSLQ_New( @@ -653,7 +680,7 @@ def Dispatch(self, cb, priv=None): self.vslq = None if i == -2: self.error = "Log abandoned" - self.lib.VSM_Close(self.vsm) + self.lva.VSM_Close(self.vsm) if i < -2: self.error = "Log overrun" return i @@ -666,7 +693,7 @@ def Fini(self): self.lib.VSL_Delete(self.vsl) self.vsl = 0 if self.vsm: - self.lib.VSM_Delete(self.vsm) + self.lva.VSM_Delete(self.vsm) self.vsm = 0 def __VSL_Arg(self, opt, arg='\0'):