void unUseStr(const char *s) { StrItem *cur, *prev; unsigned int h = hashStr(s); cur = strTbl[h]; prev = cur; while (cur != 0) { if (strcasecmp(cur->s,s) == 0) { cur->refCnt--; /* if that was the last reference to this string, kill it. */ if (cur->refCnt == 0) { if (cur == strTbl[h]) { strTbl[h] = cur->next; deleteStr(prev->s); deleteStrItem(prev); } else { prev->next = cur->next; deleteStr(cur->s); deleteStrItem(cur); } return; } } prev = cur; cur = cur->next; } }
DLLEXPORT(void) unUseStr(const char *s) { StrItem *t, *p; unsigned int h = hashStr(s); if ((t = strTbl[h]) != 0) { p = t; do { if (qstricmp(t->s,s) == 0) { t->refCnt--; if (t->refCnt == 0) { if (p == strTbl[h]) { strTbl[h] = t->next; } else { p->next = t->next; } deleteStr(t->s); deleteStrItem(t); return; } } p = t; t = t->next; } while (t); } }
/* Options Finite state machine [Start] */ void OPT_fsmStart(void) { UIF_state = OPTIONS; UIF_optionsIndex = 0; deleteStr(); printStr((void*)opt_startStr, FLASH); }
static void opt_previous(void) { // select previous credential deleteStr(); UIF_increment(&UIF_optionsIndex, MAX_OPT_SIZE); opt_apply(); }
// user input finitestate machine void USI_fsm(uint8_t button) { switch(button){ case LEFT: deleteStr(); USI_Init(); break; case UP: deleteStr(); usi_previous(); break; case RIGHT: deleteStr(); if(userTextIndex == (sizeof(LOCK)-2)) // real array elements (\0) { /* Device Unlocked */ //if(strcmp_P(userText+sizeof(PIN_str)-1, LOCK) == 0) if(USI_pinCheck(userText+sizeof(PIN_str)-1) == 1) { CRD_fsmStart(); UCP_Unlock(); } /* Device Locked */ else { printStr((void*)LOCKED_str,FLASH); userTextIndex = 0; UIF_userInputIndex = 0; memcpy_P((void*)userText, (void*)PIN_str, sizeof(PIN_str)); userText[sizeof(PIN_str)-1+userTextIndex] = pgm_read_byte(&USI_keys[UIF_userInputIndex]); userText[sizeof(PIN_str)-1+userTextIndex+1] = 0; } } else { userTextIndex++; usi_print(); } break; case DOWN: deleteStr(); usi_next(); break; default: break; } }
DLLEXPORT(void) cleanStrTbl() { int i; for (i=0; i<STRTBLSIZE;i++) { StrItem *t = strTbl[i]; while (t) { StrItem *p; deleteStr(t->s); p = t; t = t->next; deleteStrItem(p); } while (t); strTbl[i] = 0; } }
static void printValue(FILE *fp, VObject *o, int level) { switch (VALUE_TYPE(o)) { case VCVT_USTRINGZ: { char c; char *t,*s; s = t = fakeCString(USTRINGZ_VALUE_OF(o)); fputc('"',fp); while (c=*t,c) { fputc(c,fp); if (c == '\n') indent(fp,level+2); t++; } fputc('"',fp); deleteStr(s); break; } case VCVT_STRINGZ: { char c; const char *s = STRINGZ_VALUE_OF(o); fputc('"',fp); while (c=*s,c) { fputc(c,fp); if (c == '\n') indent(fp,level+2); s++; } fputc('"',fp); break; } case VCVT_UINT: fprintf(fp,"%d", INTEGER_VALUE_OF(o)); break; case VCVT_ULONG: fprintf(fp,"%ld", LONG_VALUE_OF(o)); break; case VCVT_RAW: fprintf(fp,"[raw data]"); break; case VCVT_VOBJECT: fprintf(fp,"[vobject]\n"); printVObject_(fp,VOBJECT_VALUE_OF(o),level+1); break; case 0: fprintf(fp,"[none]"); break; default: fprintf(fp,"[unknown]"); break; } }
VObject* addGroup(VObject *o, const char *g) { /* a.b.c --> prop(c) prop(VCGrouping=b) prop(VCGrouping=a) */ char *dot = strrchr(g,'.'); if (dot) { VObject *p, *t; char *gs, *n = dot+1; gs = dupStr(g,0); /* so we can write to it. */ /* used to be * t = p = addProp_(o,lookupProp_(n)); */ t = p = addProp_(o,lookupProp(n)); dot = strrchr(gs,'.'); if (dot) { *dot = 0; do { dot = strrchr(gs,'.'); if (dot) { n = dot+1; *dot=0; } else n = gs; /* property(VCGroupingProp=n); * and the value may have VCGrouping property */ t = addProp(t,VCGroupingProp); setVObjectStringZValue(t,lookupProp_(n)); } while (n != gs); } else { t = addProp(t,VCGroupingProp); setVObjectStringZValue(t,lookupProp_(n)); } deleteStr(gs); return p; } else return addProp_(o,lookupProp(g)); }
static void writeValue(OFile *fp, VObject *o, unsigned long size) { if (o == 0) return; switch (VALUE_TYPE(o)) { case VCVT_USTRINGZ: { char *s = fakeCString(USTRINGZ_VALUE_OF(o)); if (isAPropertyOf(o, VCQuotedPrintableProp)) writeQPString(fp, s, 1); else writeQPString(fp, s, 0); deleteStr(s); break; } case VCVT_STRINGZ: { if (isAPropertyOf(o, VCQuotedPrintableProp)) writeQPString(fp, STRINGZ_VALUE_OF(o), 1); else writeQPString(fp, STRINGZ_VALUE_OF(o), 0); break; } case VCVT_UINT: { char buf[16]; snprintf(buf,sizeof(buf),"%u", INTEGER_VALUE_OF(o)); appendsOFile(fp,buf); break; } case VCVT_ULONG: { char buf[16]; snprintf(buf,sizeof(buf),"%lu", LONG_VALUE_OF(o)); appendsOFile(fp,buf); break; } case VCVT_RAW: { appendcOFile(fp,'\n'); writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size); break; } case VCVT_VOBJECT: appendcOFile(fp,'\n'); writeVObject_(fp,VOBJECT_VALUE_OF(o)); break; } }
/* Credentials Finite state machine */ void CRD_fsm(uint8_t button){ deleteStr(); switch(button) { case LEFT: OPT_fsmStart(); break; case UP: crd_previous(); break; case RIGHT: crd_printDetail(CRD_USER, CRD_END); break; case DOWN: crd_next(); break; default: return; } }
void UIF_Task(void){ if((UIB_buttonChanged == 1u) && (UIB_buttonPressed != NOT_PRESSED)) { switch(UIF_state) { case START: UIF_state = USER_INPUT; deleteStr(); USI_Init(); break; case OPTIONS: OPT_fsm(UIB_buttonPressed); break; case USER_INPUT: USI_fsm(UIB_buttonPressed); break; default: //CREDENTIALS CRD_fsm(UIB_buttonPressed); break; } } return; }
static void opt_printUser(void) { deleteStr(); crd_printDetail(CRD_USER, CRD_USER+1); }
static void opt_lock(void) { deleteStr(); UIF_state = START; UIF_Init(); }
static void opt_printPass(void) { deleteStr(); crd_printDetail(CRD_PASS, CRD_PASS+1); }
static void opt_lock(void){ deleteStr(); UIF_Init(); LedOff(); }
/* Credentials Finite state machine [Start] */ void CRD_fsmStart(void){ UIF_state = CREDENTIALS; deleteStr(); crd_print(); UCP_Unlock(); }