//############################## Bool32 BLOCK::SaveCompress(Handle to) { if( myWrite(to,&UserNum,sizeof(UserNum))==sizeof(UserNum) && myWrite(to,&Flags,sizeof(Flags))==sizeof(Flags) && DATA::SaveCompress(to) && myWrite(to,&InterNum,sizeof(InterNum))==sizeof(InterNum)) return TRUE; return FALSE; }
/************************ tansBetSerAndCli *****************/ void ThreadManager::transBetSerAndCli(int serSock, int cliSock) { int iolen; // read length char buf [BUFSIZ]; // read buf fd_set rdfdset; // read file set struct timeval timeout; // time out value int selVal; // select value // wait for client and server for 1 seconds timeout.tv_sec = 1; timeout.tv_usec = 0; while (1) { // Select for readability on either of our two sockets FD_ZERO(&rdfdset); FD_SET(cliSock, &rdfdset); FD_SET(serSock, &rdfdset); if ((selVal = select(FD_SETSIZE, &rdfdset, NULL, NULL, &timeout)) < 0) { perror("Select Failed"); break; } if(selVal == 0) break; // is the client sending data? if (FD_ISSET(cliSock, &rdfdset)) { // zero length means the client disconnected if ((iolen = read(cliSock, buf, sizeof(buf))) <= 0) break; // copy to host -- blocking semantics fputs(buf, debugFile); myWrite(serSock, buf, iolen); } // is the host sending data? if (FD_ISSET(serSock, &rdfdset)) { // zero length means the host disconnected if ((iolen = read(serSock, buf, sizeof(buf))) <= 0) break; // copy to client -- blocking semantics myWrite(cliSock, buf, iolen); } } } // tranBetSerAndCli
int connectToRhostPortal( char *rodsHost, int rodsPort, int cookie, int windowSize ) { int status, nbytes; struct sockaddr_in remoteAddr; int sock, myCookie; status = setSockAddr( &remoteAddr, rodsHost, rodsPort ); if ( status < 0 ) { rodsLog( LOG_NOTICE, "connectToRhostPortal: setSockAddr error for %s, errno = %d", rodsHost, errno ); return status; } /* set timeout 11/13/2009 */ sock = connectToRhostWithRaddr( &remoteAddr, windowSize, 1 ); if ( sock < 0 ) { rodsLog( LOG_ERROR, "connectToRhostPortal: connectTo Rhost %s port %d error, status = %d", rodsHost, rodsPort, sock ); return sock; } myCookie = htonl( cookie ); nbytes = myWrite( sock, &myCookie, sizeof( myCookie ), NULL ); if ( nbytes != sizeof( myCookie ) ) { CLOSE_SOCK( sock ); return SYS_PORT_COOKIE_ERR; } return sock; }
void MySocket::state(QString &arg) { int groupID=arg.toInt(); for(int i=0;i<myWindow->group.count();i++) { if(myWindow->group.at(i)->data->ID==groupID) { qDebug("11111"); QString str=myWindow->group.at(i)->getAllState(); myWrite(str); return; } } myWrite("Not found"); }
CPAGE_FUNC(Bool32) CPAGE_SavePage(Handle page,char * lpName) { PROLOG; Bool32 rc = FALSE; SetReturnCode_cpage(IDS_ERR_NO); Handle file = myOpenSave((char *)lpName); if(file) { #ifdef SAVE_COMPRESSED uint32_t vers = VERSION_FILE_COMPRESSED; #else uint32_t vers = VERSION_FILE; #endif if(myWrite(file,&vers,sizeof(vers))==sizeof(vers)) { if(page) { int count = 1; rc = myWrite(file,&count,sizeof(count))==sizeof(count); #ifdef SAVE_COMPRESSED rc = PAGE_H(page).SaveCompress(file); #else rc = PAGE_H(page).Save(file); #endif } else { int i; int count = Page.GetCount(); rc = myWrite(file,&count,sizeof(count))==sizeof(count); for(i=0;i<count && rc == TRUE;i++) #ifdef SAVE_COMPRESSED rc = PAGE_N(i).SaveCompress(file); #else rc = PAGE_N(i).Save(file); #endif } } myClose(file); } EPILOG; return rc; }
void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis > interval) { previousMillis = currentMillis; int prev = mcount-1; myWrite(prev%8, LOW); myWrite(mcount%8 , HIGH); // for (int i=0;i<8;++i) { // if ((i+mcount)%2 == 1) { // digitalWrite(i, LOW); // } else { // digitalWrite(i, HIGH); // } // } ++mcount; } }
int _cliGetCollOprStat( rcComm_t *conn, collOprStat_t **collOprStat ) { int myBuf; int status; myBuf = htonl( SYS_CLI_TO_SVR_COLL_STAT_REPLY ); status = myWrite( conn->sock, ( void * ) &myBuf, 4, SOCK_TYPE, NULL ); status = readAndProcApiReply( conn, conn->apiInx, ( void ** ) collOprStat, NULL ); return ( status ); }
//################################# Bool32 BackupPage::SaveCompress(Handle to) { int count = backups_.GetCount(); Bool32 rc = FALSE; int i, position; rc = myWrite(to, &count, sizeof(count)) == sizeof(count); if (count) { position = backups_.GetPos(hCurBackUp); if (rc) rc = myWrite(to, &position, sizeof(position)) == sizeof(position); if (rc == TRUE && count) for (i = 0; i < count; i++) backups_.GetItem(backups_.GetHandle(i)).SaveCompress(to); } if (rc) rc = PAGE::SaveCompress(to); return rc; }
void MySocket::start(QString &arg) { QStringList args=arg.split("-"); int groupID=args.at(0).toInt(); int type=args.at(1).toInt(); int index=args.at(2).toInt(); int runType=args.at(3).toInt(); for(int i=0;i<myWindow->group.count();i++) { if(myWindow->group.at(i)->data->ID==groupID) { if(type==0) { if(myWindow->group.at(i)->startMix(index,runType)) { myWrite("OK"); } else { myWrite("Start faild"); } return; }else if(type==1){ if(myWindow->group.at(i)->startMux(index,runType)) { myWrite("OK"); } else { myWrite("Start faild"); } return; } } } myWrite("Not found"); }
int svrSendZoneCollOprStat( rsComm_t * rsComm, rcComm_t * conn, collOprStat_t * collOprStat, int retval ) { int status = retval; while ( status == SYS_SVR_TO_CLI_COLL_STAT ) { status = _svrSendCollOprStat( rsComm, collOprStat ); if ( status == SYS_CLI_TO_SVR_COLL_STAT_REPLY ) { status = _cliGetCollOprStat( conn, &collOprStat ); } else { int myBuf = htonl( status ); myWrite( conn->sock, ( void * ) &myBuf, 4, NULL ); break; } } return status; }
/* Test myRead and myWrite functions */ int main() { int access, method, fd, file = 0; while(file != -1) { char buffer[10000]; printf("Please choose a file within the directory to edit.\n"); printf("For exploit.c, enter 1.\n"); printf("For findMessage.java, enter 2.\n"); printf("For hideMessage.java, enter 3.\n"); printf("For shellcode.c, enter 4.\n"); printf("For stack.c, enter 5.\n"); printf("To exit, enter 0.\n"); /* Exit if requested */ scanf("%d", &file); if(file == 0) return 0; printf("Would you like to read(1) or write(2)?\n"); scanf("%d", &method); /* Determine if user actually has permission to manipulate file how they'd like */ if(userAccess() == 0) access = 2; else if(userAccess() == 501) access = 1; else access = 0; /* Call read or write function */ file = file - 1; if(method == 1) myRead(buffer, sizeof(buffer), file, access); else if(method == 2) myWrite(file, access); printf("\n"); } return 0; }
/************************ processRequest *******************/ void * ThreadManager::processRequest(void *cliSocketP) { // copy the client socket int cliSock = *static_cast<int *>(cliSocketP); delete static_cast<int *>(cliSocketP); char pack[BUFSIZ]; // package to be the cache between client // and server(here server is mean the server // which provide the resources that client // ask for, below is the same meaning) int bytesRead; SocketManager serSockMan; // server socket manager int serSock; // server socket if ((bytesRead = read(cliSock, pack, BUFSIZ))) { // Get the HTTP command and arguments if (bytesRead < 0 && errno != EINTR) { perror("Read Client Error"); close(cliSock); return NULL; } // set end to the pack pack[bytesRead] = '\0'; // make up the HTTP package HTTPPack firstHttpPack(pack); // Is the package valid? if (!firstHttpPack.isValid()) { close(cliSock); return NULL; } // connect to server serSock = serSockMan. makeClientSocket(firstHttpPack.getHostName().c_str(), firstHttpPack.getHostPort()); if (serSock <= 0 && errno != EINTR) { perror("Connect Server Error"); myWrite(cliSock, MS_CANNT_GET_MSG.c_str(), MS_CANNT_GET_MSG.length()); close(cliSock); return NULL; } // send the request to server fputs(firstHttpPack.getPack().c_str(), debugFile); if(myWrite(serSock, firstHttpPack.getPack().c_str(), firstHttpPack.getPack().length() * sizeof(char)) == -1) { perror("Write to Server Failure"); close(cliSock); return NULL; } transBetSerAndCli(serSock,cliSock); } close(cliSock); return NULL; } // processRequest
int main(int argc, char *memin[]) { int i, rc; int irc; int messages = true, #ifdef IBMPCCHARS box_chars = true; #else box_chars = false; #endif char indefsfnm[MAX_FILENM_SIZE], inloadfnm[MAX_FILENM_SIZE]; /* set global variables */ defssw = false; defsfnm = NULL; initmemsize = dfmemsize; quiet = false; expansion = true; quiet = false; nouserinterrupts = false; loadsw = false; triggered = true; debugging_on = true; diag_messages_on = false; interpreter_running = false; #ifdef HISTORY lasteval = -1; #endif #ifdef DEBUG debug = false; #endif #ifdef PROFILE profile = false; #endif /* Export the command line to the rest of the code */ #ifdef CMDLINE global_argv = memin; global_argc = argc; #endif /* MAJ: the following code is kept in case I decide to go back to having the console and cgi versions the same code. */ if (iscgiversion) { quiet = true; messages = false; box_chars = false; triggered = false; nouserinterrupts = true; } #ifdef UNIXSYS initunixsignals(); #endif /* process command arguments the allowed syntax is: [(+|-)size nnnn] [-defs filenm] [-q] [-m] [-b] [-s] [-d] [workspacename] */ if (iscgiversion) /* This code will allow the cgi version to accept *.nws, *.ndf or *.nfm files on the command line. No other parameters are available. */ { if (argc >= 2) { int offset = (memin[1][0] == '\"') ? -1 : 0; if (STRNCASECMP((strlen(memin[1]) + memin[1] - 4 + offset), ".NDF", 4) == 0) { /* arg is a Nial definition file name */ defssw = true; strcpy(indefsfnm, memin[1]); } else if (STRNCASECMP((strlen(memin[1]) + memin[1] - 4 + offset), ".NWS", 4) == 0) { /* arg is a Nial workspace file name */ loadsw = true; strcpy(inloadfnm, memin[1]); } } } else { i = 1; while (i < argc) { if (strcmp(memin[i], "-size") == 0) { /* set iniital size and allow expansion */ initmemsize = atol(memin[i + 1]); if (initmemsize < minmemsize) initmemsize = minmemsize; expansion = true; i += 2; } else if (strcmp(memin[i], "+size") == 0) { /* set iniital size and disallow expansion */ initmemsize = atol(memin[i + 1]); if (initmemsize < minmemsize) initmemsize = minmemsize; expansion = false; i += 2; } else if (strcmp(memin[i], "-defs") == 0) { if (i < argc) { /* explicit defs file name given */ defssw = true; strcpy(indefsfnm, memin[i + 1]); i += 2; } else { printf("missing definition file name after -defs option\n"); exit(1); } } else if (strcmp(memin[i], "-q") == 0) { /* inhibit all output */ quiet = true; i++; } else if (strcmp(memin[i], "-m") == 0) { /* do not display warning messages */ messages = false; i++; } else if (strcmp(memin[i], "-d") == 0) { /* disable Nial level debugging */ debugging_on = false; i++; } else #ifdef IBMPCCHARS if (strcmp(memin[i], "-b") == 0) { /* do not use the IMB PC box characters */ box_chars = false; i++; } else #endif if (strcmp(memin[i], "-s") == 0) { /* suppress fault triggering */ triggered = false; i++; } else if (strcmp(memin[i], "-h") == 0) { /* display the help syntax and exit */ print_syntax(); exit(1); } else if (memin[i][0] == '-') { /* invalid command line. display and exit. */ printf("invalid command line option: %s", memin[i]); exit(1); } else { /* assume rest of line is a workspace file name */ loadsw = true; strcpy(inloadfnm, memin[i]); i++; } } } /* end of code to process arguments */ /* code to check if we are running a console version under WINDOWS. If we are do not attempt to check for the keyboard, since it slows execution outrageously. This has been switched out for now. Not needed since DOS version no longer supported. */ #ifdef OMITTED checkkeyboard = (getenv("WINDIR") == NULL ? true : false); /* printf("checkkeyboard %d\n", checkkeyboard); */ #endif /* set the session variables */ sessionSettings = NC_CreateSessionSettings(); CheckErr(NC_SetSessionSetting(sessionSettings, NC_WORKSPACE_SIZE, initmemsize)); CheckErr(NC_SetSessionSetting(sessionSettings, NC_EXPANSION, expansion)); if (loadsw) CheckErr(NC_SetSessionSetting(sessionSettings, NC_INITIAL_WORKSPACE, (int) inloadfnm)); if (defssw) CheckErr(NC_SetSessionSetting(sessionSettings, NC_INITIAL_DEFS, (int) indefsfnm)); CheckErr(NC_SetSessionSetting(sessionSettings, NC_QUIET, quiet)); CheckErr(NC_SetSessionSetting(sessionSettings, NC_DEBUGGING_ON, debugging_on)); CheckErr(NC_SetCheckUserBreak(sessionSettings, myCheckUserBreak)); windSettings = NC_CreateWindowSettings(); if (iscgiversion) /* avoid output by having no prompt in CGINIAL */ CheckErr(NC_SetWindowSetting(windSettings, NC_PROMPT, (int) "")); /* The CGINIAL version is given a default 0 screen width setting, so no lines are broken. */ #ifdef WINDOWS_SYS /* The following code is added, so that we can accurately set the window's width. */ { CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); CheckErr(NC_SetWindowSetting(windSettings, NC_SCREEN_WIDTH, (iscgiversion ? 0 : ((csbi.srWindow.Right - csbi.srWindow.Left))))); } #else CheckErr(NC_SetWindowSetting(windSettings, NC_SCREEN_WIDTH, (iscgiversion ? 0 : 79))); #endif CheckErr(NC_SetWindowSetting(windSettings, NC_TRIGGERED, triggered)); CheckErr(NC_SetWindowSetting(windSettings, NC_NOUSERINTERRUPTS, nouserinterrupts)); CheckErr(NC_SetWindowSetting(windSettings, NC_MESSAGES, messages)); CheckErr(NC_SetWindowSetting(windSettings, NC_BOX_CHARS, box_chars)); #ifdef INTERNAL_BUF_MODE theContext = NC_CreateIOContext(); CheckErr(NC_SetIOMode(theContext, NC_INTERNAL_BUFFER_MODE)); NC_SetBufferSize(5000, 1000); #endif #ifdef IO_MODE theContext = NC_CreateIOContext(); CheckErr(NC_SetIOMode(theContext, NC_IO_MODE)); CheckErr(NC_SetWriteCommand(theContext, myWrite, stdout)); CheckErr(NC_SetReadStringCommand(theContext, myReadString, stdin)); CheckErr(NC_SetReadCharCommand(theContext, myReadChar, stdin)); #endif /* get nialroot path from environment on console version */ { char *nroot; nialrootname[0] = '\0'; nroot = getenv("NIALROOT"); if (nroot != NULL) strcpy(nialrootname, nroot); } /* initialize the user break capability */ signal(SIGINT, controlCcatch); /* initialize the core routines */ irc = NC_InitNial(sessionSettings, windSettings, theContext); if (NC_IsTerminate(irc)) { /* initialization has signalled a termination */ exit(0); } else { CheckErr(irc); } #ifdef INTERNAL_BUF_MODE /* display the result in the internal buffer */ printf("%s", NC_GetBuffer()); #endif /* avoid the top level loop in a RUNTIME ONLY or CGINIAL version */ #ifdef RUNTIMEONLY goto cleanup; #endif #ifdef CGINIAL goto cleanup; #endif /* the top level loop */ do { retry: /* issue the prompt to the console */ myWrite(stdout, NC_GetPrompt(windSettings)); userbreakrequested = false; /* could have been set during latent call in * NC_InitNial() */ /* get the input string */ awaitinginput = true; myReadInput(); /* check if the input included a Control C press */ if (myCheckUserBreak(NC_CS_INPUT)) { /* printf("myCheckUserBreak returned true\n"); */ /* remove after testing in UNIX */ /* make sure workspace is clean */ cleanup_ws(); #ifdef HISTORY if (lasteval != -1) { decrrefcnt(lasteval); freeup(lasteval); } lasteval = (-1); #endif #ifdef DEBUG printf("userbreakrequested set during input at top level loop\n"); #endif userbreakrequested = false; goto retry; /* to go around to the prompt again */ } if (EOFsignalled) { /* the feof() code in Borland C returns nonzero if Ctrl-C has been pressed. This leads to a premature exit here. Removing the test causes nial.exe to loop forever if used as a filter. */ goto cleanup; } awaitinginput = false; /* interpret the input */ rc = NC_CommandInterpret(inputline, windSettings, theContext); /* check if there was a Control C press during CI execution */ if (myCheckUserBreak(NC_CS_NORMAL)) { cleanup_ws(); #ifdef DEBUG printf("userbreakrequested set during input at top level loop\n"); #endif userbreakrequested = false; goto retry; /* to go around to the prompt again */ } #ifdef INTERNAL_BUF_MODE /* display the output if buffered */ printf("%s\n", NC_GetBuffer()); #endif /* check the return code from CI */ if (!(NC_IsNoError(rc) || NC_IsWarning(rc) || NC_IsBreak(rc) || NC_IsTerminate(rc))) { /* display error information to console */ printf("Return Code: %s ErrorTypeName : %s\n", NC_ErrorTypeName(rc), NC_ErrorMessage(rc)); } } while (NC_IsWarning(rc) || NC_IsNoError(rc) || NC_IsBreak(rc)); /* end of top level loop code */ cleanup: /* stop the interpreter and clean up its resource usage */ NC_StopNial(); /* clean up the core interface resources */ CheckErr(NC_DestroyIOContext(theContext)); CheckErr(NC_DestroyWindowSettings(windSettings)); CheckErr(NC_DestroySessionSettings(sessionSettings)); /* return from the console version of Q'Nial */ /* getchar(); */ /* MAJ: put in the above getchar here to delay exit so that debug output can be seen when running from the Borland interface */ exit(0); return 1; /* to satisfy syntax error checking */ }
int _write_r (struct _reent *r, int file, char * ptr, int len) { return myWrite(r,file,ptr,len); }
int main(int argc,char *argv[]){ if(argc<2) usage(0); char *sourceURL=argv[1]; clock_t begin, end; int i=0; char *handleURL; int pos; UPU *tmp; URL_FILE *buf; char prefix[10],host[1024],path[4096],filename[4096]; for(i=0;i<HashSize;i++){ URLPool[i]=NULL; finishPool[i]=NULL; failedPool[i]=NULL; } memset(prefix,0,10); memset(host,0,1024); memset(path,0,4096); memset(filename,0,4096); sepURL(sourceURL,prefix,host,path,filename); //check/create Folder folderInit(host); readRec(sourceURL); //init if(!logInit(host)){ printf("log file error\n"); exit(1); } pos=hashfn(sourceURL); myAdd(&URLPool[pos],sourceURL,strlen(sourceURL)); //start loop begin=clock(); i=0; while(getPoolSize(URLPool)!=0){ //random get one URL Structure Pointer from URLPool handleURL=randGet(URLPool); pos=hashfn(handleURL); printf("run [%d] %s\n",pos,handleURL); memset(prefix,0,10); memset(host,0,1024); memset(path,0,4096); memset(filename,0,4096); sepURL(handleURL,prefix,host,path,filename); //put the url in finishPool tmp=finishPool[pos]; if(tmp==NULL){ myAdd(&finishPool[pos],handleURL,strlen(handleURL)); }else{ while(tmp->next!=NULL){ tmp=tmp->next; } myAdd(&(tmp->next),handleURL,strlen(handleURL)); } //start run the CURL if((buf=runCURL(handleURL))!=NULL){ //write to File myWrite(host,filename,buf->buffer,buf->buffer_len,i++); getURL(buf->buffer,buf->buffer_len,handleURL,prefix,host,path,filename); printf("%d\n",getPoolSize(URLPool)); memset(buf->buffer,0,buf->buffer_len); free(buf->buffer); fflush(logfp); } else{ printf("no content\n"); } free(buf); } logClose(); end=clock(); printf("finally finish: %d 's URL, cost %lf sec\n",getPoolSize(finishPool),(double)( end - begin ) / CLOCKS_PER_SEC); myDump(host); return 0; }