AMADEUS API - XML C

Code Sample




 
Example : C program working with XML Data

/********************************************************************************** */
/* PURPOSE :  Code Sample                                                           */
/*                                                                                  */
/* This program will create a PNR                                                   */
/*  1) Create a conversation factory                                                */
/*  2) Create a conversation from the factory                                       */
/*  3) List all the transactions available for this release of Proxy                */
/*  4) Create a Passenger Name : MOZART/Wolfgang                                    */
/*  5) Create a Ticketing Arrangement Element : TK=OK                               */
/*  6) Create a Received From Element : AMADEUS DEVELOPMENT                         */
/*  7) Do an AIR Availability  : From Nice to New York on 10May04                   */
/*  8) Sell ONE Seat using a cryptic entry                                          */
/*  9) Create a Contact Element : AP B 444-555-1212  and H 555-444-1212             */
/* 10) Save the PNR                                                                 */
/* 11) Send a Query that returns a MessageOnly_Reply error message                  */
/* 12) Close the conversation                                                       */
/********************************************************************************** */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#include <Windows.h>
#endif

#include "CAI_Conversation.h"
#include "CAI_XML.h"
#ifdef INCLUDE_PLUGIN_HEADERS
#include "CAT_plugIn.h"
#endif
 
/****************************************************************/
/*  This routine checks if the message was processed correctly  */
/*  If yes ==>  display message "Successfull"                   */
/*  If no  ==>  display an error message                        */
/****************************************************************/

void checkErr(CaiErr err, char *function, 
				CAI_Conversation   **conversation,
				CAI_ConversationFactory	**factory,
				CAI_XML_BUFFER			reply)
{
  char		*strStart, *strEnd;
  char                msgZone[100];
  CAI_Dump		API_Dump;

  if (err == 0)
    printf("""%s"" was successfull\n", function);
  else if (err == CAI_FUNCTIONAL_ERROR)
  {                             /* Display the error message returned by the host */
    memset(msgZone, '\0', sizeof(msgZone));
    strStart = strstr(reply, "<Text>");
    strEnd   = strstr(reply, "</Text>");
    strncpy(msgZone, &strStart[6], strEnd-strStart-6);
    printf("Functional error detected by the host while doing a ""%s""\n", function);
    printf("Error message returned was: %s\n", msgZone);
  }
  else
  {
    printf("Error while doing a ""%s""\n", function);
    printf("Return Code = %i - %s\n", err, CAI_getErrorStr(err));
    if (conversation != NULL)
    {
      err = CAI_getConversationDump(*conversation, &API_Dump);
      if (err == CAI_OK)	
        printf("Conversation Dump:\n%s",API_Dump.dump);
      if (factory != NULL)
        CAI_closeConversationFromFactory(*factory, conversation);
      else 
        CAI_closeConversation(conversation);
    }
    if (factory != NULL)
      CAI_releaseConversationFactory(factory);

    printf("Press enter to exit\n");
    getchar();
    exit(0);
  }
}

/********************/
/* Main program     */
/* Creates the PNR  */ 
/********************/

int main(int argc, char* argv[])
{
	CaiErr 			cai_err	= CAI_OK;
	CAI_Conversation	*conversation = NULL;
	CAI_Dump		API_Dump;
	CAI_CustomSign		customsign;
	CAI_Connection_SI		connection;
	CAI_Authentication	authentication;
	CAI_OpenType		open_type;
	CAI_ConversationFactory	*factory = NULL;
	CAI_XML_BUFFER   	reply;
	CAI_Version		version;
	CAI_ConversationInfo    conversation_info;
	CAI_Conversation	*passivConv = NULL;
        CAI_MSG_LIST		msg_list;
        unsigned int		listCount   = 0;
	unsigned int            i;

#ifdef INCLUDE_PLUGIN_HEADERS
    displayPlugInInfo();
#endif


    printf("*****************************************************\n");
    printf("*  Creating the conversation Factory ...            *\n");
    printf("*****************************************************\n");

    CAI_initCustomSign(&customsign);
    CAI_initConnection_SI(&connection);
    CAI_initAuthentication(&authentication);
    CAI_initOpenType(&open_type);

    cai_err = CAI_getConnectionInfoFromINI(iniFile, &connection);
    checkErr(cai_err, "getConnectionFromINI", NULL, NULL, NULL);

    authentication.corporate_id = (unsigned char *) "Corpo";
    authentication.user_id =      (unsigned char *) "User";
    authentication.password =     (unsigned char *) "Secret";

    open_type.bind_host_resource = 0;                           /* Fast Open */
    open_type.custom_sign = &customsign;

    cai_err = CAI_createConversationFactory_SI(&connection, &authentication, &factory);
    checkErr(cai_err, "createConversationFactory", NULL, &factory, NULL);
	

    printf("*****************************************************\n");
    printf("*  Opening a conversation from the Factory ...      *\n");
    printf("*****************************************************\n");

    cai_err = CAI_openConversationFromFactory(factory, &open_type, &conversation);
    checkErr(cai_err, "openConversationFromFactory", &conversation, &factory, NULL);

    printf("*****************************************************\n");
    printf("*  List all transactions supported                  *\n");
    printf("*****************************************************\n");

    CAI_initMsgList(&msg_list);
    CAI_listTransaction(&listCount, &msg_list);
    if (listCount > 0)
    {
      for (i=0; i < listCount; i++)
        printf("%s\n", msg_list[i]);

      printf("\n");
    }
    CAI_releaseMsgList(&msg_list);
    printf("*****************************************************\n");
    printf("*  Create a PNR: Name, booking, receive from, ...   *\n");
    printf("*****************************************************\n");

    printf("Create a PNR ...\n");
    CAI_initXmlBuffer(&reply);




    printf("Send PNR_CreateName_Query\n");
    cai_err = CAI_sendAndReceiveXml(conversation,
                               
                               &reply);
    checkErr(cai_err, "sendXML: <PoweredPNR_AddMultiElements>: Add name", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);

    cai_err = CAI_sendAndReceiveXml(conversation,
                                                                                      
                               &reply);
    checkErr(cai_err, "sendXML: <PoweredPNR_AddMultiElements>: Add TKT Element", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);

    cai_err = CAI_sendAndReceiveXml(conversation, 
                               
                               &reply);  
    checkErr(cai_err, "sendXML: <PoweredPNR_AddMultiElements>: Add Receive From", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);

  /* ================================================================= */
  /* Air Availability : NCE NYC 10May04                                */
  /* ================================================================= */
    cai_err = CAI_sendAndReceiveXml(conversation,
                               
                               &reply);
    checkErr(cai_err, "sendXML: <PoweredAir_MultiAvailability>", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);

  /* ================================================================= */
  /* Cryptic Air Sell From Availability                                */
  /* ================================================================= */
    cai_err = CAI_sendAndReceiveXml(conversation,
                               
                               &reply);
    checkErr(cai_err, "sendXML: <Cryptic_GetScreen_Query>", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);

  /* ================================================================= */
  /* PNR_CreateContact : Create the Contact Element                    */
  /* ================================================================= */
    cai_err = CAI_sendAndReceiveXml(conversation,
                               
                               &reply);
    checkErr(cai_err, "sendXML: <PoweredPNR_AddMultiElements>: Add Contact information", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);

  
  /* ================================================================= */
  /* PNR_Save : Save the PNR                                           */
  /* ================================================================= */
    cai_err = CAI_sendAndReceiveXml(conversation, 
                               
                               &reply);
    checkErr(cai_err, "sendXML: <PoweredPNR_AddMultiElements>: End Transaction", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);

    printf("*****************************************************\n");
    printf("* Erroneous msg-PoweredDoc for non-existing language*\n");
    printf("*****************************************************\n");

    cai_err = CAI_sendAndReceiveXml(conversation,
                               
                               &reply);
    checkErr(cai_err, "sendXML: <PoweredDoc_DisplayItinerary>", &conversation, &factory, reply);
    CAI_releaseXmlBuffer(&reply);


    printf("*****************************************************\n");
    printf("*  Closing the conversation from the Factory ...    *\n");
    printf("*****************************************************\n");

    cai_err = CAI_closeConversationFromFactory(factory, &conversation);
    checkErr(cai_err, "closeConversationFromFactory", &conversation, &factory, NULL);

    CAI_releaseConversationFactory(&factory);

    printf("***********************\n");
    printf("* End of test Factory *\n");
    printf("***********************\n");

    exit(0);

}