Created
June 26, 2015 08:26
-
-
Save xlab/ce6e347676357a67d9d5 to your computer and use it in GitHub Desktop.
friendlistsave.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static uint32_t friends_list_save(const Messenger *m, uint8_t *data) | |
| { | |
| uint32_t i; | |
| uint32_t num = 0; | |
| for (i = 0; i < m->numfriends; i++) { | |
| if (m->friendlist[i].status > 0) { | |
| struct SAVED_FRIEND temp; | |
| memset(&temp, 0, sizeof(struct SAVED_FRIEND)); | |
| temp.status = m->friendlist[i].status; | |
| memcpy(temp.real_pk, m->friendlist[i].real_pk, crypto_box_PUBLICKEYBYTES); | |
| if (temp.status < 3) { | |
| if (m->friendlist[i].info_size > SAVED_FRIEND_REQUEST_SIZE) { | |
| memcpy(temp.info, m->friendlist[i].info, SAVED_FRIEND_REQUEST_SIZE); | |
| } else { | |
| memcpy(temp.info, m->friendlist[i].info, m->friendlist[i].info_size); | |
| } | |
| temp.info_size = htons(m->friendlist[i].info_size); | |
| temp.friendrequest_nospam = m->friendlist[i].friendrequest_nospam; | |
| } else { | |
| memcpy(temp.name, m->friendlist[i].name, m->friendlist[i].name_length); | |
| temp.name_length = htons(m->friendlist[i].name_length); | |
| memcpy(temp.statusmessage, m->friendlist[i].statusmessage, m->friendlist[i].statusmessage_length); | |
| temp.statusmessage_length = htons(m->friendlist[i].statusmessage_length); | |
| temp.userstatus = m->friendlist[i].userstatus; | |
| uint8_t last_seen_time[sizeof(uint64_t)]; | |
| memcpy(last_seen_time, &m->friendlist[i].last_seen_time, sizeof(uint64_t)); | |
| host_to_net(last_seen_time, sizeof(uint64_t)); | |
| memcpy(&temp.last_seen_time, last_seen_time, sizeof(uint64_t)); | |
| } | |
| memcpy(data + num * sizeof(struct SAVED_FRIEND), &temp, sizeof(struct SAVED_FRIEND)); | |
| num++; | |
| } | |
| } | |
| return num * sizeof(struct SAVED_FRIEND); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment