bool M2I::sendListing(ISendLine &cb) { m_status = NOT_READY; // disk title QString parsed; // Reseek from beginning of M2I. if(!m_hostFile.seek(0) or !readFirstLine(&parsed)) { cb.send(0, strError1); return false; } // First line is disk title QString line = QString("\x12\x22%1\x22%2").arg(parsed, strID); cb.send(0, line); while(!m_hostFile.atEnd()) { // Write lines uchar ftype(parseLine(0, &parsed)); if('P' == ftype or 'D' == ftype) { line = QString(" \x22%1\x22 %2").arg(parsed, 'p' == ftype ? strDotPRG : strDEL); cb.send(0, line); } } return true; } // sendListing
void WebSocketClientHeaderIETF_HYBI17::read(std::string &packet) { std::string line; std::string::size_type startPos = 0, crlfPos; line = WebSocketClientHeader::getLine(packet, startPos, crlfPos); readFirstLine(line); //Read all of the fields. Field ending is denoted by a pair of CRLF. startPos = crlfPos + 2; do { line = WebSocketClientHeader::getLine(packet, startPos, crlfPos); readFieldLine(line); startPos = crlfPos + 2; if( (startPos + 2) > packet.size() ) { throw WebSocketException(INVALID_HEADER_EXCEPTION_MESSAGE); } } while(packet[startPos] != '\r' && packet[startPos + 1] != '\n'); //Skip over the last crlf. startPos += 2; packet.erase(0, startPos); }
// method below performs init of the driver with the given ATN command string. bool M2I::openHostFile(const QString& fileName) { closeHostFile(); // Interface has just opened the m2i file, save filename m_hostFile.setFileName(fileName); if(!m_hostFile.open(QIODevice::ReadOnly)) return false; // We accept m2i file if first line is OK: return readFirstLine(); } // openHostFile
void *processRequest(void *s,char *document_root) { int sock = *((int *) s); char firstLine[1024]; char line[1024]; char delim[2] = " "; char crlf[3] = "\r\n"; char filename[100]; char *status1 = "HTTP/1.0 200 OK\r\n"; char *content1 = "Content-Type: text/html\r\n\r\n"; int num = 0; char *token; readFirstLine(firstLine, sock); token = strtok(firstLine, delim); token = strtok(NULL, delim); strcpy(filename, "."); strcat(filename, token); printf("%s\n", filename); FILE *fp; if(strcmp(filename,"./")==0){ //FILE *fp = fopen(filename, "r"); //printf("here"); //printf("%s",strcat(document_root,"index.html")); fp = fopen("/Users/Alex/Downloads/index.html", "r"); } else { fp = fopen("/Users/Alex/Downloads/index.html","r"); printf("oops\n"); } if (fp == NULL) printf("Error\n"); send(sock, status1, strlen(status1), 0); send(sock, content1, strlen(content1), 0); while (fgets(line, 1024, fp) != 0) { send(sock, line, strlen(line), 0); } close(sock); fclose(fp); return NULL; }