FileCacheItem::Pointer FileCache::operator[]( std::string fn ) { std::map<std::string, FileCacheItem::Pointer>::iterator it = _cache_map.find(fn); if(it == _cache_map.end()) { return FetchFile(fn); } return it->second; }
void FileHandle::FileOperations(){ if(FetchFile() == -1 || CheckMIME() == -1) return; if(result==false) return; if(MakeDir()==-1) return; Compile(); if(result==false){ CleanUp(); return; } if(PrepareToExecute()==-1){ CleanUp(); return; } Execute(); }
void NetplayUpdate(uint8 *joyp) { static uint8 buf[5]; /* 4 play states, + command/extra byte */ static uint8 joypb[4]; memcpy(joypb,joyp,4); /* This shouldn't happen, but just in case. 0xFF is used as a command escape elsewhere. */ if(joypb[0] == 0xFF) joypb[0] = 0xF; if(!netdcount) if(!FCEUD_SendData(joypb,numlocal)) { NetError(); return; } if(!netdcount) { do { if(!FCEUD_RecvData(buf,5)) { NetError(); return; } switch(buf[4]) { default: FCEU_DoSimpleCommand(buf[4]);break; case FCEUNPCMD_TEXT: { uint8 *tbuf; uint32 len = FCEU_de32lsb(buf); if(len > 100000) // Insanity check! { NetError(); return; } tbuf = (uint8*)malloc(len + 1); //mbg merge 7/17/06 added cast tbuf[len] = 0; if(!FCEUD_RecvData(tbuf, len)) { NetError(); free(tbuf); return; } FCEUD_NetplayText(tbuf); free(tbuf); } break; case FCEUNPCMD_SAVESTATE: { //mbg todo netplay //char *fn; //FILE *fp; ////Send the cheats first, then the save state, since ////there might be a frame or two in between the two sendfile ////commands on the server side. //fn = strdup(FCEU_MakeFName(FCEUMKF_CHEAT,0,0).c_str()); ////why?????? ////if(! // FCEUNET_SendFile(FCEUNPCMD_LOADCHEATS,fn); //// { //// free(fn); //// return; //// } //free(fn); //if(!FCEUnetplay) return; //fn = strdup(FCEU_MakeFName(FCEUMKF_NPTEMP,0,0).c_str()); //fp = fopen(fn, "wb"); //if(FCEUSS_SaveFP(fp,Z_BEST_COMPRESSION)) //{ // fclose(fp); // if(!FCEUNET_SendFile(FCEUNPCMD_LOADSTATE, fn)) // { // unlink(fn); // free(fn); // return; // } // unlink(fn); // free(fn); //} //else //{ // fclose(fp); // FCEUD_PrintError("File error. (K)ill, (M)aim, (D)estroy? Now!"); // unlink(fn); // free(fn); // return; //} } break; case FCEUNPCMD_LOADCHEATS: { FILE *fp = FetchFile(FCEU_de32lsb(buf)); if(!fp) return; FCEU_FlushGameCheats(0,1); FCEU_LoadGameCheats(fp); } break; //mbg 6/16/08 - netplay doesnt work right now anyway /*case FCEUNPCMD_LOADSTATE: { FILE *fp = FetchFile(FCEU_de32lsb(buf)); if(!fp) return; if(FCEUSS_LoadFP(fp,SSLOADPARAM_BACKUP)) { fclose(fp); FCEU_DispMessage("Remote state loaded.",0); } else FCEUD_PrintError("File error. (K)ill, (M)aim, (D)estroy?"); } break;*/ } } while(buf[4]); netdcount=(netdcount+1)%netdivisor; memcpy(netjoy,buf,4); *(uint32 *)joyp=*(uint32 *)netjoy; } }
int main(int argc, char **argv) { PRHostEnt hostentry; char buf[PR_NETDB_BUF_SIZE]; PRNetAddr addr; PRFileDesc *socket = NULL, *file = NULL; PRIntn cmdSize; char host[HOST_SIZE]; char port[PORT_SIZE]; char path[PATH_SIZE]; char line[LINE_SIZE]; int exitStatus = 0; PRBool endOfHeader = PR_FALSE; char *url; char *fileName = NULL; PRUint32 fileSize; if (argc != 2 && argc != 4) { PrintUsage(); exit(1); } if (argc == 2) { /* * case 1: httpget url */ url = argv[1]; } else { if (strcmp(argv[1], "-o") == 0) { /* * case 2: httpget -o outputfile url */ fileName = argv[2]; url = argv[3]; } else { /* * case 3: httpget url -o outputfile */ url = argv[1]; if (strcmp(argv[2], "-o") != 0) { PrintUsage(); exit(1); } fileName = argv[3]; } } if (ParseURL(url, host, sizeof(host), port, sizeof(port), path, sizeof(path)) == PR_FAILURE) { exit(1); } if (PR_GetHostByName(host, buf, sizeof(buf), &hostentry) == PR_FAILURE) { fprintf(stderr, "httpget: unknown host name: %s\n", host); exit(1); } addr.inet.family = PR_AF_INET; addr.inet.port = PR_htons((short) atoi(port)); addr.inet.ip = *((PRUint32 *) hostentry.h_addr_list[0]); socket = PR_NewTCPSocket(); if (socket == NULL) { fprintf(stderr, "httpget: cannot create new tcp socket\n"); exit(1); } if (PR_Connect(socket, &addr, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) { fprintf(stderr, "httpget: cannot connect to http server\n"); exitStatus = 1; goto done; } if (fileName == NULL) { file = PR_STDOUT; } else { file = PR_Open(fileName, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 00777); if (file == NULL) { fprintf(stderr, "httpget: cannot open file %s: (%d, %d)\n", fileName, PR_GetError(), PR_GetOSError()); exitStatus = 1; goto done; } } cmdSize = PR_snprintf(buf, sizeof(buf), "GET %s HTTP/1.0\r\n\r\n", path); PR_ASSERT(cmdSize == (PRIntn) strlen("GET HTTP/1.0\r\n\r\n") + (PRIntn) strlen(path)); if (PR_Write(socket, buf, cmdSize) != cmdSize) { fprintf(stderr, "httpget: cannot write to http server\n"); exitStatus = 1; goto done; } if (ReadLine(socket, line, sizeof(line)) <= 0) { fprintf(stderr, "httpget: cannot read line from http server\n"); exitStatus = 1; goto done; } /* HTTP response: 200 == OK */ if (strstr(line, "200") == NULL) { fprintf(stderr, "httpget: %s\n", line); exitStatus = 1; goto done; } while (ReadLine(socket, line, sizeof(line)) > 0) { if (line[0] == '\n') { endOfHeader = PR_TRUE; break; } if (strncmp(line, "Content-Length", 14) == 0 || strncmp(line, "Content-length", 14) == 0) { char *p = line + 14; while (*p == ' ' || *p == '\t') { p++; } if (*p != ':') { continue; } p++; while (*p == ' ' || *p == '\t') { p++; } fileSize = 0; while ('0' <= *p && *p <= '9') { fileSize = 10 * fileSize + (*p - '0'); p++; } } } if (endOfHeader == PR_FALSE) { fprintf(stderr, "httpget: cannot read line from http server\n"); exitStatus = 1; goto done; } if (fileName == NULL || fileSize == 0) { FetchFile(socket, file); } else { FastFetchFile(socket, file, fileSize); } done: if (socket) PR_Close(socket); if (file) PR_Close(file); PR_Cleanup(); return exitStatus; }
void NetplayUpdate(uint8 *joyp) { static uint8 buf[5]; /* 4 play states, + command/extra byte */ static uint8 joypb[4]; memcpy(joypb,joyp,4); /* This shouldn't happen, but just in case. 0xFF is used as a command escape elsewhere. */ if(joypb[0] == 0xFF) joypb[0] = 0xF; #ifdef NETWORK if(!netdcount) if(!FCEUD_SendData(joypb,numlocal)) { NetError(); return; } if(!netdcount) do { if(!FCEUD_RecvData(buf,5)) { NetError(); return; } switch(buf[4]) { default: FCEU_DoSimpleCommand(buf[4]);break; case FCEUNPCMD_TEXT: { uint8 *tbuf; uint32 len = FCEU_de32lsb(buf); if(len > 100000) // Insanity check! { NetError(); return; } tbuf = malloc(len + 1); tbuf[len] = 0; if(!FCEUD_RecvData(tbuf, len)) { NetError(); free(tbuf); return; } FCEUD_NetplayText(tbuf); free(tbuf); } break; case FCEUNPCMD_SAVESTATE: { char *fn; FILE *fp; /* Send the cheats first, then the save state, since there might be a frame or two in between the two sendfile commands on the server side. */ fn = FCEU_MakeFName(FCEUMKF_CHEAT,0,0); //if(! FCEUNET_SendFile(FCEUNPCMD_LOADCHEATS,fn); // { // free(fn); // return; // } free(fn); if(!FCEUnetplay) return; fn = FCEU_MakeFName(FCEUMKF_NPTEMP,0,0); fp = fopen(fn, "wb"); if(FCEUSS_SaveFP(fp)) { fclose(fp); if(!FCEUNET_SendFile(FCEUNPCMD_LOADSTATE, fn)) { unlink(fn); free(fn); return; } unlink(fn); free(fn); } else { fclose(fp); FCEUD_PrintError("File error. (K)ill, (M)aim, (D)estroy? Now!"); unlink(fn); free(fn); return; } } break; case FCEUNPCMD_LOADCHEATS: { FILE *fp = FetchFile(FCEU_de32lsb(buf)); if(!fp) return; FCEU_FlushGameCheats(0,1); FCEU_LoadGameCheats(fp); } break; case FCEUNPCMD_LOADSTATE: { FILE *fp = FetchFile(FCEU_de32lsb(buf)); if(!fp) return; if(FCEUSS_LoadFP(fp)) { fclose(fp); FCEU_DispMessage("Remote state loaded."); } else FCEUD_PrintError("File error. (K)ill, (M)aim, (D)estroy?"); } break; } } while(buf[4]); #endif netdcount=(netdcount+1)%netdivisor; memcpy(netjoy,buf,4); *(uint32 *)joyp=*(uint32 *)netjoy; }