1999-09-08 04:21:03 +04:00
|
|
|
/*
|
1999-11-06 05:47:15 +03:00
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
1999-09-08 04:21:03 +04:00
|
|
|
*
|
1999-11-06 05:47:15 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
1999-09-08 04:21:03 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Sun Microsystems,
|
1999-11-06 05:47:15 +03:00
|
|
|
* Inc. Portions created by Sun are
|
|
|
|
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-09-08 04:21:03 +04:00
|
|
|
*/
|
|
|
|
|
1999-11-21 02:19:40 +03:00
|
|
|
#include <stdlib.h>
|
1999-09-08 04:21:03 +04:00
|
|
|
#include "ByteRanges.h"
|
|
|
|
|
|
|
|
jfieldID ByteRanges::offsetFID = NULL;
|
|
|
|
jfieldID ByteRanges::lengthFID = NULL;
|
|
|
|
jfieldID ByteRanges::currentFID = NULL;
|
|
|
|
|
|
|
|
nsByteRange* ByteRanges::GetByteRanges(JNIEnv *env, jobject object) {
|
|
|
|
if (!currentFID) {
|
|
|
|
Initialize(env);
|
|
|
|
if (!currentFID) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jint current = 0; //curent is the last one, sorry for this name :)
|
|
|
|
current = env->GetIntField(object,currentFID);
|
|
|
|
if (env->ExceptionOccurred()) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!current) { //empty ranges
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
jintArray joffset = NULL;
|
|
|
|
joffset = (jintArray)env->GetObjectField(object,offsetFID);
|
|
|
|
if (!joffset) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
jintArray jlength = NULL;
|
|
|
|
jlength = (jintArray)env->GetObjectField(object,lengthFID);
|
|
|
|
if (!jlength) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
jint *offset = NULL;
|
|
|
|
jint *length = NULL;
|
|
|
|
offset = env->GetIntArrayElements(joffset,NULL);
|
|
|
|
if(!offset) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
length = env->GetIntArrayElements(joffset,NULL);
|
|
|
|
if(!length) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
nsByteRange *res = (nsByteRange*)malloc(sizeof(nsByteRange)*current);
|
|
|
|
if(!res) {
|
|
|
|
env->ReleaseIntArrayElements(joffset,offset,0);
|
|
|
|
env->ReleaseIntArrayElements(jlength,length,0);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-03-21 04:10:35 +03:00
|
|
|
int i;
|
|
|
|
for (i = 0;i<current;i++) {
|
1999-09-08 04:21:03 +04:00
|
|
|
res[i].offset = offset[i];
|
|
|
|
res[i].length = length[i];
|
|
|
|
res[i].next = &res[i+1];
|
|
|
|
}
|
|
|
|
res[i].next = NULL;
|
|
|
|
env->ReleaseIntArrayElements(joffset,offset,0);
|
|
|
|
env->ReleaseIntArrayElements(jlength,length,0);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ByteRanges::FreeByteRanges(nsByteRange * ranges) {
|
|
|
|
free(ranges);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ByteRanges::Initialize(JNIEnv *env) {
|
2000-01-18 10:28:22 +03:00
|
|
|
jclass clazz = env->FindClass("org/mozilla/pluglet/mozilla/ByteRanges");
|
1999-09-08 04:21:03 +04:00
|
|
|
if(!clazz) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
offsetFID = env->GetFieldID(clazz,"offset","[I");
|
|
|
|
if(!offsetFID) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lengthFID = env->GetFieldID(clazz,"length","[I");
|
|
|
|
if(!lengthFID) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentFID = env->GetFieldID(clazz,"current","I");
|
|
|
|
if(!currentFID) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|