//获取一个文件列表(每个文件有路径和文件类型两个属性) vector<file_info> get_server_list(SSL *ssl) { vector<file_info> file_list; uint32_t file_count = 0; int i = 0; char file_type; char *file_path; ssl_read_wrapper(ssl, &file_count, 4); file_count = ntoh32(file_count); for(i = 0; i < (int)file_count; i++) { file_path = read_string(ssl); if(!is_path_safe(std::string(file_path))) { fprintf(stderr, "remote host sent illegal path, aborted\n"); exit(1); } ssl_read_wrapper(ssl, &file_type, 1); file_info store(file_path, file_type); file_list.push_back(store); free(file_path); } return file_list; }
static void recv_dcc_file(irc_session_t *ircsession, irc_dcc_session_t *dcc) { int rcvdBytes, err = 0; size_t amount = LIBIRC_DCC_BUFFER_SIZE; do { #ifdef ENABLE_SSL if (dcc->ssl == 0) rcvdBytes = socket_recv(&dcc->sock, dcc->incoming_buf, amount); else { int sslError = 0; rcvdBytes = ssl_read_wrapper(ircsession, dcc, dcc->incoming_buf, amount, &sslError); if (sslError == SSL_ERROR_WANT_READ) { return; } else if (sslError == SSL_ERROR_WANT_WRITE) { dcc->state = LIBIRC_STATE_CONFIRM_SIZE; return; } } #else rcvdBytes = socket_recv(&dcc->sock, dcc->incoming_buf, amount); #endif if (unlikely(rcvdBytes < 0)) { err = LIBIRC_ERR_READ; } else if (unlikely(rcvdBytes == 0)) { err = LIBIRC_ERR_CLOSED; } else { libirc_mutex_unlock(&ircsession->mutex_dcc); dcc->file_confirm_offset += rcvdBytes; (*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, dcc->incoming_buf, rcvdBytes); /* if DONT_CONFIRM_OFFSETS_FLAG is set dont send the file offset to the bots because some bots dont want to receive the file offsets...*/ if (cfg_get_bit(getCfg(), DONT_CONFIRM_OFFSETS_FLAG)) { dcc->state = LIBIRC_STATE_CONNECTED; } else { dcc->state = LIBIRC_STATE_CONFIRM_SIZE; } libirc_mutex_lock(&ircsession->mutex_dcc); } /* * If error arises somewhere above, we inform the caller * of failure, and destroy this session. */ if (unlikely(err)) { libirc_mutex_unlock(&ircsession->mutex_dcc); (*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, 0, 0); libirc_mutex_lock(&ircsession->mutex_dcc); libirc_dcc_destroy_nolock(ircsession, dcc->id); return; } } while (hasSocketPendingData(dcc)); }