MCPcopy Create free account
hub / github.com/apache/trafficserver / parse_data

Function parse_data

example/plugins/c-api/thread_pool/psi.cc:353–416  ·  view source on GitHub ↗

------------------------------------------------------------------------- parse_data Search for psi filename in the data. Input: contp continuation for the current transaction reader reader on the iobuffer that contains data avail amount of data available in the iobuffer Output: towrite amount of data in the iobuffer that can be written to the downst

Source from the content-addressed store, hash-verified

351 1 if a psi filename was found
352 -------------------------------------------------------------------------*/
353static int
354parse_data(TSCont contp, TSIOBufferReader input_reader, int avail, int *toconsume, int *towrite)
355{
356 ContData *data;
357 int nparse = 0;
358 int status;
359
360 data = contDataGet(contp);
361 TSAssert(data->magic == MAGIC_ALIVE);
362
363 if (data->parse_state == PARSE_SEARCH) {
364 /* Search for the start pattern */
365 status = strsearch_ioreader(input_reader, PSI_START_TAG, &nparse);
366 switch (status) {
367 case STR_FAIL:
368 /* We didn't found the pattern */
369 *toconsume = avail;
370 *towrite = avail;
371 data->parse_state = PARSE_SEARCH;
372 return 0;
373 case STR_PARTIAL:
374 /* We need to read some more data */
375 *toconsume = nparse;
376 *towrite = nparse;
377 data->parse_state = PARSE_SEARCH;
378 return 0;
379 case STR_SUCCESS:
380 /* We found the start_pattern, let's go ahead */
381 data->psi_filename_len = 0;
382 data->psi_filename[0] = '\0';
383 data->parse_state = PARSE_EXTRACT;
384 break;
385 default:
386 TSAssert(!"strsearch_ioreader returned unexpected status");
387 }
388 }
389
390 /* And now let's extract the filename */
391 status = strextract_ioreader(input_reader, nparse + PSI_START_TAG_LEN, PSI_END_TAG, data->psi_filename, &data->psi_filename_len);
392 switch (status) {
393 case STR_FAIL:
394 /* We couldn't extract a valid filename */
395 *toconsume = nparse;
396 *towrite = nparse;
397 data->parse_state = PARSE_SEARCH;
398 return 0;
399 case STR_PARTIAL:
400 /* We need to read some more data */
401 *toconsume = nparse;
402 *towrite = nparse;
403 data->parse_state = PARSE_EXTRACT;
404 return 0;
405 case STR_SUCCESS:
406 /* We got a valid filename */
407 *toconsume = nparse + PSI_START_TAG_LEN + data->psi_filename_len + PSI_END_TAG_LEN;
408 *towrite = nparse;
409 data->parse_state = PARSE_SEARCH;
410 return 1;

Callers 1

handle_transformFunction · 0.85

Calls 3

contDataGetFunction · 0.85
strsearch_ioreaderFunction · 0.85
strextract_ioreaderFunction · 0.85

Tested by

no test coverage detected