Beispiel #1
0
/**
 * Deserializes string array [arr] from the char buffer [ptr]. 
 * The array is limited by '\n' or by terminated zero.
 * Each string entry delimited by a whitespace ' '.
 * After deserialization ptr is moved at start of the next line.
 * @return 0 if failed.
 */
static int fillArray(char **ptr, /*OUT*/int* len, /*OUT*/pcsl_string** arr) {
    char *p0, *p1;
    pcsl_string* str;
    int n = 1;

    p1 = p0 = *ptr;
    while (*p1 != 0 && *p1 != '\n') {
        if (*p1 == ' ')
            n++;
        p1++;
    }
    *ptr = (*p1 == 0? p1: p1 + 1);

    if ((p1 - p0) > 0) {
        str = alloc_pcsl_string_list(n);
        if (str == NULL) {
            return 0;
        }
        *arr = str;
        *len = n;

        while (n--) {
            p1 = p0;
            while (*p1 != ' ' && *p1 != 0 && *p1 != '\n')
                p1++;
            if (PCSL_STRING_OK != pcsl_string_convert_from_utf8((jbyte*)p0, p1 - p0, str))
                return 0;
            p0 = p1 + 1;
            str++;
        }
    }

    return 1;
}
Beispiel #2
0
int 
midpIterateJarEntries(void *handle, filterFuncT *filter, actionFuncT *action) {

    MidpJarInfo *pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    pcsl_string entryName;
    unsigned char *nameBuf;
    int status = 1;
    pcsl_string_status res;

    entryInfo = getFirstJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo);

    while (entryInfo.status == 0) {
        
        nameBuf =  (unsigned char*) midpMalloc(entryInfo.nameLen);
        if (nameBuf == NULL) {
            status = MIDP_JAR_OUT_OF_MEM_ERROR;
            break;
        }
        
        entryInfo.status = getJarEntryName(&pJarInfo->fileObj, &entryInfo, nameBuf);
        if (entryInfo.status != 0) {
            status = MIDP_JAR_CORRUPT_ERROR;
            midpFree(nameBuf);
            break;
        }

        res = pcsl_string_convert_from_utf8((jbyte*)nameBuf, entryInfo.nameLen,
                                            &entryName);
        midpFree(nameBuf);
        if (PCSL_STRING_OK != res) {
            status = MIDP_JAR_OUT_OF_MEM_ERROR;
            break;
        }
       
        if ((*filter)(&entryName)) {
            /* name match: call action */   
            if (!(*action)(&entryName)) {
                status = 0;
                pcsl_string_free(&entryName);
                break;
            }
        }
        
        pcsl_string_free(&entryName);
        
        entryInfo = getNextJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo, 
                                        &entryInfo);
        
    }
       
    return status;
}
Beispiel #3
0
/**
 * Gets the phone number of device
 *
 * @return The phone number of device.
 * This function returns PCSL_STRING_NULL on pcsl error.
 * Note: the caller should free return value of this function 
 * after using.
 */
pcsl_string getInternalPhoneNumber(void) {
    pcsl_string retValue = PCSL_STRING_NULL;
    const char* phoneNumber = NULL;
    pcsl_string_status status = PCSL_STRING_ERR;
    load_var_char_env_prop((char**)&phoneNumber, "JSR_120_PHONE_NUMBER",
        "com.sun.midp.io.j2me.sms.PhoneNumber");
    if (phoneNumber != NULL) {
        status = pcsl_string_convert_from_utf8((const jbyte *)phoneNumber,
            strlen(phoneNumber), &retValue);
        if (status != PCSL_STRING_OK) {
            retValue = PCSL_STRING_NULL;
        }
    }
    return retValue;
}
Beispiel #4
0
/**
 * Deserializes PCSL string [str] from the char buffer [ptr].
 * The string is limited by '\n' or by terminated zero.
 * After deserialization ptr is moved at start of the next line.
 * @return 0 if failed.
 */
static int fillString(char** ptr, /*OUT*/pcsl_string* str) {
    char *p = *ptr;
    int sz;

    while (*p != 0 && *p != '\n')
        p++;
    sz = p - *ptr;
    if (sz > 0 && 
        PCSL_STRING_OK != pcsl_string_convert_from_utf8((jbyte*)*ptr, sz, str)) {
        sz = -1;
    }
    *ptr = (*p == 0? p: p + 1);

    return sz >= 0;
}
Beispiel #5
0
/* The getNextEntry function search the next file which is  specified DIR */
int pcsl_file_getnextentry(void *handle, const pcsl_string * string, 
                           pcsl_string * result)
{
    char *pszFilename; /* name of result */
    int len;
    const jbyte * pszMatch = pcsl_string_get_utf8_data(string);

    if (NULL == pszMatch) {
	return -1;
    }

    if (result == NULL) {
      pcsl_string_release_utf8_data(pszMatch, string);
      return -1;
    }

    pszFilename = rmfsFileStartWith(pszMatch);

    pcsl_string_release_utf8_data(pszMatch, string);

    if (NULL == pszFilename) {
      * result = PCSL_STRING_NULL;
      /* End of Dir without a match. */
      return -1;
    }

    len = strlen(pszFilename);

    if (pcsl_string_convert_from_utf8(pszFilename, len, result) != 
	PCSL_STRING_OK) {
      * result = PCSL_STRING_NULL;
      return -1;
    }

    return 0;
}
Beispiel #6
0
/** 
    The getNextEntry function search the next file which is specified DIR
 */
int pcsl_file_getnextentry(void *handle, const pcsl_string * string, 
                           pcsl_string * result)
{
    pcsl_string rootpath = PCSL_STRING_NULL;
    pcsl_string returnVal = PCSL_STRING_NULL;
    pcsl_string matchName = PCSL_STRING_NULL;
    jsize matchLen;
    jsize len;
    struct dirent *de;
    char* pszFilename = NULL;
    DIR *dir;
    jsize savedRootLength = 0;
    jsize savedMatchLength = 0;

    PCSLStorageDirInfo* pPCSLStorageDirInfo = (PCSLStorageDirInfo *)handle;
    if (pPCSLStorageDirInfo == NULL) {
        return -1;
    }

    savedRootLength = pPCSLStorageDirInfo->savedRootLength;
    savedMatchLength = pPCSLStorageDirInfo->savedMatchLength;

    if (pcsl_string_substring(string, savedRootLength, 
			      savedRootLength + savedMatchLength,
			      &matchName) != PCSL_STRING_OK) {
      return -1;
    }

    {
      const jbyte * pszMatch = NULL;
      
      dir = pPCSLStorageDirInfo->savedDirectory;

      if (dir == NULL) {
        return -1;
      }

      pszMatch = pcsl_string_get_utf8_data(&matchName);
      
      if (pszMatch == NULL) {
	return -1;
      }

      matchLen = strlen((char*)pszMatch);

      /* find the first match file not "." or ".." */

      for (de = readdir(dir); de != NULL; de = readdir(dir)) {

        pszFilename = de->d_name;
        if (strcmp(pszFilename, ".") == 0 ||
            strcmp(pszFilename, "..") == 0) {
            continue;
        }

        if (strncmp(pszFilename, (char*)pszMatch, matchLen) == 0) {
            break;
        }
      }

      pcsl_string_release_utf8_data(pszMatch, &matchName);

      pcsl_string_free(&matchName);

      if (NULL == de) {
        /* End of Dir without a match. */
        return -1;
      }
      len = strlen(pszFilename);

      if (len >= 0) {
	if (pcsl_string_convert_from_utf8((jbyte*)pszFilename, len, &returnVal) != PCSL_STRING_OK) {
	  return -1;
	}

	if (pcsl_string_substring(string, 0, savedRootLength, &rootpath) != PCSL_STRING_OK) {
	  pcsl_string_free(&returnVal);
	  return -1;
	}

	if (pcsl_string_cat(&rootpath, &returnVal, result) != PCSL_STRING_OK) {
	  pcsl_string_free(&returnVal);
	  pcsl_string_free(&rootpath);
	  return -1;
	}

	pcsl_string_free(&returnVal);
	pcsl_string_free(&rootpath);
      }
    }

    return 0;

}
/**
 * Convert a C string to a pcsl_string string.
 *
 * @param in C string specifying the text to be copied to the out parameter
 * @param out pcsl_string to receive a copy of the text specified by the in parameter
 *
 * @return jchar string
 */
pcsl_string_status pcsl_string_from_chars(const char* in, pcsl_string* out) {
    return pcsl_string_convert_from_utf8((jbyte*)in, strlen(in), out);
}