Return to LanScape's home page Go back a page...       Active TopicsActive Topics   Display List of Forum MembersMember List   Knowledge Base SearchSearch   HelpHelp  RegisterRegister  LoginLogin

LanScape VOIP Media Engine™ - Technical Support
 LanScape Support Forum -> LanScape VOIP Media Engine™ - Technical Support
Subject Topic: ReadLicenseImage Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
hermes
Junior
Junior


Joined: October 27 2006
Posts: 64
Posted: January 09 2007 at 10:11am | IP Logged Quote hermes

Hello,

I´m using ReadLicenseImage procedure ('Dual Line IVR Server example') to read Microcode file and I´ve observed that last byte is never read. It is a failure?

Thanks
Back to Top View hermes's Profile Search for other posts by hermes
 
support
Administrator
Administrator


Joined: January 26 2005
Location: United States
Posts: 1666
Posted: January 09 2007 at 2:35pm | IP Logged Quote support

Hi hermes,

Thanks for pointing that out. Yes it is a bug in the example source code procedure ReadLicenseImage(). We will fix it for the next release.

The bug won't cause any effects though seeing that the last byte of license data is an internal pad byte. We got lucky.

Here is a version of the procedure that will get the last byte in the license data properly:

Code:


BOOL PhoneSetingsDlg::ReadLicenseImage(char *pLicenseFileName, BYTE **ppRuntimeMicrocode, int *pRuntimeMicrocodeLength)
{
     BOOL ret = FALSE;
     FILE *fp;
     char ch;
     char Line[256];
     char *str;
     CString tmp;
     BOOL done = FALSE;
     CCommaSeparatedList Helper;
     BYTE value;
     int NumBytes;
     int Pass;
     BYTE *pRuntimeMicrocode;
     BYTE *pCurByte;
     int RuntimeMicrocodeLength;


     fp = fopen(pLicenseFileName,"rt");

     if(fp)
     {
           // go through the data once to determine byte size. pass 2 actually
           // saves the data.
           for(Pass=0;Pass<2;Pass++)
           {
                if(Pass == 1)
                 {
                      // allocate space for converted pass 2 data.
                      pRuntimeMicrocode = new BYTE[NumBytes];

                      if(!pRuntimeMicrocode)
                      {
                           // memory error.
                           break;
                      }
                      else
                      {
                           pCurByte = pRuntimeMicrocode;
                           RuntimeMicrocodeLength = NumBytes;
                      }
                }

                NumBytes = 0;

                 // get to the open bracket.
                ch = 0;
                while((!feof(fp) && ch != '{'))
                 {
                      ch = fgetc(fp);
                }

                 // start processing lines.
                while(!done && !feof(fp))
                 {
                      if(!fgets(Line,sizeof(Line)-1,fp))
                      {
                           done = TRUE;
                      }
                      else
                      {
                           str = Line;

                           for(;!done;)
                           {
                                 str = strstr(str,"0x");

                                 if(!str)
                                {
                                      break;
                                 }
                                 else
                                {
                                     // see if we are at the end of the data.
                                      if(*(str + 4) == '\n')
                                     {
                                          // convert the last data byte.
                                            Helper.copytil(&tmp,str,"\n");

                                          // terminate further processing.
                                           done = TRUE;
                                      }
                                      else
                                     {
                                          // convert the byte as normal.
                                            Helper.copytil(&tmp,str,",");
                                      }

                                      HexToByte(CSPTR(tmp),&value);
                                     NumBytes ++;

                                      str += 2;

                                     if(Pass == 1)
                                     {
                                            *pCurByte = value;
                                           pCurByte ++;
                                      }
                                 }
                            }
                      }
                }

                if(Pass == 0)
                 {
                      if(NumBytes <= 8192)
                      {
                           // bad microcode file.
                           break;
                      }
                      else
                      {
                           done = FALSE;
                           rewind(fp);
                      }
                }
                else
                 {
                      *ppRuntimeMicrocode = pRuntimeMicrocode;
                      *pRuntimeMicrocodeLength = RuntimeMicrocodeLength;
                      done = TRUE;

                      // success.
                      ret = TRUE;
                }
           }

           fclose(fp);
     }

     return(ret);
}


Repost as neeed,

Support
Back to Top View support's Profile Search for other posts by support Visit support's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum






Contact LanScape Hear what the Lawyers have to say How youm may use this site Read your privacy rights