Exemple #1
0
static inline void load_config(void) {
	/* FIXME */
	if ((cfg = config_load("/etc/xcb/impvbaw.conf"))) {
		char *cat = category_browse(cfg, NULL);
		struct variable *var;

		while (cat) {
			if (!strcasecmp(cat, "general")) {
				var = variable_browse(cfg, cat);
				while (var) {
					if (!strcasecmp(var->name, "rate")) {
						if (strcmp(var->value, ""))
							r = atof(var->value);
					} else
						xcb_log(XCB_LOG_WARNING, "Unknown variable '%s' in "
							"category '%s' of impvbaw.conf", var->name, cat);
					var = var->next;
				}
			} else if (!strcasecmp(cat, "expiries")) {
				table_node_t node;

				var = variable_browse(cfg, cat);
				while (var) {
					/* FIXME */
					if ((node = table_insert_raw(expiries, var->name)))
						table_set_double(node, diffnow(atoi(var->value)) / 252.0);
					var = var->next;
				}
			}
			cat = category_browse(cfg, cat);
		}
	}
}
Exemple #2
0
static inline void load_config(void) {
	/* FIXME */
	if ((cfg = config_load("/etc/xcb/csi300.conf"))) {
		char *cat = category_browse(cfg, NULL);
		struct variable *var;

		while (cat) {
			if (!strcasecmp(cat, "weights")) {
				var = variable_browse(cfg, cat);
				while (var) {
					struct wp *wp;

					if (NEW(wp)) {
						wp->weight = atof(var->value);
						wp->price  = NAN;
						table_insert(contracts, var->name, wp);
					}
					var = var->next;
				}
			} else if (!strcasecmp(cat, "divisor"))
				if ((var = variable_browse(cfg, cat)) && strcmp(var->value, ""))
					divisor = atof(var->value);
			cat = category_browse(cfg, cat);
		}
	}
}
Exemple #3
0
static inline void load_config(void) {
	/* FIXME */
	if ((cfg = config_load("/etc/xcb/sse50etf.conf"))) {
		char *cat = category_browse(cfg, NULL);
		struct variable *var;

		while (cat) {
			if (!strcasecmp(cat, "general")) {
				var = variable_browse(cfg, cat);
				while (var) {
					if (!strcasecmp(var->name, "CRU")) {
						if (strcmp(var->value, ""))
							cru = atoi(var->value);
					} else if (!strcasecmp(var->name, "ECC")) {
						if (strcmp(var->value, ""))
							ecc = atof(var->value);
					} else
						xcb_log(XCB_LOG_WARNING, "Unknown variable '%s' in "
							"category '%s' of sse50etf.conf", var->name, cat);
					var = var->next;
				}
			} else if (!strcasecmp(cat, "weights")) {
				var = variable_browse(cfg, cat);
				while (var) {
					struct wp *wp;

					if (NEW(wp)) {
						wp->weight = atof(var->value);
						wp->price  = NAN;
						wp->type   = 1;
						table_insert(contracts, var->name, wp);
					}
					var = var->next;
				}
			} else if (!strcasecmp(cat, "prices")) {
				var = variable_browse(cfg, cat);
				while (var) {
					struct wp *wp;

					if (NEW(wp)) {
						wp->weight = 1.0;
						wp->price  = atof(var->value);
						wp->type   = 2;
						table_insert(contracts, var->name, wp);
					}
					var = var->next;
				}
			}
			cat = category_browse(cfg, cat);
		}
	}
}
Exemple #4
0
static inline void load_config(void) {
	/* FIXME */
	if ((cfg = config_load("/etc/xcb/pd.conf"))) {
		char *cat = category_browse(cfg, NULL);

		while (cat) {
			if (!strcasecmp(cat, "pair")) {
				struct variable *var = variable_browse(cfg, cat);
				struct cpl *cpl = NULL;

				while (var) {
					if (!strcasecmp(var->name, "contract1")) {
						if (!strcasecmp(var->value, ""))
							break;
						if (cpl == NULL) {
							if (NEW(cpl) == NULL)
								break;
							cpl->contract2 = NULL;
							cpl->price1 = cpl->price2 = cpl->prevpd = -1.0;
							pthread_spin_init(&cpl->lock, 0);
						}
						cpl->contract1 = var->value;

					} else if (!strcasecmp(var->name, "contract2")) {
						if (!strcasecmp(var->value, ""))
							break;
						if (cpl == NULL) {
							if (NEW(cpl) == NULL)
								break;
							cpl->contract1 = NULL;
							cpl->price1 = cpl->price2 = cpl->prevpd = -1.0;
							pthread_spin_init(&cpl->lock, 0);
						}
						cpl->contract2 = var->value;
					} else
						xcb_log(XCB_LOG_WARNING, "Unknown variable '%s' in "
							"category '%s' of pd.conf", var->name, cat);
					var = var->next;
				}
				if (cpl && cpl->contract1 && cpl->contract2) {
					dlist_t dlist;

					if ((dlist = table_get_value(contracts, cpl->contract1)) == NULL) {
						dlist = dlist_new(NULL, NULL);
						table_insert(contracts, cpl->contract1, dlist);
					}
					dlist_insert_tail(dlist, cpl);
					if ((dlist = table_get_value(contracts, cpl->contract2)) == NULL) {
						dlist = dlist_new(NULL, NULL);
						table_insert(contracts, cpl->contract2, dlist);
					}
					dlist_insert_tail(dlist, cpl);
					dlist_insert_tail(pairs, cpl);
				} else if (cpl)
					FREE(cpl);
			}
			cat = category_browse(cfg, cat);
		}
	}
}
Exemple #5
0
const char *variable_retrieve(struct config *cfg, const char *category, const char *variable) {
	struct variable *var;

	if (cfg == NULL)
		return NULL;
	if (category) {
		for (var = variable_browse(cfg, category); var; var = var->next)
			if (!strcasecmp(var->name, variable))
				return var->value;
	} else {
		struct category *cat;

		for (cat = cfg->first; cat; cat = cat->next)
			for (var = cat->first; var; var = var->next)
				if (!strcasecmp(var->name, variable))
					return var->value;
	}
	return NULL;
}
Exemple #6
0
static inline void load_config(void) {
	/* FIXME */
	if ((cfg = config_load("/etc/xcb/xspeed.conf"))) {
		char *cat = category_browse(cfg, NULL);

		while (cat) {
			if (!strcasecmp(cat, "general")) {
				struct variable *var = variable_browse(cfg, cat);

				while (var) {
					if (!strcasecmp(var->name, "front_ip")) {
						if (strcasecmp(var->value, ""))
							front_ip = var->value;
					} else if (!strcasecmp(var->name, "front_port")) {
						if (strcasecmp(var->value, ""))
							front_port = var->value;
					} else if (!strcasecmp(var->name, "userid")) {
						if (strcasecmp(var->value, ""))
							userid = var->value;
					} else if (!strcasecmp(var->name, "passwd")) {
						if (strcasecmp(var->value, ""))
							passwd = var->value;
					} else if (!strcasecmp(var->name, "reqid")) {
						if (strcasecmp(var->value, ""))
							reqid = atoi(var->value);
					} else if (!strcasecmp(var->name, "contracts")) {
						if (strcasecmp(var->value, ""))
							contracts= var->value;
					} else
						xcb_log(XCB_LOG_WARNING, "Unknown variable '%s' in "
							"category '%s' of xspeed.conf", var->name, cat);
					var = var->next;
				}
			}
			cat = category_browse(cfg, cat);
		}
	}
}
Exemple #7
0
static void load_config(void) {
	/* FIXME */
	if ((cfg = config_load("/etc/xcb/ema.conf"))) {
		char *cat = category_browse(cfg, NULL);

		while (cat ) {
			if (!strcasecmp(cat, "general")) {
				struct variable *var = variable_browse(cfg, cat);

				while (var) {
					if (!strcasecmp(var->name, "number")) {
						if (strcasecmp(var->value, ""))
							n = atoi(var->value);
					} else
						xcb_log(XCB_LOG_WARNING, "Unknown variable '%s' in "
							"category '%s' of ema.conf", var->name, cat);
					var = var->next;
				}
			}
			cat = category_browse(cfg, cat);
		}
	}
}
Exemple #8
0
/* FIXME */
static void init_pgm_send_cfg(struct pgm_cfg *pgm_send_cfg) {
	char *cat = category_browse(cfg, NULL);

	while (cat) {
		if (!strcasecmp(cat, "pgm_sender")) {
			struct variable *var = variable_browse(cfg, cat);

			while (var) {
				if (!strcasecmp(var->name, "network")) {
					if (strcmp(var->value, ""))
						pgm_send_cfg->network = var->value;
				} else if (!strcasecmp(var->name, "port")) {
					if (strcmp(var->value, ""))
						pgm_send_cfg->port = atoi(var->value);
				} else
					xcb_log(XCB_LOG_WARNING, "Unknown variable '%s' in category '%s'"
						" of xcb-dp2.conf", var->name, cat);
				var = var->next;
			}
		}
		cat = category_browse(cfg, cat);
	}
}
Exemple #9
0
int main(int argc, char **argv) {
	int ncmds, i;
	const char *tmp;
	pgm_error_t *pgm_err = NULL;

	/* FIXME */
	signal(SIGPIPE, SIG_IGN);
	setup_signal_handlers();
	cmds = table_new(cmpstr, hashmurmur2, NULL, NULL);
	ncmds = sizeof commands / sizeof (struct cmd);
	for (i = 0; i < ncmds; ++i) {
		struct cmd *cmd = commands + i;

		table_insert(cmds, cmd->name, cmd);
	}
	if (argc != 2 && argc != 3)
		usage();
	else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
		usage();
	else if (argc == 3 && strcmp(argv[1], "-f"))
		usage();
	if (argc == 2 && daemon(1, 0) == -1)
		fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
	/* FIXME */
	if (init_logger("/var/log/xcb/xcb-dp2.log", __LOG_DEBUG) == -1) {
		fprintf(stderr, "Error initializing logger\n");
		exit(1);
	}
	cfg_path = argc == 2 ? argv[1] : argv[2];
	if ((cfg = config_load(cfg_path)) == NULL)
		exit(1);
	if ((tmp = variable_retrieve(cfg, "general", "log_level"))) {
		if (!strcasecmp(tmp, "info"))
			set_logger_level(__LOG_INFO);
		else if (!strcasecmp(tmp, "notice"))
			set_logger_level(__LOG_NOTICE);
		else if (!strcasecmp(tmp, "warning"))
			set_logger_level(__LOG_WARNING);
	}
	/* FIXME */
	if (addms)
		times = table_new(cmpstr, hashmurmur2, kfree, vfree);
	clients_to_close = dlist_new(NULL, NULL);
	clients = dlist_new(NULL, NULL);
	monitors = dlist_new(NULL, NULL);
	tp = thrpool_new(16, 256, 200, NULL);
	if (!pgm_init(&pgm_err)) {
		xcb_log(XCB_LOG_ERROR, "Error starting PGM engine: %s", pgm_err->message);
		pgm_error_free(pgm_err);
		goto err;
	}
	/* FIXME */
	if (NEW(pgm_send_cfg) == NULL) {
		xcb_log(XCB_LOG_ERROR, "Error allocating memory for PGM cfg");
		goto err;
	}
	pgm_send_cfg->network = NULL;
	pgm_send_cfg->port    = 0;
	init_pgm_send_cfg(pgm_send_cfg);
	if (pgm_send_cfg->network == NULL) {
		xcb_log(XCB_LOG_ERROR, "PGM network can't be NULL");
		goto err;
	}
	if (pgm_send_cfg->port == 0) {
		xcb_log(XCB_LOG_ERROR, "PGM port can't be zero");
		goto err;
	}
	if ((pgm_sender = pgmsock_create(pgm_send_cfg->network, pgm_send_cfg->port, PGMSOCK_SENDER)) == NULL)
		goto err;
	/* FIXME */
	if ((el = create_event_loop(1024 + 1000)) == NULL) {
		xcb_log(XCB_LOG_ERROR, "Error creating event loop");
		goto err;
	}
	create_time_event(el, 1, server_cron, NULL, NULL);
	/* FIXME */
	if ((tmp = variable_retrieve(cfg, "modules", "module_path")) && strcmp(tmp, "")) {
		struct variable *var = variable_browse(cfg, "modules");
		dlist_t noloads = dlist_new(cmpstr, NULL);
		DIR *dir;
		struct dirent *dirent;

		while (var) {
			if (!strcasecmp(var->name, "preload")) {
				if (strcmp(var->value, "")) {
					int len = strlen(var->value);

					if (len >= 4 && !strcasecmp(var->value + len - 3, ".so") &&
						!strncasecmp(var->value, "md", 2))
						module_load(tmp, var->value);
				}
			} else if (!strcasecmp(var->name, "noload") && !strncasecmp(var->value, "md", 2))
				if (strcmp(var->value, ""))
					dlist_insert_tail(noloads, (void *)var->value);
			var = var->next;
		}
		if ((dir = opendir(tmp))) {
			while ((dirent = readdir(dir))) {
				int len = strlen(dirent->d_name);

				if (len < 4)
					continue;
				if (strcasecmp(dirent->d_name + len - 3, ".so") ||
					strncasecmp(dirent->d_name, "md", 2))
					continue;
				if (dlist_find(noloads, dirent->d_name))
					continue;
				module_load(tmp, dirent->d_name);
			}
			closedir(dir);
		} else
			xcb_log(XCB_LOG_WARNING, "Unable to open modules directory '%s'", tmp);
		dlist_free(&noloads);
	}
	if ((tmp = variable_retrieve(cfg, "general", "udp_port")) && strcmp(tmp, "")) {
		if ((udpsock = net_udp_server(NULL, atoi(tmp), neterr, sizeof neterr)) == -1) {
			xcb_log(XCB_LOG_ERROR, "Opening port '%s': %s", tmp, neterr);
			goto err;
		}
		if (net_nonblock(udpsock, neterr, sizeof neterr) == -1) {
			xcb_log(XCB_LOG_ERROR, "Setting port '%s' nonblocking: %s", tmp, neterr);
			goto err;
		}
	}
	if ((tmp = variable_retrieve(cfg, "general", "tcp_port")) && strcmp(tmp, ""))
		if ((tcpsock = net_tcp_server(NULL, atoi(tmp), neterr, sizeof neterr)) == -1) {
			xcb_log(XCB_LOG_ERROR, "Opening port '%s': %s", tmp, neterr);
			goto err;
		}
	if (udpsock > 0 && create_file_event(el, udpsock, EVENT_READABLE, read_quote, NULL) == -1) {
		xcb_log(XCB_LOG_ERROR, "Unrecoverable error creating udpsock '%d' file event", udpsock);
		goto err;
	}
	if (tcpsock > 0 && create_file_event(el, tcpsock, EVENT_READABLE, tcp_accept_handler, NULL) == -1) {
		xcb_log(XCB_LOG_ERROR, "Unrecoverable error creating tcpsock '%d' file event", tcpsock);
		goto err;
	}
	xcb_log(XCB_LOG_NOTICE, "Server dispatcher started");
	start_event_loop(el, ALL_EVENTS);
	delete_event_loop(el);
	pgm_shutdown();
	return 0;

err:
	close_logger();
	exit(1);
}
Exemple #10
0
static inline void load_config(void) {
	/* FIXME */
	if ((cfg = config_load("/etc/xcb/vxo.conf"))) {
		char *cat = category_browse(cfg, NULL);
		struct variable *var;

		while (cat) {
			if (!strcasecmp(cat, "general")) {
				struct variable *var = variable_browse(cfg, cat);

				while (var) {
					if (!strcasecmp(var->name, "inmsg")) {
						if (strcmp(var->value, ""))
							inmsg = var->value;
					} else
						xcb_log(XCB_LOG_WARNING, "Unknown variable '%s' in "
							"category '%s' of vxo.conf", var->name, cat);
					var = var->next;
				}
			} else if (!strcasecmp(cat, "expiries")) {
				var = variable_browse(cfg, cat);
				while (var) {
					char *p;

					if ((p = strrchr(var->name, 'C')) == NULL)
						p = strrchr(var->name, 'P');
					if (p && p != var->name && p != var->name + strlen(var->name) - 1 &&
						((*(p - 1) == '-' && *(p + 1) == '-') ||
						(isdigit(*(p - 1)) && isdigit(*(p + 1))))) {
						dstr spotname, strike;
						struct pd *pd;
						struct scp *scp;

						spotname = *(p - 1) == '-'
							? dstr_new_len(var->name, p - var->name - 1)
							: dstr_new_len(var->name, p - var->name);
						strike   = *(p + 1) == '-'
							? dstr_new_len(p + 2, var->name + strlen(var->name) - p - 2)
							: dstr_new_len(p + 1, var->name + strlen(var->name) - p - 1);
						if ((pd = table_get_value(spots, spotname)) == NULL) {
							if (NEW(scp)) {
								scp->strike = atof(strike);
								scp->cvol   = scp->pvol  = NAN;
								scp->cvol2  = scp->pvol2 = NAN;
								scp->cvol3  = scp->pvol3 = NAN;
								if (NEW(pd)) {
									pd->prevxo = pd->prevxo2 = pd->prevxo3 = NAN;
									pd->sep    = *(p - 1) == '-' ? "-" : "";
									pd->dlist  = dlist_new(NULL, scpfree);
									dlist_insert_tail(pd->dlist, scp);
									table_insert(spots, spotname, pd);
								} else
									FREE(scp);
							} else
								dstr_free(spotname);
						} else {
							dlist_iter_t iter = dlist_iter_new(pd->dlist, DLIST_START_HEAD);
							dlist_node_t node;

							while ((node = dlist_next(iter))) {
								scp = (struct scp *)dlist_node_value(node);
								if (scp->strike > atof(strike) ||
									fabs(scp->strike - atof(strike)) <= 0.000001)
									break;
							}
							dlist_iter_free(&iter);
							if (node == NULL || scp->strike > atof(strike)) {
								if (NEW(scp)) {
									scp->strike = atof(strike);
									scp->cvol   = scp->pvol  = NAN;
									scp->cvol2  = scp->pvol2 = NAN;
									scp->cvol3  = scp->pvol3 = NAN;
								}
								if (node == NULL)
									dlist_insert_tail(pd->dlist, scp);
								else
									dlist_insert(pd->dlist, node, scp, 0);
							}
							dstr_free(spotname);
						}
						dstr_free(strike);
					}
					var = var->next;
				}
			}
			cat = category_browse(cfg, cat);
		}
	}
}