hti/PC_Tools/HTIGateway/ServicePlugins/HtiPIM/HtiPIM.cpp
branchRCL_3
changeset 40 07b41fa8d1dd
parent 39 3406c99bc375
child 43 ca8a1b6995f6
equal deleted inserted replaced
39:3406c99bc375 40:07b41fa8d1dd
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 */
       
    16 #include "HtiPIMH.h"
       
    17 #include "HtiPlugin.h"
       
    18 #include "HtiSoapHandlerInterface.h"
       
    19 
       
    20 //**********************************************************************************
       
    21 // CONSTANTS
       
    22 //
       
    23 //**********************************************************************************
       
    24 
       
    25 // commands
       
    26 const unsigned char CMD_IMPORT_VCARD               = 0x01;
       
    27 const unsigned char CMD_IMPORT_VCALENDAR           = 0x02;
       
    28 const unsigned char CMD_DELETE_CONTACT_ENTRIES     = 0x03;
       
    29 const unsigned char CMD_DELETE_CALENDAR_ENTRIES    = 0x04;
       
    30 const unsigned char CMD_NOTEPAD_ADD_MEMO           = 0x05;
       
    31 const unsigned char CMD_NOTEPAD_ADD_MEMO_FROM_FILE = 0x06;
       
    32 const unsigned char CMD_NOTEPAD_DELETE_ALL         = 0x07;
       
    33 const unsigned char CMD_SIM_CARD_INFORMATION	   = 0x10;
       
    34 const unsigned char CMD_IMPORT_SIM_CONTACT	       = 0x11;
       
    35 const unsigned char CMD_DELETE_SIM_CONTACT	       = 0x12;
       
    36 const unsigned char CMD_CREATE_BOOKMARK	           = 0x1A;
       
    37 const unsigned char CMD_DELETE_BOOKMARK	           = 0x1B;
       
    38 
       
    39 
       
    40 //**********************************************************************************
       
    41 // UTIL FUNCTIONS
       
    42 //
       
    43 //**********************************************************************************
       
    44 //**********************************************************************************
       
    45 // GetSoapDIMEAttachment
       
    46 //**********************************************************************************
       
    47 int GetSoapDIMEAttachment(struct soap* soap,
       
    48 					      char* href,
       
    49 					      void*& data,
       
    50 					      int &dataLen )
       
    51 {
       
    52 	struct soap_multipart *attachment;
       
    53 	for ( attachment = soap->dime.list; attachment; attachment = attachment->next )
       
    54 	{
       
    55 		if( !strcmp( (*attachment).id, href ) )
       
    56 		{
       
    57 			data = attachment->ptr,
       
    58 			dataLen = (int) (*attachment).size;
       
    59 			return SOAP_OK;
       
    60 		}
       
    61 	}
       
    62 
       
    63 	soap->error = soap_receiver_fault_format(soap, "HtiGateway", 
       
    64 		"Did not find DIME attachment \"%s\"", href);
       
    65 	return SOAP_FAULT;
       
    66 }
       
    67 
       
    68 //**********************************************************************************
       
    69 // SOAP FUNCTIONS
       
    70 //
       
    71 //**********************************************************************************
       
    72 //**********************************************************************************
       
    73 // ns1__import_vCard
       
    74 //**********************************************************************************
       
    75 int ns1__import_vCard(struct soap* soap,
       
    76 					  char *vCard,
       
    77 					  int &entryId)
       
    78 {
       
    79 	if(check_mandatory_string_parameter(soap, vCard, "vCard"))
       
    80 		return SOAP_FAULT;
       
    81 
       
    82 	HtiMsgHelper msg( soap, HTI_UID, CMD_IMPORT_VCARD );
       
    83 	msg.AddString( vCard );
       
    84 	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
    85 		return SOAP_FAULT;
       
    86 
       
    87 	if ( msg.CheckMsgExactLen( 5 ) || msg.CheckCommandCode( 0xFF ) )
       
    88 		return SOAP_FAULT;
       
    89 
       
    90 	entryId = msg.GetInt( 1 );
       
    91 
       
    92 	return SOAP_OK;
       
    93 }
       
    94 
       
    95 //**********************************************************************************
       
    96 // ns1__import_vCardDime
       
    97 //**********************************************************************************
       
    98 int ns1__import_vCardDime(struct soap* soap,
       
    99                           struct ns1__HtiSoapAttachment *vCardDimeAttachment,
       
   100 						  int &entryId)
       
   101 {
       
   102 	if( check_mandatory_string_parameter( soap, vCardDimeAttachment->href, 
       
   103 		                                  "vCardDimeAttachment href" ) )
       
   104 		return SOAP_FAULT;
       
   105 
       
   106 	void* data = NULL;
       
   107 	int dataLen = 0;
       
   108 	if ( GetSoapDIMEAttachment( soap, vCardDimeAttachment->href, data, dataLen ) )
       
   109 		return SOAP_FAULT;
       
   110 
       
   111 	HtiMsgHelper msg( soap, HTI_UID, CMD_IMPORT_VCARD );
       
   112 	msg.AddData( data, dataLen );
       
   113 	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   114 		return SOAP_FAULT;
       
   115 
       
   116 	if ( msg.CheckMsgExactLen( 5 ) || msg.CheckCommandCode( 0xFF ) )
       
   117 		return SOAP_FAULT;
       
   118 
       
   119 	entryId = msg.GetInt( 1 );
       
   120 
       
   121 	return SOAP_OK;
       
   122 }
       
   123 
       
   124 //**********************************************************************************
       
   125 // ns1__import_vCalendar
       
   126 //**********************************************************************************
       
   127 int ns1__import_vCalendar(struct soap* soap,
       
   128 						  char *vCal, 
       
   129 						  int &entryId)
       
   130 {
       
   131 	if(check_mandatory_string_parameter(soap, vCal, "vCalendar"))
       
   132 		return SOAP_FAULT;
       
   133 
       
   134 	HtiMsgHelper msg( soap, HTI_UID, CMD_IMPORT_VCALENDAR );
       
   135 	msg.AddString( vCal );
       
   136 	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   137 		return SOAP_FAULT;
       
   138 
       
   139 	if ( msg.CheckMsgExactLen( 5 ) || msg.CheckCommandCode( 0xFF ) )
       
   140 		return SOAP_FAULT;
       
   141 
       
   142 	entryId = msg.GetInt( 1 );
       
   143 
       
   144 	return SOAP_OK;
       
   145 }
       
   146 
       
   147 //**********************************************************************************
       
   148 // ns1__import_vCalendarDime
       
   149 //**********************************************************************************
       
   150 int ns1__import_vCalendarDime(struct soap* soap,
       
   151                               struct ns1__HtiSoapAttachment *vCalendarDimeAttachment,
       
   152 							  int &entryId)
       
   153 {
       
   154 	if(check_mandatory_string_parameter(soap, vCalendarDimeAttachment->href, 
       
   155 		                                "vCalendarDimeAttachment href"))
       
   156 		return SOAP_FAULT;
       
   157 
       
   158 	void* data = NULL;
       
   159 	int dataLen = 0;
       
   160 	if ( GetSoapDIMEAttachment( soap, vCalendarDimeAttachment->href, data, dataLen ) )
       
   161 		return SOAP_FAULT;
       
   162 
       
   163 	HtiMsgHelper msg( soap, HTI_UID, CMD_IMPORT_VCALENDAR );
       
   164 	msg.AddData( data, dataLen );
       
   165 	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   166 		return SOAP_FAULT;
       
   167 
       
   168 	if ( msg.CheckMsgExactLen( 5 ) || msg.CheckCommandCode( 0xFF ) )
       
   169 		return SOAP_FAULT;
       
   170 
       
   171 	entryId = msg.GetInt( 1 );
       
   172 
       
   173 	return SOAP_OK;
       
   174 }
       
   175 
       
   176 //**********************************************************************************
       
   177 // ns1__deleteContactEntry
       
   178 //**********************************************************************************
       
   179 int ns1__deleteContactEntry(struct soap* soap,
       
   180 							int entryId,
       
   181                             struct ns1__deleteContactEntryResponse *out)
       
   182 {
       
   183 	HtiMsgHelper msg( soap, HTI_UID, CMD_DELETE_CONTACT_ENTRIES );
       
   184 	msg.AddInt( entryId );
       
   185 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   186 }
       
   187 
       
   188 //**********************************************************************************
       
   189 // ns1__deleteAllContactEntries
       
   190 //**********************************************************************************
       
   191 int ns1__deleteAllContactEntries(struct soap* soap,
       
   192 								 void *_,
       
   193                                  struct ns1__deleteAllContactEntriesResponse *out)
       
   194 {
       
   195 	HtiMsgHelper msg( soap, HTI_UID, CMD_DELETE_CONTACT_ENTRIES );
       
   196 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   197 }
       
   198 
       
   199 //**********************************************************************************
       
   200 // ns1__deleteCalendarEntry
       
   201 //**********************************************************************************
       
   202 int ns1__deleteCalendarEntry(struct soap* soap,
       
   203 							 int entryId,
       
   204                              struct ns1__deleteCalendarEntryResponse *out)
       
   205 {
       
   206 	HtiMsgHelper msg( soap, HTI_UID, CMD_DELETE_CALENDAR_ENTRIES );
       
   207 	msg.AddInt( entryId );
       
   208 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   209 }
       
   210 
       
   211 //**********************************************************************************
       
   212 // ns1__deleteAllCalendarEntries
       
   213 //**********************************************************************************
       
   214 int ns1__deleteAllCalendarEntries(struct soap* soap,
       
   215 								  void *_,
       
   216                                   struct ns1__deleteAllCalendarEntriesResponse *out)
       
   217 {
       
   218 	HtiMsgHelper msg( soap, HTI_UID, CMD_DELETE_CALENDAR_ENTRIES );
       
   219 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   220 }
       
   221 
       
   222 //**********************************************************************************
       
   223 // ns1__getSIMCardCaps
       
   224 //**********************************************************************************
       
   225 int ns1__getSIMCardCaps(struct soap* soap,
       
   226 						void *_,
       
   227                         struct ns1__getSIMCardCapsResponse &r)
       
   228 {
       
   229 	HtiMsgHelper msg( soap, HTI_UID, CMD_SIM_CARD_INFORMATION );
       
   230 	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   231 		return SOAP_FAULT;
       
   232 	
       
   233 	if ( msg.CheckCommandCode( 0xFF ) || msg.CheckMsgExactLen( 13 ) )
       
   234 		return SOAP_FAULT;
       
   235 
       
   236 	r._returnHtiSIMCardCaps.maxNumOfSecondNames			= msg.GetByte( 1 );
       
   237 	r._returnHtiSIMCardCaps.maxNumOfAdditionalNums		= msg.GetByte( 2 );
       
   238 	r._returnHtiSIMCardCaps.maxNumOfEmails				= msg.GetByte( 3 );
       
   239 	r._returnHtiSIMCardCaps.maxLengthOfName				= msg.GetByte( 4 );
       
   240 	r._returnHtiSIMCardCaps.maxLengthOfNumber			= msg.GetByte( 5 );
       
   241 	r._returnHtiSIMCardCaps.maxLengthOfSecondName		= msg.GetByte( 6 );
       
   242 	r._returnHtiSIMCardCaps.maxLengthOfAdditionalNum	= msg.GetByte( 7 );
       
   243 	r._returnHtiSIMCardCaps.maxLenghtOfEmail			= msg.GetByte( 8 );
       
   244 	r._returnHtiSIMCardCaps.totalSlots					= msg.GetWord( 9 );
       
   245 	r._returnHtiSIMCardCaps.usedSlots					= msg.GetWord( 11 );
       
   246 	
       
   247 	return SOAP_OK;
       
   248 }
       
   249 
       
   250 //**********************************************************************************
       
   251 // ns1__importSIMContact
       
   252 //**********************************************************************************
       
   253 int ns1__importSIMContact(struct soap* soap,
       
   254                           struct ArrayOfHtiSIMContactFields SIMContacts,
       
   255 						  int &entryId)
       
   256 {
       
   257 	HtiMsgHelper msg( soap, HTI_UID, CMD_IMPORT_SIM_CONTACT );
       
   258 
       
   259 	// Only one byte for number of contacts
       
   260 	if ( SIMContacts.__size > 0xFF )
       
   261 	{
       
   262 		soap->error = soap_receiver_fault( soap, "HtiGateway", 
       
   263 			"Too many contacts" );
       
   264 		return SOAP_FAULT;
       
   265 	}
       
   266 	msg.AddByte( (BYTE) SIMContacts.__size );
       
   267 
       
   268 	// Loop through contacts
       
   269 	for ( int i = 0; i < SIMContacts.__size; i++ )
       
   270 	{
       
   271 		msg.AddByte( SIMContacts.__ptrHtiSIMContactField[i].fieldType );
       
   272 		
       
   273 		// fieldData cannot be empty
       
   274 		if ( check_mandatory_string_parameter( soap, 
       
   275 			   SIMContacts.__ptrHtiSIMContactField[i].fieldData,
       
   276 			   "HtiSIMContactField.fieldData" ) )
       
   277 			   return SOAP_FAULT;
       
   278 		
       
   279 		msg.AddStringWithLengthByte( SIMContacts.__ptrHtiSIMContactField[i].fieldData );
       
   280 	}
       
   281 
       
   282 	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   283 		return SOAP_FAULT;
       
   284 
       
   285 	if ( msg.CheckCommandCode( 0xFF ) || msg.CheckMsgExactLen( 5 ) )
       
   286 		return SOAP_FAULT;
       
   287 
       
   288 	entryId = msg.GetInt( 1 );
       
   289 
       
   290     return SOAP_OK;	
       
   291 }
       
   292 
       
   293 //**********************************************************************************
       
   294 // ns1__deleteSIMContact
       
   295 //**********************************************************************************
       
   296 int ns1__deleteSIMContact(struct soap* soap,
       
   297 						  int entryId,
       
   298                           struct ns1__deleteSIMContactResponse *out)
       
   299 {
       
   300 	HtiMsgHelper msg( soap, HTI_UID, CMD_DELETE_SIM_CONTACT );
       
   301 	msg.AddInt( entryId );
       
   302 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   303 }
       
   304 
       
   305 //**********************************************************************************
       
   306 // ns1__deleteAllSIMContacts
       
   307 //**********************************************************************************
       
   308 int ns1__deleteAllSIMContacts(struct soap* soap,
       
   309 							  void *_,
       
   310                               struct ns1__deleteAllSIMContactsResponse *out)
       
   311 {
       
   312 	HtiMsgHelper msg( soap, HTI_UID, CMD_DELETE_SIM_CONTACT );
       
   313 	// 60 second timeout maybe not enough(?)
       
   314 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_60_SECONDS ); 
       
   315 }
       
   316 
       
   317 //**********************************************************************************
       
   318 // ns1__notepadAddMemo
       
   319 //**********************************************************************************
       
   320 int ns1__notepadAddMemo(struct soap* soap,
       
   321 						char *text,
       
   322                         struct ns1__notepadAddMemoResponse *out)
       
   323 {
       
   324 	if( check_mandatory_string_parameter( soap, text, "text" ) )
       
   325 		return SOAP_FAULT;
       
   326 
       
   327 	HtiMsgHelper msg( soap, HTI_UID, CMD_NOTEPAD_ADD_MEMO );
       
   328 	msg.AddString( text );
       
   329 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   330 }
       
   331 //**********************************************************************************
       
   332 // ns1__notepadAddMemoFromFile
       
   333 //**********************************************************************************
       
   334 int ns1__notepadAddMemoFromFile(struct soap* soap,
       
   335 						        char *filePath,
       
   336                                 struct ns1__notepadAddMemoFromFileResponse *out)
       
   337 {
       
   338 	if( check_mandatory_string_parameter( soap, filePath, "filePath" ) )
       
   339 		return SOAP_FAULT;
       
   340 	
       
   341 	HtiMsgHelper msg( soap, HTI_UID, CMD_NOTEPAD_ADD_MEMO_FROM_FILE );
       
   342 	msg.AddString( filePath );
       
   343 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   344 }
       
   345 
       
   346 //**********************************************************************************
       
   347 // ns1__notepadDeleteAll
       
   348 //**********************************************************************************
       
   349 int ns1__notepadDeleteAll(struct soap* soap,
       
   350 						  void *_,
       
   351                           struct ns1__notepadDeleteAllResponse *out)
       
   352 {
       
   353 	HtiMsgHelper msg( soap, HTI_UID, CMD_NOTEPAD_DELETE_ALL );
       
   354 	return msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS );
       
   355 }
       
   356 
       
   357 //**********************************************************************************
       
   358 // ns1__createBookmark
       
   359 //**********************************************************************************
       
   360 int ns1__createBookmark(struct soap* soap,
       
   361 					    char *folderName,
       
   362                         char *bookmarkName,
       
   363                         char *url,
       
   364                         char *accessPointName,
       
   365                         char *userName,
       
   366                         char *password,
       
   367                         int  &createdItemCount)
       
   368 {
       
   369     if( check_mandatory_string_parameter( soap, bookmarkName, "bookmarkName" ) )
       
   370 		return SOAP_FAULT;
       
   371     if( check_mandatory_string_parameter( soap, url, "url" ) )
       
   372 		return SOAP_FAULT;
       
   373 
       
   374     HtiMsgHelper msg( soap, HTI_UID, CMD_CREATE_BOOKMARK );
       
   375     msg.AddStringWithLengthByteZero( folderName );
       
   376     msg.AddStringWithLengthByte( bookmarkName );
       
   377     msg.AddStringWithLengthWordZero( url );
       
   378     msg.AddStringWithLengthByteZero( accessPointName );
       
   379     msg.AddStringWithLengthByteZero( userName );
       
   380     msg.AddStringWithLengthByteZero( password );
       
   381 
       
   382  	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   383 		return SOAP_FAULT;
       
   384 
       
   385     if ( msg.CheckCommandCode( 0xFF ) || msg.CheckMsgExactLen( 2 ) )
       
   386         return SOAP_FAULT;
       
   387 
       
   388     createdItemCount = msg.GetByte( 1 );
       
   389 
       
   390 	return SOAP_OK;
       
   391 }
       
   392 //**********************************************************************************
       
   393 // ns1__deleteBookmark
       
   394 //**********************************************************************************
       
   395 int ns1__deleteBookmark(struct soap* soap,
       
   396 					    char *folderName,
       
   397                         char *bookmarkName,
       
   398                         int  &deletedItemCount)
       
   399 {
       
   400     HtiMsgHelper msg( soap, HTI_UID, CMD_DELETE_BOOKMARK );
       
   401     msg.AddStringWithLengthByteZero( folderName );
       
   402     msg.AddStringWithLengthByteZero( bookmarkName );
       
   403 
       
   404  	if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   405 		return SOAP_FAULT;
       
   406 
       
   407     if ( msg.CheckCommandCode( 0xFF ) || msg.CheckMsgExactLen( 2 ) )
       
   408         return SOAP_FAULT;
       
   409 
       
   410     deletedItemCount = msg.GetByte( 1 );
       
   411 
       
   412 	return SOAP_OK;
       
   413 }