Datasheet

API in C
218
DEBUG ? printf("Closing socket\n") : 0;
close(fdSock);
}
/********************************************************************
* Login to the API
* 1 is returned on successful login
* 0 is returned on unsuccessful login
********************************************************************/
int login(int fdSock, char *username, char *password)
{
struct Sentence stReadSentence;
struct Sentence stWriteSentence;
char *szMD5Challenge;
char *szMD5ChallengeBinary;
char *szMD5PasswordToSend;
char *szLoginUsernameResponseToSend;
char *szLoginPasswordResponseToSend;
md5_state_t state;
md5_byte_t digest[16];
char cNull[1] = {0};
writeWord(fdSock, "/login");
writeWord(fdSock, "");
stReadSentence = readSentence(fdSock);
DEBUG ? printSentence (&stReadSentence) : 0;
if (stReadSentence.iReturnValue != DONE)
{
printf("error.\n");
exit(0);
}
// extract md5 string from the challenge sentence
szMD5Challenge = strtok(stReadSentence.szSentence[1], "=");
szMD5Challenge = strtok(NULL, "=");
DEBUG ? printf("MD5 of challenge = %s\n", szMD5Challenge) : 0;
// convert szMD5Challenge to binary
szMD5ChallengeBinary = md5ToBinary(szMD5Challenge);