void AbstractHost::forwardJob(Job *theJob) { if(state != Connected && state != Established) { return; } Job *forwardedJob = new Job(this, theJob, getNextPackageID()); if(theJob->getType() == Request) { server->jobManagerInstance()->addRequestResponseMapping(theJob, forwardedJob); } else { server->jobManagerInstance()->addJob(forwardedJob); server->jobManagerInstance()->addDependency(theJob, forwardedJob); } sendPackage(forwardedJob, false); }
void serialSend(char * data , int size) // size = størrelse af hvad der skal sendes { // Size checking if(size > MAX_DATA_LENGTH) size = MAX_DATA_LENGTH; static char seq = 0; char crchigh; char crclow; char array[1028]; char buffer[1028]; crcCalc(data, size, crchigh, crclow); array[0] = crchigh; array[1] = crclow; array[2] = 0; array[3] = seq; for(int i = 4; i < size+4; i++) { array[i] = data[i-4]; } do { sendPackage(array, size+4); // NOTICE: ONLY FOR TESTING. REMOVE AFTERWARDS printf("Data: %u %u %u %u %s\n", (unsigned char)array[0], (unsigned char)array[1], (unsigned char)array[2], (unsigned char)array[3], array + 4); while(!receivePackage(buffer)) {} }while(!buffer[2] == 1 && buffer[3] == seq); seq = !seq; }
void AbstractHost::sendPackageAndDelete(Package *thePackage, bool withID) { sendPackage(thePackage, withID); delete thePackage; }
ServerItem::ServerItem(SOCKET *socket, SOCKADDR_IN addr, char *message, int length) { fileError = false; blksize = 512; finished = false; this->socket = socket; this->addr = addr; package *pac = (package *)message; unsigned short op = ntohs(pac->opCode); int i = 2; for (i = 2; i < length; i++) { if (message[i] == 0) { break; } } filename = (char *)malloc(i - 1); strcpy(filename, message + 2); strcpy(mode, message + 2 + strlen(filename) + 1); int index = 2 + strlen(filename) + 1 + strlen(mode) + 1; while (index < length) { char *x = (char *)malloc(strlen(message + index) + 1); index += strlen(x) + 1; char *y = (char *)malloc(strlen(message + index) + 1); index += strlen(y) + 1; if (strcmp(x, "blksize") == 0) { sscanf(y, "%d", &blksize); } } if (op == TFTP_OP_READ || op == TFTP_OP_WRITE) { string x = string(); x.append(inet_ntoa(addr.sin_addr)); x.append(" Client connected"); logMessage((char *)x.c_str()); } if (op == TFTP_OP_READ) { fp = fopen(filename, "r"); int err = errno; if (fp == NULL) { if (err == EACCES) { sendErr(TFTP_ERR_ACCESS_DENIED); } else if (err == ENOENT) { sendErr(TFTP_ERR_FILE_NOT_FOUND); } else if (err == EEXIST) { sendErr(TFTP_ERR_FILE_ALREADY_EXISTS); } else { sendErr(TFTP_ERR_UNDEFINED); } fileError = true; } else { sendPackage(1); } } else if (op == TFTP_OP_WRITE) { fp = fopen(filename, "w"); int err = errno; if (fp == NULL) { if (err == EACCES) { sendErr(TFTP_ERR_ACCESS_DENIED); } else if (err == ENOENT) { sendErr(TFTP_ERR_FILE_NOT_FOUND); } else if (err == EEXIST) { sendErr(TFTP_ERR_FILE_ALREADY_EXISTS); } else { sendErr(TFTP_ERR_UNDEFINED); } fileError = true; } else { sendACK(0); packageIndex = 0; } } else { sendErr(TFTP_ERR_UNEXPECTED_OPCODE); } }
/** * initiateIPC - sets up the memory-mapped file to do IPC messaging * 1 file is created: to handle requests for information * initiated from Windows AT. The package is placed into * the memory-mapped file (char *memoryMappedView), * and then a special SendMessage() is sent. When the * JavaDLL returns from SendMessage() processing, the * data will be in memoryMappedView. The SendMessage() * return value tells us if all is right with the world. * * The set-up proces involves creating the memory-mapped * file, and handshaking with the JavaDLL so it knows * about it as well. * */ LRESULT AccessBridgeJavaVMInstance::initiateIPC() { DEBUG_CODE(char debugBuf[256]); DWORD errorCode; DEBUG_CODE(AppendToCallInfo(" in AccessBridgeJavaVMInstance::initiateIPC()\r\n")); // create Windows-initiated IPC file & map it to a ptr memoryMappedFileMapHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, // 8 bytes for return code sizeof(WindowsInitiatedPackages) + 8, memoryMappedFileName); if (memoryMappedFileMapHandle == NULL) { errorCode = GetLastError(); DEBUG_CODE(sprintf(debugBuf, " Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode)); DEBUG_CODE(AppendToCallInfo(debugBuf)); return errorCode; } else { DEBUG_CODE(sprintf(debugBuf, " CreateFileMapping worked - filename: %s\r\n", memoryMappedFileName)); DEBUG_CODE(AppendToCallInfo(debugBuf)); } memoryMappedView = (char *) MapViewOfFile(memoryMappedFileMapHandle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (memoryMappedView == NULL) { errorCode = GetLastError(); DEBUG_CODE(sprintf(debugBuf, " Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode)); DEBUG_CODE(AppendToCallInfo(debugBuf)); return errorCode; } else { DEBUG_CODE(sprintf(debugBuf, " MapViewOfFile worked - view: %p\r\n", memoryMappedView)); DEBUG_CODE(AppendToCallInfo(debugBuf)); } // write some data to the memory mapped file strcpy(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_QUERY); // inform the JavaDLL that we've a memory mapped file ready for it char buffer[sizeof(PackageType) + sizeof(MemoryMappedFileCreatedPackage)]; PackageType *type = (PackageType *) buffer; MemoryMappedFileCreatedPackage *pkg = (MemoryMappedFileCreatedPackage *) (buffer + sizeof(PackageType)); *type = cMemoryMappedFileCreatedPackage; pkg->bridgeWindow = ABHandleToLong(ourAccessBridgeWindow); strncpy(pkg->filename, memoryMappedFileName, cMemoryMappedNameSize); sendPackage(buffer, sizeof(buffer)); // look for the JavaDLL's answer to see if it could read the file if (strcmp(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_ANSWER) != 0) { DEBUG_CODE(sprintf(debugBuf, " JavaVM failed to deal with memory mapped file %s\r\n", memoryMappedFileName)); DEBUG_CODE(AppendToCallInfo(debugBuf)); return -1; } else { DEBUG_CODE(sprintf(debugBuf, " Success! JavaVM accpeted our file\r\n")); DEBUG_CODE(AppendToCallInfo(debugBuf)); } return 0; }