Esempio n. 1
0
/* 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;
}
Esempio n. 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;
}
Esempio n. 3
0
/* 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
}
Esempio n. 4
0
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;
}
Esempio n. 5
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);
}