示例#1
0
bool SBBTA252::getStatus()
{
  // Declare variables.
  int bytes_to_discard = 0;

  // Get the number of bytes available on the serial port.
  getBytesAvailable();

  // Make sure we don't read too many bytes and overrun the buffer.
  if (bytes_available >= SERIAL_MAX_DATA)
  {
    bytes_available = SERIAL_MAX_DATA - 1;
  }
  if (bytes_available + strlen(buf_recv) >= SERIAL_MAX_DATA)
  {
    bytes_to_discard = bytes_available + strlen(buf_recv) - SERIAL_MAX_DATA - 1;
    memmove(buf_recv, &buf_recv[bytes_to_discard], bytes_to_discard);
  }

  // Read data off the serial port.
  if (bytes_available > 0)
  {
    recv();
    
    // Look for entire message.
    if (findMsg())
    {
      // Parse the status.
      return parseStatus();
    }
  }
  
  return false;
} // end getStatus()
int checkStatus(int tid, char * status, char * transStr)
{
  int fd[2];
  int done = 0;
  pid_t pid;

  /* 
     Set up a pipe to redirect the stdout of the child process
     to the parent process.
  */
  pipe(fd);   
  pid = fork();

  if (pid == 0) {
    dup2(fd[1], STDOUT_FILENO);
    execvp("transmission-remote", buildArgsArr(transStr, tid));
  }
  else
  {
    FILE * fp = NULL;
    close(fd[1]);
    dup2(fd[0], STDIN_FILENO);

    fp = fdopen(fd[0], "r");
    done = parseStatus(fp, tid, status);
    waitpid(pid, NULL, 0);
    close(fd[0]);
  }

  return done;
}
示例#3
0
Response parseResponse(char const* str) {
    // Parse an HTTP response 
    auto version = parseToken(str);
    auto code = parseStatus(version.ch);
    auto message = parseUntil(code.ch, [](char ch) { return ch == '\r'; });
    
    auto response = Response();
    if (version.value != "HTTP/1.1") {
        throw Error("bad HTTP version");
    }
      
    auto ch = parseCrLf(message.ch).ch;
    while (*ch != '\0' && *ch != '\r') {
        auto name = parseUntil(ch, [](char ch) { return ch == ':'; });
        if (*name.ch) {
            name.ch++; // For ":"
        }
        auto ws = parseWhile(name.ch, isspace);
        auto value = parseUntil(ws.ch, [](char ch) { return ch == '\r'; });   
        response.headerIs(name.value, value.value);
        if (name.value == "Set-Cookie") {
            response.cookieIs(Cookie(value.value));
        }
        ch = parseCrLf(value.ch).ch;
    }
    ch = parseCrLf(ch).ch;
    
    response.statusIs(code.value);
    response.dataIs(ch); 
    return response;
}
示例#4
0
qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket)
{
    if (fragment.isEmpty()) {
        // reserve bytes for the status line. This is better than always append() which reallocs the byte array
        fragment.reserve(32);
    }

    qint64 bytes = 0;
    char c;
    qint64 haveRead = 0;

    do {
        haveRead = socket->read(&c, 1);
        if (haveRead == -1)
            return -1; // unexpected EOF
        else if (haveRead == 0)
            break; // read more later

        bytes++;

        // allow both CRLF & LF (only) line endings
        if (c == '\n') {
            // remove the CR at the end
            if (fragment.endsWith('\r')) {
                fragment.truncate(fragment.length()-1);
            }
            bool ok = parseStatus(fragment);
            state = ReadingHeaderState;
            fragment.clear();
            if (!ok) {
                return -1;
            }
            break;
        } else {
            fragment.append(c);
        }

        // is this a valid reply?
        if (fragment.length() >= 5 && fragment.startsWith("ICY"))
        {
          state = ReadingDataState;
          statusCode = 200;
          autoDecompress = false;
          bytes = 0;
          break;
        }

        if (fragment.length() >= 5 && !fragment.startsWith("HTTP/") && !fragment.startsWith("ICY"))
        {
            fragment.clear();
            return -1;
        }
    } while (haveRead == 1);

    return bytes;
}
示例#5
0
QList<Status*> XmlParser::parseFriendsTimeLine(const QString &data){
    QList<Status*> listStatus;
    QDomDocument doc;
     doc.setContent(data);
     if(!doc.isNull()){
        QDomNodeList nodeList = doc.elementsByTagName("status");
        for(int i = 0; i != nodeList.size(); i++){
          // Status *status = new Status;
           Status *status = parseStatus(nodeList.at(i));
           listStatus.append(status);
        }
     }
     return listStatus;
}
示例#6
0
qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket)
{
    if (fragment.isEmpty()) {
        // reserve bytes for the status line. This is better than always append() which reallocs the byte array
        fragment.reserve(32);
    }

    qint64 bytes = 0;
    char c;
    qint64 haveRead = 0;

    do {
        haveRead = socket->read(&c, 1);
        if (haveRead == -1)
            return -1; // unexpected EOF
        else if (haveRead == 0)
            break; // read more later
        else if (haveRead == 1 && fragment.size() == 0 && (c == 11 || c == '\n' || c == '\r' || c == ' ' || c == 31))
            continue; // Ignore all whitespace that was trailing froma previous request on that socket

        bytes++;

        // allow both CRLF & LF (only) line endings
        if (c == '\n') {
            // remove the CR at the end
            if (fragment.endsWith('\r')) {
                fragment.truncate(fragment.length()-1);
            }
            bool ok = parseStatus(fragment);
            state = ReadingHeaderState;
            fragment.clear();
            if (!ok) {
                return -1;
            }
            break;
        } else {
            fragment.append(c);
        }

        // is this a valid reply?
        if (fragment.length() >= 5 && !fragment.startsWith("HTTP/"))
        {
            fragment.clear();
            return -1;
        }
    } while (haveRead == 1);

    return bytes;
}
示例#7
0
int Process::wait(const T_timestamp timeout)
{
  logTrace("Process::wait");

  if (pid_ < 0)
  {
    logError("Process::wait", ESET(ECHILD));

    return 1;
  }

  //
  // Wait for the process until the timeout.
  //

  int status;

  int options = WUNTRACED;

  setTimer(timeout);

  int result;

  if ((result = waitpid(pid_, &status, options)) == -1)
  {
    if (EGET() == EINTR)
    {
      logTest("Process::wait", "Timeout raised waiting "
                  "for pid %d", pid_);

      return 0;
    }
    else
    {
      logError("Process::wait", EGET());

      return -1;      
    }
  }

  resetTimer();

  result = parseStatus(result, status);

  return result;
}
示例#8
0
int Process::isRunning()
{
  logTrace("Process::isRunning");

  if (pid_ < 0)
  {
    return 0;
  }

  int status;

  int options = WNOHANG | WUNTRACED;

  int result = waitpid(pid_, &status, options);

  return (parseStatus(result, status) <= 0);
}
示例#9
0
int Process::wait()
{
  logTrace("Process::wait");

  if (pid_ < 0)
  {
    logError("Process::wait", ESET(ECHILD));

    return -1;
  }

  int status;

  int options = WUNTRACED;

  int result = waitpid(pid_, &status, options);

  return parseStatus(result, status);
}
示例#10
0
STATUS _minParse(char* inputBuffer, min_parser_data* result) {
    currentBuffer = inputBuffer;
    for (char i=0;i < MIN_PARSER_INTERNAL_BUFFER_SIZE;i++) {
        char c = inputBuffer[i];

        switch(state) {
            case SEARCHING_HEADER: searchHeader(c); break;
            case SKIPPING_TIME: skipTime(c, i); break;
            case PARSING_STATUS: parseStatus(c, i); break;
            case PARSING_LAT_COORD: parseCoord(c, i, &(result->latCoord), PARSING_LAT_HEM); break;
            case PARSING_LAT_HEM: parseHem(c, i, &(result->latHem), PARSING_LONG_COORD); break;
            case PARSING_LONG_COORD: parseCoord(c, i, &(result->longCoord), PARSING_LONG_HEM); break;
            case PARSING_LONG_HEM: parseHem(c, i, &(result->longHem), DONE); break;
            case DONE: status = 1; break;
            default: state = SEARCHING_HEADER; break;
        }
    }

    memcpy(previousBuffer, currentBuffer, MIN_PARSER_INTERNAL_BUFFER_SIZE);

    return status;
}