Example #1
0
// {
//   node: <node_public>,
//   comment: <comment>             // optional
// }
Json::Value doUnlAdd (RPC::Context& context)
{
    auto lock = make_lock(context.app.getMasterMutex());

    if (!context.params.isMember (jss::node))
        return rpcError (rpcINVALID_PARAMS);

    auto const id = parseBase58<PublicKey>(
        TokenType::TOKEN_NODE_PUBLIC,
        context.params[jss::node].asString ());

    if (!id)
        return rpcError (rpcINVALID_PARAMS);

    auto const added = context.app.validators().insertPermanentKey (
        *id,
        context.params.isMember (jss::comment)
            ? context.params[jss::comment].asString ()
            : "");

    Json::Value ret (Json::objectValue);
    ret[jss::pubkey_validator] = context.params[jss::node];
    ret[jss::status] = added ? "added" : "already present";
    return ret;
}
Example #2
0
// {
//   ip: <string>,
//   port: <number>
// }
// XXX Might allow domain for manual connections.
Json::Value doConnect (RPC::Context& context)
{
    auto lock = make_lock(context.app.getMasterMutex());
    if (context.app.config().standalone())
        return "cannot connect in standalone mode";

    if (!context.params.isMember (jss::ip))
        return RPC::missing_field_error (jss::ip);

    if (context.params.isMember (jss::port) &&
        !context.params[jss::port].isConvertibleTo (Json::intValue))
    {
        return rpcError (rpcINVALID_PARAMS);
    }

    int iPort;

    if(context.params.isMember (jss::port))
        iPort = context.params[jss::port].asInt ();
    else
        iPort = 6561;

    auto ip = beast::IP::Endpoint::from_string(
        context.params[jss::ip].asString ());

    if (! is_unspecified (ip))
        context.app.overlay ().connect (ip.at_port(iPort));

    return RPC::makeObjectValue ("connecting");
}
Example #3
0
Environment *make_environment ()
{
    int i;

    Environment *env = (Environment *) malloc (sizeof (Environment));
    if (env == NULL) {
	perror ("malloc failed");
	exit (-1);
    }
    env->next_id = 0;

    for (i=0; i<SIZE; i++) {
	env->array[i] = 0;
    }

    env->lock = make_lock ();
    return env;
}
Example #4
0
Json::Value doUnlList (RPC::Context& context)
{
    auto lock = make_lock(context.app.getMasterMutex());
    Json::Value obj (Json::objectValue);

    context.app.validators().for_each_listed (
        [&unl = obj[jss::unl]](
            PublicKey const& publicKey,
            bool trusted)
        {
            Json::Value node (Json::objectValue);

            node[jss::pubkey_validator] = toBase58(
                TokenType::TOKEN_NODE_PUBLIC, publicKey);
            node[jss::trusted] = trusted;

            unl.append (node);
        });

    return obj;
}
Example #5
0
int main(int argc, char *argv[])
{
	int n,
		show_days = 0,
		but_stat  = 0,
		microtm   = 0,
		running   = 0,
		force     = 0;
	time_t
		last_time = 0;
	char
		*geometry = NULL,
		*xdisplay = NULL;
	static int signals[] =
		{SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2, 0};
	XEvent Event;

	assert(sizeof(char) == 1);

	umask(077);
	do_opts(argc, argv, &show_days, &xdisplay, &geometry, &force);

	path_len = strlen(getenv("HOME")) + strlen("/.wmwork/worklog") + 1;
	if ((dirName = malloc(path_len)) == NULL || (logname = malloc(path_len)) == NULL || (lockname = malloc(path_len)) == NULL) {
		fprintf(stderr, "%s: cannot allocate memory for path variable\n", PACKAGE_NAME);
		fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
		exit(1);
	}
	snprintf(dirName,  path_len, "%s/.wmwork", getenv("HOME"));
	snprintf(logname,  path_len, "%s/worklog", dirName);
	snprintf(lockname, path_len, "%s/.#LOCK",  dirName);
	if (chdir(dirName) < 0) {
		if (errno == ENOENT) {
			if (mkdir(dirName, 0777)) {
				fprintf(stderr, "%s: cannot mkdir '%s'\n", PACKAGE_NAME, dirName);
				fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
				exit(1);
			}
			compat();
		} else {
			fprintf(stderr, "%s: cannot chdir into '%s'\n", PACKAGE_NAME, dirName);
			fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
			exit(1);
		}
	}

	for (n = 0; signals[n]; n++) {
		if (signal(signals[n], handler) == SIG_ERR) {
			fprintf(stderr, "%s: cannot set handler for signal %d\n", PACKAGE_NAME, signals[n]);
			fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
		}
	}

	make_lock(force);
	atexit(at_exit);
	read_log();
	current = first;

	initXwindow(xdisplay);
	createXBMfromXPM(wmwork_mask_bits, wmwork_master_xpm, 64, 64);
	openXwindow(argc, argv, wmwork_master_xpm, wmwork_mask_bits, 64, 64, geometry, NULL);
	AddMouseRegion(BUT_START,  5, 48, 22, 58);
	AddMouseRegion(BUT_PAUSE, 23, 48, 40, 58);
	AddMouseRegion(BUT_STOP,  41, 48, 58, 58);
	AddMouseRegion(BUT_PREV,   5, 33, 16, 43);
	AddMouseRegion(BUT_NEXT,  47, 33, 58, 43);
	drawTime(current->time, sess_time, microtm, show_days, running);
	drawProject(current->name);

	while (1) {
		last_time = now.tv_sec;
		gettimeofday(&now, &tz);
		if (running) {
			current->time += now.tv_sec - last_time;
			sess_time     += now.tv_sec - last_time;
			microtm        = now.tv_usec;
			drawTime(current->time, sess_time, microtm, show_days, running);
			RedrawWindow();
		}
		while (XPending(display)) {
			XNextEvent(display, &Event);
			switch (Event.type) {
			case Expose:
				RedrawWindow();
				break;
			case DestroyNotify:
				XCloseDisplay(display);
				exit(0);
			case ButtonPress:
				n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
				switch (n) {
				case BUT_START:
				case BUT_PAUSE:
				case BUT_STOP:
				case BUT_PREV:
				case BUT_NEXT:
					ButtonDown(n);
					break;
				}
				but_stat = n;
				RedrawWindow();
				break;
			case ButtonRelease:
				n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
				switch (but_stat) {
				case BUT_START:
				case BUT_PAUSE:
				case BUT_STOP:
				case BUT_PREV:
				case BUT_NEXT:
					ButtonUp(but_stat);
					break;
				}
				if (but_stat && n == but_stat) {
					switch (but_stat) {
					case BUT_START:
						running = 1;
						break;
					case BUT_PAUSE:
						running = 0;
						break;
					case BUT_STOP:
						write_log();
						write_record();
						running   = 0;
						sess_time = 0;
						break;
					case BUT_PREV:
						if (!running && sess_time == 0)
							current = current->prev;
						break;
					case BUT_NEXT:
						if (!running && sess_time == 0)
							current = current->next;
						break;
					}
					drawTime(current->time, sess_time, microtm, show_days, running);
					drawProject(current->name);
				}
				RedrawWindow();
				but_stat = 0;
				break;
			}
		}
		usleep(50000L);
		if (do_exit)
			exit(0);
	}
}