Ejemplo n.º 1
0
NS_IMETHODIMP nsMsgHeaderParser::ParseHeadersWithArray(const PRUnichar * aLine, PRUnichar *** aEmailAddresses,
        PRUnichar *** aNames, PRUnichar *** aFullNames, PRUint32 * aNumAddresses)
{
    char * names = nsnull;
    char * addresses = nsnull;
    PRUint32 numAddresses = 0;
    nsresult rv = NS_OK;

    // need to convert unicode to UTF-8...
    nsAutoString tempString (aLine);
    char * utf8String = ToNewUTF8String(tempString);

    rv = ParseHeaderAddresses(utf8String, &names, &addresses, &numAddresses);
    NS_Free(utf8String);
    if (NS_SUCCEEDED(rv) && numAddresses)
    {
        // allocate space for our arrays....
        *aEmailAddresses = (PRUnichar **) PR_MALLOC(sizeof(PRUnichar *) * numAddresses);
        *aNames = (PRUnichar **) PR_MALLOC(sizeof(PRUnichar *) * numAddresses);
        *aFullNames = (PRUnichar **) PR_MALLOC(sizeof(PRUnichar *) * numAddresses);

        // for simplicities sake...
        PRUnichar ** outgoingEmailAddresses = *aEmailAddresses;
        PRUnichar ** outgoingNames = *aNames;
        PRUnichar ** outgoingFullNames = *aFullNames;

        // iterate over the results and fill in our arrays....
        PRUint32 index = 0;
        const char * currentName = names;
        const char * currentAddress = addresses;
        char * unquotedName = nsnull;
        while (index < numAddresses)
        {
            if (NS_SUCCEEDED(UnquotePhraseOrAddr(currentName, PR_TRUE, &unquotedName)))
                rv = FillResultsArray(unquotedName, currentAddress, &outgoingEmailAddresses[index], &outgoingNames[index], &outgoingFullNames[index], this);
            else
                rv = FillResultsArray(currentName, currentAddress, &outgoingEmailAddresses[index], &outgoingNames[index], &outgoingFullNames[index], this);

            PR_FREEIF(unquotedName);
            currentName += strlen(currentName) + 1;
            currentAddress += strlen(currentAddress) + 1;
            index++;
        }
    }

    *aNumAddresses = numAddresses;
    PR_FREEIF(names);
    PR_FREEIF(addresses);
    return rv;
}
Ejemplo n.º 2
0
static int
MimeInlineTextVCard_parse_line (const char *line, int32_t length, MimeObject *obj)
{
  // This routine gets fed each line of data, one at a time.
  char* linestring;
  MimeInlineTextVCardClass *clazz = ((MimeInlineTextVCardClass *) obj->clazz);

  if (!obj->output_p) return 0;
  if (!obj->options || !obj->options->output_fn) return 0;
  if (!obj->options->write_html_p)
  {
    return COM_MimeObject_write(obj, line, length, true);
  }

  linestring = (char *) PR_MALLOC (length + 1);
  memset(linestring, 0, (length + 1));

  if (linestring)
  {
    strcpySafe((char *)linestring, line, length + 1);
    NS_MsgSACat (&clazz->vCardString, linestring);
    PR_Free (linestring);
  }

  return 0;
}
Ejemplo n.º 3
0
static int
MimeContainer_add_child (MimeObject *parent, MimeObject *child)
{
  MimeContainer *cont = (MimeContainer *) parent;
  MimeObject **old_kids, **new_kids;

  NS_ASSERTION(parent && child, "1.1 <*****@*****.**> 19 Mar 1999 12:00");
  if (!parent || !child) return -1;

  old_kids = cont->children;
  new_kids = (MimeObject **)PR_MALLOC(sizeof(MimeObject *) * (cont->nchildren + 1));
  if (!new_kids) return MIME_OUT_OF_MEMORY;

  if (cont->nchildren > 0)
    memcpy(new_kids, old_kids, sizeof(MimeObject *) * cont->nchildren);
  new_kids[cont->nchildren] = child;
  PR_Free(old_kids);
  cont->children = new_kids;
  cont->nchildren++;

  child->parent = parent;

  /* Copy this object's options into the child. */
  child->options = parent->options;

  return 0;
}
Ejemplo n.º 4
0
static bool MimeUntypedText_yenc_begin_line_p(const char *line, int32_t length,
                                              MimeDisplayOptions *opt,
                                              char **type_ret,
                                              char **name_ret) {
  const char *s;
  const char *endofline = line + length;
  char *name = 0;
  char *type = 0;

  if (type_ret) *type_ret = 0;
  if (name_ret) *name_ret = 0;

  /* we don't support yenc V2 neither multipart yencode,
     therefore the second parameter should always be "line="*/
  if (length < 13 || strncmp(line, "=ybegin line=", 13)) return false;

  /* ...then couple digits. */
  for (s = line + 13; s < endofline; s++)
    if (*s < '0' || *s > '9') break;

  /* ...next, look for <space>size= */
  if ((endofline - s) < 6 || strncmp(s, " size=", 6)) return false;

  /* ...then couple digits. */
  for (s += 6; s < endofline; s++)
    if (*s < '0' || *s > '9') break;

  /* ...next, look for <space>name= */
  if ((endofline - s) < 6 || strncmp(s, " name=", 6)) return false;

  /* anything left is the file name */
  s += 6;
  name = (char *)PR_MALLOC((endofline - s) + 1);
  if (!name) return false; /* grr... */
  memcpy(name, s, endofline - s);
  name[endofline - s] = 0;

  /* take off newline. */
  if (name[strlen(name) - 1] == '\n') name[strlen(name) - 1] = 0;
  if (name[strlen(name) - 1] == '\r') name[strlen(name) - 1] = 0;

  /* Now try and figure out a type.
   */
  if (opt && opt->file_type_fn)
    type = opt->file_type_fn(name, opt->stream_closure);
  else
    type = 0;

  if (name_ret)
    *name_ret = name;
  else
    PR_FREEIF(name);

  if (type_ret)
    *type_ret = type;
  else
    PR_FREEIF(type);

  return true;
}
Ejemplo n.º 5
0
nsresult
RDFContentSinkImpl::AddText(const PRUnichar* aText, PRInt32 aLength)
{
    // Create buffer when we first need it
    if (0 == mTextSize) {
        mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
        if (!mText) {
            return NS_ERROR_OUT_OF_MEMORY;
        }
        mTextSize = 4096;
    }

    // Copy data from string into our buffer; grow the buffer as needed.
    // It never shrinks, but since the content sink doesn't stick around,
    // this shouldn't be a bloat issue.
    PRInt32 amount = mTextSize - mTextLength;
    if (amount < aLength) {
        // Grow the buffer by at least a factor of two to prevent thrashing.
        // Since PR_REALLOC will leave mText intact if the call fails,
        // don't clobber mText or mTextSize until the new mem is allocated.
        PRInt32 newSize = (2 * mTextSize > (mTextSize + aLength)) ?
                          (2 * mTextSize) : (mTextSize + aLength);
        PRUnichar* newText = 
            (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * newSize);
        if (!newText)
            return NS_ERROR_OUT_OF_MEMORY;
        mTextSize = newSize;
        mText = newText;
    }
    memcpy(&mText[mTextLength], aText, sizeof(PRUnichar) * aLength);
    mTextLength += aLength;

    return NS_OK;
}
Ejemplo n.º 6
0
//This filter apply to all scripts that does not use latin letters (english letter)
PRBool SBCSGroupProber::FilterWithoutEnglishLetters(const char* aBuf, PRUint32 aLen, char** newBuf, PRUint32& newLen)
{
  //do filtering to reduce load to probers
  char *newptr;
  char *prevPtr, *curPtr;
  
  PRBool meetMSB = PR_FALSE;   
  newptr = *newBuf = (char*)PR_MALLOC(aLen);
  if (!newptr)
    return PR_FALSE;

  for (curPtr = prevPtr = (char*)aBuf; curPtr < aBuf+aLen; curPtr++)
  {
    if (*curPtr & 0x80)
      meetMSB = PR_TRUE;
    else if (*curPtr < 'A' || (*curPtr > 'Z' && *curPtr < 'a') || *curPtr > 'z') 
    {
      //current char is a symbol, most likely a punctuation. we treat it as segment delimiter
      if (meetMSB && curPtr > prevPtr) 
      //this segment contains more than single symbol, and it has upper ascii, we need to keep it
      {
        while (prevPtr < curPtr) *newptr++ = *prevPtr++;  
        prevPtr++;
        *newptr++ = ' ';
        meetMSB = PR_FALSE;
      }
      else //ignore current segment. (either because it is just a symbol or just a english word
        prevPtr = curPtr+1;
    }
  }

  newLen = newptr - *newBuf;

  return PR_TRUE;
}
Ejemplo n.º 7
0
/*
 * Assemble the command line by concatenating the argv array.
 * Special characters intentionally do not get escaped, and it is
 * expected that the caller wraps arguments in quotes if needed
 * (e.g. for filename with spaces).
 *
 * On success, this function returns 0 and the resulting command
 * line is returned in *cmdLine.  On failure, it returns -1.
 */
static int assembleCmdLine(char *const *argv, char **cmdLine)
{
    char *const *arg;
    int cmdLineSize;

    /*
     * Find out how large the command line buffer should be.
     */
    cmdLineSize = 1; /* final null */
    for (arg = argv+1; *arg; arg++) {
        cmdLineSize += strlen(*arg) + 1; /* space in between */
    }
    *cmdLine = PR_MALLOC(cmdLineSize);
    if (*cmdLine == NULL) {
        return -1;
    }

    (*cmdLine)[0] = '\0';

    for (arg = argv+1; *arg; arg++) {
        if (arg > argv +1) {
            strcat(*cmdLine, " ");
        }
        strcat(*cmdLine, *arg);
    } 
    return 0;
}
Ejemplo n.º 8
0
/*  binary block Allocate and Concatenate
 *
 *   destination_length  is the length of the existing block
 *   source_length   is the length of the block being added to the
 *   destination block
 */
static char *il_BACat (char **destination,
                       size_t destination_length,
                       const char *source,
                       size_t source_length)
{
  if (source) {
    if (*destination) {
      *destination = (char *) PR_REALLOC (*destination,
                                          destination_length + source_length);
      if (*destination == nsnull)
        return (nsnull);

      memmove(*destination + destination_length, source, source_length);
    }
    else {
      *destination = (char *) PR_MALLOC (source_length);
      if (*destination == nsnull)
        return (nsnull);

      memcpy(*destination, source, source_length);
    }
  }

  return *destination;
}
Ejemplo n.º 9
0
MimeHeaders *
MimeHeaders_copy (MimeHeaders *hdrs)
{
  MimeHeaders *hdrs2;
  if (!hdrs) return 0;

  hdrs2 = (MimeHeaders *) PR_MALLOC(sizeof(*hdrs));
  if (!hdrs2) return 0;
  memset(hdrs2, 0, sizeof(*hdrs2));

  if (hdrs->all_headers)
  {
    hdrs2->all_headers = (char *) PR_MALLOC(hdrs->all_headers_fp);
    if (!hdrs2->all_headers)
    {
      PR_Free(hdrs2);
      return 0;
    }
    memcpy(hdrs2->all_headers, hdrs->all_headers, hdrs->all_headers_fp);

    hdrs2->all_headers_fp   = hdrs->all_headers_fp;
    hdrs2->all_headers_size = hdrs->all_headers_fp;
  }

  hdrs2->done_p = hdrs->done_p;

  if (hdrs->heads)
  {
    int i;
    hdrs2->heads = (char **) PR_MALLOC(hdrs->heads_size
                    * sizeof(*hdrs->heads));
    if (!hdrs2->heads)
    {
      PR_FREEIF(hdrs2->all_headers);
      PR_Free(hdrs2);
      return 0;
    }
    hdrs2->heads_size = hdrs->heads_size;
    for (i = 0; i < hdrs->heads_size; i++)
    {
      hdrs2->heads[i] = (hdrs2->all_headers +
               (hdrs->heads[i] - hdrs->all_headers));
    }
  }
  return hdrs2;
}
Ejemplo n.º 10
0
/*
** Stubs for default hash allocator ops.
*/
static void * PR_CALLBACK
DefaultAllocTable(void *pool, PRSize size)
{
#if defined(XP_MAC)
#pragma unused (pool)
#endif

    return PR_MALLOC(size);
}
Ejemplo n.º 11
0
static bool MimeUntypedText_uu_begin_line_p(const char *line, int32_t length,
                                            MimeDisplayOptions *opt,
                                            char **type_ret, char **name_ret) {
  const char *s;
  char *name = 0;
  char *type = 0;

  if (type_ret) *type_ret = 0;
  if (name_ret) *name_ret = 0;

  if (strncmp(line, "begin ", 6)) return false;
  /* ...then three or four octal digits. */
  s = line + 6;
  if (*s < '0' || *s > '7') return false;
  s++;
  if (*s < '0' || *s > '7') return false;
  s++;
  if (*s < '0' || *s > '7') return false;
  s++;
  if (*s == ' ')
    s++;
  else {
    if (*s < '0' || *s > '7') return false;
    s++;
    if (*s != ' ') return false;
  }

  while (IS_SPACE(*s)) s++;

  name = (char *)PR_MALLOC(((line + length) - s) + 1);
  if (!name) return false; /* grr... */
  memcpy(name, s, (line + length) - s);
  name[(line + length) - s] = 0;

  /* take off newline. */
  if (name[strlen(name) - 1] == '\n') name[strlen(name) - 1] = 0;
  if (name[strlen(name) - 1] == '\r') name[strlen(name) - 1] = 0;

  /* Now try and figure out a type.
   */
  if (opt && opt->file_type_fn)
    type = opt->file_type_fn(name, opt->stream_closure);
  else
    type = 0;

  if (name_ret)
    *name_ret = name;
  else
    PR_FREEIF(name);

  if (type_ret)
    *type_ret = type;
  else
    PR_FREEIF(type);

  return true;
}
Ejemplo n.º 12
0
pr_context* _pr_context_create(const PRcontextdesc* desc, PRuint width, PRuint height)
{
    if (desc == NULL || desc->window == NULL || width <= 0 || height <= 0)
    {
        _pr_error_set(PR_ERROR_INVALID_ARGUMENT, __FUNCTION__);
        return NULL;
    }

    // Create render context
    pr_context* context = PR_MALLOC(pr_context);

    // Setup bitmap info structure
    BITMAPINFO* bmi = (&context->bmpInfo);
    memset(bmi, 0, sizeof(BITMAPINFO));

    bmi->bmiHeader.biSize           = sizeof(BITMAPINFOHEADER);
    bmi->bmiHeader.biWidth          = (LONG)width;
    bmi->bmiHeader.biHeight         = (LONG)height;
    bmi->bmiHeader.biPlanes         = 1;
    bmi->bmiHeader.biBitCount       = 24;
    bmi->bmiHeader.biCompression    = BI_RGB;

    // Setup context
    context->wnd        = *((HWND*)desc->window);
    context->dc         = GetDC(context->wnd);
    context->dcBmp      = CreateCompatibleDC(context->dc);
    context->bmp        = CreateCompatibleBitmap(context->dc, width, height);
    context->colors     = PR_CALLOC(pr_color, width*height);
    context->width      = width;
    context->height     = height;

    SelectObject(context->dcBmp, context->bmp);

    // Create color palette
    context->colorPalette = PR_MALLOC(pr_color_palette);
    _pr_color_palette_fill_r3g3b2(context->colorPalette);

    // Initialize state machine
    _pr_state_machine_init(&(context->stateMachine));
    _pr_context_makecurrent(context);

    return context;
}
Ejemplo n.º 13
0
static char*
MimePgpe_generate(void *output_closure)
{
  const char htmlMsg[] = "<html><body><b>GEN MSG<b></body></html>";
  char* msg = (char *) PR_MALLOC(strlen(htmlMsg) + 1);
  if (msg)
    PL_strcpy(msg, htmlMsg);

  return msg;
}
Ejemplo n.º 14
0
pr_vertexbuffer* _pr_vertexbuffer_create()
{
    pr_vertexbuffer* vertexBuffer = PR_MALLOC(pr_vertexbuffer);

    vertexBuffer->numVertices   = 0;
    vertexBuffer->vertices      = NULL;

    _pr_ref_add(vertexBuffer);

    return vertexBuffer;
}
Ejemplo n.º 15
0
MimeHeaders *
MimeHeaders_new (void)
{
  MimeHeaders *hdrs = (MimeHeaders *) PR_MALLOC(sizeof(MimeHeaders));
  if (!hdrs) return 0;

  memset(hdrs, 0, sizeof(*hdrs));
  hdrs->done_p = false;

  return hdrs;
}
Ejemplo n.º 16
0
PR_IMPLEMENT(void) PR_SetLogBuffering(PRIntn buffer_size)
{
    PR_LogFlush();

    if (logBuf)
        PR_DELETE(logBuf);

    if (buffer_size >= LINE_BUF_SIZE) {
        logp = logBuf = (char*) PR_MALLOC(buffer_size);
        logEndp = logp + buffer_size;
    }
}
Ejemplo n.º 17
0
// Release the retun value with PR_FREEIF
static char* getPRErrorText ()
{
  PRInt32 errTextLen = PR_GetErrorTextLength ();
  char *s = (char*)PR_MALLOC (errTextLen + 1);
  if (s)
  {
    s[0] = '\0';
    (void)PR_GetErrorText (s);
  }

  return s;
}
Ejemplo n.º 18
0
// Release the retun value with PR_FREEIF
static char* getPRErrorText ()
{
  PRInt32 errTextLen = PR_GetErrorTextLength ();
  char *rv = (char*)PR_MALLOC (errTextLen + 1);
  if (rv)
  {
    rv[0] = '\0';
    (void)PR_GetErrorText (rv);
  }

  return rv;
}
Ejemplo n.º 19
0
static char*
MimeEnig_generate(void *output_closure)
{
  fprintf(stderr, "MimeEnig_generate:\n");

  const char htmlMsg[] = "<html><body><b>GEN MSG<b></body></html>";
  char* msg = (char *) PR_MALLOC(strlen(htmlMsg) + 1);
  if (msg) {
    PL_strcpy(msg, htmlMsg);
  }
  return msg;
}
Ejemplo n.º 20
0
PR_ProcessAttrSetCurrentDirectory(
    PRProcessAttr *attr,
    const char *dir)
{
    PR_FREEIF(attr->currentDirectory);
    attr->currentDirectory = (char *) PR_MALLOC(strlen(dir) + 1);
    if (!attr->currentDirectory) {
        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
        return PR_FAILURE;
    }
    strcpy(attr->currentDirectory, dir);
    return PR_SUCCESS;
}
void _MD_EarlyInit(void)
{
#ifndef _PR_PTHREADS
    /*
     * The following piece of code is taken from ns/nspr/src/md_HP-UX.c.
     * In the comment for revision 1.6, dated 1995/09/11 23:33:34,
     * robm says:
     *     This version has some problems which need to be addressed.
     *     First, intercept all system calls and prevent them from
     *     executing the library code which performs stack switches
     *     before normal system call invocation.  In order for library
     *     calls which make system calls to work (like stdio), however,
     *     we must also allocate our own stack and switch the primordial
     *     stack to use it. This isn't so bad, except that I fudged the
     *     backtrace length when copying the old stack to the new one.
     *
     * This is the original comment of robm in the code:
     *    XXXrobm Horrific. To avoid a problem with HP's system call
     *    code, we allocate a new stack for the primordial thread and
     *    use it. However, we don't know how far back the original stack
     *    goes. We should create a routine that performs a backtrace and
     *    finds out just how much we need to copy. As a temporary measure,
     *    I just copy an arbitrary guess.
     *
     * In an email to servereng dated 2 Jan 1997, Mike Patnode (mikep)
     * suggests that this only needs to be done for HP-UX 9.
     */
#ifdef HPUX9
#define PIDOOMA_STACK_SIZE 524288
#define BACKTRACE_SIZE 8192
    {
        jmp_buf jb;
        char *newstack;
        char *oldstack;

        if(!setjmp(jb)) {
            newstack = (char *) PR_MALLOC(PIDOOMA_STACK_SIZE);
	    oldstack = (char *) (*(((int *) jb) + 1) - BACKTRACE_SIZE);
            memcpy(newstack, oldstack, BACKTRACE_SIZE);
            *(((int *) jb) + 1) = (int) (newstack + BACKTRACE_SIZE);
            longjmp(jb, 1);
        }
    }
#endif  /* HPUX9 */
#endif  /* !_PR_PTHREADS */
}
Ejemplo n.º 22
0
static int
push_tag(MimeMultipartRelated* relobj, const char* buf, int32_t size)
{
  if (size + relobj->curtag_length > relobj->curtag_max) {
    relobj->curtag_max += 2 * size;
    if (relobj->curtag_max < 1024) relobj->curtag_max = 1024;
    if (!relobj->curtag) {
      relobj->curtag = (char*) PR_MALLOC(relobj->curtag_max);
    } else {
      relobj->curtag = (char*) PR_Realloc(relobj->curtag,
                        relobj->curtag_max);
    }
    if (!relobj->curtag) return MIME_OUT_OF_MEMORY;
  }
  memcpy(relobj->curtag + relobj->curtag_length, buf, size);
  relobj->curtag_length += size;
  return 0;
}
Ejemplo n.º 23
0
nsresult
XULContentSinkImpl::AddText(const PRUnichar* aText, 
                            PRInt32 aLength)
{
  // Create buffer when we first need it
  if (0 == mTextSize) {
      mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
      if (nsnull == mText) {
          return NS_ERROR_OUT_OF_MEMORY;
      }
      mTextSize = 4096;
  }

  // Copy data from string into our buffer; flush buffer when it fills up
  PRInt32 offset = 0;
  while (0 != aLength) {
    PRInt32 amount = mTextSize - mTextLength;
    if (amount > aLength) {
        amount = aLength;
    }
    if (0 == amount) {
      if (mConstrainSize) {
        nsresult rv = FlushText();
        if (NS_OK != rv) {
            return rv;
        }
      }
      else {
        mTextSize += aLength;
        mText = (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * mTextSize);
        if (nsnull == mText) {
            return NS_ERROR_OUT_OF_MEMORY;
        }
      }
    }
    memcpy(&mText[mTextLength],aText + offset, sizeof(PRUnichar) * amount);
    
    mTextLength += amount;
    offset += amount;
    aLength -= amount;
  }

  return NS_OK;
}
Ejemplo n.º 24
0
/* This routine is only necessary because the mailbox URL fed to us
   by the winfe can contain spaces and '>'s in it. It's a hack. */
static char *
escape_for_mrel_subst(char *inURL)
{
  char *output, *inC, *outC, *temp;

  int size = strlen(inURL) + 1;

  for(inC = inURL; *inC; inC++)
    if ((*inC == ' ') || (*inC == '>'))
      size += 2; /* space -> '%20', '>' -> '%3E', etc. */

  output = (char *)PR_MALLOC(size);
  if (output)
  {
    /* Walk through the source string, copying all chars
      except for spaces, which get escaped. */
    inC = inURL;
    outC = output;
    while(*inC)
    {
      if (*inC == ' ')
      {
        *outC++ = '%'; *outC++ = '2'; *outC++ = '0';
      }
      else if (*inC == '>')
      {
        *outC++ = '%'; *outC++ = '3'; *outC++ = 'E';
      }
      else
        *outC++ = *inC;

      inC++;
    }
    *outC = '\0';

    temp = escape_unescaped_percents(output);
    if (temp)
    {
      PR_FREEIF(output);
      output = temp;
    }
  }
  return output;
}
Ejemplo n.º 25
0
NS_IMETHODIMP nsMimeHeaders::GetAllHeaders(char **_retval)
{
    if (!mHeaders)
        return NS_ERROR_NOT_INITIALIZED;

    if (!mHeaders->all_headers)
        return NS_ERROR_NULL_POINTER;

    char *allHeaders = (char *) PR_MALLOC(mHeaders->all_headers_fp + 1);
    NS_ASSERTION (allHeaders, "nsMimeHeaders - out of memory");
    if (!allHeaders)
        return NS_ERROR_OUT_OF_MEMORY;

    memcpy(allHeaders, mHeaders->all_headers, mHeaders->all_headers_fp);
    *(allHeaders + mHeaders->all_headers_fp) = 0;
    *_retval = allHeaders;

    return NS_OK;
}
Ejemplo n.º 26
0
nsresult nsByteArray::GrowBuffer(PRUint32 desired_size, PRUint32 quantum)
{
  if (m_bufferSize < desired_size)
  {
    char *new_buf;
    PRUint32 increment = desired_size - m_bufferSize;
    if (increment < quantum) /* always grow by a minimum of N bytes */
      increment = quantum;
    
    
    new_buf = (m_buffer
      ? (char *) PR_REALLOC (m_buffer, (m_bufferSize + increment))
      : (char *) PR_MALLOC (m_bufferSize + increment));
    if (! new_buf)
      return NS_ERROR_OUT_OF_MEMORY;
    m_buffer = new_buf;
    m_bufferSize += increment;
  }
  return 0;
}
Ejemplo n.º 27
0
extern "C" int
mime_GrowBuffer (PRUint32 desired_size, PRUint32 element_size, PRUint32 quantum,
        char **buffer, PRInt32 *size)
{
  if ((PRUint32) *size <= desired_size)
  {
    char *new_buf;
    PRUint32 increment = desired_size - *size;
    if (increment < quantum) /* always grow by a minimum of N bytes */
    increment = quantum;

    new_buf = (*buffer
         ? (char *) PR_Realloc (*buffer, (*size + increment)
                    * (element_size / sizeof(char)))
         : (char *) PR_MALLOC ((*size + increment)
                    * (element_size / sizeof(char))));
    if (! new_buf)
      return MIME_OUT_OF_MEMORY;
    *buffer = new_buf;
    *size += increment;
  }
  return 0;
}
Ejemplo n.º 28
0
//This filter apply to all scripts that does use latin letters (english letter)
PRBool SBCSGroupProber::FilterWithEnglishLetters(const char* aBuf, PRUint32 aLen, char** newBuf, PRUint32& newLen)
{
  //do filtering to reduce load to probers
  char *newptr;
  char *prevPtr, *curPtr;
  PRBool isInTag = PR_FALSE;

  newptr = *newBuf = (char*)PR_MALLOC(aLen);
  if (!newptr)
    return PR_FALSE;

  for (curPtr = prevPtr = (char*)aBuf; curPtr < aBuf+aLen; curPtr++)
  {
		if (*curPtr == '>')
			isInTag = PR_FALSE;
    else if (*curPtr == '<')
      isInTag = PR_TRUE;

    if (!(*curPtr & 0x80) &&
        (*curPtr < 'A' || (*curPtr > 'Z' && *curPtr < 'a') || *curPtr > 'z') )
    {
      if (curPtr > prevPtr && !isInTag) //current segment contains more than just a symbol 
                                        // and it is not inside a tag, keep it
      {
        while (prevPtr < curPtr) *newptr++ = *prevPtr++;  
        prevPtr++;
        *newptr++ = ' ';
      }
      else
        prevPtr = curPtr+1;
    }
  }

  newLen = newptr - *newBuf;

  return PR_TRUE;
}
Ejemplo n.º 29
0
PRBool latin1_filterwithenglishletters(const char* abuf, PRUint32 alen, 
                                       char** newbuf, PRUint32* newlen) {

	/* Do filtering to reduce the load the the probers */
	char* newptr;
	char* prevptr;
	char* curptr;

	newptr = *newbuf = (char*)PR_MALLOC(alen);
	if (!newptr) {
		return PR_FALSE;
	}

	/* DANGEROUS ptr arithmetic, find cleaner solution */
	for (curptr = prevptr = (char*)abuf; curptr < abuf + alen; curptr++) {
		
		if(!(*curptr & 0x80) &&
		  (*curptr < 'A' || (*curptr > 'Z' && *curptr < 'a' || *curptr >'z'))) {
			/* current segment contains more than just a symbol, keep it */
			if (curptr > prevptr) {
				while(prevptr < curptr) *newptr++ = *prevptr++;
				prevptr++;
				*newptr++ = ' '; /* this code is also ambiguous */
			}
			else {
				prevptr = curptr + 1;
			}
		}
	}

	/* more ptr arithmetic, I'm in hell ;) */
	*newlen = newptr - *newbuf;

	return PR_TRUE;

}
Ejemplo n.º 30
0
static void *
DefaultAllocTable(void *pool, size_t size)
{
    return PR_MALLOC(size);
}