// Run after a client connects int32 DoAccept(void *pointer) { LogWindow* logWindow; BString received,status,path; int32 offset; uint32 fileLength, bytesRead; BString nick; BString filename; BString lengthStr; unsigned char* buffer; // For holding whatever it is we receive logWindow = (LogWindow *)pointer; buffer = (unsigned char *)malloc(1024); // We'll take the data in 1K // Chunks logWindow->netEndpoint->Send("\n", 1); // Get a line from the connection while(logWindow->netEndpoint->IsDataPending()) { bytesRead = logWindow->netEndpoint->Receive((unsigned char *)buffer, 1024); *(buffer + bytesRead) = '\0'; received += (char *)buffer; if(isdigit(*(buffer + (bytesRead - 1)))) break; } if(received.Compare("GET", 3) == 0) { // Looks like somebody wants a file offset = received.FindFirst("\"", 3); // Figure out where the filename starts received.CopyInto(nick, 3, (offset - 3)); received.CopyInto(filename, (offset + 1), ((received.FindLast("\"") - 1) - offset) ); status << "Received request from " << nick << " To download " << filename; //logWindow->LogMessage(status.String(), BN_MESSAGE); if((SendAFile(logWindow, filename.String()) == false)) { status << "\nAn Error Occured While Sending " << filename << " to " << nick; //logWindow->LogMessage(status.String(), BN_ERROR); } else { status << "\nTransfer of " << filename << " to " << nick << " successful"; //logWindow->LogMessage(status.String(), BN_STATUS); } } if(received.Compare("SEND", 4) == 0) { offset = received.FindFirst("\"", 4); received.CopyInto(nick, 4, (offset -4)); received.CopyInto(filename, (offset + 1), ((received.FindLast("\"") - 1) - offset) ); received.CopyInto(lengthStr, (received.FindLast("\"")+2), (received.Length() - (received.FindLast("\"")+2))); fileLength = strtoul(lengthStr.String(), NULL, 10); status << "Received Request from " << nick << " To Upload " << filename << " To Us."; //logWindow->LogMessage(status.String(), BN_MESSAGE); if((UploadFromUser(logWindow, filename.String(), fileLength) == false)) { //logWindow->LogMessage(status.String(), BN_ERROR); } else { status << "\nSuccesfully Received " << filename << " from " << nick; //logWindow->LogMessage(status.String(), BN_STATUS); } } // Close the connection logWindow->netEndpoint->Close(); return 0; }
static int UUTCLFUNC uutcl_EncodeToNews (ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { int encoding=UU_ENCODED, linperfile=0, res; char errstring[256]; if (argc < 3 || argc > 10) { Tcl_SetResult (interp, "wrong # args", TCL_STATIC); return TCL_ERROR; } uutcl_UpdateParameter (interp); if (uutcl_GetEncodeParams (interp, argc, argv, 7, &encoding, 6, &linperfile) != TCL_OK) return TCL_ERROR; if ((res = SendAFile (interp, NULL, argv[1], encoding, linperfile, /* outfname */ (argc>3) ? argv[3] : NULL, /* towhom */ argv[2], /* subject */ (argc>4) ? argv[4] : NULL, /* from */ (argc>8) ? argv[8] : NULL, /* replyto */ (argc>9) ? argv[9] : NULL, 0)) != UURET_OK) { /* * If res==UURET_ILLVAL, SendAMail has already filled in the result */ if (res != UURET_ILLVAL) { sprintf (errstring, "error while posting %s: %s (%s)", argv[1], UUstrerror(res), (res==UURET_IOERR)? strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):""); Tcl_SetResult (interp, errstring, TCL_VOLATILE); } return TCL_ERROR; } return TCL_OK; }