example/thread-pool/psi.c
static StrOperationResult
strsearch_ioreader(INKIOBufferReader reader, const char *pattern, int *nparse)
{
  int index = 0;
  INKIOBufferBlock block = INKIOBufferReaderStart(reader);
  int slen = strlen(pattern);

  if (slen <= 0) {
    return STR_FAIL;
  }
  if (block == INK_ERROR_PTR) {
    INKError("[strsearch_ioreader] Error while getting block from ioreader");
    return STR_FAIL;
  }

  *nparse = 0;

  /* Loop thru each block while we've not yet found the pattern */
  while ((block != NULL) && (index < slen)) {
    int blocklen;
    const char *blockptr = INKIOBufferBlockReadStart(block, reader, &blocklen);
    const char *ptr;

    if (blockptr == INK_ERROR_PTR) {
      INKError("[strsearch_ioreader] Error while getting block pointer");
      break;
    }

    for (ptr = blockptr; ptr < blockptr + blocklen; ptr++) {
      (*nparse)++;
      if (*ptr == pattern[index]) {
        index++;
        if (index == slen) {
          break;
        }
      } else {
        index = 0;
      }
    }

    /* Parse next block */
    block = INKIOBufferBlockNext(block);
    if (block == INK_ERROR_PTR) {
      INKError("[strsearch_ioreader] Error while getting block from ioreader");
      return STR_FAIL;
    }
  }

  *nparse -= index;             /* Adjust nparse so it doesn't include matching chars */
  if (index == slen) {
    INKDebug(DBG_TAG, "strfind: match for %s at position %d", pattern, *nparse);
    return STR_SUCCESS;
  } else if (index > 0) {
    INKDebug(DBG_TAG, "strfind: partial match for %s at position %d", pattern, *nparse);
    return STR_PARTIAL;
  } else {
    INKDebug(DBG_TAG, "strfind no match for %s", pattern);
    return STR_FAIL;
  }
}
/*-------------------------------------------------------------------------
  strsearch_ioreader
  Looks for string pattern in an iobuffer

  Input:
    reader   reader on a iobuffer
    pattern  string to look for (nul terminated)
  Output:
    nparse   number of chars scanned, excluding the matching pattern
  Return Value:
    STR_SUCCESS if pattern found
    STR_PARTIAL if pattern found partially
    STR_FAIL    if pattern not found
  -------------------------------------------------------------------------*/
strsearch_ioreader
Looks for string pattern in an iobuffer

reader   reader on a iobuffer
pattern  string to look for (nul terminated)
Output:
nparse   number of chars scanned, excluding the matching pattern
Return Value:
STR_SUCCESS if pattern found
STR_PARTIAL if pattern found partially
STR_FAIL    if pattern not found
strsearch_ioreader Looks for string pattern in an iobuffer reader reader on a iobuffer pattern string to look for ( nul terminated ) Output : nparse number of chars scanned excluding the matching pattern Return Value : STR_SUCCESS if pattern found STR_PARTIAL if pattern found partially STR_FAIL if pattern not found
static StrOperationResult
strsearch_ioreader(INKIOBufferReader reader, const char *pattern, int *nparse)
{
  int index = 0;
  INKIOBufferBlock block = INKIOBufferReaderStart(reader);
  int slen = strlen(pattern);
  if (slen <= 0) {
    return STR_FAIL;
  }
  if (block == INK_ERROR_PTR) {
    INKError("[strsearch_ioreader] Error while getting block from ioreader");
    return STR_FAIL;
  }
  *nparse = 0;
  while ((block != NULL) && (index < slen)) {
    int blocklen;
    const char *blockptr = INKIOBufferBlockReadStart(block, reader, &blocklen);
    const char *ptr;
    if (blockptr == INK_ERROR_PTR) {
      INKError("[strsearch_ioreader] Error while getting block pointer");
      break;
    }
    for (ptr = blockptr; ptr < blockptr + blocklen; ptr++) {
      (*nparse)++;
      if (*ptr == pattern[index]) {
        index++;
        if (index == slen) {
          break;
        }
      } else {
        index = 0;
      }
    }
    block = INKIOBufferBlockNext(block);
    if (block == INK_ERROR_PTR) {
      INKError("[strsearch_ioreader] Error while getting block from ioreader");
      return STR_FAIL;
    }
  }
  *nparse -= index;             
  if (index == slen) {
    INKDebug(DBG_TAG, "strfind: match for %s at position %d", pattern, *nparse);
    return STR_SUCCESS;
  } else if (index > 0) {
    INKDebug(DBG_TAG, "strfind: partial match for %s at position %d", pattern, *nparse);
    return STR_PARTIAL;
  } else {
    INKDebug(DBG_TAG, "strfind no match for %s", pattern);
    return STR_FAIL;
  }
}
static StrOperationResult strsearch_ioreader ( INKIOBufferReader reader , const char * pattern , int * nparse ) { int index = 0 ; INKIOBufferBlock block = INKIOBufferReaderStart ( reader ) ; int slen = strlen ( pattern ) ; if ( slen <= 0 ) { return STR_FAIL ; } if ( block == INK_ERROR_PTR ) { INKError ( " " ) ; return STR_FAIL ; } * nparse = 0 ; while ( ( block != NULL ) && ( index < slen ) ) { int blocklen ; const char * blockptr = INKIOBufferBlockReadStart ( block , reader , & blocklen ) ; const char * ptr ; if ( blockptr == INK_ERROR_PTR ) { INKError ( " " ) ; break ; } for ( ptr = blockptr ; ptr < blockptr + blocklen ; ptr ++ ) { ( * nparse ) ++ ; if ( * ptr == pattern [ index ] ) { index ++ ; if ( index == slen ) { break ; } } else { index = 0 ; } } block = INKIOBufferBlockNext ( block ) ; if ( block == INK_ERROR_PTR ) { INKError ( " " ) ; return STR_FAIL ; } } * nparse -= index ; if ( index == slen ) { INKDebug ( DBG_TAG , " " , pattern , * nparse ) ; return STR_SUCCESS ; } else if ( index > 0 ) { INKDebug ( DBG_TAG , " " , pattern , * nparse ) ; return STR_PARTIAL ; } else { INKDebug ( DBG_TAG , " " , pattern ) ; return STR_FAIL ; } }
strsearch_ioreader
Looks for string pattern in an iobuffer
strsearch_ioreader Looks for string pattern in an iobuffer
/* Loop thru each block while we've not yet found the pattern */ /* Parse next block */ /* Adjust nparse so it doesn't include matching chars */