/******************************************************************** * FUNCTION xml_rd_open_file * * Read the value for the specified obj from an open FILE in XML format * * INPUTS: * fp == open FILE control block * obj == object template for the output value * val == address of value for output * * RETURNS: * status *********************************************************************/ status_t xml_rd_open_file (FILE *fp, obj_template_t *obj, val_value_t **val) { xml_node_t top; status_t res; /* get a dummy session control block */ ses_cb_t *scb = ses_new_dummy_scb(); if (!scb) { return ERR_INTERNAL_MEM; } scb->fp = fp; res = xml_get_reader_for_session(my_ses_read_cb, NULL, scb/*context*/, &scb->reader); if(res != NO_ERR) { return res; } /* parse */ *val = val_new_value(); if(*val == NULL) { return ERR_INTERNAL_MEM; } xml_init_node(&top); res = xml_consume_node(scb->reader, &top, TRUE, TRUE); if (res != NO_ERR) { return res; } res = val_parse(scb, obj, &top, *val); scb->fp = NULL; /* skip fclose inside ses_free_scb */ ses_free_scb(scb); xml_clean_node(&top); return res; } /* xml_rd_open_file */
/******************************************************************** * FUNCTION agt_ses_process_first_ready * * Check the readyQ and process the first message, if any * * RETURNS: * TRUE if a message was processed * FALSE if the readyQ was empty *********************************************************************/ boolean agt_ses_process_first_ready (void) { ses_cb_t *scb; ses_ready_t *rdy; ses_msg_t *msg; status_t res; uint32 cnt; xmlChar buff[32]; rdy = ses_msg_get_first_inready(); if (!rdy) { return FALSE; } /* get the session control block that rdy is embedded into */ scb = agtses[rdy->sid]; if (scb == NULL) { log_debug("\nagt_ses: session %d gone", rdy->sid); return FALSE; } log_debug2("\nagt_ses msg ready for session %d", scb->sid); /* check the session control block state */ if (scb->state >= SES_ST_SHUTDOWN_REQ) { /* don't process the message or even it mark it * It will be cleaned up when the session is freed */ log_debug("\nagt_ses drop input, session %d shutting down", scb->sid); return TRUE; } /* make sure a message is really there */ msg = (ses_msg_t *)dlq_firstEntry(&scb->msgQ); if (!msg || !msg->ready) { SET_ERROR(ERR_INTERNAL_PTR); log_error("\nagt_ses ready Q message not correct"); if (msg && scb->state != SES_ST_INIT) { /* do not echo the ncx-connect message */ cnt = xml_strcpy(buff, (const xmlChar *)"Incoming msg for session "); snprintf((char *)(&buff[cnt]), sizeof(buff) - cnt, "%u", scb->sid); ses_msg_dump(msg, buff); } return FALSE; } else if (LOGDEBUG2 && scb->state != SES_ST_INIT) { cnt = xml_strcpy(buff, (const xmlChar *)"Incoming msg for session "); snprintf((char *)(&buff[cnt]), sizeof(buff) - cnt, "%u", scb->sid); ses_msg_dump(msg, buff); } /* setup the XML parser */ if (scb->reader) { /* reset the xmlreader */ res = xml_reset_reader_for_session(ses_read_cb, NULL, scb, scb->reader); } else { res = xml_get_reader_for_session(ses_read_cb, NULL, scb, &scb->reader); } /* process the message */ if (res == NO_ERR) { /* process the message * the scb pointer may get deleted !!! */ agt_top_dispatch_msg(&scb); } else { if (LOGINFO) { log_info("\nReset xmlreader failed for session %d (%s)", scb->sid, get_error_string(res)); } agt_ses_kill_session(scb, 0, SES_TR_OTHER); scb = NULL; } if (scb) { /* free the message that was just processed */ dlq_remove(msg); ses_msg_free_msg(scb, msg); /* check if any messages left for this session */ msg = (ses_msg_t *)dlq_firstEntry(&scb->msgQ); if (msg && msg->ready) { ses_msg_make_inready(scb); } } return TRUE; } /* agt_ses_process_first_ready */