int ZMPI_Reduce_scatter_block_intsum_proclists_isendirecv(const int *sendbuf, int nsendprocs, int *sendprocs, int *recvbuf, int recvcount, int nrecvprocs, int *recvprocs, MPI_Comm comm) /* zmpi_func ZMPI_Reduce_scatter_block_intsum_proclists_isendirecv */ { int i, j; int *recvbuf_full; MPI_Request *reqs; recvbuf_full = z_alloc(nrecvprocs * recvcount, sizeof(int)); reqs = z_alloc(nsendprocs + nrecvprocs, sizeof(MPI_Request)); for (j = 0; j < nrecvprocs; ++j) MPI_Irecv(&recvbuf_full[j * recvcount], recvcount, MPI_INT, recvprocs[j], 0, comm, &reqs[j]); for (j = 0; j < nsendprocs; ++j) MPI_Isend((void *) &sendbuf[sendprocs[j] * recvcount], recvcount, MPI_INT, sendprocs[j], 0, comm, &reqs[nrecvprocs + j]); MPI_Waitall(nsendprocs + nrecvprocs, reqs, MPI_STATUSES_IGNORE); for (i = 0; i < recvcount; ++i) recvbuf[i] = DEFAULT_INT; for (j = 0; j < nrecvprocs; ++j) for (i = 0; i < recvcount; ++i) recvbuf[i] += recvbuf_full[j * recvcount + i]; z_free(reqs); z_free(recvbuf_full); return MPI_SUCCESS; }
int ZMPI_Alltoallv_proclists(void* sendbuf, int *sendcounts, int *sdispls, MPI_Datatype sendtype, int nsendprocs, int *sendprocs, void* recvbuf, int *recvcounts, int *rdispls, MPI_Datatype recvtype, int nrecvprocs, int *recvprocs, MPI_Comm comm) /* zmpi_func ZMPI_Alltoallv_proclists */ { int i, j; const int tag = 0; int nreqs; MPI_Request *reqs; MPI_Status *stats; MPI_Aint sendtype_lb, sendtype_extent, recvtype_lb, recvtype_extent; reqs = z_alloc(nrecvprocs + nsendprocs, sizeof(MPI_Request)); stats = z_alloc(nrecvprocs + nsendprocs, sizeof(MPI_Status)); MPI_Type_get_extent(sendtype, &sendtype_lb, &sendtype_extent); MPI_Type_get_extent(recvtype, &recvtype_lb, &recvtype_extent); nreqs = 0; for (i = 0; i < nrecvprocs; ++i) { j = recvprocs[i]; if (recvcounts[j] > 0) { MPI_Irecv(((char *) recvbuf) + (rdispls[j] * recvtype_extent), recvcounts[j], recvtype, j, tag, comm, &reqs[nreqs]); ++nreqs; } } for (i = 0; i < nsendprocs; ++i) { j = sendprocs[i]; if (sendcounts[j] > 0) { MPI_Isend(((char *) sendbuf) + (sdispls[j] * sendtype_extent), sendcounts[j], sendtype, j, tag, comm, &reqs[nreqs]); ++nreqs; } } MPI_Waitall(nreqs, reqs, stats); z_free(reqs); z_free(stats); return MPI_SUCCESS; }
int ZMPI_Alltoall_int_proclists_alltoallv(int *sendbuf, int nsprocs, int *sprocs, int *recvbuf, int nrprocs, int *rprocs, MPI_Comm comm) /* zmpi_func ZMPI_Alltoall_int_proclists_alltoallv */ { int i, size; int *scounts2, *sdispls2, *rcounts2, *rdispls2; MPI_Comm_size(comm, &size); scounts2 = z_alloc(4 * size, sizeof(int)); sdispls2 = scounts2 + 1 * size; rcounts2 = scounts2 + 2 * size; rdispls2 = scounts2 + 3 * size; for (i = 0; i < size; ++i) { scounts2[i] = rcounts2[i] = DEFAULT_INT; sdispls2[i] = rdispls2[i] = i; recvbuf[i] = 0; } for (i = 0; i < nsprocs; ++i) scounts2[sprocs[i]] = 1; for (i = 0; i < nrprocs; ++i) rcounts2[rprocs[i]] = 1; MPI_Alltoallv(sendbuf, scounts2, sdispls2, MPI_INT, recvbuf, rcounts2, rdispls2, MPI_INT, comm); z_free(scounts2); return MPI_SUCCESS; }
int ZMPI_Reduce_scatter_block_intsum_proclists_alltoallv(const int *sendbuf, int nsendprocs, int *sendprocs, int *recvbuf, int recvcount, int nrecvprocs, int *recvprocs, MPI_Comm comm) /* zmpi_func ZMPI_Reduce_scatter_block_intsum_proclists_alltoallv */ { int i, j, size, rank; int *recvbuf_full; int *scounts, *sdispls, *rcounts, *rdispls; MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank); recvbuf_full = z_alloc(nrecvprocs * recvcount, sizeof(int)); scounts = z_alloc(4 * size, sizeof(int)); sdispls = scounts + 1 * size; rcounts = scounts + 2 * size; rdispls = scounts + 3 * size; memset(scounts, 0, 4 * size * sizeof(int)); for (j = 0; j < nrecvprocs; ++j) { rcounts[recvprocs[j]] = recvcount; rdispls[recvprocs[j]] = j * recvcount; } for (j = 0; j < nsendprocs; ++j) { scounts[sendprocs[j]] = recvcount; sdispls[sendprocs[j]] = sendprocs[j] * recvcount; } MPI_Alltoallv((void *) sendbuf, scounts, sdispls, MPI_INT, recvbuf_full, rcounts, rdispls, MPI_INT, comm); for (i = 0; i < recvcount; ++i) recvbuf[i] = DEFAULT_INT; for (j = 0; j < nrecvprocs; ++j) for (i = 0; i < recvcount; ++i) recvbuf[i] += recvbuf_full[j * recvcount + i]; z_free(scounts); z_free(recvbuf_full); return MPI_SUCCESS; }
void z_digest_hash_close(void *hdl) /* z_proto, z_func z_digest_hash_close */ { #ifdef HAVE_GCRYPT_H gcry_md_hd_t *gcry_hdl = hdl; gcry_md_close(*gcry_hdl); z_free(gcry_hdl); #endif }
int freeSystemConfig(PSystemConfig *pConfigList,int l) { int i = 0; for(i = 0; i < l; i ++) { if(pConfigList[i]) { z_free(pConfigList[i]->name); z_free(pConfigList[i]->value); z_free(pConfigList[i]); } } if(pConfigList) { z_free(pConfigList); } return 0; }
int freeSystemConfig(PSystemConfig *pConfigList,int count) { int i = 0; for(i = 0; i < count ; i ++) { if(pConfigList[i]) { z_free(pConfigList[i]->name); z_free(pConfigList[i]->value); z_free(pConfigList[i]); } } if(pConfigList) { z_free(pConfigList); } return ZSUCCESS; }
int retrieveDNS(char * DNSArray[],int * DNSCount) { const unsigned int MAXDNSLINESIZE =1024; FILE * pFile; char * buffer; char * pch; int i=0; /*Check if DNS definition file exists ,otherwise return */ if(0==fileExists(DNSCONFIGFILE )) { fprintf(stderr,"DNS file ->%s does not exist",DNSCONFIGFILE); return -1; } pFile = fopen ( DNSCONFIGFILE , "rb" ); if (pFile==NULL) return -1; /*allocate memory to contain the whole file.*/ buffer = (char*) malloc (sizeof(char)*MAXDNSLINESIZE ); if (buffer == NULL) return -1; /* copy the file into the buffer.*/ while (1) { if(!fgets(buffer,MAXDNSLINESIZE ,pFile)) break; /*** the whole file is loaded in the buffer. ***/ pch = strstr (buffer,DNSKEYWORD); if(pch) { if(strlen(pch)>1) { if(strlen(pch)>strlen(DNSKEYWORD)+1) { strncpy(DNSArray[i],(pch+strlen(DNSKEYWORD)+1),(strlen(pch)-2-strlen(DNSKEYWORD))); i++; } } } else continue; } *DNSCount=i; fclose (pFile); z_free(buffer); return 0; }
/************************************************************************** * Function: UpdateItem * Functionality: update the database item * @IN : zDB: database handle Item: the database item name value: the item value * @OUT: * Used description: this function check the database and update or insert the item. * Date: 20080117 * Changed history: * Date Who Reason * 20080117 sandy First creation ***************************************************************************/ void UpdateItem(PZDB_HANDLE zDB, char *Item, char * value) { char *TmpVal = NULL; int ret = -1; if(value) { ret = GetValueFromDB(zDB, Item , &TmpVal); if(TmpVal == NULL || strcmp(value, TmpVal) != 0) updateDB(zDB, Item , value); } z_free(TmpVal); }
// zcode -------------- int librlc_z_encode(int k, int m, int packet_size, const char *orig_data, int orig_data_len, char **encoded_data, char **encoded_parity, int *chunk_len) { z_coder_t z_code; // z init z_init(&z_code, m, k, packet_size); // z encode int ret = z_encode(z_code.pzi, orig_data, orig_data_len, encoded_data, encoded_parity, chunk_len); // rs free z_free(&z_code); return ret; }
int librlc_z_repair(int k, int m, int packet_size, char *available_data, int *data_list, int data_num,int chunk_len, int node, char **out_data) { int ret = 0; z_coder_t z_code; //z init z_init(&z_code, m, k, packet_size); // re repair ret = z_repair(z_code.pzi, available_data, data_list, data_num, chunk_len, node, out_data); // z free z_free(&z_code); return ret; }
int ZMPI_Reduce_scatter_block(const void *sendbuf, void *recvbuf, int recvcount, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) /* zmpi_func ZMPI_Reduce_scatter_block */ { #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 return MPI_Reduce_scatter_block((void *) sendbuf, recvbuf, recvcount, datatype,op, comm); #else int comm_size, *recvcounts, i, exit_code; MPI_Comm_size(comm, &comm_size); recvcounts = z_alloc(comm_size, sizeof(int)); for (i = 0; i < comm_size; ++i) recvcounts[i] = recvcount; exit_code = MPI_Reduce_scatter((void *) sendbuf, recvbuf, recvcounts, datatype, op, comm); z_free(recvcounts); return exit_code; #endif }
static void destroy_proclists(int **send_procs, int **recv_procs) { z_free(*send_procs); }
int FARMail::ProcessHeaderDirectives(MAILSEND *parm) { const char *maxptr; const char *ptr; const char *org; size_t len; char *processed; char *prc_ptr; size_t offset; for (size_t i=0; i < parm->Header.CountHeader(); i++) { parm->Header.DecodeName(this, parm->charset, i ); parm->Header.DecodeValues(this, parm->charset, i ); for (size_t j=0; j < parm->Header.CountValues(i); j++) { org = parm->Header.GetValue(i,j); len = lstrlen(org); maxptr = org+len; for (int pass=0; pass<2; pass++) { ptr = org; if (pass==1) { prc_ptr = processed = (char *) z_calloc(len+1, sizeof(char)); if (!processed) return 0; } while ( ptr < maxptr ) { if ( *ptr != '%' ) { if (pass == 1) *(prc_ptr++) = *(ptr++); else ptr++; } else { if ( !FSF.LStrnicmp( ptr, X_TO , lstrlen(X_TO) ) ) { if (pass == 1) { lstrcpy( prc_ptr, parm->Recipient); ptr+=lstrlen(X_TO); prc_ptr+=lstrlen(parm->Recipient); } else { offset=lstrlen(X_TO); len+=lstrlen(parm->Recipient)-offset; } } else if ( !FSF.LStrnicmp( ptr, X_CC , lstrlen(X_CC) ) ) { if (pass == 1) { lstrcpy( prc_ptr, parm->CC); ptr+=lstrlen(X_CC); prc_ptr+=lstrlen(parm->CC); } else { offset=lstrlen(X_CC); len+=lstrlen(parm->CC)-offset; } } else if ( !FSF.LStrnicmp( ptr, X_BCC , lstrlen(X_BCC) ) ) { if (pass == 1) { lstrcpy( prc_ptr, parm->BCC); ptr+=lstrlen(X_BCC); prc_ptr+=lstrlen(parm->BCC); } else { offset=lstrlen(X_BCC); len+=lstrlen(parm->BCC)-offset; } } else if ( !FSF.LStrnicmp( ptr, X_SUBJ , lstrlen(X_SUBJ) ) ) { if (pass == 1) { lstrcpy( prc_ptr, parm->Subject); ptr+=lstrlen(X_SUBJ); prc_ptr+=lstrlen(parm->Subject); } else { offset=lstrlen(X_SUBJ); len+=lstrlen(parm->Subject)-offset; } } else if ( !FSF.LStrnicmp( ptr, X_FROM , lstrlen(X_FROM) ) ) { if (pass == 1) { lstrcpy( prc_ptr, parm->Sender); ptr+=lstrlen(X_FROM); prc_ptr+=lstrlen(parm->Sender); } else { offset=lstrlen(X_FROM); len+=lstrlen(parm->Sender)-offset; } } else if ( !FSF.LStrnicmp( ptr, X_REPLY , lstrlen(X_REPLY) ) ) { if (pass == 1) { lstrcpy( prc_ptr, parm->ReplyTo); ptr+=lstrlen(X_REPLY); prc_ptr+=lstrlen(parm->ReplyTo); } else { offset=lstrlen(X_REPLY); len+=lstrlen(parm->ReplyTo)-offset; } } else { if (pass==0) offset = 1; else *(prc_ptr++)= *(ptr++); } if (pass==0) ptr += offset; } } } parm->Header.SetValue(i,j,processed); z_free(processed); } } return 0; }
int WriteDNS( char * DNSItem,int index) { const int maxdns=10; char *dnsname[maxdns]; int dnscount,i,err; char strRetVal[ZMAXELEMVALUE]; char buffer[MAXLINELENGTH]; int target=0; int iRet=0; FILE * pFile; /* We need check DNS item , if the DNSitem is valid ??? we support IP address and empty DNS item value for item 2 currently.*/ /* if(!DNSItem)*/ /* return 0; */ for(i=0;i<maxdns;i++) { dnsname[i]=(char *)malloc(sizeof(char)*ZMAXELEMVALUE); if(!dnsname[i]) { fprintf(stderr, "Allocation error\n"); return -1; } memset(dnsname[i],0,sizeof(char)*ZMAXELEMVALUE); } memset(strRetVal,0,ZMAXELEMVALUE); err=0; iRet=retrieveDNS(dnsname,&dnscount); if(index==1) target=0; strcpy(strRetVal,dnsname[index]); pFile = fopen (DNSCONFIGFILE , "rb" ); if (pFile==NULL) { fprintf(stderr, "Could not find DNS file %s\n",DNSCONFIGFILE); goto errout; } memset(buffer,0,sizeof(char)*MAXLINELENGTH); /*This are default dns information*/ strcpy(buffer,"; generated by /sbin/dhclient-script\n"); strcat(buffer,"search localdomain\n"); #if 1 /*----add the default DNS server :127.0.0.1 by jyan 09-04-20----*/ if(strlen(dnsname[0])&&strcmp(dnsname[0],"127.0.0.1")) { strcat(buffer,"nameserver 127.0.0.1"); strcat(buffer,"\n"); } if(dnscount>0) { for(i=0;i<dnscount;i++) { strcat(buffer,"nameserver "); strcat(buffer,dnsname[i]); strcat(buffer,"\n"); } } freopen(DNSCONFIGFILE,"w",pFile); fwrite ( buffer, sizeof(char) , strlen(buffer) , pFile); fclose (pFile); #endif if(!DNSItem) { goto errout; return 0; } memset(buffer,0,sizeof(char)*MAXLINELENGTH); if(strlen(dnsname[0])&&strcmp(dnsname[0],"127.0.0.1")) { strcat(buffer,"nameserver 127.0.0.1\n"); } /*----add end----*/ if(0==index) { strcat(buffer,"nameserver "); strcat(buffer,DNSItem); if(strlen(dnsname[1])>0) { strcat(buffer,"\nnameserver "); strcat(buffer,dnsname[1]); strcat(buffer,"\n"); } else strcat(buffer,"\n"); } else { strcat(buffer,"nameserver "); strcat(buffer,dnsname[0]); if(strlen(DNSItem)>0) { strcat(buffer,"\nnameserver "); strcat(buffer,DNSItem); strcat(buffer,"\n\n"); } else strcat(buffer,"\n\n"); } pFile = fopen(DNSCONFIGFILE,"w"); fwrite ( buffer, sizeof(char) , strlen(buffer) , pFile); for(i=0;i<maxdns;i++) z_free(dnsname[i]); fclose (pFile); return 0; errout: for(i=0;i<maxdns;i++) z_free(dnsname[i]); return -1; }
/************************************************************************** * Function: GetTimeConfig * Functionality: fill the struct parameters from the received xmlstring * Used description: receive the xml string the prase it; * input para:no * return value: 0 render ok,else fail; * Date: 20090612 * Changed history: * Date Who Reason * 20090612 jyan First creation ***************************************************************************/ int GetTimeConfig() { char date[11] = {0}; char time[9] = {0}; char timezone[64] = {0}; char timeDST[64] = {0}; char dateFormat[64] = {0}; char timeFormat[64] = {0}; char *delim = "|"; char buf[64] = { 0 }; char *p; char *datetimeCmd ="date +%Y'-'%m'-'%d'|'%H:%M:%S"; const int MAXTESTSITEBUF =64; char sTestNTPDateSite1[MAXTESTSITEBUF]; char sTestNTPDateSite2[MAXTESTSITEBUF]; char sTestNTPDateSite3[MAXTESTSITEBUF]; char NTPAvailable[64] = {0}; char responeString[1024] = {0}; void * zdbhandle = NULL; char * str_valBuf=NULL; int iLen = 0; if(ZDBOpen(Z_UTIL_ZQDEV,DBfile,&zdbhandle) != Z_SUCCESS){ ZCommandResponseError(GETTIMECONFIGURATION,1); return -1; } /* NOTE: not good enough */ FILE *fp = NULL; if ((fp = popen (datetimeCmd, "r")) == NULL) { ZCommandResponseError(GETTIMECONFIGURATION,2); return -1; } fread (&buf[0], sizeof (char), 63, fp); pclose (fp); if (strlen (buf) > 0) { buf[strlen(buf)-1] = '\0'; } //get the date if((p=strtok(buf,delim))) { strcpy(date,p); } //get the time if((p=strtok(NULL,delim))) { strcpy(time,p); } //get TimeZone and DST GetValueFromDB(zdbhandle, "TimeZone", &str_valBuf); if( str_valBuf && strlen(str_valBuf)>0) { strcpy(timezone,str_valBuf); z_free(str_valBuf); } GetValueFromDB(zdbhandle, "TimeDST", &str_valBuf); if( str_valBuf && strlen(str_valBuf)>0) { strcpy(timeDST,str_valBuf); z_free(str_valBuf); } //get NTP Date Site GetTestNTPDateSite(zdbhandle,0,sTestNTPDateSite1); GetTestNTPDateSite(zdbhandle,1,sTestNTPDateSite2); GetTestNTPDateSite(zdbhandle,2,sTestNTPDateSite3); //get NTPAvailable GetValueFromDB(zdbhandle, "NTPAvailable", &str_valBuf); if( str_valBuf && strlen(str_valBuf)>0) { strcpy(NTPAvailable,str_valBuf); z_free(str_valBuf); } //get dateFormat and timeFormat GetValueFromDB(zdbhandle, "dateFormat", &str_valBuf); if( str_valBuf && strlen(str_valBuf)>0) { strcpy(dateFormat,str_valBuf); z_free(str_valBuf); } GetValueFromDB(zdbhandle, "timeFormat", &str_valBuf); if( str_valBuf && strlen(str_valBuf)>0) { strcpy(timeFormat,str_valBuf); z_free(str_valBuf); } sprintf(responeString,"<?xml version=\"1.0\" encoding=\"utf-8\"?><ret><err>0</err><msg/><Date>%s</Date><Time>%s</Time><Timezone>%s</Timezone><Timedst>%s</Timedst><NTP-IP1>%s</NTP-IP1><NTP-IP2>%s</NTP-IP2><NTP-IP3>%s</NTP-IP3><NTPAvailable>%s</NTPAvailable><DateFormat>%s</DateFormat><TimeFormat>%s</TimeFormat></ret>",date,time,timezone,timeDST,sTestNTPDateSite1,sTestNTPDateSite2,sTestNTPDateSite3,NTPAvailable,dateFormat,timeFormat); iLen = fputs(responeString,stdout); fflush(stdout); ZDBClose(zdbhandle); return 0; }