//*********************************************************************
//
//  NAV_UPGRADE.CMD - Command script to upgrade POI Data
//
//*********************************************************************

//! @li 2013/03/29 Mark                 : Separate radars and dangerous zone

//! @li 2009/12/02 P. CHAPELET Def27966 : Double display popup
//! @li 2009/11/27 P. CHAPELET Def27844 : Wrong message displayed for a radars upgrade
//!                            Def27977 : Impossible to upgrade with CD containing POI
//! @li 2009/02/11 P. CHAPELET Def25786 : Manage good popups at the end of upgrade
//! @li 2007/05/11 B. DAVID    EVO 3293 : POI upgrade

/*** UPGRADE FLAGS ***/



/*** GLOBAL DEFINES ****/



// Script Types
typedef int  STATUS;
typedef void DIR;
typedef int  BOOL;
typedef int  size_t;
typedef void FILE;
#define TRUE     (1)
#define FALSE    (0)
#define OK       (0)
#define ERROR    (-1)
#define NULL     (void*) 0
#define O_RDWR   (2)
#define DELAY_5S (int) 2500
#define DELAY_1S (int) 500

// Constants
#define MAX_DRIVE_NAME_LENGTH 10
#define MAX_FILENAME_LENGTH   50
#define MAX_PATH_LENGTH       100
#define MAX_INF_LINE_LENGTH   100
#define MAX_QUESTION_LENGTH   100

#define MAX_COUNTRY_NAME_HDD  30
#define MAX_DATA_PROVIDER     20
#define MAX_DATE_LENGTH       20
#define STRING_CONTINENT_ID   "CONTINENT_ID:"
#define STRING_CONTINENT_NAME "CONTINENT_NAME:"
#define STRING_CD_NAME        "CD_NAME:"
#define STRING_POI_PROVIDER   "POI_PROVIDER:"
#define STRING_DATA_POI       "DATA_POI:"
#define ALL_FILES             "*"
#define MAPPE_PATH            "/MAPPE/POI_USER"
#define POI_SOURCE_PATH       "POI_USER/"
#define POI_TARGET_PATH       "POI_USER/TEMP_"
#define POI_VER_FILE          "/TEMP_"
#define POI_RADAR_PREFIX      "RADAR"
#define POI_DANGERZ_PREFIX    "DANGERZ"
#define STRING_POI_RADAR      "RADARS RUSSIA EAST EUR"
#define STRING_POI_DANGERZ    "DANGEROUS ZONE"

// Drive letters
#define DRIVE_CDROM "/D"
#define DRIVE_HDD   "/SDC"
#define DRIVE_NAV   "/SDH"
#define DRIVE_TFFS  "/F"
#define DRIVE_USB   "/bd0"

// Key Files
#define KEY_FILE_POI              "POI_VER.POI"

#define MMI_UPG_DISPLAY_ASK_MOTOR 1


/*** SOFTWARE UPGRADE DEFINES ***/
// Continents
typedef enum
{
  UNKNOWN_CONTINENT = 0,
  EUROPE,
  AUSTRALIA,
  NORTH_AMERICA,
  SOUTH_AMERICA,
  INDIA,
  CHINA
} t_continent;

typedef struct
{
  t_continent m_continent;
  char m_continent_name[MAX_COUNTRY_NAME_HDD];
  char m_cd_name[MAX_COUNTRY_NAME_HDD];
  char m_poi_provider[MAX_DATA_PROVIDER];
  char m_date[MAX_DATE_LENGTH];
}t_poi_content;

typedef struct
{
  char  m_pFileName[MAX_PATH_LENGTH];
  char  m_pTargetPath[MAX_PATH_LENGTH];
  int   m_iSize;
} t_NavUpgData;


/*** EXTERN FUNCTION DECLARATIONS ***/

// File operations
int logMsg (char*,int,int,int,int,int,int);
int xdelete (const char * source);
int xcopy (const char* source, const char* dest);
int UPGSearchFile(char *Filename, char *RootDir, char *Param, char *TableDir );
STATUS UPGGetSearchResult(int index , char *SearchResult );
STATUS GetFileSize(char *file, int *size);
char* fgets(char * buf, size_t n, FILE * fp);
FILE* fopen(char * file, char * mode );
int fclose(FILE * fp);
int feof(FILE * fp);
STATUS UPGCopy(char* source, char* destination, int cut);
STATUS UPGSpawnCopy(char* source, char* destination, int cut);

// String operations
STATUS strcpy (char* target, char* source);
STATUS strcat (char* target, char* source);
int strcmp (char* str1, char* str2);
int strncmp (char* str1, char* str2, int n);
STATUS strlen (char* str);
char* strstr(char* str, char* substr);

// MMI UPG Panel management
STATUS ClearScreen(void);
STATUS ShowNavigationBargraph(void);
STATUS StepBargraph(char *text, int index);
STATUS ShowCDVerification(void);
STATUS ShowCDIdentification(void);
STATUS ShowCDProblem(void);
STATUS ShowCDCanceled (void);
STATUS ShowNavigationQuestionScreen(char *text, int *answer);
STATUS ShowNavigationExtendedQuestionScreen (int p_InfoIndex, char * p_Text, int * p_Answer);

// Others
unsigned long tickGet (void);
STATUS taskDelay (int ticks);
void *malloc(size_t nBytes);
void *realloc(void *pBlock, size_t newSize );
void free(void * ptr);
int atoi(char * p_str);

STATUS UPGCDEject(void);
int IsUpgCheatCodeActivated(void);
STATUS SendMessageMMINavPOILoaded(void);
STATUS GetMessageMMINavCIDLoaded (void);
STATUS CompareToDBContinent(int p_cd_continent);

/*** INTERN FUNCTION DECLARATION ***/
STATUS  ComputePOITargetPath (char* p_file_name,
                            char* p_source_drive,
                            char* p_target_drive,
                            char* p_target_name);

STATUS ReplaceInPath(char *p_pPath, char *p_pStringToReplace, char *p_pStringToReplaceWhith );

STATUS ExtractPOIInfo(const char* p_filepath, t_poi_content* p_content);


/************** Some user functions **********************/
void _itoa ( int i, char* s, int base )
{
  char l_s[16];
  int  n=0,m=0;
  if( i<0 )
  {
    s[m++]='-';
    i=-i;
  }
  do
  {
    l_s[n++]=(char)('0'+(i%base));
    i/=base;
  }
  while( i );
  for( --n ; n>=0 ; n--,m++ )
    s[m]=l_s[n];
  s[m]=0;
}

void _substr (char* dest, char* src, int beg, int len)
{
int i;
int j;

  if (src[0] > 0)
    {
      for (i = beg - 1, j = 0; (src[i] > 0) && (j < len); i++, j++)
       { 
         dest[j] = src[i];
       }
     dest[j] = '\0'; 
    }  
}


/****************************** MAIN ******************************/

int main(int argc, char **argv)
{
  // Local variables for general purpose
  STATUS l_script_status = OK;
  char l_source_drive[MAX_DRIVE_NAME_LENGTH];
  char l_target_drive[MAX_DRIVE_NAME_LENGTH];

  int  l_i=0;
  int  l_j=0;
  int  l_zone=0;
  int  l_numcopy=0;

  char l_path[MAX_PATH_LENGTH];
  char l_key_file_name[MAX_FILENAME_LENGTH];
  char l_msg[1024];
  char l_msg1[1024];
  char l_prefix[32];
  char strtmp[128];
  char partdate[128];

  int l_UpgReq[2];
  int l_bUpgRequired = FALSE;
  char l_pQuestionText[MAX_QUESTION_LENGTH];

  t_NavUpgData *l_poi_file_list = NULL;
  unsigned int l_poi_file_number = 0;
  char l_search_result[MAX_PATH_LENGTH];
  unsigned long l_lTotalSize = 0;
  unsigned long l_lCompletedSize = 0;
  int l_iPercentage = 0;


  t_poi_content l_poi_content;
  l_poi_content.m_continent = UNKNOWN_CONTINENT;
  l_poi_content.m_continent_name[0] = '\0';
  l_poi_content.m_cd_name[0] = '\0';
  l_poi_content.m_poi_provider[0] = '\0';
  l_poi_content.m_date[0] = '\0';

  /*** SCRIPT INITIALIZATION ***/

  logMsg("Script initialization +, Time = %ld\n",tickGet(),0,0,0,0,0);

  //Get current source drive
  if(argc != 3)
  {
    logMsg("Incorrect number of params\n",0,0,0,0,0,0);
    l_script_status = ERROR;
  }
  else
  {
    strcpy(l_source_drive,argv[1]);
    logMsg("Source drive is %s\n",l_source_drive,0,0,0,0,0);

    //Get key file
    strcpy (l_key_file_name, KEY_FILE_POI);
  }

  //Get current target drive "/H"
  strcpy ( l_target_drive, DRIVE_NAV );

  if(OK == l_script_status)
  {
    logMsg("Target drive is %s\n",l_target_drive,0,0,0,0,0);
    logMsg("Source key file is %s\n",l_key_file_name,0,0,0,0,0 );
  }

  logMsg("Script initialization -, Time = %ld\n",tickGet(),0,0,0,0,0);


  /*** VERSION CHECK ***/

  if ( OK == l_script_status )
  {
    logMsg("Version check +, Time = %ld\n",tickGet(),0,0,0,0,0);

    strcpy ( l_path, l_source_drive);
    strcat ( l_path, "/" );
    strcat ( l_path, l_key_file_name);

    // Read the information file
    if(OK == ExtractPOIInfo (l_path, &l_poi_content))
    {
      if(ERROR == CompareToDBContinent((int)l_poi_content.m_continent))
      {
        logMsg ( "CompareToDBContinent failed continent : %d\n",
                  l_poi_content.m_continent,0,0,0,0,0 );
        l_script_status = ERROR;
      }
      else
      {
        logMsg ( "CompareToDBContinent OK\n",0,0,0,0,0,0 );
      }
    }
    else
    {
      logMsg ( "ExtractPOIInfo error on %s\n",l_path,0,0,0,0,0 );
      l_script_status = ERROR;
    }
  }

  //If no exception detected test all CD countries
  if (l_script_status!=ERROR)
  {
    strcpy ( l_path, l_source_drive);
    strcat ( l_path, MAPPE_PATH);
    l_poi_file_number = UPGSearchFile (ALL_FILES, l_path, NULL, NULL );
    logMsg ( "File search done for ALL_FILES ... l_poi_file_number:%d\n",l_poi_file_number,0,0,0,0,0 );

    //Allocate list
    if ( 0 == l_poi_file_number )
    {
      logMsg ( "0 files found\n",0,0,0,0,0,0 );
      l_script_status = ERROR;
    }
  }

  // delete temp directory
  if ( OK == l_script_status )
    {
      logMsg("Delete Temp files begin  -, Time = %ld\n",tickGet(),0,0,0,0,0);
      xdelete("/SDH/MAPPE/POI_USER/TEMP*.*");
      xdelete("/SDH/MAPPE/POI_USER/TEMP*");
      logMsg("Delete Temp files end -, Time = %ld\n",tickGet(),0,0,0,0,0);
    }


  /*** ASK USER AGREEMENT ***/
  /*** TWO TIMES          ***/ 
  for ( l_zone=0; l_zone<=1; l_zone++ )
  {
   l_numcopy = 0;
   l_lTotalSize = 0;
   l_lCompletedSize = 0;

   if ( NULL != l_poi_file_list)
   {
     free(l_poi_file_list);
     l_poi_file_list = NULL;
   }

  if ( ERROR != l_script_status )
  {
    if (0 == l_zone)
     {
      strcpy ( l_pQuestionText, STRING_POI_RADAR);
      strcpy (l_prefix, POI_RADAR_PREFIX);
     }
    else
     {
      strcpy ( l_pQuestionText, STRING_POI_DANGERZ);
      strcpy (l_prefix, POI_DANGERZ_PREFIX);
     }

    strcat ( l_pQuestionText, " " );
    _substr(partdate, l_poi_content.m_date, 4, 2);
    strcat ( l_pQuestionText, partdate);
    strcat ( l_pQuestionText, "/" );
    _substr(partdate, l_poi_content.m_date, 9, 2);
    strcat ( l_pQuestionText, partdate);
//    strcat ( l_pQuestionText, l_poi_content.m_date);

    //Do not ask user agreement if drive is empty
    ShowNavigationExtendedQuestionScreen (MMI_UPG_DISPLAY_ASK_MOTOR, l_pQuestionText, &l_bUpgRequired );
    l_UpgReq[l_zone] = l_bUpgRequired;
  }


  /*** PREPARE UPGRADE ***/
  if ( ( OK == l_script_status ) && ( TRUE == l_bUpgRequired ) )
  {
    logMsg ( "Prepare upgrade +, Time = %ld\n",tickGet(),0,0,0,0,0 );

    ShowNavigationBargraph();
    taskDelay(100);

    l_poi_file_list = (t_NavUpgData*) malloc ( sizeof(t_NavUpgData)*(l_poi_file_number+1) );

    for ( l_i=0; l_i<l_poi_file_number;l_i++ )
    {
      if ( ERROR == UPGGetSearchResult(l_i, l_search_result) )
      {
        logMsg ( "UPGGetSearchResult error\n",0,0,0,0,0,0 );
        l_script_status = ERROR;
        break;
      }
      else
      {
        if (strstr(l_search_result, l_prefix))
         {
          strcpy ( l_poi_file_list[l_numcopy].m_pFileName, l_search_result );
          if(ERROR == ComputePOITargetPath(l_poi_file_list[l_numcopy].m_pFileName,
                                           l_source_drive,
                                           l_target_drive,
                                           l_poi_file_list[l_numcopy].m_pTargetPath))
           {
            logMsg ( "ComputePOITargetPath failed on %s\n",
                     (char*)l_poi_file_list[l_numcopy].m_pTargetPath,0,0,0,0,0 );
           }
          else
           {
            if ( ERROR == GetFileSize ( l_search_result,
                                        &l_poi_file_list[l_numcopy].m_iSize ) )
             {
              logMsg ( "GetFileSize error\n",0,0,0,0,0,0 );
              l_script_status = ERROR;
              break;
             }
            l_lTotalSize += (unsigned long) l_poi_file_list[l_numcopy].m_iSize;
           }
          l_numcopy++;
         }
      }
    }
    logMsg ( "Total file size to install %d  (files:%d)\n",
            l_lTotalSize,l_numcopy,0,0,0,0 );

    //Print list
//    for ( l_i=0; l_i<l_poi_file_number; l_i++ )
    for ( l_i=0; l_i<l_numcopy; l_i++ )

    {
      logMsg ( "\nSRC:%s\nDST:%s\nSIZE:%d\n",(char*)l_poi_file_list[l_i].m_pFileName,
               (char*)l_poi_file_list[l_i].m_pTargetPath,
               l_poi_file_list[l_i].m_iSize,0,0,0 );
    }
  }

  logMsg ( "Prepare upgrade -, Time = %ld\n",tickGet(),0,0,0,0,0 );

  /*** UPGRADE ***/

  if ( ( OK == l_script_status ) && ( TRUE == l_bUpgRequired ) && (l_numcopy > 0))
  {
    logMsg ( "File copy +, Time = %ld\n",tickGet(),0,0,0,0,0 );

    //File copy
//    for ( l_i=0; l_i<l_poi_file_number; l_i++ )
    for ( l_i=0; l_i<l_numcopy; l_i++ )
    {
      for ( l_j=0; l_j<3; l_j++ )
      {
        if ( ERROR == UPGSpawnCopy ( l_poi_file_list[l_i].m_pFileName,
                                  l_poi_file_list[l_i].m_pTargetPath, FALSE ))
        {
          logMsg ( "UPGSpawnCopy error %s -> %s \n",
                   (char*)l_poi_file_list[l_i].m_pFileName,
                   (char*)l_poi_file_list[l_i].m_pTargetPath,0,0,0,0 );
        }
        else
        {
          l_script_status = OK;
          break;
        }
      }

      //Copy failed
      if ( 3 == l_j )
      {
        l_script_status = ERROR;
        break;
      }

      l_lCompletedSize += l_poi_file_list[l_i].m_iSize;
      l_iPercentage = (int) ( (l_lCompletedSize*100.0)/l_lTotalSize );

      _itoa(l_i, l_msg, 10 );
      _itoa(l_lCompletedSize, l_msg1, 10 );
      strcat(l_msg, " file (");
      strcat(l_msg, l_msg1);
      strcat(l_msg, " ) bytes copied...");

      StepBargraph(l_msg, l_iPercentage);
      taskDelay(50);
    }

    if(OK == l_script_status)
    {
      char l_destination[MAX_PATH_LENGTH];
      strcpy ( l_path, l_source_drive);
      strcat ( l_path, "/" );
      strcat ( l_path, l_key_file_name);
      strcpy ( l_destination, l_target_drive);
      strcat ( l_destination, POI_VER_FILE );
      strcat ( l_destination, l_key_file_name);

      if(ERROR == UPGCopy(l_path,l_destination,0))
      {
        logMsg("UPGCopy error %s -> %s \n",(int)l_path,(int)l_destination,0,0,0,0);
        l_script_status = ERROR;
      }

    }
  }

  } // end of two times

  l_bUpgRequired = FALSE;
  if (TRUE == l_UpgReq[0])
   {
    l_bUpgRequired = TRUE;
   }
  if (TRUE == l_UpgReq[1])
   {
    l_bUpgRequired = TRUE;
   }


  if ( NULL != l_poi_file_list)
  {
    free(l_poi_file_list);
    l_poi_file_list = NULL;
  }

  /*** TERMINATION ***/
  if ( !strcmp(l_source_drive, DRIVE_CDROM) )
  {
    if ( ERROR == UPGCDEject() )
    {
      logMsg ( "UPG Media Eject error\n",0,0,0,0,0,0 );
    }
  }

  if ( (OK == l_script_status) && ( TRUE == l_bUpgRequired ))
  {
    if(ERROR == SendMessageMMINavPOILoaded())
    {
      logMsg ( "SendMessageMMINavPOILoaded failed\n",0,0,0,0,0,0 );
      l_script_status = ERROR;
    }
    logMsg ("Waiting  for 'POILoaded'\n", 0, 0, 0, 0, 0, 0);
    GetMessageMMINavCIDLoaded();
    logMsg ("GetMessageMMINavCIDLoaded OK \n", 0, 0, 0, 0, 0, 0);
  }

  if ( FALSE == l_bUpgRequired )
  {
    logMsg ( "UPGRADE CANCELED BY USER!\n",0,0,0,0,0,0 );
    ShowCDCanceled ();
    taskDelay (DELAY_5S);
  }

  if ( OK == l_script_status)
  {
    logMsg("UPGRADE COMPLETE!\n",0,0,0,0,0,0);
  }
  else
  {
    logMsg("SCRIPT ERROR!\n",0,0,0,0,0,0);
    ShowCDProblem();
    taskDelay (DELAY_5S);
  }


  ClearScreen();
  taskDelay(100);

  return ( l_script_status );
}


/********************** INTERN FUNCTION DEFINITION **********************/

STATUS  ComputePOITargetPath (char* p_file_name,
                            char* p_source_drive,
                            char* p_target_drive,
                            char* p_target_name)
{
  STATUS l_status = OK;
  char l_temp_name[MAX_PATH_LENGTH];

  strcpy(l_temp_name,p_file_name);

  if(OK == ReplaceInPath(l_temp_name,p_source_drive,p_target_drive))
  {
    if(OK == ReplaceInPath(l_temp_name,POI_SOURCE_PATH,POI_TARGET_PATH))
    {
      strcpy(p_target_name,l_temp_name);
    }
    else
    {
      logMsg ( "ReplaceInPath POI_USER by TEMP_POI_USER failed on %s \n",
                (char*)l_temp_name,0,0,0,0,0 );
      l_status = ERROR;
    }
  }
  else
  {
    logMsg ( "ReplaceInPath %s by %s failed on %s \n",
              (char*)p_source_drive,
              (char*)p_target_drive,
              (char*)l_temp_name,0,0,0);
    l_status = ERROR;
  }
  return ( l_status );
}


STATUS ReplaceInPath(char *p_pPath, char *p_pStringToReplace, char *p_pStringToReplaceWhith )
{
  int l_iLenPath = 0;
  int l_iLenStrToReplace = 0;
  int l_iLenStrToReplaceWith = 0;

  char *l_pPrefPtr = NULL;
  char *l_pPostPtr = NULL;
  char l_pPath[MAX_PATH_LENGTH];

  char l_pPostString[MAX_PATH_LENGTH];


  //Check parameters
  if ( ( NULL == p_pPath ) || ( NULL == p_pStringToReplace ) || ( NULL == p_pStringToReplaceWhith ) )
  {
    logMsg("ReplaceInPath: NULL param\n",0,0,0,0,0,0);
    return ( ERROR );
  }

  l_iLenPath = strlen(p_pPath);
  l_iLenStrToReplace = strlen(p_pStringToReplace);
  l_iLenStrToReplaceWith = strlen(p_pStringToReplaceWhith);

  //Check substring lengths
  if ( (l_iLenStrToReplace > l_iLenPath) || (l_iLenStrToReplaceWith > l_iLenPath) )
  {
    logMsg("ReplaceInPath: substring is longer than string\n",0,0,0,0,0,0);
    return ( ERROR );
  }

  //Local copy
  strcpy ( l_pPath, p_pPath );

  //Look for pref ptr
  l_pPrefPtr = strstr ( l_pPath, p_pStringToReplace );
  if ( NULL == l_pPrefPtr )
  {
    logMsg("ReplaceInPath: Cannot find substring\n",0,0,0,0,0,0);
    return ( ERROR );
  }

  //Look for post ptr
  l_pPostPtr = l_pPrefPtr + l_iLenStrToReplace;

  //Get post string
  strcpy ( l_pPostString, l_pPostPtr );

  //Replace substring
  strcpy ( l_pPrefPtr, p_pStringToReplaceWhith );

  //Append post string
  strcat ( l_pPath, l_pPostString );

  //Copy back
  strcpy ( p_pPath, l_pPath );

  return ( OK );
}



STATUS ExtractPOIInfo(const char* p_filepath, t_poi_content* p_content)
{
  STATUS l_status = OK;
  FILE* l_file = NULL;
  char l_data[MAX_INF_LINE_LENGTH];
  if(NULL == p_filepath || NULL == p_content)
  {
    logMsg("ExtractPOIInfo: bad parameter\n",0,0,0,0,0,0);
    return (ERROR);
  }
  l_file = fopen((char*)p_filepath,"r");
  if(NULL != l_file)
  {
    char* l_ptr_data = NULL;

    if(NULL != fgets(l_data,MAX_INF_LINE_LENGTH,l_file))
    {
      l_ptr_data = strstr(l_data,STRING_CONTINENT_ID);
      if(NULL != l_ptr_data)
      {
        p_content->m_continent = (t_continent)atoi(l_ptr_data +
                                                    strlen(STRING_CONTINENT_ID));
      }
      else
      {
        logMsg("ExtractPOIInfo: Can't find CONTINENT_ID:\n",0,0,0,0,0,0);
        l_status = ERROR;
      }
    }
    else
    {
      logMsg("ExtractPOIInfo: fgets failed\n",0,0,0,0,0,0);
      l_status = ERROR;
    }

    if(NULL != l_ptr_data
        && NULL != fgets(l_data,MAX_INF_LINE_LENGTH,l_file))
    {
      l_ptr_data = strstr(l_data,STRING_CONTINENT_NAME);
      if(NULL != l_ptr_data)
      {
        strcpy(p_content->m_continent_name,
                l_ptr_data + strlen(STRING_CONTINENT_NAME));
        p_content->m_continent_name[MAX_COUNTRY_NAME_HDD-1]='\0';
      }
      else
      {
        logMsg("ExtractPOIInfo: Can't find CONTINENT_NAME:\n",0,0,0,0,0,0);
        l_status = ERROR;
      }
    }
    else
    {
      logMsg("ExtractPOIInfo: fgets failed\n",0,0,0,0,0,0);
      l_status = ERROR;
    }

    if(NULL != l_ptr_data
        && NULL != fgets(l_data,MAX_INF_LINE_LENGTH,l_file))
    {
      l_ptr_data = strstr(l_data,STRING_CD_NAME);
      if(NULL != l_ptr_data)
      {
        strcpy(p_content->m_cd_name,
                l_ptr_data + strlen(STRING_CD_NAME));
        p_content->m_cd_name[MAX_COUNTRY_NAME_HDD-1]='\0';
      }
      else
      {
        logMsg("ExtractPOIInfo: Can't find CD_NAME:\n",0,0,0,0,0,0);
        l_status = ERROR;
      }
    }
    else
    {
      logMsg("ExtractPOIInfo: fgets failed\n",0,0,0,0,0,0);
      l_status = ERROR;
    }

    if(NULL != l_ptr_data
        && NULL != fgets(l_data,MAX_INF_LINE_LENGTH,l_file))
    {
      l_ptr_data = strstr(l_data,STRING_POI_PROVIDER);
      if(NULL != l_ptr_data)
      {
        strcpy(p_content->m_poi_provider,
                l_ptr_data + strlen(STRING_POI_PROVIDER));
        p_content->m_poi_provider[MAX_DATA_PROVIDER-1]='\0';
      }
      else
      {
        logMsg("ExtractPOIInfo: Can't find POI_PROVIDER:\n",0,0,0,0,0,0);
        l_status = ERROR;
      }
    }
    else
    {
      logMsg("ExtractPOIInfo: fgets failed\n",0,0,0,0,0,0);
      l_status = ERROR;
    }

    if(NULL != l_ptr_data
        && NULL != fgets(l_data,MAX_INF_LINE_LENGTH,l_file))
    {
      l_ptr_data = strstr(l_data,STRING_DATA_POI);
      if(NULL != l_ptr_data)
      {
        strcpy(p_content->m_date,
                l_ptr_data + strlen(STRING_DATA_POI));
        p_content->m_date[MAX_DATE_LENGTH-1]='\0';
      }
      else
      {
        logMsg("ExtractPOIInfo: Can't find DATA_POI:\n",0,0,0,0,0,0);
        l_status = ERROR;
      }
    }
    else
    {
      logMsg("ExtractPOIInfo: fgets failed\n",0,0,0,0,0,0);
      l_status = ERROR;
    }

    fclose(l_file);
  }
  else
  {
    logMsg("ExtractPOIInfo: Can't open %s file\n",(int)p_filepath,0,0,0,0,0);
    l_status = ERROR;
  }

  return (l_status);
}

