void CMailMessage::FormatMessage() { start_header(); prepare_header(); end_header(); prepare_body(); }
static int tar_mkgeneric(const char *name, char type, unsigned int mode, uid_t uid, gid_t gid) { prepare_header(name, type, mode, uid, gid); write_header(); return 0; }
inline static void personal_read(char *fname, struct account *account) { struct csv_header *header; struct csv_row *row; FILE *stream; touch_file(fname); if ((stream = fopen(fname, "r")) == NULL) ERROR("read personal %s", fname); header = csv_read_header(stream); if (header == NULL) header = csv_read_header_from_string(DEFAULT_HEADER); prepare_header(header); row = csv_read_row(stream, header); if (row == NULL) return; account->cardno = csv_find_row(row, "cardno")->value.i; account->expire = strdup(csv_find_row(row, "expire")->value.s); account->balance = csv_find_row(row, "balance")->value.d; account->state = csv_find_row(row, "state")->value.i; account->faculty = strdup(csv_find_row(row, "faculty")->value.s); csv_destory_row(row); csv_destory_header(header); fclose(stream); }
static void write_global_extended_header(struct archiver_args *args) { const unsigned char *sha1 = args->commit_sha1; struct strbuf ext_header = STRBUF_INIT; struct ustar_header header; unsigned int mode; if (sha1) strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40); if (args->time > USTAR_MAX_MTIME) { strbuf_append_ext_header_uint(&ext_header, "mtime", args->time); args->time = USTAR_MAX_MTIME; } if (!ext_header.len) return; memset(&header, 0, sizeof(header)); *header.typeflag = TYPEFLAG_GLOBAL_HEADER; mode = 0100666; xsnprintf(header.name, sizeof(header.name), "pax_global_header"); prepare_header(args, &header, mode, ext_header.len); write_blocked(&header, sizeof(header)); write_blocked(ext_header.buf, ext_header.len); strbuf_release(&ext_header); }
static int tar_mklink(const char *name, const char *target, char type, unsigned int mode, uid_t uid, gid_t gid) { prepare_header(name, type, mode, uid, gid); strncpy(tar.formated.linkname, target, sizeof(tar.formated.linkname)-1); write_header(); return 0; }
BOOL CSMTP::FormatMailMessage( MailHeader * msg ) { ASSERT( msg != NULL ); if( prepare_header( msg ) == FALSE ) { return FALSE; } if( msg->TextBody.Right( 2 ) != "\r\n" ) msg->TextBody += "\r\n"; return TRUE; }
static void write_extended_header(struct archiver_args *args, const struct object_id *oid, const void *buffer, unsigned long size) { struct ustar_header header; unsigned int mode; memset(&header, 0, sizeof(header)); *header.typeflag = TYPEFLAG_EXT_HEADER; mode = 0100666; xsnprintf(header.name, sizeof(header.name), "%s.paxheader", oid_to_hex(oid)); prepare_header(args, &header, mode, size); write_blocked(&header, sizeof(header)); write_blocked(buffer, size); }
static int write_extended_header(struct archiver_args *args, const unsigned char *sha1, const void *buffer, unsigned long size) { struct ustar_header header; unsigned int mode; memset(&header, 0, sizeof(header)); *header.typeflag = TYPEFLAG_EXT_HEADER; mode = 0100666; sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1)); prepare_header(args, &header, mode, size); write_blocked(&header, sizeof(header)); write_blocked(buffer, size); return 0; }
static int write_global_extended_header(struct archiver_args *args) { const unsigned char *sha1 = args->commit_sha1; struct strbuf ext_header = STRBUF_INIT; struct ustar_header header; unsigned int mode; int err = 0; strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40); memset(&header, 0, sizeof(header)); *header.typeflag = TYPEFLAG_GLOBAL_HEADER; mode = 0100666; strcpy(header.name, "pax_global_header"); prepare_header(args, &header, mode, ext_header.len); write_blocked(&header, sizeof(header)); write_blocked(ext_header.buf, ext_header.len); strbuf_release(&ext_header); return err; }
inline static void personal_save(char *fname, struct account *account) { struct csv_header *header; struct csv_row *row; FILE *stream; if ((stream = fopen(fname, "w")) == NULL) ERROR("write personal: %s", fname); header = csv_read_header_from_string(DEFAULT_HEADER); prepare_header(header); row = csv_create_row(header); prepare_row(row, account); csv_write_header(stream, header); csv_write_row(stream, row); csv_destory_row(row); csv_destory_header(header); fclose(stream); }
static int write_tar_entry(struct archiver_args *args, const unsigned char *sha1, const char *path, size_t pathlen, unsigned int mode) { struct ustar_header header; struct strbuf ext_header = STRBUF_INIT; unsigned int old_mode = mode; unsigned long size; void *buffer; int err = 0; memset(&header, 0, sizeof(header)); if (S_ISDIR(mode) || S_ISGITLINK(mode)) { *header.typeflag = TYPEFLAG_DIR; mode = (mode | 0777) & ~tar_umask; } else if (S_ISLNK(mode)) { *header.typeflag = TYPEFLAG_LNK; mode |= 0777; } else if (S_ISREG(mode)) { *header.typeflag = TYPEFLAG_REG; mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask; } else { return error("unsupported file mode: 0%o (SHA1: %s)", mode, sha1_to_hex(sha1)); } if (pathlen > sizeof(header.name)) { size_t plen = get_path_prefix(path, pathlen, sizeof(header.prefix)); size_t rest = pathlen - plen - 1; if (plen > 0 && rest <= sizeof(header.name)) { memcpy(header.prefix, path, plen); memcpy(header.name, path + plen + 1, rest); } else { sprintf(header.name, "%s.data", sha1_to_hex(sha1)); strbuf_append_ext_header(&ext_header, "path", path, pathlen); } } else memcpy(header.name, path, pathlen); if (S_ISREG(mode) && !args->convert && sha1_object_info(sha1, &size) == OBJ_BLOB && size > big_file_threshold) buffer = NULL; else if (S_ISLNK(mode) || S_ISREG(mode)) { enum object_type type; buffer = sha1_file_to_archive(args, path, sha1, old_mode, &type, &size); if (!buffer) return error("cannot read %s", sha1_to_hex(sha1)); } else { buffer = NULL; size = 0; } if (S_ISLNK(mode)) { if (size > sizeof(header.linkname)) { sprintf(header.linkname, "see %s.paxheader", sha1_to_hex(sha1)); strbuf_append_ext_header(&ext_header, "linkpath", buffer, size); } else memcpy(header.linkname, buffer, size); } prepare_header(args, &header, mode, size); if (ext_header.len > 0) { err = write_extended_header(args, sha1, ext_header.buf, ext_header.len); if (err) { free(buffer); return err; } } strbuf_release(&ext_header); write_blocked(&header, sizeof(header)); if (S_ISREG(mode) && size > 0) { if (buffer) write_blocked(buffer, size); else err = stream_blocked(sha1); } free(buffer); return err; }
int main(int narg,char **arg) { if(narg<2) { fprintf(stderr,"Error, use: %s run_input\n",arg[0]); exit(1); } int big_endian=check_endianess(); FILE *frun_input=open_file(arg[1],"r"); //read the analysis templ sun_string analysis_templ_path; read_formatted_from_file_expecting(analysis_templ_path,frun_input,"%s","analysis_templ_path"); FILE *fatempl=open_file(analysis_templ_path,"r"); read_formatted_from_file_expecting((char*)&nlevel,fatempl,"%d","nlevel"); //allocate room for the header format var_name=(sun_string*)malloc(nlevel*sizeof(sun_string)); var_value_tot=(int*)malloc(nlevel*sizeof(int)); var_values=(sun_string**)malloc(nlevel*sizeof(sun_string*)); level_header_templ=(sun_string*)malloc(nlevel*sizeof(sun_string)); required_header=(int*)malloc(nlevel*sizeof(int)); //read the name of the looping variables and their values for(int ilevel=0;ilevel<nlevel;ilevel++) { read_formatted_from_file_expecting(var_name[ilevel],fatempl,"%s","var_name"); expect_string_from_file(frun_input,var_name[ilevel]); read_formatted_from_file_expecting((char*)&(var_value_tot[ilevel]),frun_input,"%d","var_value_tot"); var_values[ilevel]=(sun_string*)malloc(var_value_tot[ilevel]*sizeof(sun_string)); expect_string_from_file(frun_input,"list_of_var_values"); for(int ival=0;ival<var_value_tot[ilevel];ival++) read_formatted_from_file(var_values[ilevel][ival],frun_input,"%s","var_value"); read_formatted_from_file_expecting(level_header_templ[ilevel],fatempl,"%s","header"); required_header[ilevel]=strcmp(level_header_templ[ilevel],"NO"); } fclose(fatempl); //read T int T; read_formatted_from_file_expecting((char*)&T,frun_input,"%d","T"); //read the output file sun_string outpath; read_formatted_from_file_expecting(outpath,frun_input,"%s","outfile"); FILE *fout=open_file(outpath,"w"); //read the number of jacknives unsigned int njack; read_formatted_from_file_expecting((char*)&njack,frun_input,"%d","njack"); //read the path templ sun_string path_templ; read_formatted_from_file_expecting(path_templ,frun_input,"%s","path_templ"); //read the number of files to open int tfiles; read_formatted_from_file_expecting((char*)&tfiles,frun_input,"%d","nfiles"); //calculate cluster size int clus_size=tfiles/njack; int nfiles=clus_size*njack; printf("Njack: %d, cluster size: %d\n",njack,clus_size); //open all the input files, reading each entry expect_string_from_file(frun_input,"list_of_files"); FILE *fdata[nfiles]; for(int ifile=0;ifile<nfiles;ifile++) { sun_string chunk; read_formatted_from_file(chunk,frun_input,"%s","particular file name"); sun_string file_path; sprintf(file_path,path_templ,chunk); fdata[ifile]=open_file(file_path,"r"); //printf("file %d = %s\n",ifile,file_path); } ///////////////////////////////////////////////////////////////////////////////// //calculate the number of combo on which to loop int ncombo=1; for(int ilevel=0;ilevel<nlevel;ilevel++) ncombo*=var_value_tot[ilevel]; //loop over all the combo for(int icombo=0;icombo<ncombo;icombo++) { int level_entry[nlevel]; memset(level_entry,0,sizeof(int)*nlevel); int temp_icombo=icombo; for(int ilevel=nlevel-1;ilevel>=0;ilevel--) { level_entry[ilevel]=temp_icombo%var_value_tot[ilevel]; temp_icombo/=var_value_tot[ilevel]; } //now read all the required header for(int ilevel=0;ilevel<nlevel;ilevel++) if(required_header[ilevel] && (ilevel==nlevel-1||level_entry[ilevel+1]==0)) { sun_string header; prepare_header(header,level_header_templ[ilevel],level_entry); for(int ifile=0;ifile<nfiles;ifile++) { sun_string read_header; int nchar; do { char *read=fgets(read_header,1024,fdata[ifile]); if(read!=read_header) { fprintf(stderr,"Error while reading header: %s\n",header); exit(1); } nchar=0; do if(*read!=' ' && *read!='\n' && *read!='\0') nchar++; while(*(read++)!='\0' && nchar==0); } while(nchar==0); if(strcmp(read_header,header)) { fprintf(stderr,"Error while reading header: '%s', obtained: '%s'\n",header,read_header); exit(1); } } } //now read a whole correlation double data[nfiles][T][2]; for(int ifile=0;ifile<nfiles;ifile++) for(int t=0;t<T;t++) for(int ri=0;ri<2;ri++) read_formatted_from_file((char*)&data[ifile][t][ri],fdata[ifile],"%lg","data"); //clusterize double clus[2][T][njack+1]; memset(clus,0,sizeof(double)*2*T*(njack+1)); for(int ri=0;ri<2;ri++) for(int t=0;t<T;t++) { for(int ifile=0;ifile<nfiles;ifile++) { int iclus=ifile%njack; clus[ri][t][iclus]+=data[ifile][t][ri]; } for(unsigned int iclus=0;iclus<njack;iclus++) clus[ri][t][njack]+=clus[ri][t][iclus]; for(unsigned int ijack=0;ijack<njack;ijack++) clus[ri][t][ijack]=(clus[ri][t][njack]-clus[ri][t][ijack])/(nfiles-clus_size); clus[ri][t][njack]/=nfiles; } if(big_endian==0) doubles_to_doubles_changing_endianess((double*)clus,(double*)clus,2*T*(njack+1)); for(int t=0;t<T;t++) printf("%d %lg %lg\n",t,clus[0][t][njack],clus[1][t][njack]); if(fwrite(clus,sizeof(double),2*T*(njack+1),fout)!=2*T*(njack+1)) { fprintf(stderr,"Error while writing double!\n"); exit(1); } if(icombo%100==0) printf("Completed correlation: %d\n",icombo); } return 0; }
BOOL Smtp::CreateSmtpMessage( CHAR *cpSmtpServer, CHAR *cpFrom, CHAR *cpTo[], INT cTo, CHAR *cpSubject, INT nMimeType, // 1 - text; 2 - html CHAR *cpBody, INT nHasAttachment, // 0 - No; 1 -yes CHAR *cpAttachFile) { FILE *fp1; CHAR szBody1[5120] = "" ; CHAR szString1[1024]; m_iCount++; if ( m_bEhloNotSent ) { if ( !SendRecv( "EHLO ", "\r\n" ) ) return( FALSE ); m_bEhloNotSent = FALSE; } if ( !SendRecv( "MAIL FROM: ", cpFrom, "\r\n" ) ) return( FALSE ); for ( INT j = 0; j < cTo; j++ ) { if ( !SendRecv( "RCPT TO: ", cpTo[ j ], "\r\n" ) ) return( FALSE ); } if ( !SendRecv( "DATA", "\r\n" ) ) return( FALSE ); FormatedDate fd; _TCHAR *tcpDate = fd.GetFormatedDate(); if ( !Send( tcpDate, "\r\n" ) ) return( FALSE ); delete [] tcpDate; if ( !Send( "FROM: ", cpFrom, "\r\n" ) ) return( FALSE ); for ( j = 0; j < cTo; j++ ) { if ( !Send( "TO: ", cpTo[ j ], "\r\n" ) ) return( FALSE ); } if ( !Send( "SUBJECT: ", cpSubject, "\r\n" ) ) return( FALSE ); prepare_header(); if ( nMimeType == 2 ) { if (nHasAttachment == 1 ) // so this is HTML And Attachment { insert_mixed_part(); insert_boundry(); } insert_html_part(); } else // plain text with or without attachment { if (nHasAttachment == 1 ) // this is plain text with attachment { insert_mixed_part(); insert_boundry(); } insert_text_part(); } // set the encoding if ( !Send( "Content-Transfer-Encoding: ", "7bit", "\r\n", "\r\n" ) ) return( FALSE ); // do the body if ( !Send( cpBody ) ) return( FALSE ); if ( !Send( "\r\n" ) ) return( FALSE ); // add attachments here if necessary if (nHasAttachment == 1 ) { //insert_end_boundry(); insert_boundry(); if ( !Send( "Content-Type: APPLICATION/octet-stream; name=\"", cpAttachFile,"\"", "\r\n" ) ) return( FALSE ); if ( !Send( "Content-Transfer-Encoding: 7bit", "\r\n" ) ) return( FALSE ); if ( !Send( "Content-Disposition: attachment; filename=\"", cpAttachFile,"\"", "\r\n" ) ) return( FALSE ); if ( !Send( "\r\n" ) ) return( FALSE ); ///////////////////// strcpy( szBody1, ""); fp1 = fopen(cpAttachFile,"r"); while (fgets(szString1,1024,fp1)) { strcat( szBody1, szString1 ); } fclose(fp1); ///////////////////// if ( !Send( szBody1 ) ) return( FALSE ); insert_end_boundry(); } // end th body if ( !Send( "\r\n" ) ) return( FALSE ); if ( !SendRecv( ".", "\r\n" ) ) return( FALSE ); return( TRUE ); }