/* $Id: smscrypt.c,v 1.2 2010/06/03 01:26:56 khorben Exp $ */ /* Copyright (c) 2010 Pierre Pronchery */ /* This file is part of DeforaOS Desktop Phone */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "../src/plugins/smscrypt.c" /* helper_config_get */ static char const * _helper_config_get(Phone * phone, char const * section, char const * variable) { Config * config = (Config *)phone; return config_get(config, section, variable); } /* hexdump */ static void _hexdump(char const * buf, size_t len) { unsigned char const * b = (unsigned char *)buf; size_t i; for(i = 0; i < len; i++) { printf(" %02x", b[i]); if((i % 16) == 7) fputc(' ', stdout); else if((i % 16) == 15) fputc('\n', stdout); } fputc('\n', stdout); } /* main */ int main(void) { PhonePluginHelper helper; Config * config; char const message[] = "A sample message."; PhoneEncoding encoding = PHONE_ENCODING_UTF8; char * p; size_t len; config = config_new(); config_load(config, "/home/khorben/.phone"); /* FIXME hardcoded */ helper.phone = (Phone *)config; helper.config_get = _helper_config_get; plugin.helper = &helper; if(_smscrypt_init(&plugin) != 0) { error_print("smscrypt"); return 2; } printf("Message: \"%s\"\n", message); if((p = strdup(message)) == NULL) return 2; len = strlen(p); _smscrypt_event(&plugin, PHONE_EVENT_SMS_SENDING, &encoding, &p, &len); printf("Encrypted:\n"); _hexdump(p, len); _smscrypt_event(&plugin, PHONE_EVENT_SMS_RECEIVING, &encoding, &p, &len); printf("Message: \"%s\"\n", p); free(p); _smscrypt_destroy(&plugin); config_delete(config); return 0; }