int main(int argc, char *argv) { char s[128]; myItoa(INT_MAX, s); printf("%s\n", s); myItoa(INT_MIN, s); printf("%s\n", s); return 0; }
int Drawboard::authenticate(Client* client) { uint32_t curpos = 1; uint32_t len=getUint16((uint8_t *)(&client->buffer[0]+curpos)); curpos += 2; #ifdef DEBUG std::cout << " Len: " << len << std::endl; #endif if(client->buffer.size()-curpos < len) { return NEED_MORE_DATA; } std::string hash(' ',32); int32_t UID=getSint16((uint8_t *)(&client->buffer[0]+curpos)); curpos += 2; uint8_t chanID = client->buffer[curpos]; curpos++; uint64_t timestamp = getUint64((uint8_t *)(&client->buffer[0]+curpos)); curpos += 8; uint8_t adminbit = client->buffer[curpos]; curpos++; memcpy((void *)hash.data(), (uint8_t *)(&client->buffer[0]+curpos),32); curpos += 32; uint32_t nicklen=client->buffer[curpos]; curpos++; std::string nick; for(uint32_t i = 0; i < nicklen; i++) { nick+=(char)client->buffer[curpos]; curpos ++; } //Clear the data from the buffer client->eraseFromBuffer(curpos); //ToDo: implement configuration reader etc if(0)//config.check_auth) { std::string user_time; myItoa(timestamp,user_time,10); //Check the auth data std::string combination=user_time+"|SECRET_STRING|"+(char)('0'+adminbit)+"|"+nick; std::string hash2; MD5_CTX mdContext; MD5Init (&mdContext); MD5Update (&mdContext, (unsigned char *)(combination.c_str()), combination.size()); MD5Final (&mdContext); for (int iii = 0; iii < 16; iii++) hash2+=toHex((unsigned int)mdContext.digest[iii]); if(hash2 != hash) { return DATA_ERROR; } } client->nick = nick; client->admin = (adminbit==0)?false:true; return DATA_OK; }
void test_itoa_zero() { clear_all(); //ITOA for 0 int f = 0; myItoa(f, b); assert(b != 0); assert(strlen(b) == 1); assert(b[0] == '0'); //accepted }
void test_itoa_negative() { clear_all(); //negative int value int x=-980; int f = myItoa(x,a); assert(strlen(a)==4); assert(a[0]=='-' && a[1]=='9' && a[2]=='8' && a[3]=='0'); assert(f == 0); //accepted }
void test_itoa_positive() { clear_all(); //positive int value int x=123; int f=myItoa(x,a); assert(strlen(a)==3); assert(a[0]=='1' && a[1]=='2' && a[2]=='3'); assert(f==0); //accepted }
void test_itoa_bigvalue() { clear_all(); //big int value int x=1000000000; int f = myItoa(x,a); assert(strlen(a)==10); strcpy(b,"1000000000"); assert(!strcmp(a,b)); assert(f==0); //accepted }
int readlines(char *lineptr[], int maxlines) { int len, nlines; char *p, line[MAXLEN]; OPEN_FD(); nlines = 0; while ((len = _getline(line, MAXLEN)) > 1) if (nlines >= MAXLINES ) { CLOSE_FD(); return nlines*(-1) - 1; } else if(!(p=malloc(len))) { CLOSE_FD(); return nlines*(-1) - 1; } else { line[len - 1] = '\0'; strcpy(p, line); int ans; int ff=myAtoi(p,&ans); if(numeric) { myItoa(ans,p); } if(numeric && ff==-1) { drop_error_string_format(); CLOSE_FD(); free(p); strcpy(line,""); return nlines*(-1) - 1; } lineptr[nlines++] = p; } CLOSE_FD(); return nlines; }
void Touch_Test(void) { #define X_OFFSET 0 #define Y_OFFSET 10 float r = 4; // Brush size char str[8]; Cursor strCursor1, strCursor2, strCursor3, strCursor4, strCursor5, strCursor6, buttonCursor;// String cursor touchscreen_data ts_data; Lcd_ClearScr(320,240,0xFFFF); strCursor1 = Set_Cursor(16 + X_OFFSET,0 + Y_OFFSET); strCursor2 = Set_Cursor(16 + X_OFFSET,16 + Y_OFFSET); strCursor3 = Set_Cursor(16 + X_OFFSET,32 + Y_OFFSET); strCursor4 = Set_Cursor(0 + X_OFFSET,0 + Y_OFFSET); strCursor5 = Set_Cursor(0 + X_OFFSET,16 + Y_OFFSET); strCursor6 = Set_Cursor(0 + X_OFFSET,32 + Y_OFFSET); GLCD_printf("x:", 0x0000, 0xffff, strCursor4); GLCD_printf("y:", 0x0000, 0xffff, strCursor5); GLCD_printf("p:", 0x0000, 0xffff, strCursor6); GLCD_RoundRect(10,90,80,110,5,LIGHT_BLUE); GLCD_RoundRect(10,90,120,150,5,LIGHT_BLUE); GLCD_RoundRect(10,90,160,190,5,LIGHT_BLUE); GLCD_RoundRect(10,90,200,230,5,LIGHT_BLUE); buttonCursor = Set_Cursor(46,87); GLCD_printf("+", WHITE, LIGHT_BLUE, buttonCursor); buttonCursor = Set_Cursor(46,127); GLCD_printf("-", WHITE, LIGHT_BLUE, buttonCursor); buttonCursor = Set_Cursor(22,167); GLCD_printf("Refresh", WHITE, LIGHT_BLUE, buttonCursor); buttonCursor = Set_Cursor(34,207); GLCD_printf("Back", WHITE, LIGHT_BLUE, buttonCursor); while(1) { ts_data = GetTS_Fast(); GLCD_Ellipsoid(75-r,75+r,35-r,35+r,BLACK); putarea(91,105,0,239,WHITE); myItoa(ts_data.xvalue,str,10); GLCD_printf_window(str,0x0000, 0xffff, strCursor1, 4); myItoa(ts_data.yvalue,str,10); GLCD_printf_window(str,0x0000, 0xffff, strCursor2, 4); myItoa(ts_data.pvalue,str,10); GLCD_printf_window(str,0x0000, 0xffff, strCursor3, 4); if(ts_data.pvalue == 1024 && ts_data.xvalue > 105) { GLCD_Ellipsoid(ts_data.xvalue-r,ts_data.xvalue+r,ts_data.yvalue-r,ts_data.yvalue+r, BLACK); } else if(r < 15 && ts_data.pvalue == 1024 && ts_data.xvalue > 10 && ts_data.xvalue < 90 && ts_data.yvalue > 80 && ts_data.yvalue < 110) { r++; putarea(75-r,75+r,35-r,35+r,WHITE); } else if(r > 4 && ts_data.pvalue == 1024 && ts_data.xvalue > 10 && ts_data.xvalue < 90 && ts_data.yvalue > 120 && ts_data.yvalue < 150) { r--; putarea(50,90,20,50,WHITE); } else if(ts_data.pvalue == 1024 && ts_data.xvalue > 10 && ts_data.xvalue < 90 && ts_data.yvalue > 160 && ts_data.yvalue < 190) { putarea(106,319,0,239,WHITE); } else if(ts_data.pvalue == 1024 && ts_data.xvalue > 10 && ts_data.xvalue < 90 && ts_data.yvalue > 200 && ts_data.yvalue < 230) { return; } } }