| 348 | } |
| 349 | |
| 350 | EsiProcessor::ReturnCode |
| 351 | EsiProcessor::flush(string &data, int &overall_len) |
| 352 | { |
| 353 | if (_curr_state == ERRORED) { |
| 354 | overall_len = 0; |
| 355 | data.assign(""); |
| 356 | return FAILURE; |
| 357 | } |
| 358 | if (_curr_state == PROCESSED) { |
| 359 | overall_len = _overall_len; |
| 360 | data.assign(""); |
| 361 | return SUCCESS; |
| 362 | } |
| 363 | DocNodeList::iterator node_iter, iter; |
| 364 | bool attempt_succeeded; |
| 365 | bool attempt_pending; |
| 366 | bool node_pending; |
| 367 | _output_data.clear(); |
| 368 | TryBlockList::iterator try_iter = _try_blocks.begin(); |
| 369 | for (int i = 0; i < _n_try_blocks_processed; ++i, ++try_iter) { |
| 370 | ; |
| 371 | } |
| 372 | for (; _n_try_blocks_processed < static_cast<int>(_try_blocks.size()); ++try_iter) { |
| 373 | attempt_pending = false; |
| 374 | for (node_iter = try_iter->attempt_nodes.begin(); node_iter != try_iter->attempt_nodes.end(); ++node_iter) { |
| 375 | if ((node_iter->type == DocNode::TYPE_INCLUDE) || (node_iter->type == DocNode::TYPE_SPECIAL_INCLUDE)) { |
| 376 | if (_getIncludeStatus(*node_iter) == STATUS_DATA_PENDING) { |
| 377 | attempt_pending = true; |
| 378 | break; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | if (attempt_pending) { |
| 383 | break; |
| 384 | } |
| 385 | |
| 386 | ++_n_try_blocks_processed; |
| 387 | attempt_succeeded = true; |
| 388 | for (node_iter = try_iter->attempt_nodes.begin(); node_iter != try_iter->attempt_nodes.end(); ++node_iter) { |
| 389 | if ((node_iter->type == DocNode::TYPE_INCLUDE) || (node_iter->type == DocNode::TYPE_SPECIAL_INCLUDE)) { |
| 390 | const Attribute &url = (*node_iter).attr_list.front(); |
| 391 | string raw_url(url.value, url.value_len); |
| 392 | if (_getIncludeStatus(*node_iter) != STATUS_DATA_AVAILABLE) { |
| 393 | attempt_succeeded = false; |
| 394 | TSError("[%s] attempt section errored; due to url [%s]", __FUNCTION__, raw_url.c_str()); |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (attempt_succeeded) { |
| 401 | DBG("[%s] attempt section succeeded; using attempt section", __FUNCTION__); |
| 402 | _n_prescanned_nodes = _n_prescanned_nodes + try_iter->attempt_nodes.size(); |
| 403 | _node_list.splice(try_iter->pos, try_iter->attempt_nodes); |
| 404 | } else { |
| 405 | DBG("[%s] attempt section errored; trying except section", __FUNCTION__); |
| 406 | int n_prescanned_nodes = 0; |
| 407 | if (!_preprocess(try_iter->except_nodes, n_prescanned_nodes)) { |