Exemplo n.º 1
0
static bool cfg_get_log_target(gn_log_target *t, const char *opt)
{
	char *val;

	if (!(val = gn_cfg_get(gn_cfg_info, "logging", opt)))
		val = "off";

	if (!strcasecmp(val, "off"))
		*t = GN_LOG_T_NONE;
	else if (!strcasecmp(val, "on"))
		*t = GN_LOG_T_STDERR;
	else {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), "logging", opt, val);
		fprintf(stderr, _("Use either \"%s\" or \"%s\".\n"), "off", "on");
		fprintf(stderr, _("Assuming: %s\n"), "off");
		*t = GN_LOG_T_NONE;
	}

	return true;
}
Exemplo n.º 2
0
/* Load phone flags from config or fallback to the static array in misc.c */
gn_phone_model *gn_cfg_get_phone_model(struct gn_cfg_header *cfg, const char *product_name)
{
	struct gn_cfg_header *hdr;
	char *val, *comma, *end, *section = "flags";
	int count;
	static gn_phone_model phone_model = {NULL, NULL, 0};
	gn_phone_model *found_phone_model;
	static char model[GN_MODEL_MAX_LENGTH] = "";

	if (phone_model.model)
		return &phone_model;

	val = gn_cfg_get(gn_cfg_info, section, product_name);
	if (val) {
		phone_model.model = model;
		/* Ignore trailing whitespace (leading whitespace has been stripped when loading the config file) */
		comma = val;
		while (*comma && *comma != ',')
			comma++;
		end = comma;
		while (end > val && (isspace(*end) || *end == ','))
			end--;
		count = end - val + 1;
		snprintf(model, GN_MODEL_MAX_LENGTH, "%.*s", count, val);

		/* Check flags */
		val = comma;
		for (;;) {
			while (*val && *val != ',')
				val++;
			/* This skips also empty fields */
			while (*val && (*val == ',' || isspace(*val)))
				val++;
			if (!*val)
				break;
			SETFLAG(OLD_DEFAULT);
			SETFLAG(DEFAULT);
			SETFLAG(DEFAULT_S40_3RD);
			SETFLAG(CALLERGROUP);
			SETFLAG(NETMONITOR);
			SETFLAG(KEYBOARD);
			SETFLAG(SMS);
			SETFLAG(CALENDAR);
			SETFLAG(DTMF);
			SETFLAG(DATA);
			SETFLAG(SPEEDDIAL);
			SETFLAG(EXTPBK);
			SETFLAG(AUTHENTICATION);
			SETFLAG(FOLDERS);
			SETFLAG(FULLPBK);
			SETFLAG(SMSFILE);
			SETFLAG(EXTPBK2);
			SETFLAG(EXTCALENDAR);
			SETFLAG(XGNOKIIBREAKAGE);
			/* FIXME? duplicated code from above */
			comma = val;
			while (*comma && *comma != ',')
				comma++;
			end = comma;
			while (end > val && (isspace(*end) || *end == ','))
				end--;
			count = end - val + 1;
			dprintf("Unknown flag \"%.*s\"\n", count, val);
		}
		return &phone_model;
	}
#undef SETFLAG

	found_phone_model = gn_phone_model_get(product_name);
	if (found_phone_model->model)
		return found_phone_model;

	/* Give the user some hint on why the product_name wasn't found */
	hdr = cfg_header_get(cfg, (char *)section);
	if (!hdr) {
		fprintf(stderr, _("No %s section in the config file.\n"), section);
	}

	return &phone_model;
}
Exemplo n.º 3
0
static gn_error cfg_psection_load(gn_config *cfg, const char *section, const gn_config *def)
{
	const char *val;
	char ch;

	memset(cfg, '\0', sizeof(gn_config));

	if (!cfg_section_exists(gn_cfg_info, section)) {
		fprintf(stderr, _("No %s section in the config file.\n"), section);
		return GN_ERR_NOPHONE;
	}

	/* You need to specify at least model, port and connection in the phone section */
	if (!(val = gn_cfg_get(gn_cfg_info, section, "model"))) {
		fprintf(stderr, _("You need to define '%s' in the config file.\n"), "model");
		return GN_ERR_NOMODEL;
	} else
		snprintf(cfg->model, sizeof(cfg->model), "%s", val);

	if (!(val = gn_cfg_get(gn_cfg_info, section, "port"))) {
		fprintf(stderr, _("You need to define '%s' in the config file.\n"), "port");
		return GN_ERR_NOPORT;
	} else
		snprintf(cfg->port_device, sizeof(cfg->port_device), "%s", val);

	if (!(val = gn_cfg_get(gn_cfg_info, section, "connection"))) {
		fprintf(stderr, _("You need to define '%s' in the config file.\n"), "connection");
		return GN_ERR_NOCONNECTION;
	} else {
		cfg->connection_type = gn_get_connectiontype(val);
		if (cfg->connection_type == GN_CT_NONE) {
			fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "connection", val);
			return GN_ERR_NOCONNECTION;
		}
		if (!strcmp("pcsc", val))
			fprintf(stderr, "WARNING: %s=%s is deprecated and will soon be removed. Use %s=%s instead.\n", "connection", val, "connection", "libpcsclite");
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "initlength")))
		cfg->init_length = def->init_length;
	else {
		if (!strcasecmp(val, "default"))
			cfg->init_length = 0;
		else if (sscanf(val, " %d %c", &cfg->init_length, &ch) != 1) {
			fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "initlength", val);
			fprintf(stderr, _("Assuming: %d\n"), def->init_length);
			cfg->init_length = def->init_length;
		}
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "serial_baudrate")))
		cfg->serial_baudrate = def->serial_baudrate;
	else if (sscanf(val, " %d %c", &cfg->serial_baudrate, &ch) != 1) {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "serial_baudrate", val);
		fprintf(stderr, _("Assuming: %d\n"), def->serial_baudrate);
		cfg->serial_baudrate = def->serial_baudrate;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "serial_write_usleep")))
		cfg->serial_write_usleep = def->serial_write_usleep;
	else if (sscanf(val, " %d %c", &cfg->serial_write_usleep, &ch) != 1) {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "serial_write_usleep", val);
		fprintf(stderr, _("Assuming: %d\n"), def->serial_write_usleep);
		cfg->serial_write_usleep = def->serial_write_usleep;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "handshake")))
		cfg->hardware_handshake = def->hardware_handshake;
	else if (!strcasecmp(val, "software") || !strcasecmp(val, "rtscts"))
		cfg->hardware_handshake = false;
	else if (!strcasecmp(val, "hardware") || !strcasecmp(val, "xonxoff"))
		cfg->hardware_handshake = true;
	else {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "handshake", val);
		fprintf(stderr, _("Use either \"%s\" or \"%s\".\n"), "software", "hardware");
		fprintf(stderr, _("Assuming: %s\n"), def->hardware_handshake ? "software" : "hardware");
		cfg->hardware_handshake = def->hardware_handshake;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "require_dcd")))
		cfg->require_dcd = def->require_dcd;
	else if (sscanf(val, " %d %c", &cfg->require_dcd, &ch) != 1) {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "require_dcd", val);
		fprintf(stderr, _("Assuming: %d\n"), def->require_dcd);
		cfg->require_dcd = def->require_dcd;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "set_dtr_rts")))
		cfg->set_dtr_rts = def->set_dtr_rts;
	else if (sscanf(val, " %d %c", &cfg->set_dtr_rts, &ch) != 1) {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "set_dtr_rts", val);
		fprintf(stderr, _("Assuming: %d\n"), def->set_dtr_rts);
		cfg->set_dtr_rts = def->set_dtr_rts;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "smsc_timeout")))
		cfg->smsc_timeout = def->smsc_timeout;
	else if (sscanf(val, " %d %c", &cfg->smsc_timeout, &ch) == 1)
		cfg->smsc_timeout *= 10;
	else {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "smsc_timeout", val);
		fprintf(stderr, _("Assuming: %d\n"), def->smsc_timeout);
		cfg->smsc_timeout = def->smsc_timeout;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "connect_script")))
		snprintf(cfg->connect_script, sizeof(cfg->connect_script), "%s", def->connect_script);
	else
		snprintf(cfg->connect_script, sizeof(cfg->connect_script), "%s", val);

	if (!(val = gn_cfg_get(gn_cfg_info, section, "disconnect_script")))
		snprintf(cfg->disconnect_script, sizeof(cfg->disconnect_script), "%s", def->disconnect_script);
	else
		snprintf(cfg->disconnect_script, sizeof(cfg->disconnect_script), "%s", val);

	if (!(val = gn_cfg_get(gn_cfg_info, section, "rfcomm_channel")))
		cfg->rfcomm_cn = def->rfcomm_cn;
	else if (sscanf(val, " %hhu %c", &cfg->rfcomm_cn, &ch) != 1) {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "rfcomm_channel", val);
		fprintf(stderr, _("Assuming: %d\n"), def->rfcomm_cn);
		cfg->rfcomm_cn = def->rfcomm_cn;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "sm_retry")))
		cfg->sm_retry = def->sm_retry;
	else if (sscanf(val, " %d %c", &cfg->sm_retry, &ch) != 1) {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "sm_retry", val);
		fprintf(stderr, _("Assuming: %d\n"), def->sm_retry);
		cfg->sm_retry = def->sm_retry;
	}

	/* There is no global setting. You need to set irda_string
	 * in each section if you want it working */
	if (!(val = gn_cfg_get(gn_cfg_info, section, "irda_string")))
		cfg->irda_string[0] = 0;
	else {
		snprintf(cfg->irda_string, sizeof(cfg->irda_string), "%s", val);
		dprintf("Setting irda_string in section %s to %s\n", section, cfg->irda_string);
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "use_locking")))
		cfg->use_locking = def->use_locking;
	else if (!strcasecmp(val, "no"))
		cfg->use_locking = 0;
	else if (!strcasecmp(val, "yes"))
		cfg->use_locking = 1;
	else {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "use_locking", val);
		fprintf(stderr, _("Use either \"%s\" or \"%s\".\n"), "yes", "no");
		fprintf(stderr, _("Assuming: %s\n"), def->use_locking ? "yes" : "no");
		cfg->use_locking = def->use_locking;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "authentication_type")))
		cfg->auth_type = GN_AUTH_TYPE_NONE;
	else if (!strcasecmp(val, "text"))
		cfg->auth_type = GN_AUTH_TYPE_TEXT;
	else if (!strcasecmp(val, "interactive"))
		cfg->auth_type = GN_AUTH_TYPE_INTERACTIVE;
	else if (!strcasecmp(val, "noninteractive"))
		cfg->auth_type = GN_AUTH_TYPE_NONINTERACTIVE;
	else if (!strcasecmp(val, "binary"))
		cfg->auth_type = GN_AUTH_TYPE_BINARY;
	else if (!strcasecmp(val, "none"))
		cfg->auth_type = GN_AUTH_TYPE_NONE;
	else {
		fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), section, "authentication_type", val);
		fprintf(stderr, _("Assuming: %s\n"), "none");
		cfg->auth_type = def->auth_type;
	}

	if (!(val = gn_cfg_get(gn_cfg_info, section, "auth_file")))
		snprintf(cfg->auth_file, sizeof(cfg->auth_file), "%s", def->auth_file);
	else
		snprintf(cfg->auth_file, sizeof(cfg->auth_file), "%s", val);

	return GN_ERR_NONE;
}
Exemplo n.º 4
0
/* DEPRECATED */
static gn_error cfg_file_or_memory_read(const char *file, const char **lines)
{
	char *val;
	gn_error error;

	error = gn_lib_init();
	if (error != GN_ERR_NONE) {
		fprintf(stderr, _("Failed to initialize libgnokii.\n"));
		return error;
	}

	if (file == NULL && lines == NULL) {
		fprintf(stderr, _("Couldn't open a config file or memory.\n"));
		return GN_ERR_NOCONFIG;
	}

	/* I know that it doesn't belong here but currently there is now generic
	 * application init function anywhere.
	 */
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);

	/*
	 * Try opening a given config file
	 */
	if (file != NULL)
		gn_cfg_info = cfg_file_read(file);
	else
		gn_cfg_info = cfg_memory_read(lines);

	if (gn_cfg_info == NULL) {
		/* this is bad, but the previous was much worse - bozo */
		return GN_ERR_NOCONFIG;
	}
	gn_config_default.model[0] = 0;
	gn_config_default.port_device[0] = 0;
	gn_config_default.connection_type = GN_CT_Serial;
	gn_config_default.init_length = 0;
	gn_config_default.serial_baudrate = 19200;
	gn_config_default.serial_write_usleep = -1;
	gn_config_default.hardware_handshake = false;
	gn_config_default.require_dcd = false;
	gn_config_default.set_dtr_rts = true;
	gn_config_default.smsc_timeout = -1;
	gn_config_default.irda_string[0] = 0;
	gn_config_default.connect_script[0] = 0;
	gn_config_default.disconnect_script[0] = 0;
	gn_config_default.rfcomm_cn = 0;
	gn_config_default.sm_retry = 0;
	gn_config_default.use_locking = 0;
	gn_config_default.auth_type = GN_AUTH_TYPE_NONE;
	gn_config_default.auth_file[0] = 0;

	if ((error = cfg_psection_load(&gn_config_global, "global", &gn_config_default)) != GN_ERR_NONE)
		return error;

	/* hack to support [sms] / smsc_timeout parameter */
	if (gn_config_global.smsc_timeout < 0) {
		if (!(val = gn_cfg_get(gn_cfg_info, "sms", "timeout")))
			gn_config_global.smsc_timeout = 100;
		else
			gn_config_global.smsc_timeout = 10 * atoi(val);
	}

	if (!cfg_get_log_target(&gn_log_debug_mask, "debug") ||
	    !cfg_get_log_target(&gn_log_rlpdebug_mask, "rlpdebug") ||
	    !cfg_get_log_target(&gn_log_xdebug_mask, "xdebug"))
		return GN_ERR_NOLOG;

	gn_log_debug("LOG: debug mask is 0x%x\n", gn_log_debug_mask);
	gn_log_rlpdebug("LOG: rlpdebug mask is 0x%x\n", gn_log_rlpdebug_mask);
	gn_log_xdebug("LOG: xdebug mask is 0x%x\n", gn_log_xdebug_mask);
	if (file)
		dprintf("Config read from file %s.\n", file);
	return GN_ERR_NONE;
}
Exemplo n.º 5
0
static QString businit(void)
{
	gn_error error;
	char *aux;

	if (gn_cfg_read(&BinDir)<0 || !gn_cfg_phone_load("", &state))
		return i18n("GNOKII isn't yet configured.");

	gn_data_clear(&data);

	aux = gn_cfg_get(gn_cfg_info, "global", "use_locking");
	// Defaults to 'no'
	if (aux && !strcmp(aux, "yes")) {
		lockfile = gn_device_lock(state.config.port_device);
		if (lockfile == NULL) {
			return i18n("Lock file error.\n "
			"Please exit all other running instances of gnokii and try again.");
		}
	}

	// Initialise the code for the GSM interface.
	int old_dcd = state.config.require_dcd; // work-around for older gnokii versions
	state.config.require_dcd = false;
	error = gn_gsm_initialise(&state);
	GNOKII_CHECK_ERROR(error);
	state.config.require_dcd = old_dcd;
	if (error != GN_ERR_NONE) {
		busterminate();
		return i18n("Mobile phone interface initialization failed:\n%1").arg(gn_error_print(error));
	}

	// model
	gn_data_clear(&data);
	data.model = model;
	model[0] = 0;
	error = gn_sm_functions(GN_OP_GetModel, &data, &state);
	GNOKII_CHECK_ERROR(error);
	if (model[0] == 0)
		strcpy(model, i18n("unknown").utf8());
	data.model = NULL;

	// revision
	data.revision = revision;
	revision[0] = 0;
	error = gn_sm_functions(GN_OP_GetRevision, &data, &state);
	GNOKII_CHECK_ERROR(error);
	data.revision = NULL;

	// imei	
	data.imei = imei;
	imei[0] = 0;
	error = gn_sm_functions(GN_OP_GetImei, &data, &state);
	GNOKII_CHECK_ERROR(error);
	data.imei = NULL;

	GNOKII_DEBUG( QString("Found mobile phone: Model: %1, Revision: %2, IMEI: %3\n")
				.arg(model).arg(revision).arg(imei) ); 

	PhoneProductId = QString("%1-%2-%3-%4").arg(APP).arg(model).arg(revision).arg(imei);

	return QString::null;
}
Exemplo n.º 6
0
static int install_log_handler(void)
{
	int retval = 0;
	char logname[MAX_PATH_LEN];
	char *path, *basepath;
	char *file = "gnokii-errors";
	int free_path = 0;
	struct stat buf;
	int st;
#if !defined WIN32 && !defined __MACH__
	int home = 0;
#endif

	path = gn_cfg_get(gn_cfg_info, "gnokii", "errorlogpath");
	if (!path) {
#ifdef WIN32
		basepath = getenv("APPDATA");
#elif __MACH__
		basepath = getenv("HOME");
#else
/* freedesktop.org compliancy: http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html */
#define XDG_CACHE_HOME "/.cache" /* $HOME/.cache */
		basepath = getenv("XDG_CACHE_HOME");
		if (!basepath) {
			basepath = getenv("HOME");
			home = 1;
		}
#endif
		if (!basepath)
			path = ".";
		else {
			path = calloc(MAX_PATH_LEN, sizeof(char));
			free_path = 1;
#ifdef WIN32 /* Windows */
			snprintf(path, MAX_PATH_LEN, "%s\\gnokii", basepath);
#elif __MACH__
			snprintf(path, MAX_PATH_LEN, "%s/Library/Logs/gnokii", basepath);
#else
			if (home) {
				snprintf(path, MAX_PATH_LEN, "%s%s/gnokii", basepath, XDG_CACHE_HOME);
			} else {
				snprintf(path, MAX_PATH_LEN, "%s/gnokii", basepath);
			}
#endif
		}

		st = stat(basepath, &buf);
		if (st)
	        mkdir(basepath, S_IRWXU);

		st = stat(path, &buf);
		if (st)
			mkdir(path, S_IRWXU);
	}

	snprintf(logname, sizeof(logname), "%s/%s", path, file);

	if ((logfile = fopen(logname, "a")) == NULL) {
		fprintf(stderr, _("Cannot open logfile %s\n"), logname);
		retval = -1;
		goto out;
	}

	gn_elog_handler = gnokii_error_logger;

out:
	if (free_path)
		free(path);
	return retval;
}