Beispiel #1
0
RS232_LIB unsigned int
rs232_write(struct rs232_port_t *p, unsigned char *buf, unsigned int buf_len,
		unsigned int *write_len)
{
	unsigned int w = 0;
	struct rs232_windows_t *wx = p->pt;

	DBG("p=%p p->pt=%p buf_len:%d\n", (void *)p, p->pt, buf_len);

	if (!rs232_port_open(p))
		return RS232_ERR_PORT_CLOSED;

	if (!WriteFile(wx->fd, buf, buf_len, &w, NULL)) {
		*write_len = 0;
		DBG("WriteFile() %s\n", last_error());
		return RS232_ERR_WRITE;
	}

	if (buf_len != w)
		DBG("WriteFile() %s\n", last_error());

	*write_len = w;
	DBG("write_len=%d hex='%s' ascii='%s'\n", w, rs232_hex_dump(buf, w),
	    rs232_ascii_dump(buf, w));

	return RS232_ERR_NOERROR;
}
Beispiel #2
0
void CALLBACK RemoveDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
    try {
        WCHAR *s, *vol, *dev;
        uint64_t devid;
        win_handle h, token;
        TOKEN_PRIVILEGES tp;
        LUID luid;
        NTSTATUS Status;
        IO_STATUS_BLOCK iosb;

        set_dpi_aware();

        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
            throw last_error(GetLastError());

        if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
            throw last_error(GetLastError());

        tp.PrivilegeCount = 1;
        tp.Privileges[0].Luid = luid;
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

        if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
            throw last_error(GetLastError());

        s = wcsstr(lpszCmdLine, L"|");
        if (!s)
            return;

        s[0] = 0;

        vol = lpszCmdLine;
        dev = &s[1];

        devid = _wtoi(dev);
        if (devid == 0)
            return;

        h = CreateFileW(vol, FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
                        OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);

        if (h == INVALID_HANDLE_VALUE)
            throw last_error(GetLastError());

        Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_REMOVE_DEVICE, &devid, sizeof(uint64_t), nullptr, 0);
        if (!NT_SUCCESS(Status)) {
            if (Status == STATUS_CANNOT_DELETE)
                throw string_error(IDS_CANNOT_REMOVE_RAID);
            else
                throw ntstatus_error(Status);

            return;
        }

        BtrfsBalance bb(vol, true);
        bb.ShowBalance(hwnd);
    } catch (const exception& e) {
        error_message(hwnd, e.what());
    }
}
Beispiel #3
0
ConnectResult TCPSocket::connect(const IPAddress& ip, u16 port)
{
	close();
	_socket = socket_internal::open();

	sockaddr_in addr_in;
	addr_in.sin_family = AF_INET;
	addr_in.sin_addr.s_addr = htonl(ip.address());
	addr_in.sin_port = htons(port);

	int err = ::connect(_socket, (const sockaddr*)&addr_in, sizeof(sockaddr_in));

	ConnectResult cr;
	cr.error = ConnectResult::SUCCESS;

	if (err == SOCKET_ERROR)
	{
		if (last_error() == WSAECONNREFUSED)
			cr.error = ConnectResult::REFUSED;
		else if (last_error() == WSAETIMEDOUT)
			cr.error = ConnectResult::TIMEOUT;
		else
			cr.error = ConnectResult::UNKNOWN;
	}

	return cr;
}
Beispiel #4
0
static int read_block(FILE *in, int offset, int size, void *buf)
{
    int len;

    if (size < 0) {
        printc_err("coff: invalid size: %d\n", size);
        return -1;
    }

    if (fseek(in, offset, SEEK_SET) < 0) {
        printc_err("coff: can't seek to offset %d: %s\n",
                   offset, last_error());
        return -1;
    }

    len = fread(buf, 1, size, in);
    if (len < 0) {
        printc_err("coff: can't read %d bytes from "
                   "offset %d: %s\n",
                   size, offset, last_error());
        return -1;
    }

    if (len < size) {
        printc_err("coff: can't read %d bytes from "
                   "offset %d: short read\n",
                   size, offset);
        return -1;
    }

    return 0;
}
Beispiel #5
0
void CALLBACK AddDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
    try {
        win_handle token;
        TOKEN_PRIVILEGES tp;
        LUID luid;

        set_dpi_aware();

        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
            throw last_error(GetLastError());

        if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
            throw last_error(GetLastError());

        tp.PrivilegeCount = 1;
        tp.Privileges[0].Luid = luid;
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

        if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
            throw last_error(GetLastError());

        BtrfsDeviceAdd bda(hinst, hwnd, lpszCmdLine);
        bda.ShowDialog();
    } catch (const exception& e) {
        error_message(hwnd, e.what());
    }
}
Beispiel #6
0
static int cmd_sym_savemap(char **arg)
{
	FILE *savemap_out;
	char *fname = get_arg(arg);

	if (!fname) {
		printc_err("sym: filename required to save map\n");
		return -1;
	}

	savemap_out = fopen(fname, "w");
	if (!savemap_out) {
		printc_err("sym: couldn't write to %s: %s\n", fname,
			last_error());
		return -1;
	}

	if (stab_enum(savemap_cb, savemap_out) < 0) {
		fclose(savemap_out);
		return -1;
	}

	if (fclose(savemap_out) < 0) {
		printc_err("sym: error on close: %s\n", last_error());
		return -1;
	}

	unmark_modified(MODIFY_SYMS);
	return 0;
}
Beispiel #7
0
static int recv_packet(sport_t fd, struct packet *pkt)
{
	uint8_t header[4];

	if (sport_read_all(fd, header, 4) < 0) {
		printc_err("goodfet: recv_packet (header): %s\n",
			   last_error());
		return -1;
	}

	pkt->app = header[0];
	pkt->verb = header[1];
	pkt->len = ((uint16_t)header[2]) | (((uint16_t)header[3]) << 8);

	if (pkt->len > MAX_LEN) {
		printc_err("goodfet: recv_packet: maximum length "
			   "exceeded (%d)\n", pkt->len);
		return -1;
	}

	if (sport_read_all(fd, pkt->data, pkt->len) < 0) {
		printc_err("goodfet: recv_packet (data): %s\n",
			   last_error());
		return -1;
	}

#ifdef DEBUG_GOODFET
	printc_dbg("RECV: %02x/%02x\n", pkt->app, pkt->verb);
	if (pkt->len)
		debug_hexdump("Data", pkt->data, pkt->len);
#endif

	return 0;
}
Beispiel #8
0
RS232_LIB void
rs232_end(struct rs232_port_t *p)
{
	struct rs232_windows_t *wx = p->pt;

	DBG("p=%p p->pt=%p\n", (void *)p, p->pt);

	if (!rs232_port_open(p)) {
		free(p->pt);
		free(p);
		return;
	}

	rs232_flush(p);

	if (!SetCommState(wx->fd, &wx->old_dcb)) {
		DBG("SetCommState() %s\n", last_error());
		return;
	}

	if (!SetCommTimeouts(wx->fd, &wx->old_tm)) {
		DBG("SetCommTimeouts() %s\n", last_error());
		return;
	}

	rs232_close(p);
	free(p->pt);
	free(p);
}
void* mmap(void* addr, size_t len, int prot, int flags, int fildes, oft__ off)
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4293)
#endif

    const DWORD access  = protect_file(prot);
    const DWORD protect = protect_page(prot);

    const oft__ max = off + (oft__)len;

    const DWORD max_lo  = large ? (DWORD)((max)       & MAXDWORD) : (DWORD)max;
    const DWORD max_hi  = large ? (DWORD)((max >> 32) & MAXDWORD) : (DWORD)0;
    const DWORD file_lo = large ? (DWORD)((off)       & MAXDWORD) : (DWORD)off;
    const DWORD file_hi = large ? (DWORD)((off >> 32) & MAXDWORD) : (DWORD)0;

#ifdef _MSC_VER
#pragma warning(pop)
#endif

    if (len == 0 || (flags & MAP_FIXED) != 0 || prot == PROT_EXEC)
    {
        errno = EINVAL;
        return MAP_FAILED;
    }

    const HANDLE handle = ((flags & MAP_ANONYMOUS) == 0) ? 
        (HANDLE)_get_osfhandle(fildes) : INVALID_HANDLE_VALUE;

    if ((flags & MAP_ANONYMOUS) == 0 && handle == INVALID_HANDLE_VALUE)
    {
        errno = EBADF;
        return MAP_FAILED;
    }

    const HANDLE mapping = CreateFileMappingW(handle, NULL, protect, max_hi,
        max_lo, NULL);

    if (mapping == NULL)
    {
        errno = last_error(EPERM);
        return MAP_FAILED;
    }

    const LPVOID map = MapViewOfFile(mapping, access, file_hi, file_lo, len);

    /* TODO: verify mapping handle may be closed here and then use the map. */
    if (map == NULL || CloseHandle(mapping) == FALSE)
    {
        errno = last_error(EPERM);
        return MAP_FAILED;
    }

    errno = 0;
    return map;
}
Beispiel #10
0
void TCPSocket::set_timeout(u32 seconds)
{
	struct timeval timeout;
	timeout.tv_sec = seconds;
	timeout.tv_usec = 0;

	int err = setsockopt(_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));
	CE_ASSERT(err == 0, "setsockopt: last_error(): %d", last_error());
	err = setsockopt(_socket, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(timeout));
	CE_ASSERT(err == 0, "setsockopt: last_error(): %d", last_error());
	CE_UNUSED(err);
}
Beispiel #11
0
static ERL_NIF_TERM run(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    struct regexp *rp = NULL;
    struct regexp r;
    ErlNifBinary strbin;
    ERL_NIF_TERM ret;

    if (!enif_get_resource(env, argv[1], regexp_type, (void **)&rp)) {
        ErlNifBinary patternbin;
        if (enif_inspect_iolist_as_binary(env, argv[1], &patternbin)) {
            char patternstr[patternbin.size + 1];
            xmlRegexpPtr xre;
            patternstr[patternbin.size] = 0;
            memcpy(patternstr, patternbin.data, patternbin.size);
            if ((xre = xmlRegexpCompile((xmlChar *)patternstr)) != NULL) {
                r.xre = xre;
                r.string = NULL;
                rp = &r;
            } else {
                return last_error(env, "Bad Pattern");
            }
        } else {
            return enif_make_badarg(env);
        }
    }

    if (enif_inspect_iolist_as_binary(env, argv[0], &strbin)) {
        char string[strbin.size + 1];
        string[strbin.size] = 0;
        memcpy(string, strbin.data, strbin.size);
        switch (xmlRegexpExec(rp->xre, (xmlChar *)string)) {
        case 1:
            /* FIXME NYI */
            ret = enif_make_tuple2(env, am_match(env),
                                   enif_make_list(env, 0));
            break;
        case 0:
            ret = am_nomatch(env);
            break;
        default:
            ret = last_error(env, NULL);
        }
    } else {
        ret = enif_make_badarg(env);
    }

    if (rp == &r) {
        xmlRegFreeRegexp(r.xre);
    }

    return ret;
}
Beispiel #12
0
static device_t goodfet_open(const struct device_args *args)
{
	struct goodfet *gc;

	if (!(args->flags & DEVICE_FLAG_TTY)) {
		printc_err("goodfet: this driver does not support raw "
			   "USB access\n");
		return NULL;
	}

	if (!(args->flags & DEVICE_FLAG_JTAG)) {
		printc_err("goodfet: this driver does not support "
			   "Spy-Bi-Wire\n");
		return NULL;
	}

	gc = malloc(sizeof(*gc));
	if (!gc) {
		printc_err("goodfet: malloc: %s\n", last_error());
		return NULL;
	}

        memset(gc, 0, sizeof(*gc));
	gc->base.type = &device_goodfet;
	gc->base.max_breakpoints = 0;
	gc->base.need_probe = 1;

	gc->serial_fd = sport_open(args->path, 115200, 0);
	if (SPORT_ISERR(gc->serial_fd)) {
		printc_err("goodfet: sport_open: %s: %s\n",
			   args->path, last_error());
		free(gc);
		return NULL;
	}

	if ((args->flags & DEVICE_FLAG_FORCE_RESET) &&
	    reset_sequence(gc->serial_fd) < 0)
		printc_err("warning: goodfet: reset failed\n");

	if (sport_flush(gc->serial_fd) < 0)
		printc_err("warning: goodfet: sport_flush: %s\n",
			   last_error());

	if (init_device(gc->serial_fd) < 0) {
		printc_err("goodfet: initialization failed\n");
		free(gc);
		return NULL;
	}

	return &gc->base;
}
Beispiel #13
0
static ERL_NIF_TERM compile(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary patternbin;

    if (enif_inspect_iolist_as_binary(env, argv[0], &patternbin)) {
        ERL_NIF_TERM ret;
        xmlRegexpPtr xre;
        char *patternstr = enif_alloc(patternbin.size + 1);
        patternstr[patternbin.size] = 0;
        memcpy(patternstr, patternbin.data, patternbin.size);

        if ((xre = xmlRegexpCompile((xmlChar *)patternstr)) != NULL) {
            struct regexp *r;
            r = enif_alloc_resource(regexp_type, sizeof(struct regexp));
            memset(r, 0, sizeof(*r));
            r->xre = xre;
            r->string = patternstr;

            /* transfer ownership to calling process */
            ret = enif_make_tuple2(env, am_ok(env),
                                   enif_make_resource(env, r));
            enif_release_resource(r);
        } else {
            enif_free(patternstr);
            ret = last_error(env, "Bad Pattern");
        }

        return ret;
    }

    return enif_make_badarg(env);
}
Beispiel #14
0
void 
    listen_pipe(char *name, void (*onconnect)(HANDLE client,void *params), void *args)
{
    LPWSTR _name = tomb(name);
    WINE_TRACE("begin '%s'->'%s'\n", name, (char*)_name);    
    
    HANDLE p;
    for (;;) {
	// hangs here
	p = CreateNamedPipeW(
	    _name,
	    PIPE_ACCESS_DUPLEX,
	    PIPE_TYPE_BYTE | PIPE_WAIT,
	    1,
	    1024,
	    1024,
	    0,
	    NULL);
	WINE_TRACE("pipe \"%s\" created\n",name);
	if (p==INVALID_HANDLE_VALUE) {
	    WINE_TRACE("could not create pipe \"%s\", error: %s\n",name,last_error());
	    break;
	}
	
	WINE_TRACE("pipe \"%s\" created, listen\n",name);
        if (ConnectNamedPipe(p,NULL)) {        
    	    WINE_TRACE("client connected...\n");
	    onconnect(p,args);
	    continue;
	} else {
	    CloseHandle(p);
	}
    }
    WINE_TRACE("exit...\n");
}
Beispiel #15
0
static int read_shdr(struct elf32_info *info, FILE *in)
{
	int i;

	if (info->file_ehdr.e_shnum > MAX_SHDRS) {
		printc_err("elf32: too many section headers: %d\n",
			info->file_ehdr.e_shnum);
		return -1;
	}

	for (i = 0; i < info->file_ehdr.e_shnum; i++) {
		if (fseek(in, i * info->file_ehdr.e_shentsize +
			  info->file_ehdr.e_shoff,
			  SEEK_SET) < 0) {
			printc_err("elf32: can't seek to shdr %d\n", i);
			return -1;
		}

		if (parse_shdr(&info->file_shdrs[i], in) < 0) {
			printc_err("elf32: can't read shdr %d: %s\n",
				i, last_error());
			return -1;
		}
	}

	return 0;
}
Beispiel #16
0
RS232_LIB unsigned int
rs232_read_timeout(struct rs232_port_t *p, unsigned char *buf,
		   unsigned int buf_len, unsigned int *read_len,
		   unsigned int timeout)
{
	unsigned int r = 0;
	struct rs232_windows_t *wx = p->pt;
	unsigned int rt = wx->r_timeout;

	DBG("p=%p p->pt=%p buf_len: %d timeout: %d\n", (void *)p, p->pt, buf_len, timeout);

	if (!rs232_port_open(p))
		return RS232_ERR_PORT_CLOSED;

	*read_len = 0;

	if (port_timeout(p, timeout, wx->w_timeout))
		return RS232_ERR_UNKNOWN;

	if (!ReadFile(wx->fd, buf, buf_len, &r, NULL)) {
		*read_len = 0;
		DBG("ReadFile() %s\n", last_error());
		return RS232_ERR_READ;
	}

	if (port_timeout(p, rt, wx->w_timeout))
		return RS232_ERR_UNKNOWN;

	*read_len = r;
	DBG("read_len=%d hex='%s' ascii='%s'\n", r, rs232_hex_dump(buf, r),
	    rs232_ascii_dump(buf, r));

	return RS232_ERR_NOERROR;
}
Beispiel #17
0
static int do_isearch(address_t addr, address_t len,
		      const struct isearch_query *q)
{
	uint8_t *mbuf;
	address_t i;

	mbuf = malloc(len);
	if (!mbuf) {
		printc_err("isearch: couldn't allocate memory: %s\n",
			last_error());
		return -1;
	}

	if (device_readmem(addr, mbuf, len) < 0) {
		printc_err("isearch: couldn't read device memory\n");
		free(mbuf);
		return -1;
	}

	addr &= ~1;
	len &= ~1;
	for (i = 0; i < len; i += 2) {
		struct msp430_instruction insn;
		int count = dis_decode(mbuf + i, addr + i, len - i, &insn);

		if (count >= 0 && isearch_match(&insn, q))
			disassemble(addr + i, mbuf + i, count,
				    device_default->power_buf);
	}

	free(mbuf);
	return 0;
}
Beispiel #18
0
static int send_packet(sport_t fd,
		       uint8_t app, uint8_t verb, uint16_t len,
		       const uint8_t *data)
{
	uint8_t raw[MAX_LEN + 4];

	if (len > MAX_LEN) {
		printc_err("goodfet: send_packet: maximum length "
			   "exceeded (%d)\n", len);
		return -1;
	}

#ifdef DEBUG_GOODFET
	printc_dbg("SEND: %02x/%02x\n", app, verb);
	if (len)
		debug_hexdump("Data", data, len);
#endif

	raw[0] = app;
	raw[1] = verb;
	raw[2] = len & 0xff;
	raw[3] = len >> 8;

	memcpy(raw + 4, data, len);

	if (sport_write_all(fd, raw, len + 4) < 0) {
		printc_err("goodfet: send_packet: %s\n", last_error());
		return -1;
	}

	return 0;
}
Beispiel #19
0
void TCPSocket::set_reuse_address(bool reuse)
{
	int optval = (int)reuse;
	int err = setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&optval, sizeof(optval));
	CE_ASSERT(err == 0, "setsockopt: last_error() = %d", last_error());
	CE_UNUSED(err);
}
Beispiel #20
0
BindResult TCPSocket::bind(u16 port)
{
	close();
	_socket = socket_internal::open();
	set_reuse_address(true);

	sockaddr_in address;
	address.sin_family = AF_INET;
	address.sin_addr.s_addr = htonl(INADDR_ANY);
	address.sin_port = htons(port);

	int err = ::bind(_socket, (const sockaddr*)&address, sizeof(sockaddr_in));

	BindResult br;
	br.error = BindResult::SUCCESS;

	if (err == SOCKET_ERROR)
	{
		if (last_error() == WSAEADDRINUSE)
			br.error = BindResult::ADDRESS_IN_USE;
		else
			br.error = BindResult::UNKNOWN;
	}

	return br;
}
Beispiel #21
0
void window_init(){

  ATOM at;

  wcex.cbSize        = sizeof(wcex);
  wcex.style         = 0;/* CS_HREDRAW | CS_VREDRAW; */
  wcex.lpfnWndProc   = WndProc;
  wcex.cbClsExtra    = 0;
  wcex.cbWndExtra    = 0;
  wcex.hInstance     = NULL;
  wcex.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  wcex.hCursor       = LoadCursor(NULL,IDC_ARROW);
  wcex.hbrBackground = NULL;
  wcex.lpszMenuName  = NULL;
  wcex.lpszClassName = szWindowClass;
  wcex.hIconSm       = NULL;

  at = RegisterClassEx(&wcex);
  if (at==0){
    if(vb) printf("no ATOM after registring class\n");
    last_error();
    exit(1);
  }else{
    if(vb) printf("got at atom..\n");
  }
}
void BEXMLTextReader::move_to_element()
{
	int return_code = xmlTextReaderMoveToElement ( reader );
	if ( return_code == kBE_XMLReaderError ) {
		throw BEXMLReaderInterface_Exception ( last_error() );
	}
}
Beispiel #23
0
/* www.gitorious.org/git-win32/mainline/source/9ae6b7513158e0b1523766c9ad4a1ad286a96e2c:win32/ftruncate.c */
int ftruncate(int fd, oft__ size)
{
    LARGE_INTEGER big;

    if (fd < 0)
    {
        errno = EBADF;
        return -1;
    }

    /* guard against overflow from unsigned to signed */
    if (size >= (uint64_t)(large ? MAXINT64 : MAXINT32))
    {
        errno = EFBIG;
        return -1;
    }

    /* unsigned to signed, splits to high and low */
    big.QuadPart = (LONGLONG)size;

    const HANDLE handle = (HANDLE)_get_osfhandle(fd);
    const position = SetFilePointerEx(handle, big, NULL, FILE_BEGIN);

    if (position == INVALID_SET_FILE_POINTER || SetEndOfFile(handle) == FALSE)
    {
        errno = last_error(EIO);
        return -1;
    }

    errno = 0;
    return 0;
}
Beispiel #24
0
static char *readline(const char *prompt)
{
	char *buf = malloc(LINE_BUF_SIZE);

	if (!buf) {
		fprintf(stdout, "readline: can't allocate memory: %s\n",
			last_error());
		return NULL;
	}

	for (;;) {
		printf("%s", prompt);
		fflush(stdout);

		if (fgets(buf, LINE_BUF_SIZE, stdin)) {
			int len = strlen(buf);

			while (len > 0 && isspace(buf[len - 1]))
				len--;

			buf[len] = 0;
			return buf;
		}

		if (feof(stdin))
			break;

		printf("\n");
	}

	free(buf);
	return NULL;
}
Beispiel #25
0
static int cmd_sym_load_add(int clear, char **arg)
{
	FILE *in;
	char * path;

	if (clear && prompt_abort(MODIFY_SYMS))
		return 0;

	path = expand_tilde(*arg);
	if (!path)
		return -1;

	in = fopen(path, "rb");
	free(path);
	if (!in) {
		printc_err("sym: %s: %s\n", *arg, last_error());
		return -1;
	}

	if (clear) {
		stab_clear();
		unmark_modified(MODIFY_SYMS);
	} else {
		mark_modified(MODIFY_SYMS);
	}

	if (binfile_syms(in) < 0) {
		fclose(in);
		return -1;
	}

	fclose(in);

	return 0;
}
Beispiel #26
0
    error::errors start_p2p_engine(
        char const * gid,
        char const * pid,
        char const * auth)
    {
        LOG_SECTION();

        error_code ec;
        if (is_started()) {
            ec = already_start;
        } else {
#ifndef PPBOX_DISABLE_CERTIFY
            ppbox::certify::Certifier & cert =
                util::daemon::use_module<ppbox::certify::Certifier>(*this);
            cert.set_auth_code(gid, pid, auth);
#endif

#ifndef PPBOX_DISABLE_DAC
            ppbox::dac::DacModule & dac =
                util::daemon::use_module<ppbox::dac::DacModule>(*this);
            dac.set_auth_code(gid, pid, auth);
#endif
            ec = start(1);
        }

        return last_error(__FUNCTION__, ec);
    }
int BEXMLTextReader::depth()
{
	int depth = xmlTextReaderDepth ( reader );
	if ( depth == kBE_XMLReaderError ) {
		throw BEXMLReaderInterface_Exception ( last_error() );
	}
	return depth;
}
Beispiel #28
0
void_func PluginLib::symbol(const std::string& name) const 
{
    if (m_libhandle == NULL)
    {
        last_error("Library not loaded", "The library handle is NULL. Cannot resolve simbol " + name);
        return NULL;
    }
    void_func sym = (void_func) dlsym(m_libhandle, name.c_str());
    char* error_string = dlerror();
    if (error_string)
    {
        last_error("Error loading symbol "+name,  error_string, m_libhandle);
        return NULL;
    }

    return sym;
}
Beispiel #29
0
        void sqlite3_db::open()
        {

            if (db_ != NULL) return;

            if (sqlite3_open(filename_.c_str(), &db_) != SQLITE_OK)
                throw database_exception(last_error());
        }
Beispiel #30
0
/* Load and registrate all the dll */
bool MP_Dll_Manager_c::load_dll()
{
	const char *func = "MP_Dll_Manager::load_dll";
	const char *directory = MPTK_Env_c::get_env()->get_config_path("dll_directory"); 
	if (NULL!= directory){
		mp_debug_msg( MP_DEBUG_CONSTRUCTION, func, "Plug-in localisation: [%s].\n", directory);          	
		if (MP_Dll_Manager_c::search_library(dllVectorName,directory)) {
			// Loop on found shared libs 
		  mp_debug_msg( MP_DEBUG_CONSTRUCTION, func, "Found %d plug-ins.\n", dllVectorName->size());	
			for (unsigned int k = 0; k < dllVectorName->size(); k++) {
			  const char *plugin = (*dllVectorName)[k].c_str();
			        mp_debug_msg( MP_DEBUG_CONSTRUCTION, func, "Trying to load plug-in: [%s].\n",plugin );
				MP_Dll_Manager_c::get_dll((*dllVectorName)[k].c_str());
				if ( last_error()==0 ) {
					void (*c)(void) = NULL;
					void *t=NULL;
					mp_debug_msg( MP_DEBUG_CONSTRUCTION, func, "Trying to retrieve registry function.\n");
					if (MP_Dll_Manager_c::get_symbol((void **)&t,"registry")) {
						c=(void (*)(void)) t;
						// test if plugin has the symbol "registry"
						if (NULL!=c) {
						  // Register the plugin in the concerned factory
						  mp_debug_msg( MP_DEBUG_CONSTRUCTION, func, "Executing registry function %p.\n", c);
						  c();
						} else {
							mp_warning_msg( func,"No registry function in '%s' shared library; \n",
											(*dllVectorName)[k].c_str());
						}
					} else  {
						mp_warning_msg( func,"No registry symbol in '%s' shared library.\n",
										(*dllVectorName)[k].c_str());
					}
				} else {
					mp_error_msg( func,"Error when loading the dll: '%s' .\n ",last_error());
				}
			} // End loop on found shared libraries
			return true;
		} else { // Else if search_library
			mp_error_msg( func,"No library found in '%s' .\n",directory);
			return false;
		}
	} else {
		mp_error_msg( func,"Problem with config path 'dll_directory' not found in  config file.\n");
		return false;
	}
}