int out_attachment_write(std::string my_email_address, std::string he_email_address, std::string subject, char* text_content, std::string out_attachment_file_name, std::string pop_file_name){ std::ifstream in(out_attachment_file_name.c_str(),std::ios::in|std::ios::binary); std::ofstream out(pop_file_name.c_str(),std::ios::out); std::ifstream local_in(pop_file_name.c_str(),std::ios::in|std::ios::binary); std::ofstream local_out("out.txt",std::ios::out|std::ios::app); std::string s="ff\n\nk"; char* _buf; int sendsize; int _sendsize; int my_ops=my_email_address.find('@',0); std::string my_header_mail=my_email_address.substr(0,my_ops); std::string my_dns_mail=my_email_address.substr(my_ops+1,my_email_address.size()-my_ops); int he_ops=he_email_address.find('@',0); std::string he_header_mail=he_email_address.substr(0,he_ops); std::string he_dns_mail=he_email_address.substr(he_ops+1,he_email_address.size()-he_ops); time_t my_time; my_time=time(NULL); std::string str_time=ctime(&my_time); std::string str_week=string_date_get_week(str_time); std::string str_month=string_date_get_month(str_time); std::string str_date=string_date_get_date(str_time); std::string str_only_time=string_date_get_time(str_time); std::string str_year=string_date_get_year(str_time); out<<"Date: "<<str_week<<", "<<str_date<<" "<<str_month; out<<" "<<str_year<<" "<<str_only_time<<" +0800"<<std::endl; out<<"From: \""<<my_header_mail<<"\" <"<<my_email_address<<">"<<std::endl; out<<"To: \""<<he_header_mail<<"\" <"<<he_email_address<<">"<<std::endl; out<<"Subject: "<<subject<<std::endl; out<<"Message-ID: <"<<str_year<<str_month<<str_date<<string_empty_trim(str_only_time) <<"@"<<my_dns_mail<<">"<<std::endl; out<<"X-mailer: Foxmail 6, 10, 201, 20 [cn]"<<std::endl; out<<"Mime-Version: 1.0"<<std::endl; out<<"Content-Type: multipart/mixed;"<<std::endl; std::string boundary="=====001_ENNAN"+string_empty_trim(str_time)+"_====="; out<<" boundary=\""+boundary+"\""<<std::endl; //note random out<<std::endl; out<<"This is a multi-part message in MIME format."<<std::endl; out<<std::endl; out<<"--"<<boundary<<std::endl; std::string text_boundary="=====003_ZB"+string_empty_trim(str_time)+"_====="; out<<"Content-Type: multipart/alternative;"<<std::endl; out<<" boundary=\""+text_boundary+"\""<<std::endl; //note random out<<std::endl; out<<std::endl; out<<"--"<<text_boundary<<std::endl; out<<"Content-Type: text/plain;"<<std::endl; out<<" charset=\"gb2312\""<<std::endl; out<<"Content-Transfer-Encoding: base64"<<std::endl; out<<std::endl; std::string test_str=text_content; _buf=base64_encode(text_content,test_str.size()); _sendsize=strlen(_buf); out.write(_buf,static_cast<std::streamsize>(_sendsize)); out<<std::endl; out<<std::endl; out<<"--"<<text_boundary<<std::endl; out<<"--"<<boundary<<std::endl; //local_out<<std::endl; std::string attachment_name=string_file_name(out_attachment_file_name); char* x_buf=base64_encode(str_to_char(attachment_name),strlen(str_to_char(attachment_name))); out<<"Content-Type: application/app"<<std::endl; out<<" name=\"=?gb2312?B?"<<x_buf<<"?=\""<<std::endl; out<<"Content-Transfer-Encoding: base64"<<std::endl; out<<"Content-Disposition: attachment;"<<std::endl; //std::string attachment_name=string_file_name(out_attachment_file_name); //char* x_buf=base64_encode(str_to_char(attachment_name),strlen(str_to_char(attachment_name))); out<<" filename=\"=?gb2312?B?"<<x_buf<<"?=\""<<std::endl; out<<std::endl; char buf[1008+1]; memset(buf,'\0',1008+1); while(1){ in.read(buf,static_cast<std::streamsize>(1008)); sendsize=in.gcount(); _buf=base64_encode(buf,sendsize); _sendsize=strlen(_buf); if(sendsize<0){ std::cout<<"error"<<std::endl; } else if(sendsize==0) break; else{ out.write(_buf,static_cast<std::streamsize>(_sendsize)); //cout<<_sendsize<<endl; } } out<<std::endl; out<<"--"<<boundary<<std::endl; out<<std::endl; int num=get_last_number(0); char read_buf[1025]; memset(read_buf,'\0',1025); out<<std::endl; while(local_in.read(read_buf,1024)){ local_out.write(read_buf,1024); } local_out.write(read_buf,local_in.gcount()); local_out<<std::endl; char file_number[1024]; sprintf(file_number,"%d",num+1); local_out<<"!@#$%"<<file_number<<"!@#$%"<<std::endl; return 1; }
void fork_clients(int client_NUM, uint32_t tkcc) { TKCC=tkcc; intitalize_msgs(); //cout<< "total clients are:"<<client_NUM<<endl; for (int i=0; i<client_NUM; i++) { int pid= fork(); if (pid==-1) { cout<< "not able to fork\n"; } else if (pid==0) { //pid_t pid_child= getpid(); //cout <<" in child" << i <<" pid is "<< pid_child<<"\n"; /////////////////////////////////////////////////////////////////// // get the PORT to connect on through shared memory and populate struct to //talk to manager through TCP on: address_client, sockfd_client /////////////////////////////////////////////////////////////////// int numbytes_client; struct sockaddr_in address_client; int addresslen_client = sizeof(address_client); address_client.sin_family = AF_INET; address_client.sin_port = PORT; address_client.sin_addr.s_addr = INADDR_ANY; if ((sockfd_client = socket(AF_INET,SOCK_STREAM,0)) == -1) { perror("client: socket"); } if (connect(sockfd_client, (struct sockaddr*)&address_client, addresslen_client) == -1) { close(sockfd_client); perror("client: connect"); } /////////////////////////////////////////////////////////////////// //starting to recieve boot info from manager /////////////////////////////////////////////////////////////////// getsockname(sockfd_client,(struct sockaddr *)&address_client, (socklen_t*)&addresslen_client); // receiving the nonce from manager if ((numbytes_client = recv(sockfd_client, NONCE, sizeof NONCE, 0)) == -1) { perror("recv_NONCE"); exit(1); } NONCE[numbytes_client] = '\0'; //outfile_client<<"received nonce:"<<NONCE<<endl; // receiving the client name from manager if ((numbytes_client = recv(sockfd_client, CLIENT_NAME, sizeof CLIENT_NAME, 0)) == -1) { perror("recv_NAME"); exit(1); } CLIENT_NAME[numbytes_client] = '\0'; char client_name[100]; strcpy(client_name,CLIENT_NAME); MY_TOKEN=nonce_name_hash(uint32_t(htonl(atoi(NONCE))), client_name); //c<<"hash is ------------"<<hex<<MY_TOKEN<<endl; string file_name= "stage"+STAGE+"."+(string)CLIENT_NAME+".out"; outfile_client.open(str_to_char(file_name)); outfile_client<<"client "<<CLIENT_NAME<<" created with hash "<<hex<<MY_TOKEN<<endl; //outfile_client<<"received the host name from manager:"<<CLIENT_NAME<<endl; // receiving the FP from manager if ((numbytes_client = recv(sockfd_client, FP, sizeof FP, 0)) == -1) { perror("recvFP"); exit(1); } FP[numbytes_client] = '\0'; //outfile_client<<"received FP:"<<dec<<FP<<endl; // receiving the FS from manager if ((numbytes_client = recv(sockfd_client, FS, sizeof FS, 0)) == -1) { perror("recvFS"); exit(1); } FS[numbytes_client] = '\0'; //outfile_client<<"received FS:"<<FS<<endl; //int client_nonce = atoi(buf_client); //////////////////////////////////////////////////////////////////// // creating a UDP socket for triad messages- UDP_private //////////////////////////////////////////////////////////////////// create_main_udp_port(); //////////////////////////////////////////////////////////////////// // creating a UDP socket for hello messages- UDP_hello //////////////////////////////////////////////////////////////////// create_hello_udp_port(); create_lazy_udp_port(); //printf("DGRAM port is : %d\n",DGRAM_PORT); //outfile_client<< "my udp port is : "<<dec<<DGRAM_PORT<<endl; ////////////////////////////////////////////// // finding position in the ring ////////////////////////////////////////////// if ((STAGE.compare("2")==0) || (STAGE.compare("3")==0)) { position_in_ring(); } else if((STAGE.compare("6")==0) || (STAGE.compare("7")==0)) {//cout<<" inside the right intializer"<<endl; position_in_ring_FT(); } //////////////////////////////////////////////////////////////////////////////////////////// // sending dgram port and NONCE+Sx to manager through tcp socket - sockfd_client //////////////////////////////////////////////////////////////////////////////////////////// sprintf(buf,"%d",DGRAM_PORT); if(send(sockfd_client, buf, sizeof(buf), 0) == -1) perror("send"); //outfile_client<<"dgram port sent is:"<<dec<<DGRAM_PORT<<endl; char q[100]; strcpy (q,NONCE); strcat (q,client_name); if(send(sockfd_client, q, sizeof(q), 0) == -1) perror("send"); //outfile_client<<"concat nonce+Sx sent is:"<<dec<<q<<endl; ////////////////////////////////////////////////////////////////////////// // SELECT between the TCP and UDP sockets ////////////////////////////////////////////////////////////////////////// //SELECT(); TestApp *app; app = new TestApp; //Start the timers app->start(); close(sockfd_client); outfile_client.close(); //outfile_client.close(); exit(0); //once the child is done sending the info kill the child } // end child code } // end for loop } // end function