PRIVATE void get_scaled_row( double **src, int y, int new_width, double *row, W8 *src_tmp, W8 *srcPR, int old_width, int old_height, int bytes ) { /* get the necesary lines from the source image, scale them, and put them into src[] */ rotate_pointers( (unsigned char **)src, 4 ); if( y < 0 ) { y = 0; } if( y < old_height ) { get_premultiplied_double_row( srcPR, bytes, 0, y, old_width, row, src_tmp, 1 ); if( new_width > old_width ) { expand_line( src[3], row, bytes, old_width, new_width ); } else if( old_width > new_width ) { shrink_line( src[3], row, bytes, old_width, new_width ); } else /* no scailing needed */ { memcpy( src[3], row, sizeof( double ) * new_width * bytes ); } } else { memcpy( src[3], src[2], sizeof( double ) * new_width * bytes ); } }
//there should be lock handle, such as global_stat_spin, but I just don't want to implement it now. int update_peer_table(struct peer_profile_t** peer_table, FILE *secrets_file, int max_id) { if(NULL == peer_table || NULL == secrets_file) { ERROR(0, "update_peer_table: peer_table or secrets_file is NULL"); return -1; } int i; for(i = 0; i < max_id+1; i++) if(peer_table[i] != NULL) peer_table[i]->discard = true; size_t len = 1024; char *line = (char *)malloc(len); if(line == NULL) { ERROR(errno, "update_peer_table: malloc failed"); return -1; } else bzero(line, len); while(-1 != getline(&line, &len, secrets_file)) //why line is an array of char*, not a char* ? { int id = 0; char *id_str = NULL; char *psk_str = NULL; char *ip_name_str = NULL; char *ip6_str = NULL; char *port_str = NULL; if(shrink_line(line) <= 1) continue; id_str = strtok(line, " "); psk_str = strtok(NULL, " "); ip_name_str = strtok(NULL, " "); ip6_str = strtok(NULL, " "); port_str = strtok(NULL, " "); if(NULL == id_str) continue; if(NULL == psk_str) { WARNING("PSK of ID %s not found, ignore this peer!", id_str); continue; } id = inet_ptons(id_str); if(0 == id || id > max_id) { WARNING("The ID of %s may be wrong, ignore this peer!", id_str); continue; } struct peer_profile_t * tmp_peer = add_peer(); if(tmp_peer == NULL) { ERROR(errno, "update_peer_table: add_peer failed."); return -1; } if(peer_table[id] != NULL) if(copy_peer(tmp_peer, peer_table[id]) < 0) ERROR(0, "Copy the ID of %s failed.", id_str); tmp_peer->id = id; tmp_peer->discard = false; if(strlen(psk_str) > 2*AES_TEXT_LEN) WARNING("PSK of ID %s is longer than %d, ignore some bytes.", id_str, 2*AES_TEXT_LEN); strncpy((char*)tmp_peer->psk, psk_str, 2*AES_TEXT_LEN); if(port_str != NULL) //port_str must be parsed before ip, because servaddr.sin_port uses it. { int port = atoi(port_str); if(port < 1) WARNING("Invalid PORT of peer: %s, ingore it's port value!", id_str); tmp_peer->port = port; } if(ip_name_str != NULL && strcmp(ip_name_str, "none") != 0) { char ip_str[IPV4_LEN] = "\0"; if(hostname_to_ip(ip_name_str, ip_str) < 0) WARNING("Invalid host of peer: %s, %s nslookup failed, ingore it's IP/Port value!", id_str, ip_name_str); else { inet_pton(AF_INET, ip_str, &(tmp_peer->peeraddr->sin_addr)); tmp_peer->peeraddr->sin_family = AF_INET; tmp_peer->peeraddr->sin_port = htons(tmp_peer->port); tmp_peer->restricted = true; } } if(ip6_str != NULL && strcmp(ip6_str, "none") != 0) WARNING("IPv6 not supported now, ignore it!"); tmp_peer->vip = htonl(id); //0.0.x.x in network byte order, used inside tunnel. //tmp_peer->rip = (global_tunif.addr & global_tunif.mask) | htonl(id); //in network byte order. if(peer_table[id] != NULL && tmp_peer->peeraddr->sin_addr.s_addr == peer_table[id]->peeraddr->sin_addr.s_addr && tmp_peer->peeraddr->sin_port == peer_table[id]->peeraddr->sin_port && strncmp((char *)(tmp_peer->psk), (char *)(peer_table[id]->psk), 2*AES_TEXT_LEN) == 0) { //the peer does not change peer_table[id]->discard = false; delete_peer(tmp_peer); tmp_peer = NULL; continue; } if(peer_table[id] != NULL) { INFO("update the ID of %s.", id_str); if(copy_peer(peer_table[id], tmp_peer) < 0) ERROR(0, "Update the ID of %s failed", id_str); delete_peer(tmp_peer); tmp_peer = NULL; } else { INFO("Add the ID of %s.", id_str); peer_table[id] = tmp_peer; } } free(line); for(i = 0; i < max_id+1; i++) if(peer_table[i] != NULL) if(peer_table[i]->discard) { WARNING("Delete the ID of %d.%d.", i/256, i%256); delete_peer(peer_table[i]); peer_table[i] = NULL; } return 0; }