Skip to content

Commit

Permalink
clang-format files
Browse files Browse the repository at this point in the history
  • Loading branch information
javorszky committed Oct 25, 2024
1 parent e22a773 commit 38cdc9e
Show file tree
Hide file tree
Showing 63 changed files with 4,879 additions and 5,462 deletions.
36 changes: 14 additions & 22 deletions src/java/nxt_jni.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright (C) NGINX, Inc.
*/
Expand All @@ -12,19 +11,19 @@
#include "nxt_jni.h"


static jclass nxt_java_NoSuchElementException_class;
static jclass nxt_java_IOException_class;
static jclass nxt_java_IllegalStateException_class;
static jclass nxt_java_File_class;
static jmethodID nxt_java_File_ctor;

static inline char nxt_java_lowcase(char c);
static jclass nxt_java_NoSuchElementException_class;
static jclass nxt_java_IOException_class;
static jclass nxt_java_IllegalStateException_class;
static jclass nxt_java_File_class;
static jmethodID nxt_java_File_ctor;

static inline char
nxt_java_lowcase(char c);

int
nxt_java_jni_init(JNIEnv *env)
{
jclass cls;
jclass cls;

cls = (*env)->FindClass(env, "java/util/NoSuchElementException");
if (cls == NULL) {
Expand Down Expand Up @@ -81,35 +80,31 @@ nxt_java_jni_init(JNIEnv *env)
return NXT_UNIT_OK;
}


void
nxt_java_throw_NoSuchElementException(JNIEnv *env, const char *msg)
{
(*env)->ThrowNew(env, nxt_java_NoSuchElementException_class, msg);
}


void
nxt_java_throw_IOException(JNIEnv *env, const char *msg)
{
(*env)->ThrowNew(env, nxt_java_IOException_class, msg);
}


void
nxt_java_throw_IllegalStateException(JNIEnv *env, const char *msg)
{
(*env)->ThrowNew(env, nxt_java_IllegalStateException_class, msg);
}


nxt_unit_field_t *
nxt_java_findHeader(nxt_unit_field_t *f, nxt_unit_field_t *end,
const char *name, uint8_t name_len)
const char *name, uint8_t name_len)
{
const char *field_name;
const char *field_name;

for (/* void */ ; f < end; f++) {
for (/* void */; f < end; f++) {
if (f->skip != 0 || f->name_length != name_len) {
continue;
}
Expand All @@ -124,12 +119,11 @@ nxt_java_findHeader(nxt_unit_field_t *f, nxt_unit_field_t *end,
return NULL;
}


int
nxt_java_strcaseeq(const char *str1, const char *str2, int len)
{
char c1, c2;
const char *end1;
const char *end1;

end1 = str1 + len;

Expand All @@ -145,19 +139,17 @@ nxt_java_strcaseeq(const char *str1, const char *str2, int len)
return 1;
}


static inline char
nxt_java_lowcase(char c)
{
return (c >= 'A' && c <= 'Z') ? c | 0x20 : c;
}


jstring
nxt_java_newString(JNIEnv *env, char *str, uint32_t len)
{
char tmp;
jstring res;
char tmp;
jstring res;

tmp = str[len];

Expand Down
40 changes: 22 additions & 18 deletions src/java/nxt_jni.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright (C) NGINX, Inc.
*/
Expand All @@ -11,35 +10,40 @@
#include <nxt_unit_typedefs.h>


int nxt_java_jni_init(JNIEnv *env);

void nxt_java_throw_NoSuchElementException(JNIEnv *env, const char *msg);
int
nxt_java_jni_init(JNIEnv *env);

void nxt_java_throw_IOException(JNIEnv *env, const char *msg);
void
nxt_java_throw_NoSuchElementException(JNIEnv *env, const char *msg);

void nxt_java_throw_IllegalStateException(JNIEnv *env, const char *msg);
void
nxt_java_throw_IOException(JNIEnv *env, const char *msg);

nxt_unit_field_t *nxt_java_findHeader(nxt_unit_field_t *f, nxt_unit_field_t *e,
const char *name, uint8_t name_len);
void
nxt_java_throw_IllegalStateException(JNIEnv *env, const char *msg);

int nxt_java_strcaseeq(const char *str1, const char *str2, int len);
nxt_unit_field_t *
nxt_java_findHeader(nxt_unit_field_t *f, nxt_unit_field_t *e, const char *name,
uint8_t name_len);

jstring nxt_java_newString(JNIEnv *env, char *str, uint32_t len);
int
nxt_java_strcaseeq(const char *str1, const char *str2, int len);

jstring
nxt_java_newString(JNIEnv *env, char *str, uint32_t len);

typedef struct {
uint32_t header_size;
uint32_t buf_size;
uint32_t header_size;
uint32_t buf_size;

jobject jreq;
jobject jresp;
jobject jreq;
jobject jresp;

nxt_unit_buf_t *first;
nxt_unit_buf_t *buf;
nxt_unit_buf_t *first;
nxt_unit_buf_t *buf;

} nxt_java_request_data_t;


static inline jlong
nxt_ptr2jlong(void *ptr)
{
Expand All @@ -52,4 +56,4 @@ nxt_jlong2ptr(jlong l)
return (void *) (intptr_t) l;
}

#endif /* _NXT_JAVA_JNI_H_INCLUDED_ */
#endif /* _NXT_JAVA_JNI_H_INCLUDED_ */
69 changes: 31 additions & 38 deletions src/java/nxt_jni_Context.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright (C) NGINX, Inc.
*/
Expand All @@ -13,22 +12,23 @@
#include "nxt_jni_URLClassLoader.h"


static jclass nxt_java_Context_class;
static jmethodID nxt_java_Context_start;
static jmethodID nxt_java_Context_service;
static jmethodID nxt_java_Context_stop;

static void JNICALL nxt_java_Context_log(JNIEnv *env, jclass cls,
jlong ctx_ptr, jstring msg, jint msg_len);
static void JNICALL nxt_java_Context_trace(JNIEnv *env, jclass cls,
jlong ctx_ptr, jstring msg, jint msg_len);
static jclass nxt_java_Context_class;
static jmethodID nxt_java_Context_start;
static jmethodID nxt_java_Context_service;
static jmethodID nxt_java_Context_stop;

static void JNICALL
nxt_java_Context_log(JNIEnv *env, jclass cls, jlong ctx_ptr, jstring msg,
jint msg_len);
static void JNICALL
nxt_java_Context_trace(JNIEnv *env, jclass cls, jlong ctx_ptr, jstring msg,
jint msg_len);

int
nxt_java_initContext(JNIEnv *env, jobject cl)
{
int res;
jclass cls;
int res;
jclass cls;

cls = nxt_java_loadClass(env, cl, "nginx.unit.Context");
if (cls == NULL) {
Expand All @@ -38,17 +38,18 @@ nxt_java_initContext(JNIEnv *env, jobject cl)

nxt_java_Context_class = (*env)->NewGlobalRef(env, cls);
(*env)->DeleteLocalRef(env, cls);
cls = nxt_java_Context_class;
cls = nxt_java_Context_class;

nxt_java_Context_start = (*env)->GetStaticMethodID(env, cls, "start",
"(Ljava/lang/String;[Ljava/net/URL;)Lnginx/unit/Context;");
nxt_java_Context_start = (*env)->GetStaticMethodID(
env, cls, "start",
"(Ljava/lang/String;[Ljava/net/URL;)Lnginx/unit/Context;");
if (nxt_java_Context_start == NULL) {
nxt_unit_warn(NULL, "nginx.unit.Context.start() not found");
goto failed;
}

nxt_java_Context_service = (*env)->GetMethodID(env, cls, "service",
"(Lnginx/unit/Request;Lnginx/unit/Response;)V");
nxt_java_Context_service = (*env)->GetMethodID(
env, cls, "service", "(Lnginx/unit/Request;Lnginx/unit/Response;)V");
if (nxt_java_Context_service == NULL) {
nxt_unit_warn(NULL, "nginx.unit.Context.service() not found");
goto failed;
Expand All @@ -61,18 +62,15 @@ nxt_java_initContext(JNIEnv *env, jobject cl)
}

JNINativeMethod context_methods[] = {
{ (char *) "log",
(char *) "(JLjava/lang/String;I)V",
nxt_java_Context_log },
{(char *) "log", (char *) "(JLjava/lang/String;I)V",
nxt_java_Context_log},

{ (char *) "trace",
(char *) "(JLjava/lang/String;I)V",
nxt_java_Context_trace },
{(char *) "trace", (char *) "(JLjava/lang/String;I)V",
nxt_java_Context_trace},

};

res = (*env)->RegisterNatives(env, nxt_java_Context_class,
context_methods,
res = (*env)->RegisterNatives(env, nxt_java_Context_class, context_methods,
sizeof(context_methods)
/ sizeof(context_methods[0]));

Expand All @@ -91,7 +89,6 @@ nxt_java_initContext(JNIEnv *env, jobject cl)
return NXT_UNIT_ERROR;
}


jobject
nxt_java_startContext(JNIEnv *env, const char *webapp, jobject classpaths)
{
Expand All @@ -107,29 +104,26 @@ nxt_java_startContext(JNIEnv *env, const char *webapp, jobject classpaths)
classpaths);
}


void
nxt_java_service(JNIEnv *env, jobject ctx, jobject jreq, jobject jresp)
{
(*env)->CallVoidMethod(env, ctx, nxt_java_Context_service, jreq, jresp);
}


void
nxt_java_stopContext(JNIEnv *env, jobject ctx)
{
(*env)->CallVoidMethod(env, ctx, nxt_java_Context_stop);
}


static void JNICALL
nxt_java_Context_log(JNIEnv *env, jclass cls, jlong ctx_ptr, jstring msg,
jint msg_len)
jint msg_len)
{
const char *msg_str;
nxt_unit_ctx_t *ctx;
const char *msg_str;
nxt_unit_ctx_t *ctx;

ctx = nxt_jlong2ptr(ctx_ptr);
ctx = nxt_jlong2ptr(ctx_ptr);

msg_str = (*env)->GetStringUTFChars(env, msg, NULL);
if (msg_str == NULL) {
Expand All @@ -141,16 +135,15 @@ nxt_java_Context_log(JNIEnv *env, jclass cls, jlong ctx_ptr, jstring msg,
(*env)->ReleaseStringUTFChars(env, msg, msg_str);
}


static void JNICALL
nxt_java_Context_trace(JNIEnv *env, jclass cls, jlong ctx_ptr, jstring msg,
jint msg_len)
jint msg_len)
{
#if (NXT_DEBUG)
const char *msg_str;
nxt_unit_ctx_t *ctx;
const char *msg_str;
nxt_unit_ctx_t *ctx;

ctx = nxt_jlong2ptr(ctx_ptr);
ctx = nxt_jlong2ptr(ctx_ptr);

msg_str = (*env)->GetStringUTFChars(env, msg, NULL);
if (msg_str == NULL) {
Expand Down
17 changes: 9 additions & 8 deletions src/java/nxt_jni_Context.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright (C) NGINX, Inc.
*/
Expand All @@ -10,14 +9,16 @@
#include <jni.h>


int nxt_java_initContext(JNIEnv *env, jobject cl);

jobject nxt_java_startContext(JNIEnv *env, const char *webapp,
jobject classpaths);
int
nxt_java_initContext(JNIEnv *env, jobject cl);

void nxt_java_service(JNIEnv *env, jobject ctx, jobject jreq, jobject jresp);
jobject
nxt_java_startContext(JNIEnv *env, const char *webapp, jobject classpaths);

void nxt_java_stopContext(JNIEnv *env, jobject ctx);
void
nxt_java_service(JNIEnv *env, jobject ctx, jobject jreq, jobject jresp);

#endif /* _NXT_JAVA_CONTEXT_H_INCLUDED_ */
void
nxt_java_stopContext(JNIEnv *env, jobject ctx);

#endif /* _NXT_JAVA_CONTEXT_H_INCLUDED_ */
Loading

0 comments on commit 38cdc9e

Please sign in to comment.