Example #1
0
bool async_result_handler<T>::check(error_info *error)
{
	if (!m_data->checker(m_data->statuses, m_data->total)) {
		if (error) {
			size_t success = 0;
			dnet_cmd command;
			command.status = 0;
			for (auto it = m_data->statuses.begin(); it != m_data->statuses.end(); ++it) {
				const bool failed_to_send = !(it->flags & DNET_FLAGS_REPLY);
				const bool ignore_error = failed_to_send && it->status == -ENXIO;

				if (it->status == 0) {
					++success;
				} else if (command.status == 0 && !ignore_error) {
					command = *it;
				}
			}
			if (success == 0 && command.status) {
				*error = create_error(command);
			} else {
				*error = create_error(-ENXIO, "insufficient results count due to checker: "
						"%zu of %zu (%zu)",
					success, m_data->total, m_data->statuses.size());
			}
		}
		return false;
	}
	if (error)
		*error = error_info();
	return true;
}
Example #2
0
File: error.c Project: bilboed/wine
static HRESULT error_constr(script_ctx_t *ctx, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei, DispatchEx *constr) {
    DispatchEx *err;
    VARIANT numv;
    UINT num;
    BSTR msg = NULL;
    HRESULT hres;

    V_VT(&numv) = VT_NULL;

    if(arg_cnt(dp)) {
        hres = to_number(ctx, get_arg(dp, 0), ei, &numv);
        if(FAILED(hres) || (V_VT(&numv)==VT_R8 && isnan(V_R8(&numv))))
            hres = to_string(ctx, get_arg(dp, 0), ei, &msg);
        else if(V_VT(&numv) == VT_I4)
            num = V_I4(&numv);
        else
            num = V_R8(&numv);

        if(FAILED(hres))
            return hres;
    }

    if(arg_cnt(dp)>1 && !msg) {
        hres = to_string(ctx, get_arg(dp, 1), ei, &msg);
        if(FAILED(hres))
            return hres;
    }

    switch(flags) {
    case INVOKE_FUNC:
    case DISPATCH_CONSTRUCT:
        if(V_VT(&numv) == VT_NULL)
            hres = create_error(ctx, constr, NULL, msg, &err);
        else
            hres = create_error(ctx, constr, &num, msg, &err);
        SysFreeString(msg);

        if(FAILED(hres))
            return hres;

        if(retv) {
            V_VT(retv) = VT_DISPATCH;
            V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(err);
        }
        else
            jsdisp_release(err);

        return S_OK;

    default:
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }
}
Example #3
0
static HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str, jsdisp_t *constr)
{
    WCHAR buf[1024], *pos = NULL;
    jsdisp_t *err;
    jsstr_t *msg;
    HRESULT hres;

    if(!is_jscript_error(error))
        return error;

    buf[0] = '\0';
    LoadStringW(jscript_hinstance, HRESULT_CODE(error),  buf, sizeof(buf)/sizeof(WCHAR));

    if(str) pos = strchrW(buf, '|');
    if(pos) {
        int len = strlenW(str);
        memmove(pos+len, pos+1, (strlenW(pos+1)+1)*sizeof(WCHAR));
        memcpy(pos, str, len*sizeof(WCHAR));
    }

    WARN("%s\n", debugstr_w(buf));

    msg = jsstr_alloc(buf);
    if(!msg)
        return E_OUTOFMEMORY;

    hres = create_error(ctx, constr, error, msg, &err);
    jsstr_release(msg);
    if(FAILED(hres))
        return hres;

    jsval_release(ctx->ei.val);
    ctx->ei.val = jsval_obj(err);
    return error;
}
Example #4
0
File: error.c Project: bilboed/wine
static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str, DispatchEx *constr)
{
    WCHAR buf[1024], *pos = NULL;
    DispatchEx *err;
    HRESULT hres;

    buf[0] = '\0';
    LoadStringW(jscript_hinstance, id&0xFFFF,  buf, sizeof(buf)/sizeof(WCHAR));

    if(str) pos = strchrW(buf, '|');
    if(pos) {
        int len = strlenW(str);
        memmove(pos+len, pos+1, (strlenW(pos+1)+1)*sizeof(WCHAR));
        memcpy(pos, str, len*sizeof(WCHAR));
    }

    WARN("%s\n", debugstr_w(buf));

    id |= JSCRIPT_ERROR;
    hres = create_error(ctx, constr, &id, buf, &err);
    if(FAILED(hres))
        return hres;

    if(!ei)
        return id;

    V_VT(&ei->var) = VT_DISPATCH;
    V_DISPATCH(&ei->var) = (IDispatch*)_IDispatchEx_(err);

    return id;
}
Example #5
0
File: stash.c Project: aep/libgit2
static int ensure_there_are_changes_to_stash(
	git_repository *repo,
	bool include_untracked_files,
	bool include_ignored_files)
{
	int error;
	git_status_options opts = GIT_STATUS_OPTIONS_INIT;

	opts.show  = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
	if (include_untracked_files)
		opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
		GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;

	if (include_ignored_files)
		opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED;

	error = git_status_foreach_ext(repo, &opts, is_dirty_cb, NULL);

	if (error == GIT_EUSER)
		return 0;

	if (!error)
		return create_error(GIT_ENOTFOUND, "There is nothing to stash.");

	return error;
}
Example #6
0
pascal OSStatus
filedsn_setdir_clicked (EventHandlerCallRef inHandlerRef,
    EventRef inEvent, void *inUserData)
{
  TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData;
  char msg[4096];

  if (!choose_t)
    return noErr;

  /* confirm setting a directory */
  snprintf (msg, sizeof (msg),
      "Are you sure that you want to make '%s' the default file DSN directory?",
      choose_t->curr_dir);
  if (!create_confirm (choose_t->mainwnd, NULL, msg))
    return noErr;

  /* write FileDSNPath value */
  if (!SQLWritePrivateProfileString ("ODBC", "FileDSNPath",
	   choose_t->curr_dir, "odbcinst.ini"))
    {
      create_error (choose_t->mainwnd, NULL,
	  "Error setting default file DSN directory", NULL);
      return noErr;
    }
  return noErr;
}
Example #7
0
pascal OSStatus
filedsn_remove_clicked (EventHandlerCallRef inHandlerRef,
    EventRef inEvent, void *inUserData)
{
  TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData;
  DataBrowserItemID first, last;
  OSStatus err;

  if (!choose_t)
    return noErr;

  /* Retrieve the DSN name */
  if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist,
        &first, &last)) == noErr)
    {
      if (first > DBITEM_ID && first <= DBITEM_ID + FDSN_nrows)
        {
          char str[1024];
          char *path;

          if (FDSN_type[first - DBITEM_ID - 1] == 0)
            return noErr;

          /* Get the DSN */
          CFStringGetCString(FDSN_array[first - DBITEM_ID - 1], str, sizeof(str), kCFStringEncodingUTF8);
          asprintf (&path, "%s/%s", choose_t->curr_dir, str);

          if (path)
            {
              if (create_confirm (choose_t->mainwnd, path,
                   "Are you sure you want to remove this File DSN ?"))
                {
                  /* Call the right function */
                  if (unlink(path) < 0)
                    {
                      create_error (choose_t->mainwnd, NULL, 
                        "Error removing file DSN:", strerror (errno));
                    }
                }
              free(path);
              addfdsns_to_list (choose_t, choose_t->curr_dir, true);
            }
        }
    }

  if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist,
        &first, &last)) == noErr)
    {
      if (!first && !last)
        {
          DeactivateControl (choose_t->fremove);
          DeactivateControl (choose_t->fconfigure);
          DeactivateControl (choose_t->ftest);
        }
    }

  return noErr;
}
Example #8
0
File: stash.c Project: aep/libgit2
static int retrieve_head(git_reference **out, git_repository *repo)
{
	int error = git_repository_head(out, repo);

	if (error == GIT_EORPHANEDHEAD)
		return create_error(error, "You do not have the initial commit yet.");

	return error;
}
Example #9
0
File: error.c Project: nhst/trema
/*
 * @overload initialize(transaction_id=nil, type=OFPET_HELLO_FAILED, code=OFPHFC_INCOMPATIBLE, user_data=nil)
 *
 * @param [Number] transaction_id
 *   a positive number, not recently attached to any previous pending commands to
 *   guarantee message integrity auto-generated if not specified.
 *
 * @param [Number] type
 *   a command or action that failed. Defaults to +OFPET_HELLO_FAILED+ if 
 *   not specified.
 *
 * @param [Number] code
 *   the reason of the failed type error. Defaults to +OFPHFC_INCOMPATIBLE+ if 
 *   not specified.
 *
 * @param [String] user_data
 *   a more user friendly explanation of the error. Defaults to nil if not 
 *   specified.
 *
 * @example Instantiate with type and code
 *   Error.new(OFPET_BAD_REQUEST, OFPBRC_BAD_TYPE)
 *
 * @example Instantiate with transaction_id, type and code.
 *   Error.new(1234, OFPET_BAD_ACTION, OFPBAC_BAD_VENDOR)
 *
 * @example Instantiate with transaction_id, type, code, user_data
 *   Error.new(6789, OFPET_FLOW_MOD_FAILED, OFPFMFC_BAD_EMERG_TIMEOUT, "this is a test") 
 *
 * @raise [ArgumentError] if transaction id is negative.
 * @raise [ArgumentError] if user data is not a string.
 *
 * @return [Error] 
 *   an object that encapsulates the +OFPT_ERROR+ openflow message.
 */
static VALUE
error_new( int argc, VALUE *argv, VALUE klass ) {
  buffer *data = NULL;
  uint32_t xid = get_transaction_id();
  VALUE xid_r;
  VALUE user_data;
  VALUE type_r;
  VALUE code_r;
  uint16_t type;
  uint16_t code;

  switch ( argc ) {
    case 2:
      // type, code specified.
      rb_scan_args( argc, argv, "02", &type_r, &code_r );
      type = ( uint16_t ) NUM2UINT( type_r );
      code = ( uint16_t ) NUM2UINT( code_r );
      break;
    case 3:
      // transaction id, type, code specified.
      rb_scan_args( argc, argv, "03", &xid_r, &type_r, &code_r );
      if ( NUM2INT( xid_r ) < 0 ) {
        rb_raise( rb_eArgError, "Transaction ID must be >= 0" );
      }
      xid = ( uint32_t ) NUM2UINT( xid_r );
      type = ( uint16_t ) NUM2UINT( type_r );
      code = ( uint16_t ) NUM2UINT( code_r );
      break;
    case 4:
      rb_scan_args( argc, argv, "04", &xid_r, &type_r, &code_r, &user_data );
      if ( NUM2INT( xid_r ) < 0 ) {
        rb_raise( rb_eArgError, "Transaction ID must be >= 0" );
      }
      if ( rb_obj_is_kind_of( user_data, rb_cString ) == Qfalse ) {
        rb_raise( rb_eArgError, "User data must be a string" );
      }
      xid = ( uint32_t ) NUM2UINT( xid_r );
      type = ( uint16_t ) NUM2UINT( type_r );
      code = ( uint16_t ) NUM2UINT( code_r );
      uint16_t length = ( u_int16_t ) RSTRING_LEN( user_data );
      data = alloc_buffer_with_length( length );
      void *p = append_back_buffer( data, length );
      memcpy( p, RSTRING_PTR( user_data ), length );
      break;
    default:
      type = OFPET_HELLO_FAILED;
      code = OFPHFC_INCOMPATIBLE;
      break;
  }
  buffer *error = create_error( xid, type, code, data );
  if ( data != NULL ) {
    free_buffer( data );
  }
  return Data_Wrap_Struct( klass, NULL, free_buffer, error );
}
Example #10
0
/*
 * call-seq:
 *   nwfilter.uuid -> string
 *
 * Call +virNWFilterGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetUUIDString]
 * to retrieve the network filter UUID.
 */
static VALUE libvirt_nwfilter_uuid(VALUE s) {
    virNWFilterPtr nwfilter = nwfilter_get(s);
    int r;
    char uuid[VIR_UUID_STRING_BUFLEN];

    r = virNWFilterGetUUIDString(nwfilter, uuid);
    _E(r < 0, create_error(e_RetrieveError, "virNWFilterGetUUIDString",
                           conn(s)));

    return rb_str_new2((char *)uuid);
}
Example #11
0
/* open callback */
static int kplugs_open(struct inode *inode, struct file *filp)
{
	int err = 0;

	if (!capable(CAP_SYS_MODULE)) {
		return -EPERM;
	}

	/* create a new context for this file descriptor */
	err = context_create((context_t **)&filp->private_data);

	return err ? create_error(NULL, err) : 0;
}
Example #12
0
static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r, jsdisp_t *constr) {
    jsdisp_t *err;
    UINT num = 0;
    jsstr_t *msg = NULL;
    HRESULT hres;

    if(argc) {
        double n;

        hres = to_number(ctx, argv[0], &n);
        if(FAILED(hres)) /* FIXME: really? */
            n = NAN;
        if(isnan(n))
            hres = to_string(ctx, argv[0], &msg);
        if(FAILED(hres))
            return hres;
        num = n;
    }

    if(!msg) {
        if(argc > 1) {
            hres = to_string(ctx, argv[1], &msg);
            if(FAILED(hres))
                return hres;
        }else {
            msg = jsstr_empty();
        }
    }

    switch(flags) {
    case INVOKE_FUNC:
    case DISPATCH_CONSTRUCT:
        hres = create_error(ctx, constr, num, msg, &err);
        jsstr_release(msg);
        if(FAILED(hres))
            return hres;

        if(r)
            *r = jsval_obj(err);
        else
            jsdisp_release(err);
        return S_OK;

    default:
        if(msg)
            jsstr_release(msg);
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }
}
Example #13
0
p_data_t creater_t::create_argument_number_error(
const std::string& name,size_t min_number,size_t got_number,bool is_kahencho) {
	std::string message="invalid number of arguments for "+name+" : expected ";
	char buffer[16];
	if(is_kahencho) {
		message+=" at least ";
	}
	sprintf(buffer,"%u",(unsigned int)min_number);
	message+=buffer;
	message+=", got ";
	sprintf(buffer,"%u",(unsigned int)got_number);
	message+=buffer;
	return create_error(message);
}
Example #14
0
int
ofpmsg_send_error_msg( struct switch_info *sw_info, uint16_t type, uint16_t code, buffer *data ) {
  int ret;
  buffer *buf;

  if (data->length > OFP_ERROR_MSG_MAX_DATA ) {
    // FIXME
    data->length = OFP_ERROR_MSG_MAX_DATA;
  }

  buf = create_error( generate_xid(), type, code, data );

  ret = send_to_secure_channel( sw_info, buf );
  if ( ret == 0 ) {
    debug( "Send 'error' to a switch %#" PRIx64 ".", sw_info->datapath_id );
  }

  return ret;
}
Example #15
0
void server_node::start()
{
    if (is_started())
        throw std::runtime_error("Server node \"" + m_path + "\" is already started");

    if (m_fork) {
        m_kill_sent = false;
        m_pid = fork();
        if (m_pid == -1) {
            m_pid = 0;
            int err = -errno;
            throw_error(err, "Failed to fork process");
        } else if (m_pid == 0) {
            char buffer[3][1024] = {
                " ",
                "-c"
            };
            std::string ios_path = ioserv_path();
            char * const args[] = {
                const_cast<char*>(ios_path.c_str()),
                buffer[1],
                const_cast<char*>(m_path.c_str()),
                NULL
            };
            auto ld_path = std::string("LD_LIBRARY_PATH=") + getenv("LD_LIBRARY_PATH");
            char * const env[] = {
                const_cast<char*>(ld_path.c_str()),
                NULL
            };
            if (execve(ios_path.data(), args, env) == -1) {
                int err = -errno;
                std::cerr << create_error(err, "Failed to start process \"%s\"", ios_path.c_str()).message() << std::endl;
                quick_exit(1);
            }
        }
    } else {
        m_node = dnet_parse_config(m_path.c_str(), 0);
    }

    if (!is_started())
        throw std::runtime_error("Can not start server with config file: \"" + m_path + "\"");
}
Example #16
0
void
create_errorw (HWND hwnd, LPCWSTR dsn, LPCWSTR text, LPCWSTR errmsg)
{
  LPSTR _dsn = NULL;
  LPSTR _text = NULL;
  LPSTR _errmsg = NULL;

  _dsn = dm_SQL_WtoU8(dsn, SQL_NTS);
  _text = dm_SQL_WtoU8(text, SQL_NTS);
  _errmsg = dm_SQL_WtoU8(errmsg, SQL_NTS);

  create_error(hwnd, _dsn, _text, _errmsg);

  if (_dsn)
    free(_dsn);
  if (_text)
    free(_text);
  if (_errmsg)
    free(_errmsg);
}
Example #17
0
int		main(int ac, char **av)
{
	int		i;

	if (ac > 1)
	{
		i = 1;
		while (i < ac)
		{
			if (ac != 2)
				put_file_path(av[i]);
			solve_map(av[i++]);
		}
	}
	else
	{
		generate_map();
		solve_map(MAP_PATH);
		if ((i = open(MAP_PATH, O_TRUNC)) <= 0)
			create_error(MAP_PATH);
		close(i);
	}
	return (0);
}
Example #18
0
void
addfdsns_to_list (TDSNCHOOSER *dsnchoose_t, char *path, Boolean b_reset)
{
  DataBrowserItemID item = DBITEM_ID + 1;
  DataBrowserCallbacks dbCallbacks;
  ThemeDrawingState outState = NULL;
  UInt16 colSize[3] = { 400, 100, 150 };
  SInt16 outBaseline;
  Point ioBound;
  int i;
  DIR *dir;
  char *path_buf;
  struct dirent *dir_entry;
  struct stat fstat;
  int b_added;
  ControlRef widget;
  WindowRef dlg;

  if (!dsnchoose_t || !path)
    return; 

  widget = dsnchoose_t->fdsnlist;
  dlg = dsnchoose_t->mainwnd;

  GetThemeDrawingState (&outState);

  /* Install an event handler on the component databrowser */
  dbCallbacks.version = kDataBrowserLatestCallbacks;
  InitDataBrowserCallbacks (&dbCallbacks);
  dbCallbacks.u.v1.itemNotificationCallback =
      NewDataBrowserItemNotificationUPP (fdsn_notification_item);
  /* On Mac OS X 10.0.x : clientDataCallback */
  dbCallbacks.u.v1.itemDataCallback =
      NewDataBrowserItemDataUPP (fdsn_getset_item);
  SetDataBrowserCallbacks (widget, &dbCallbacks);
  /* Begin the draw of the data browser */
  SetDataBrowserTarget (widget, DBITEM_ID);

  /* Make the clean up */
  for (i = 0; i < FDSN_nrows; i++, item++)
    {
      CFRelease (FDSN_array[i]);
      FDSN_array[i] = NULL;
      FDSN_type[i] = 0;
      RemoveDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID);
    }

  ActivateControl (widget);
  DrawOneControl (widget);

  /* Global Initialization */
  FDSN_nrows = 0;
  item = DBITEM_ID + 1;

  if ((dir = opendir (path)))
    {
      while ((dir_entry = readdir (dir)) && FDSN_nrows < MAX_ROWS)
	{
	  asprintf (&path_buf, "%s/%s", path, dir_entry->d_name);
	  b_added = 0;

	  if (stat ((LPCSTR) path_buf, &fstat) >= 0 && S_ISDIR (fstat.st_mode))
	    {
	      if (dir_entry->d_name && dir_entry->d_name[0] != '.') 
	        {
                  FDSN_array[FDSN_nrows] = CFStringCreateWithCString(NULL, dir_entry->d_name, kCFStringEncodingUTF8);
                  FDSN_type[FDSN_nrows] = 0;
                  b_added = 1;
	        }
	    }
	  else if (stat ((LPCSTR) path_buf, &fstat) >= 0 && !S_ISDIR (fstat.st_mode)
	           && strstr (dir_entry->d_name, ".dsn"))
	    {
              FDSN_array[FDSN_nrows] = CFStringCreateWithCString(NULL, dir_entry->d_name, kCFStringEncodingUTF8);
              FDSN_type[FDSN_nrows] = 1;
              b_added = 1;
	    }

	  if (path_buf)
	    free (path_buf);

	  if (b_added)
	    {
              GetThemeTextDimensions (FDSN_array[FDSN_nrows], kThemeSystemFont,
                kThemeStateActive, false, &ioBound, &outBaseline);
              if(colSize[0] < ioBound.h) colSize[0] = ioBound.h;

              AddDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID);
              item++;
              FDSN_nrows++;
            }
	}

      /* Close the directory entry */
      closedir (dir);
    }
  else
    create_error (NULL, NULL, "Error during accessing directory information",
	strerror (errno));

  ActivateControl (widget);
  /* Resize the columns to have a good look */
  SetDataBrowserTableViewNamedColumnWidth (widget, DBNAME_ID, colSize[0] + 20);
  DrawOneControl (widget);
  /* Remove the DataBrowser callback */
  SetDataBrowserCallbacks (NULL, &dbCallbacks);
  if(outState) DisposeThemeDrawingState (outState);

  if (b_reset)
    SetDataBrowserScrollPosition(widget, 0, 0);

  fill_dir_menu(dsnchoose_t, path);
}
Example #19
0
static VALUE
error_alloc( VALUE klass ) {
  buffer *error = create_error( 0, 0, 0, NULL );
  return Data_Wrap_Struct( klass, NULL, free_buffer, error );
}
Example #20
0
connection::pointer node::connect(const std::string &addr_str, typename connection::process_fn_t process)
{
	connection::pointer cn = connection::create(m_io_pool, process,
			std::bind(&node::drop, this, std::placeholders::_1, std::placeholders::_2));

	auto it = m_resolver.resolve(addr_str);

	cn->connect(it);
	auto id = cn->ids()[0];

	VLOG(2) << "connection: " << cn->connection_string() << ", node has been connected";
	if (m_route.add(cn)) {
		cn->close();

		auto dump = [] (const std::vector<connection::cid_t> &cids) {
			std::ostringstream ss;

			for (auto &id: cids) {
				ss << id;
				if (id != cids.back())
					ss << ",";
			}

			return ss.str();
		};

		for (auto cn: m_route.connections()) {
			VLOG(2) << "connection: " << cn->connection_string() << ", routes: " << dump(cn->ids());
		}
		return m_route.find(id);
	}

	std::promise<int> p;
	std::future<int> f = p.get_future();

	std::vector<address> addrs;
	cn->request_remote_nodes([&] (connection::pointer, message &msg) {
				if (msg.hdr.status) {
					LOG(ERROR) << "connection: " << cn->connection_string() <<
						", reply: " << msg.to_string() <<
						", error: could not request remote connections";

					p.set_exception(std::make_exception_ptr(
							create_error(msg.hdr.status, "connect: could not request remote connections")));
					return;
				}

				try {
					msgpack::unpacked up;
					msgpack::unpack(&up, msg.data(), msg.hdr.size);

					up.get().convert(&addrs);
					p.set_value(0);
				} catch (const std::exception &e) {
					LOG(ERROR) << "connection: " << cn->connection_string() <<
						", message: " << msg.to_string() <<
						", error: could not unpack array of endpoints: " << e.what();

					p.set_exception(std::current_exception());
					return;
				}
			});

	f.get();

	for (auto &addr: addrs) {
		LOG(INFO) << "received address: " << addr.to_string();
		if (addr.endpoint() == cn->socket().remote_endpoint())
			continue;

		auto eps_it = connection::resolver_iterator::create(addr.endpoint(), addr.host(), std::to_string(addr.port()));
		connection::pointer c = connection::create(m_io_pool, process,
				std::bind(&node::drop, this, std::placeholders::_1, std::placeholders::_2));

		c->connect(eps_it);
		VLOG(2) << "connection: " << c->connection_string() << ", node has been connected";
		if (m_route.add(c)) {
			c->close();
		}
	}
	return cn;
}
Example #21
0
/* the module init function */
static int __init kplugs_init(void)
{
	int err = 0;
	struct device *device = NULL;

	memory_start();

	err = context_create(&GLOBAL_CONTEXT);
	if (err < 0) {
		output_string("Couldn't create the global context.\n");
		ERROR_CLEAN(create_error(NULL, err));
	}

	err = alloc_chrdev_region(&kplugs_devno , 0, 1, DEVICE_NAME);
	if (err < 0) {
		output_string("Couldn't allocate a region.\n");
		ERROR_CLEAN(create_error(NULL, err));
	}

	kplugs_class = class_create(THIS_MODULE, DEVICE_NAME);
	if (NULL == kplugs_class) {
		output_string("Couldn't create class.\n");
		ERROR_CLEAN(-ENOMEM);
	}
	
	kplugs_cdev = cdev_alloc();
	if (NULL == kplugs_cdev) {
		output_string("Couldn't allocate a cdev.\n");
		ERROR_CLEAN(-ENOMEM);
	}

	cdev_init(kplugs_cdev, &kplugs_ops);

	err = cdev_add(kplugs_cdev, kplugs_devno, 1);
	if (err < 0) {
		output_string("Couldn't add the cdev.\n");
		ERROR_CLEAN(create_error(NULL, err));
	}

	device = device_create(kplugs_class, NULL, kplugs_devno, NULL, DEVICE_NAME);
	if (device == NULL) {
		output_string("Couldn't create the device.\n");
		ERROR_CLEAN(-ENOMEM);
	}

	return 0;

clean:
	if (NULL != kplugs_cdev) {
		cdev_del(kplugs_cdev);
	}
	if (NULL != kplugs_class) {
		class_destroy(kplugs_class);
	}
	if (kplugs_devno) {
		unregister_chrdev_region(kplugs_devno, 1);
	}
	if (NULL != GLOBAL_CONTEXT) {
		context_free(GLOBAL_CONTEXT);
	}
	memory_stop();
	return err;
}
Example #22
0
pascal OSStatus
filedsn_configure_clicked (EventHandlerCallRef inHandlerRef,
    EventRef inEvent, void *inUserData)
{
  TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData;
  DataBrowserItemID first, last;
  OSStatus err;
  char str[1024], path[1024];
  int id;
  char *drv = NULL;
  char *attrs = NULL;
  char *_attrs = NULL;	/* attr list */
  size_t len = 0;	/* current attr list length (w/o list-terminating NUL) */
  char *p, *p_next;
  WORD read_len;
  char entries[4096];
  char *curr_dir;

  if (!choose_t)
    return noErr;

  curr_dir = choose_t->curr_dir;

  /* Retrieve the DSN name */
  if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist,
       &first, &last)) == noErr)
    {
      if (first > DBITEM_ID && first <= DBITEM_ID + FDSN_nrows)
        {
          id = first - DBITEM_ID - 1;
          CFStringGetCString(FDSN_array[id], str, sizeof(str), kCFStringEncodingUTF8);

          if (*curr_dir == '/' && strlen(curr_dir) == 1)
            snprintf(path, sizeof(path), "/%s", str);
          else
            snprintf(path, sizeof(path), "%s/%s", curr_dir, str);

          if (FDSN_type[id] == 0)  /* Directory */
            {
              addfdsns_to_list (choose_t, path, true);
            }

          else  /* File DSN*/
            {
              /* Get list of entries in .dsn file */
              if (!SQLReadFileDSN (path, "ODBC", NULL,
		       entries, sizeof (entries), &read_len))
                {
                  create_error (choose_t->mainwnd, NULL, "SQLReadFileDSN failed", NULL);
                  goto done;
                }

              /* add params from the .dsn file */
              for (p = entries; *p != '\0'; p = p_next)
                {
                  char *tmp;
                  size_t add_len;		/* length of added attribute */
                  char value[1024];

                  /* get next entry */
                  p_next = strchr (p, ';');
                  if (p_next)
                    *p_next++ = '\0';

                  if (!SQLReadFileDSN (path, "ODBC", p, value, sizeof(value), &read_len))
                    {
                      create_error (choose_t->mainwnd, NULL, "SQLReadFileDSN failed", NULL);
                      goto done;
                    }

                  if (!strcasecmp (p, "DRIVER"))
                    {
                      /* got driver keyword */
                      add_len = strlen ("DRIVER=") + strlen (value) + 1;
                      drv = malloc (add_len);
                      snprintf (drv, add_len, "DRIVER=%s", value);
                      continue;
                    }

                  /* +1 for '=', +1 for NUL */
                  add_len = strlen (p) + 1 + strlen (value) + 1;
                  /* +1 for list-terminating NUL */;
                  tmp = realloc (attrs, len + add_len + 1);
                  if (tmp == NULL)
                    {
                      create_error (choose_t->mainwnd, NULL, "Error adding file DSN:",
                         strerror (errno));
                      goto done;
                    }
                  attrs = tmp;
                  snprintf (attrs + len, add_len, "%s=%s", p, value);
                  len += add_len;
                }

              if (drv == NULL)
                {
                  /* no driver found, probably unshareable file data source */
                  create_error (choose_t->mainwnd, NULL,
            	    "Can't configure file DSN without DRIVER keyword (probably unshareable data source?)", NULL);
                  goto done;
                }

              if (attrs == NULL)
                attrs = "\0\0";
              else
                {
                  /* NUL-terminate the list */
                  attrs[len] = '\0';
                  _attrs = attrs;
                }

              /* Configure file DSN */
              filedsn_configure (choose_t, drv, path, attrs, FALSE, TRUE);
              addfdsns_to_list (choose_t, curr_dir, true);
            }
        }
    }

done:
  if (drv != NULL)
    free (drv);
  if (_attrs != NULL)
    free (_attrs);

  if ((err = GetDataBrowserSelectionAnchor (choose_t->sdsnlist,
        &first, &last)) == noErr)
    {
      if (!first && !last)
        {
          DeactivateControl (choose_t->sremove);
          DeactivateControl (choose_t->sconfigure);
          DeactivateControl (choose_t->stest);
        }
    }
  return noErr;
}
Example #23
0
/* write callback */
static ssize_t kplugs_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos)
{
	kplugs_command_t *cmd = NULL;
	context_t *file_cont = NULL;
	context_t *cont = NULL;
	bytecode_t *code = NULL;
	function_t *func = NULL;
	exception_t excep;
	stack_t stack;
	word iter, arg;
	word args;
	byte little_endian;
	byte func_name[MAX_FUNC_NAME + 1];
	int err = 0;

#ifdef __LITTLE_ENDIAN
	little_endian = 1;
#else
	little_endian = 0;
#endif
	/* get the user's command */
	cmd = (kplugs_command_t *)buf;
	file_cont = (context_t *)filp->private_data;

	if (count < sizeof(byte) * 3) { /* three bytes of header */
		return create_error(file_cont, -ERROR_PARAM);
	}

	if (cmd->word_size != sizeof(word) || cmd->l_endian != little_endian) {
		return create_error(file_cont, -ERROR_ARCH);
	}

	if (cmd->version_major != VERSION_MAJOR || cmd->version_minor != VERSION_MINOR) {
		return create_error(file_cont, -ERROR_VERSION);
	}

	if (count != sizeof(kplugs_command_t)) {
		return create_error(file_cont, -ERROR_PARAM);
	}

	cont = cmd->is_global ? GLOBAL_CONTEXT : file_cont;

	switch (cmd->type) {
	case KPLUGS_LOAD:
		/* load a new function */

		if (cmd->len2 != 0 || cmd->ptr2 != NULL) {
			return create_error(file_cont, -ERROR_PARAM);
		}

		code = memory_alloc(cmd->len1);
		if (NULL == code) {
			ERROR(create_error(file_cont, -ERROR_MEM));
		}

		err = memory_copy_from_outside(code, cmd->uptr1, cmd->len1);
		if (err < 0) {
			err = create_error(file_cont, err);
			goto clean;
		}

		/* create the function */
		err = function_create(code, cmd->len1, &func);
		if (err < 0) {
			err = create_error(file_cont, err);
			goto clean;
		}

		err = context_add_function(cont, func);
		if (err < 0) {
			err = create_error(file_cont, err);
			goto clean;
		}

		/* return the function's address */
		context_create_reply(file_cont, (word)&func->func_code, NULL);

		return count;

	case KPLUGS_UNLOAD:
		/* unload a function with a name */
		if (NULL != cmd->uptr2) {
			return create_error(file_cont, -ERROR_PARAM);
		}
	case KPLUGS_EXECUTE:
		/* execute (and unload) a function with a name */
		if (cmd->len1 > MAX_FUNC_NAME || (cmd->len2 % sizeof(word)) != 0) {
			return create_error(file_cont, -ERROR_PARAM);
		}

		err = memory_copy_from_outside(func_name, cmd->uptr1, cmd->len1);
		if (err < 0) {
			return create_error(file_cont, err);
		}

		func_name[cmd->len1] = '\0';

		/* find the function */

		if (cmd->type == KPLUGS_UNLOAD) {
			func = context_find_function(cont, func_name);
			if (NULL == func) {
				return create_error(file_cont, -ERROR_UFUNC);
			}
			/* delete the function */
			context_free_function(func);
			err = (int)count;

			goto clean;
		}

		if (!cmd->is_global) {
			func = context_find_function(file_cont, func_name);
		}
		if (NULL == func) {
			func = context_find_function(GLOBAL_CONTEXT, func_name);
			if (NULL == func) {
				return create_error(file_cont, -ERROR_UFUNC);
			}
		}

		goto execute_func;

	case KPLUGS_UNLOAD_ANONYMOUS:
		/* unload an anonymous function */
		if (NULL != cmd->uptr2 || cmd->len1 || cmd->len2) {
			return create_error(file_cont, -ERROR_PARAM);
		}
		func = context_find_anonymous(cont, cmd->ptr1);
		if (NULL == func) {
			return create_error(file_cont, -ERROR_UFUNC);
		}

		/* delete the function */
		context_free_function(func);

		err = (int)count;
		goto clean;
	break;

	case KPLUGS_EXECUTE_ANONYMOUS:
		/* execute (and unload) an anonymous function */
		if (cmd->len1 || (cmd->len2 % sizeof(word)) != 0) {
			return create_error(file_cont, -ERROR_PARAM);
		}

		/* find the function */
		if (!cmd->is_global) {
			func = context_find_anonymous(file_cont, cmd->ptr1);
		}
		if (NULL == func) {
			func = context_find_anonymous(GLOBAL_CONTEXT, cmd->ptr1);
			if (NULL == func) {
				return create_error(file_cont, -ERROR_UFUNC);
			}
		}

execute_func:
		/* do the execution of a function: */

		args = cmd->len2 / sizeof(word);
		if (args > func->num_maxargs || args < func->num_minargs) {
			ERROR_CLEAN(create_error(file_cont, -ERROR_ARGS));
		}

		err = stack_alloc(&stack, sizeof(word), CALL_STACK_SIZE);
		if (err < 0) {
			err = create_error(file_cont, err);
			goto clean;
		}

		/* push the arguments to a stack */
		for (iter = 0; iter < args; ++iter) {
			err = memory_copy_from_outside(&arg, cmd->ptr2 + (iter * sizeof(word)), sizeof(arg));
			if (err < 0) {
				stack_free(&stack);
				err = create_error(file_cont, err);
				goto clean;
			}

			if (NULL == stack_push(&stack, &arg)) {
				stack_free(&stack);
				ERROR_CLEAN(create_error(file_cont, -ERROR_MEM));
			}
		}

		/* execute the function and create an answer */
		arg = vm_run_function(func, &stack, &excep);

		stack_free(&stack);

		if (excep.had_exception) {
			err = -EINVAL; /* it dosen't really matter which error. the value of the error will be taken from the answer */
			arg = excep.value;
		} else {
			err = (int)count;
		}

		context_create_reply(file_cont, arg, &excep);

		goto clean;

	case KPLUGS_GET_LAST_EXCEPTION:
		if (NULL != cmd->uptr2 || cmd->len1 < sizeof(exception_t) || cmd->len2) {
			ERROR(create_error(file_cont, -ERROR_PARAM));
		}

		err = context_get_last_exception(file_cont, (exception_t *)cmd->ptr1);
		if (err < 0) {
			return create_error(file_cont, err);
		}

		return count;

	default:
		return create_error(file_cont, -ERROR_PARAM);
	}
clean:
	if (NULL != func) {
		function_put(func);
	} else if (NULL != code) {
		memory_free(code);
	}
	return err;
}
Example #24
0
texception::texception(const std::string& operation, const bool use_sdl_error)
	: game::error(create_error(operation, use_sdl_error))
{
}
Example #25
0
error_info create_error(const dnet_cmd &cmd)
{
	return create_error(cmd.status, cmd.id, "Failed to process %s command", dnet_cmd_string(cmd.cmd));
}
Example #26
0
static void
filedsn_configure (TDSNCHOOSER *choose_t, char *drv, char *dsn, char *in_attrs,
	BOOL b_add, BOOL verify_conn)
{
  char *connstr = NULL;
  size_t len;			/* current connstr len    */
  size_t add_len;		/* len of appended string */
  LPSTR attrs = NULL, curr, tmp, attr_lst = NULL;
  BOOL b_Save = TRUE;
  
  attrs = in_attrs;

  if (!b_add && !_CheckDriverLoginDlg(drv + STRLEN("DRIVER=")))
    {
      /*  Get DSN name and additional attributes  */
      attr_lst = create_gensetup (choose_t->mainwnd, dsn, in_attrs, 
         b_add, &verify_conn);
      attrs = attr_lst;
    }

  if (!attrs)
    {
      create_error (choose_t->mainwnd, NULL, "Error adding File DSN:",
          strerror (ENOMEM));
      return;
    }
  if (attrs == (LPSTR) - 1L)
    return;


  /* Build the connection string */
  connstr = strdup (drv);
  len = strlen (connstr);
  for (curr = attrs; *curr; curr += (STRLEN (curr) + 1))
    {
      if (!strncasecmp (curr, "DSN=", STRLEN ("DSN=")))
        {
          if (dsn == NULL)
            {
	      /* got dsn name */
              dsn = curr + STRLEN ("DSN=");
            }
	  continue;
	}

      /* append attr */
      add_len = 1 + strlen (curr);			/* +1 for ';' */
      tmp = realloc (connstr, len + add_len + 1);	/* +1 for NUL */
      if (tmp == NULL)
        {
          create_error (choose_t->mainwnd, NULL, "Error adding File DSN:",
	      strerror (errno));
	  goto done;
	}
      connstr = tmp;
      snprintf (connstr + len, add_len + 1, ";%s", curr);
      len += add_len;
    }

  /* Nothing to do if no DSN */
  if (!dsn || STRLEN (dsn) == 0)
    goto done;

  if (verify_conn)
    {
      BOOL ret;

      /* Append SAVEFILE */
      add_len = strlen (";SAVEFILE=") + strlen (dsn);
      tmp = realloc (connstr, len + add_len + 1);		/* +1 for NUL */
      if (tmp == NULL)
        {
          create_error (choose_t->mainwnd, NULL, "Error adding file DSN:",
	      strerror (errno));
          goto done;
        }
      connstr = tmp;
      snprintf (connstr + len, add_len + 1, ";SAVEFILE=%s", dsn);
      len += add_len;

      /* Connect to data source */
      ret = test_driver_connect (choose_t, connstr);
      if (!ret && b_add)
        { 
	  if (create_confirm (choose_t->mainwnd, dsn,
	      "Can't check the connection. Do you want to store the FileDSN without verification ?"))
            b_Save = TRUE;
          else
            b_Save = FALSE;
        }
      else
        b_Save = FALSE;
    }

  if (b_Save)
    {
      char key[512];
      char *p;
      size_t sz;

      if (drv)
        {
	  p = strchr(drv, '=');
          if (!SQLWriteFileDSN (dsn, "ODBC", "DRIVER", p + 1))
            {
              create_error (choose_t->mainwnd, NULL, "Error adding File DSN:",
	          strerror (errno));
	      goto done;
	    }
        }

      for (curr = attrs; *curr; curr += (STRLEN (curr) + 1))
        {
          if (!strncasecmp (curr, "DSN=", STRLEN ("DSN=")))
	    continue;
	  else if (!strncasecmp (curr, "PWD=", STRLEN ("PWD=")))
	    continue;
	  else if (!strncasecmp (curr, "SAVEFILE=", STRLEN ("SAVEFILE=")))
	    continue;
	  else if (!strncasecmp (curr, "FILEDSN=", STRLEN ("FILEDSN=")))
	    continue;

	  p = strchr(curr, '=');
	  sz = p - curr < sizeof(key) ? p - curr : sizeof(key);
	  memset(key, 0, sizeof(key));
	  strncpy(key, curr, sz);

          if (!SQLWriteFileDSN (dsn, "ODBC", key, p + 1))
            {
              create_error (choose_t->mainwnd, NULL, "Error adding File DSN:",
	          strerror (errno));
	      goto done;
	    }
        }
    }

done:
  if (attr_lst != NULL)
    free (attr_lst);
  if (connstr != NULL)
    free (connstr);
}