示例#1
0
文件: video.c 项目: DeforaOS/Phone
/* video_on_can_read */
static gboolean _video_on_can_read(GIOChannel * channel, GIOCondition condition,
		gpointer data)
{
	VideoPhonePlugin * video = data;
	PhonePluginHelper * helper = video->helper;
	ssize_t s;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	if(channel != video->channel || condition != G_IO_IN)
		return FALSE;
	if((s = read(video->fd, video->raw_buffer, video->raw_buffer_cnt))
			<= 0)
	{
		/* this error can be ignored */
		if(errno == EAGAIN)
			return TRUE;
		close(video->fd);
		video->fd = -1;
		/* FIXME also free video->buffers */
		helper->error(helper->phone, strerror(errno), 1);
		video->source = 0;
		return FALSE;
	}
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() %lu %ld\n", __func__,
			video->raw_buffer_cnt, s);
#endif
	video->source = g_idle_add(_video_on_refresh, video);
	return FALSE;
}
示例#2
0
static int _smscrypt_event_sms_receiving(SMSCrypt * smscrypt,
		char const * number, PhoneEncoding * encoding, char * buf,
		size_t * len)
{
	PhonePluginHelper * helper = smscrypt->helper;
	char const * error = "There is no known secret for this number."
		" The message could not be decrypted.";
	size_t i;
	size_t j = 0;
	SHA_CTX sha1;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%u, buf, %lu)\n", __func__, *encoding,
			(unsigned long)*len);
#endif
	if(*encoding != PHONE_ENCODING_DATA)
		return 0; /* not for us */
	if(_smscrypt_secret(smscrypt, number) != 0)
		return helper->error(helper->phone, error, 1);
	for(i = 0; i < *len; i++)
	{
		buf[i] ^= smscrypt->buf[j];
		smscrypt->buf[j++] ^= buf[i];
		if(j != smscrypt->len)
			continue;
		SHA1_Init(&sha1);
		SHA1_Update(&sha1, smscrypt->buf, smscrypt->len);
		SHA1_Final(smscrypt->buf, &sha1);
		j = 0;
	}
	*encoding = PHONE_ENCODING_UTF8;
	_smscrypt_clear(smscrypt);
	return 0;
}
示例#3
0
文件: video.c 项目: DeforaOS/Phone
/* video_on_can_mmap */
static gboolean _video_on_can_mmap(GIOChannel * channel, GIOCondition condition,
		gpointer data)
{
	VideoPhonePlugin * video = data;
	PhonePluginHelper * helper = video->helper;
	struct v4l2_buffer buf;

	if(channel != video->channel || condition != G_IO_IN)
		return FALSE;
	if(_video_ioctl(video, VIDIOC_DQBUF, &buf) == -1)
	{
		helper->error(helper->phone, "Could not save picture", 1);
		return FALSE;
	}
	video->raw_buffer = video->buffers[buf.index].start;
	video->raw_buffer_cnt = buf.bytesused;
#if 0 /* FIXME the raw buffer is not meant to be free()'d */
	video->source = g_idle_add(_video_on_refresh, video);
	return FALSE;
#else
	_video_on_refresh(video);
	video->raw_buffer = NULL;
	video->raw_buffer_cnt = 0;
	return TRUE;
#endif
}
示例#4
0
/* openmoko_deepsleep */
static void _openmoko_deepsleep(Openmoko * openmoko)
{
	PhonePluginHelper * helper = openmoko->helper;
	char const * cmd = "AT%SLEEP=4"; /* allow deep sleep */
	char const * p;

	if((p = helper->config_get(helper->phone, "openmoko", "deepsleep"))
			!= NULL && strtoul(p, NULL, 10) != 0)
		cmd = "AT%SLEEP=2"; /* prevent deep sleep */
	/* XXX this may reset the hardware modem */
	_openmoko_queue(openmoko, cmd);
}
示例#5
0
文件: debug.c 项目: khorben/DeforaOS
static void _debug_on_queue_trigger(gpointer data)
{
	Debug * debug = data;
	PhonePluginHelper * helper = debug->helper;
	gchar * text;
	size_t i;

	if((text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
						debug->triggers))) == NULL)
		return;
	for(i = 0; _debug_modem_triggers[i].name != NULL; i++)
		if(strcmp(_debug_modem_triggers[i].name, text) == 0)
			break;
	g_free(text);
	helper->trigger(helper->phone, _debug_modem_triggers[i].event);
}
示例#6
0
/* smscrypt_secret */
static int _smscrypt_secret(SMSCrypt * smscrypt, char const * number)
{
	PhonePluginHelper * helper = smscrypt->helper;
	char const * secret = NULL;
	SHA_CTX sha1;

	if(number != NULL)
		secret = helper->config_get(helper->phone, "smscrypt", number);
	if(secret == NULL)
		secret = helper->config_get(helper->phone, "smscrypt",
				"secret");
	if(secret == NULL)
		return 1;
	SHA1_Init(&sha1);
	SHA1_Update(&sha1, (unsigned char const *)secret, strlen(secret));
	SHA1_Final(smscrypt->buf, &sha1);
	return 0;
}
示例#7
0
static void _on_settings_reason_edited(GtkCellRenderer * renderer, gchar * arg1,
		gchar * arg2, gpointer data)
{
	Blacklist * blacklist = data;
	PhonePluginHelper * helper = blacklist->helper;
	GtkTreeModel * model = GTK_TREE_MODEL(blacklist->store);
	GtkTreeIter iter;
	char * number = NULL;
	(void) renderer;

	if(gtk_tree_model_get_iter_from_string(model, &iter, arg1) == TRUE)
		gtk_tree_model_get(model, &iter, 0, &number, -1);
	if(number == NULL)
		return;
	if(helper->config_set(helper->phone, "blacklist", number, arg2) == 0)
		gtk_list_store_set(blacklist->store, &iter, 1, arg2, -1);
	g_free(number);
}
示例#8
0
static void _on_settings_secret_edited(GtkCellRenderer * renderer, gchar * arg1,
		gchar * arg2, gpointer data)
{
	SMSCrypt * smscrypt = data;
	PhonePluginHelper * helper = smscrypt->helper;
	GtkTreeModel * model = GTK_TREE_MODEL(smscrypt->store);
	GtkTreeIter iter;
	char * number = NULL;

	if(gtk_tree_model_get_iter_from_string(model, &iter, arg1) == TRUE)
		gtk_tree_model_get(model, &iter, SMSCC_NUMBER, &number, -1);
	if(number == NULL)
		return;
	/* XXX report errors */
	if(helper->config_set(helper->phone, "smscrypt", number, arg2) == 0)
		gtk_list_store_set(smscrypt->store, &iter, SMSCC_SECRET, arg2,
				-1);
	g_free(number);
}
示例#9
0
文件: debug.c 项目: khorben/DeforaOS
static void _debug_on_queue_request(gpointer data)
{
	Debug * debug = data;
	PhonePluginHelper * helper = debug->helper;
	gchar * text;
	size_t i;
	ModemRequest request;

	if((text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
						debug->requests))) == NULL)
		return;
	for(i = 0; _debug_modem_requests[i].name != NULL; i++)
		if(strcmp(_debug_modem_requests[i].name, text) == 0)
			break;
	g_free(text);
	memset(&request, 0, sizeof(request));
	request.type = _debug_modem_requests[i].request;
	helper->request(helper->phone, &request);
}
示例#10
0
/* ussd_on_settings_send */
static void _ussd_on_settings_send(gpointer data)
{
	USSD * ussd = data;
	PhonePluginHelper * helper = ussd->helper;
	int i;
	USSDCode * codes;
	ModemRequest request;

	i = gtk_combo_box_get_active(GTK_COMBO_BOX(ussd->operators));
	codes = _ussd_operators[i].codes;
	i = gtk_combo_box_get_active(GTK_COMBO_BOX(ussd->codes));
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, codes[i].number);
#endif
	memset(&request, 0, sizeof(request));
	request.type = MODEM_REQUEST_CALL;
	request.call.call_type = MODEM_CALL_TYPE_VOICE;
	request.call.number = codes[i].number;
	helper->request(helper->phone, &request);
}
示例#11
0
static void _on_settings_delete(gpointer data)
{
	SMSCrypt * smscrypt = data;
	PhonePluginHelper * helper = smscrypt->helper;
	GtkTreeSelection * treesel;
	GtkTreeIter iter;
	char * number = NULL;

	if((treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(
						smscrypt->view))) == NULL)
		return;
	if(gtk_tree_selection_get_selected(treesel, NULL, &iter) != TRUE)
		return;
	gtk_tree_model_get(GTK_TREE_MODEL(smscrypt->store), &iter,
			SMSCC_NUMBER, &number, -1);
	if(number == NULL)
		return;
	helper->config_set(helper->phone, "smscrypt", number, NULL);
	gtk_list_store_remove(smscrypt->store, &iter);
	g_free(number);
}
示例#12
0
文件: ussd.c 项目: DeforaOS/Phone
/* ussd_on_settings_send */
static void _ussd_on_settings_send(gpointer data)
{
	USSD * ussd = data;
	PhonePluginHelper * helper = ussd->helper;
	GtkTreeModel * model;
	GtkTreeIter iter;
	gchar * code;
	ModemRequest request;

	model = gtk_combo_box_get_model(GTK_COMBO_BOX(ussd->codes));
	if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ussd->codes), &iter)
			!= TRUE)
		return;
	gtk_tree_model_get(model, &iter, UC_CODE, &code, -1);
	memset(&request, 0, sizeof(request));
	request.type = MODEM_REQUEST_CALL;
	request.call.call_type = MODEM_CALL_TYPE_VOICE;
	request.call.number = code;
	helper->request(helper->phone, &request);
	g_free(code);
}
示例#13
0
文件: video.c 项目: DeforaOS/Phone
static gboolean _video_on_open(gpointer data)
{
	const int timeout = 10000;
	VideoPhonePlugin * video = data;
	PhonePluginHelper * helper = video->helper;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, video->device);
#endif
	if((video->fd = open(video->device, O_RDWR)) < 0)
	{
		error_set_code(1, "%s: %s (%s)", video->device,
				"Could not open the video capture device",
				strerror(errno));
		helper->error(helper->phone, error_get(NULL), 1);
		video->source = g_timeout_add(timeout, _video_on_open, video);
		return FALSE;
	}
	if(_open_setup(video) != 0)
	{
		helper->error(helper->phone, error_get(NULL), 1);
		close(video->fd);
		video->fd = -1;
		video->source = g_timeout_add(timeout, _video_on_open, video);
		return FALSE;
	}
	video->source = 0;
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() %dx%d\n", __func__,
			video->format.fmt.pix.width,
			video->format.fmt.pix.height);
#endif
	/* FIXME allow the window to be smaller */
	gtk_widget_set_size_request(video->area, video->format.fmt.pix.width,
			video->format.fmt.pix.height);
	return FALSE;
}
示例#14
0
/* blacklist_event */
static int _blacklist_event(Blacklist * blacklist, PhoneEvent * event)
{
	PhonePluginHelper * helper = blacklist->helper;
	char const * number = NULL;
	char const * reason;

	switch(event->type)
	{
		case PHONE_EVENT_TYPE_MODEM_EVENT:
			if(event->modem_event.event->type
					!= MODEM_EVENT_TYPE_CALL)
				break; /* FIXME many more events to handle */
			number = event->modem_event.event->call.number;
			break;
		default:
			return 0;
	}
	if(number == NULL)
		return 0;
	reason = helper->config_get(helper->phone, "blacklist", number);
	if(reason == NULL)
		return 0;
	return helper->error(helper->phone, reason, 1);
}
示例#15
0
/* openmoko_mixer_open */
static int _openmoko_mixer_open(Openmoko * openmoko)
{
#ifdef __linux__
	PhonePluginHelper * helper = openmoko->helper;
	char const * audio_device;
	snd_mixer_elem_t * elem;

	openmoko->mixer_elem = NULL;
	openmoko->mixer_elem_headphone = NULL;
	openmoko->mixer_elem_speaker = NULL;
	if((audio_device = helper->config_get(helper->phone, "openmoko",
					"audio_device")) == NULL)
		audio_device = "hw:0";
	if(snd_mixer_open(&openmoko->mixer, 0) != 0)
	{
		openmoko->mixer = NULL;
		return -1;
	}
	if(snd_mixer_attach(openmoko->mixer, audio_device) != 0
			|| snd_mixer_selem_register(openmoko->mixer, NULL, NULL)
			|| snd_mixer_load(openmoko->mixer) != 0)
	{
		_openmoko_mixer_close(openmoko);
		return -1;
	}
	for(elem = snd_mixer_first_elem(openmoko->mixer); elem != NULL;
			elem = snd_mixer_elem_next(elem))
		if(strcmp(snd_mixer_selem_get_name(elem), "Headphone") == 0
				&& snd_mixer_selem_has_playback_volume(elem))
			openmoko->mixer_elem_headphone = elem;
		else if(strcmp(snd_mixer_selem_get_name(elem), "Speaker") == 0
				&& snd_mixer_selem_has_playback_volume(elem))
			openmoko->mixer_elem_speaker = elem;
#endif /* __linux__ */
	return 0;
}