/* * Copyright (C) 2005 BLADOX, s.r.o. All rights reserved. * * This file is part of an example program for Turbo. This example * program may be used, distributed and modified without limitation. * */ #include <config.h> #include <turbo/turbo.h> #include <string.h> #include <stdlib.h> /* *INDENT-OFF* */ lc_char PROGMEM lc_TSMS_ACL[]={ LC_EN("TSMS ACL") LC_END }; lc_char PROGMEM lc_Send[]={ LC_EN("Send") LC_END }; lc_char PROGMEM lc_Block[]={ LC_EN("Block") LC_END }; lc_char PROGMEM lc_Unblock[]={ LC_EN("Unblock") LC_END }; lc_char PROGMEM lc_Everyone_On[]={ LC_EN("Everyone On") LC_END }; lc_char PROGMEM lc_Everyone_Off[]={ LC_EN("Everyone Off") LC_END }; /* *INDENT-ON* */ u8 PROGMEM t_mime[] = "tsmsacl"; u8 PROGMEM t_rec_sms[] = "RECSMS!"; SNodeP tsms_n; SNodeP tsms_delete_n; SNodeP tsms_block_n; SNodeP tsms_unblock_n; SNodeP tsms_everyone_on_n; SNodeP tsms_everyone_off_n; u8 tsms_acl (SCtx * ctx, u8 action) { if (action == APP_ENTER) { spider_append_r (ctx, &tsms_delete_n); } else if (action == APP_LEAVE) { spider_clear_r (ctx); } return APP_OK; } u8 tsms_block (SCtx * ctx, u8 action) { if (action == APP_ENTER) { TSMS_ACL *acl = lookup_tsms_tag (t_mime, SMS_TYPE_MSG); u8 i = rb (&acl->general); i |= TSMS_ACL_BLOCKED; wb (&acl->general, i); return APP_BACK; } return APP_OK; } u8 tsms_unblock (SCtx * ctx, u8 action) { if (action == APP_ENTER) { TSMS_ACL *acl = lookup_tsms_tag (t_mime, SMS_TYPE_MSG); u8 i = rb (&acl->general); i &= ~TSMS_ACL_BLOCKED; wb (&acl->general, i); return APP_BACK; } return APP_OK; } u8 tsms_everyone_on (SCtx * ctx, u8 action) { if (action == APP_ENTER) { TSMS_ACL *acl = lookup_tsms_tag (t_mime, SMS_TYPE_MSG); u8 i = rb (&acl->general); i |= TSMS_ACL_EVERYONE; wb (&acl->general, i); return APP_BACK; } return APP_OK; } u8 tsms_everyone_off (SCtx * ctx, u8 action) { if (action == APP_ENTER) { TSMS_ACL *acl = lookup_tsms_tag (t_mime, SMS_TYPE_MSG); u8 i = rb (&acl->general); i &= ~TSMS_ACL_EVERYONE; wb (&acl->general, i); return APP_BACK; } return APP_OK; } u8 tsms_new (SCtx * ctx, u8 action) { if (action == APP_ENTER) { TSMS_ACL *acl = lookup_tsms_tag (t_mime, SMS_TYPE_MSG); SNode *n = NULL; SEdge *e = NULL; u8 *t = NULL; u8 *ms = NULL; u8 alpha[ALPHA_LEN]; u8 i; u8 *res; res = msisdn (alpha); if (res == ENULL) return APP_END; if (res == NULL) return APP_BACK; ms = msisdncpy (res, MSISDN_ADN, MEM_E); if (ms == NULL) goto X_END; n = emalloc (sizeof (SNode)); if (n == NULL) goto X_END; e = emalloc (sizeof (SEdge)); if (e == NULL) goto X_END; t = emalloc (strlen (alpha) + 1); if (t == NULL) goto X_END; memcpy (t, alpha, strlen (alpha)); wb (t + strlen (alpha), '\0'); ww (&n->text, t); ww (&n->cb, tsms_acl); ww (&n->p, ms); ww (&e->f, &tsms_n); ww (&e->t, n); ww (&e->next, rw (&acl->access_list)); wb (&e->source, MEM_F_P | MEM_T_E); ww (&acl->access_list, e); return APP_BACK; X_END: efree (n); efree (e); efree (ms); efree (t); return perror (ERR_NO_EEPROM); } return APP_OK; } u8 tsms_delete (SCtx * ctx, u8 action) { if (action == APP_ENTER) { u8 res; SNode *n = ctx->parent->f; res = yesno (rw (&n->text), Q_YESNO_DELETE_QMARK, 0); if (res == APP_END) return APP_END; if (res == APP_YES) { TSMS_ACL *acl = lookup_tsms_tag (t_mime, SMS_TYPE_MSG); SEdge *e = rw (&acl->access_list); SEdge *f = e; while (e) { if (rw (&e->t) == n) break; f = e; e = rw (&e->next); } if (f == e) ww (&acl->access_list, rw (&e->next)); else ww (&f->next, rw (&e->next)); efree (e); efree (rw (&n->text)); efree (rw (&n->p)); efree (n); spider_back (ctx); } return APP_BACK; } return APP_OK; } u8 tsms_send (SCtx * ctx, u8 action) { if (action == APP_ENTER) { u8 *res, *q; u8 *tmp = NULL; u8 *ms = NULL; res = msisdn (NULL); if (res == ENULL) return APP_END; if (res == NULL) return APP_BACK; ms = msisdncpy (res, MSISDN_ADN, MEM_R); if (ms == NULL) return perror (ERR_NO_RAM); //not enough memory tmp = malloc (30); if (tmp != NULL) { q = create_head_msg (tmp, t_mime); send_sms (tmp, q - tmp, ms, MSISDN_ADN, tsms_dcs (), tsms_pid (), NULL, NULL); } free (tmp); free (ms); return APP_BACK; } return APP_OK; } u8 tsms_ctx (SCtx * ctx, u8 action) { if (action == APP_ENTER) { TSMS_ACL *acl = lookup_tsms_tag (t_mime, SMS_TYPE_MSG); u8 i = rb (&acl->general); if (i & TSMS_ACL_EVERYONE) spider_append_r (ctx, &tsms_everyone_off_n); else spider_append_r (ctx, &tsms_everyone_on_n); if (i & TSMS_ACL_BLOCKED) spider_append_r (ctx, &tsms_unblock_n); else spider_append_r (ctx, &tsms_block_n); ctx->eE = rw (&acl->access_list); } else if (action == APP_LEAVE) { ctx->eE = NULL; spider_clear_r (ctx); } return APP_OK; } SNodeP tsms_n = { lc_TSMS_ACL, tsms_ctx }; SNodeP tsms_send_n = { lc_Send, tsms_send }; SNodeP tsms_new_n = { LC_NEW, tsms_new }; SNodeP tsms_delete_n = { LC_DELETE, tsms_delete }; SNodeP tsms_block_n = { lc_Block, tsms_block }; SNodeP tsms_unblock_n = { lc_Unblock, tsms_unblock }; SNodeP tsms_everyone_on_n = { lc_Everyone_On, tsms_everyone_on }; SNodeP tsms_everyone_off_n = { lc_Everyone_Off, tsms_everyone_off }; /* *INDENT-OFF* */ SEdgeP tsms_edges_p[] = { {&tsms_n, &tsms_send_n}, {&tsms_n, &tsms_new_n}, NULL }; /* *INDENT-ON* */ void action_menu (void *data) { SCtx *c = spider_init (); c->n = &tsms_n; c->eP = &tsms_edges_p; spider_set_order (c, ORDER_P, ORDER_R, ORDER_E, ORDER_D); spider (c); } void rec_sms (void *data) { dbsp ("Test TSMS ACL received"); display_text_raw (t_rec_sms, Q_DISPLAY_TEXT_USER_CLEAR); } void turbo_handler (u8 action, void *data) { switch (action) { case ACTION_APP_REGISTER: reg_sms_tag (locale (lc_TSMS_ACL), t_mime, SMS_TYPE_MSG); break; case ACTION_INSERT_MENU: insert_menu (locale (lc_TSMS_ACL)); break; case ACTION_MENU_SELECTION: stk_thread (action_menu, data); break; case ACTION_SMS_MSG: stk_thread (rec_sms, data); default: break; } }
Copyright © 2004-2006 BLADOX | Turbo version 1.2
|