Allow plug-ins to prevent sending a message
This commit is contained in:
parent
15c5f55e2a
commit
6a7df43a97
19
src/phone.c
19
src/phone.c
@ -700,8 +700,9 @@ void phone_dialer_hangup(Phone * phone)
|
||||
|
||||
/* events */
|
||||
/* phone_event */
|
||||
void phone_event(Phone * phone, PhoneEvent event, ...)
|
||||
int phone_event(Phone * phone, PhoneEvent event, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
size_t i;
|
||||
PhonePlugin * plugin;
|
||||
va_list ap;
|
||||
@ -725,11 +726,11 @@ void phone_event(Phone * phone, PhoneEvent event, ...)
|
||||
{
|
||||
case PHONE_EVENT_SET_OPERATOR:
|
||||
operator = va_arg(ap, char const *);
|
||||
plugin->event(plugin, event, operator);
|
||||
ret |= plugin->event(plugin, event, operator);
|
||||
break;
|
||||
case PHONE_EVENT_SET_SIGNAL_LEVEL:
|
||||
level = va_arg(ap, gdouble);
|
||||
plugin->event(plugin, event, level);
|
||||
ret |= plugin->event(plugin, event, level);
|
||||
break;
|
||||
case PHONE_EVENT_SMS_RECEIVING:
|
||||
case PHONE_EVENT_SMS_SENDING:
|
||||
@ -737,8 +738,8 @@ void phone_event(Phone * phone, PhoneEvent event, ...)
|
||||
encoding = va_arg(ap, GSMEncoding *);
|
||||
buf = va_arg(ap, char **);
|
||||
len = va_arg(ap, size_t *);
|
||||
plugin->event(plugin, event, number, encoding,
|
||||
buf, len);
|
||||
ret |= plugin->event(plugin, event, number,
|
||||
encoding, buf, len);
|
||||
break;
|
||||
/* no arguments */
|
||||
case PHONE_EVENT_CALL_ESTABLISHED:
|
||||
@ -754,11 +755,12 @@ void phone_event(Phone * phone, PhoneEvent event, ...)
|
||||
case PHONE_EVENT_SPEAKER_ON:
|
||||
case PHONE_EVENT_VIBRATOR_OFF:
|
||||
case PHONE_EVENT_VIBRATOR_ON:
|
||||
plugin->event(plugin, event);
|
||||
ret |= plugin->event(plugin, event);
|
||||
break;
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -2031,12 +2033,13 @@ void phone_write_send(Phone * phone)
|
||||
FALSE);
|
||||
if(number == NULL || number[0] == '\0' || text == NULL)
|
||||
return;
|
||||
if(phone_event(phone, PHONE_EVENT_SMS_SENDING, number, &encoding, &text,
|
||||
&length) != 0)
|
||||
return;
|
||||
phone->wr_progress = _phone_create_progress(phone->wr_window,
|
||||
_("Sending message..."));
|
||||
_phone_track(phone, PHONE_TRACK_MESSAGE_SENT, TRUE);
|
||||
length = strlen(text);
|
||||
phone_event(phone, PHONE_EVENT_SMS_SENDING, number, &encoding, &text,
|
||||
&length);
|
||||
gsm_message_send(phone->gsm, number, encoding, text, length);
|
||||
g_free(text);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void phone_dialer_call(Phone * phone, char const * number);
|
||||
void phone_dialer_hangup(Phone * phone);
|
||||
|
||||
/* events */
|
||||
void phone_event(Phone * phone, PhoneEvent event, ...);
|
||||
int phone_event(Phone * phone, PhoneEvent event, ...);
|
||||
|
||||
/* interface */
|
||||
void phone_show_call(Phone * phone, gboolean show, ...); /* PhoneCall */
|
||||
|
@ -103,15 +103,16 @@ static int _smscrypt_destroy(PhonePlugin * plugin)
|
||||
|
||||
|
||||
/* smscrypt_event */
|
||||
static void _smscrypt_event_sms_receiving(SMSCrypt * smscrypt,
|
||||
static int _smscrypt_event_sms_receiving(SMSCrypt * smscrypt,
|
||||
char const * number, PhoneEncoding * encoding, char ** buf,
|
||||
size_t * len);
|
||||
static void _smscrypt_event_sms_sending(SMSCrypt * smscrypt,
|
||||
static int _smscrypt_event_sms_sending(SMSCrypt * smscrypt,
|
||||
char const * number, PhoneEncoding * encoding, char ** buf,
|
||||
size_t * len);
|
||||
|
||||
static int _smscrypt_event(PhonePlugin * plugin, PhoneEvent event, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
SMSCrypt * smscrypt = plugin->priv;
|
||||
va_list ap;
|
||||
char const * number;
|
||||
@ -128,7 +129,7 @@ static int _smscrypt_event(PhonePlugin * plugin, PhoneEvent event, ...)
|
||||
encoding = va_arg(ap, PhoneEncoding *);
|
||||
buf = va_arg(ap, char **);
|
||||
len = va_arg(ap, size_t *);
|
||||
_smscrypt_event_sms_receiving(smscrypt, number,
|
||||
ret = _smscrypt_event_sms_receiving(smscrypt, number,
|
||||
encoding, buf, len);
|
||||
break;
|
||||
case PHONE_EVENT_SMS_SENDING:
|
||||
@ -136,18 +137,18 @@ static int _smscrypt_event(PhonePlugin * plugin, PhoneEvent event, ...)
|
||||
encoding = va_arg(ap, PhoneEncoding *);
|
||||
buf = va_arg(ap, char **);
|
||||
len = va_arg(ap, size_t *);
|
||||
_smscrypt_event_sms_sending(smscrypt, number, encoding,
|
||||
buf, len);
|
||||
ret = _smscrypt_event_sms_sending(smscrypt, number,
|
||||
encoding, buf, len);
|
||||
break;
|
||||
/* ignore the rest */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
va_end(ap);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void _smscrypt_event_sms_receiving(SMSCrypt * smscrypt,
|
||||
static int _smscrypt_event_sms_receiving(SMSCrypt * smscrypt,
|
||||
char const * number, PhoneEncoding * encoding, char ** buf,
|
||||
size_t * len)
|
||||
{
|
||||
@ -159,16 +160,17 @@ static void _smscrypt_event_sms_receiving(SMSCrypt * smscrypt,
|
||||
*len);
|
||||
#endif
|
||||
if(*encoding != PHONE_ENCODING_DATA)
|
||||
return; /* not for us */
|
||||
return 0; /* not for us */
|
||||
for(i = 0; i < *len; i++)
|
||||
{
|
||||
(*buf)[i] ^= smscrypt->secret[j++];
|
||||
j %= smscrypt->secret_len;
|
||||
}
|
||||
*encoding = PHONE_ENCODING_UTF8;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _smscrypt_event_sms_sending(SMSCrypt * smscrypt,
|
||||
static int _smscrypt_event_sms_sending(SMSCrypt * smscrypt,
|
||||
char const * number, PhoneEncoding * encoding, char ** buf,
|
||||
size_t * len)
|
||||
{
|
||||
@ -179,13 +181,14 @@ static void _smscrypt_event_sms_sending(SMSCrypt * smscrypt,
|
||||
fprintf(stderr, "DEBUG: %s(%u, buf, %lu)\n", __func__, *encoding, *len);
|
||||
#endif
|
||||
if(*encoding != PHONE_ENCODING_UTF8)
|
||||
return; /* not for us */
|
||||
return 0; /* not for us */
|
||||
for(i = 0; i < *len; i++)
|
||||
{
|
||||
(*buf)[i] ^= smscrypt->secret[j++];
|
||||
j %= smscrypt->secret_len;
|
||||
}
|
||||
*encoding = PHONE_ENCODING_DATA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user