Exemple #1
0
/*
 * [flag, title, data]
 * flag:
 * 0   Not found.
 * 1   found
 * 2   http link
 */
jobjectArray
Java_com_hace_fastwiki_FastWiki_WikiParseUrl(JNIEnv* env, jobject thiz, jstring _url)
{
	jobjectArray args;
	jstring str;
	const char *url = my_get_string(_url);
	char flag[8], title[256], *data = NULL;
	const char *buf[3] = {flag, title, NULL};

	args = env->NewObjectArray(3, env->FindClass("java/lang/String"), 0);

	m_wiki_manage->wiki_parse_url(url, flag, title, &data);

	buf[2] = data;

	if (buf[2] == NULL)
		buf[2] = "";

	for (int i = 0; i < 3; i++) {
		str = env->NewStringUTF(buf[i]);
		env->SetObjectArrayElement(args, i, str);
	}

	return args;
}
Exemple #2
0
jstring
Java_com_hace_fastwiki_FastWiki_N(JNIEnv* env, jobject thiz, jstring flag)
{
	const char *tmp = my_get_string(flag);

	return env->NewStringUTF(local_msg(tmp));
}
Exemple #3
0
int
Java_com_hace_fastwiki_FastWiki_WikiInitLang(JNIEnv* env, jobject thiz, jstring _lang)
{
	const char *lang = my_get_string(_lang);

	return m_wiki_manage->wiki_init_one_lang(lang);
}
Exemple #4
0
void
Java_com_hace_fastwiki_FastWiki_LOG(JNIEnv* env, jobject thiz, jstring arg)
{
	const char *tmp = my_get_string(arg);

	LOG("%s", tmp);

	env->ReleaseStringUTFChars(arg, tmp);
}
Exemple #5
0
jstring
Java_com_hace_fastwiki_FastWiki_TransLate(JNIEnv* env, jobject thiz, jstring flag)
{
	char *buf;
	const char *key = my_get_string(flag);

	m_wiki_manage->wiki_translate(key, &buf);

	return env->NewStringUTF(buf);
}
Exemple #6
0
jint
Java_com_hace_fastwiki_FastWiki_IsValidDir(JNIEnv* env, jobject thiz, jstring dir)
{
	const char *tmp = my_get_string(dir);

	if (m_wiki_manage->wiki_add_dir(tmp) == -1)
		return 0;

	return 1;
}
Exemple #7
0
jobjectArray
Java_com_hace_fastwiki_FileBrowse_GetFiles(JNIEnv* env, jobject thiz, jstring path)
{
	int total = 0;
	char buf[_MAX_IMAGE_TOTAL][64], tmp[128];
	jobjectArray ret;

	const char *file = my_get_string(path);

	DIR *dirp;
	struct dirent *d;

	if ((dirp = opendir(file)) == NULL)
		dirp = opendir("/");

	sprintf(buf[total++], "1..");

	while ((d = readdir(dirp))) {
		if (d->d_name[0] == '.')
			continue;

		if (total >= _MAX_IMAGE_TOTAL - 1)
			break;

		snprintf(tmp, sizeof(tmp), "%s/%s", file, d->d_name);
		
		if (dashf(tmp) && access(tmp, R_OK) == 0) {
			if (is_image_fname(d->d_name))
				snprintf(buf[total++], sizeof(buf[0]), "0%s", d->d_name);
		} else if (dashd(tmp) && access(tmp, R_OK | X_OK) == 0) {
			snprintf(buf[total++], sizeof(buf[0]), "1%s", d->d_name);
		}
	}

	closedir(dirp);

	qsort(buf, total, 64, _cmp_file_name);

	ret = env->NewObjectArray(total, env->FindClass("java/lang/String"), 0);

	for (int i = 0; i < total; i++) {
		env->SetObjectArrayElement(ret, i, env->NewStringUTF(buf[i]));
	}

	return ret;
}
Exemple #8
0
jstring
Java_com_hace_fastwiki_FileBrowse_RealPath(JNIEnv* env, jobject thiz, jstring path)
{
	int len;
	char *p, buf[256];

	memset(buf, 0, sizeof(buf));
	strncpy(buf, my_get_string(path), sizeof(buf) - 1);

	len = strlen(buf);

	if (len > 2 && strncmp(buf + len - 3, "/..", 3) == 0) {
		buf[len - 3] = 0;
		if ((p = strrchr(buf, '/')))
			*p = 0;
	}

	if (buf[0] == 0)
		strcpy(buf, "/");

	return env->NewStringUTF(buf);
}
Exemple #9
0
jobjectArray
Java_com_hace_fastwiki_FastWiki_WikiMatch(JNIEnv* env, jobject thiz, jstring _start)
{
	int total;
	wiki_title_t *buf;
	jobjectArray args;
	jstring str;

	const char *start;
	
	start = my_get_string(_start);
	m_wiki_manage->wiki_match(start, &buf, &total);

	args = env->NewObjectArray(total, env->FindClass("java/lang/String"),0);

	for (int i = 0; i < total; i++) {
		str = env->NewStringUTF(buf[i].title);
		env->SetObjectArrayElement(args, i, str);
	}

	return args;
}
Exemple #10
0
jint
Java_com_hace_fastwiki_FastwikiSetting_SetBodyImagePath(JNIEnv* env, jobject thiz, jstring path)
{
	return m_wiki_manage->wiki_set_body_image_path(my_get_string(path));
}
Exemple #11
0
jint
Java_com_hace_fastwiki_FastwikiSetting_SetTranslateDefault(JNIEnv* env, jobject thiz, jstring lang)
{
	return m_wiki_manage->wiki_set_translate_default(my_get_string(lang));
}
Exemple #12
0
static int silc_config_main_internal(SilcConfigEntity ent)
{
  SilcConfigFile *file = ent->file;
  char **p = &file->p;

  /* loop throught statements */
  while (1) {
    char buf[BUF_SIZE];
    SilcConfigOption *thisopt;

    /* makes it pointing to the next interesting char */
    my_skip_comments(file);
    /* got eof? */
    if (**p == '\0' || **p == EOF) {
      if (file->level > 1) /* cannot get eof in a sub-level! */
	return SILC_CONFIG_EEXPECTED;
      goto finish;
    }
    /* check if we completed this (sub) section (it doesn't matter if this
     * is the main section) */
    if (**p == '}') {
      if (file->level < 2) /* can't be! must be at least one sub-block */
	return SILC_CONFIG_EUNEXPECTED;
      (*p)++;
      goto finish;
    }
    //SILC_LOG_HEXDUMP(("Preparing lookup at line=%lu", file->line), *p, 16);

    /* obtain the keyword */
    my_next_token(file, buf);
    SILC_CONFIG_DEBUG(("Looking up keyword=\"%s\" [line=%lu]",
		       buf, file->line));

    /* handle special directive */
    if (!strcasecmp(buf, "include")) {
      int ret;
      SilcConfigFile *inc_file;
      SilcConfigEntity inc_ent;

      my_trim_spaces(file); /* prepare next char */

      /* Now trying to include the specified file.  The included file will
       * be allowed to include sub-files but it will preserve the block-level
       * of the including block. Note that the included file won't be allowed
       * to raise the block level of the including block. */

      my_get_string(file, buf); /* get the filename */
      SILC_LOG_DEBUG(("Including file \"%s\"", buf));
      /* before getting on, check if this row is REALLY complete */
      if (*(*p)++ != ';')
	return SILC_CONFIG_EMISSCOLON;

      /* open the file and start the parsing */
      inc_file = silc_config_open(buf);
      if (!inc_file) /* does it point a valid filename? */
        return SILC_CONFIG_ECANTOPEN;
      inc_file->included = TRUE;

      /* create a new entity and hack it to use the same options */
      inc_ent = silc_config_init(inc_file);
      inc_ent->opts = ent->opts;
      ret = silc_config_main(inc_ent);

      /* Cleanup.
       * If the included file returned an error, the application will probably
       * want to output some kind of error message. Because of this, we can't
       * destroy THIS file object. The hack works this way: The application
       * expects to destroy the originally created object file, so we'll swap
       * the original file with the included file. */
      if (ret) {
        SilcConfigFile tmp_file;
        SILC_CONFIG_DEBUG(("SWAPPING FILE OBJECTS"));
        memcpy(&tmp_file, inc_file, sizeof(tmp_file));
        memcpy(inc_file, file, sizeof(tmp_file));
        silc_config_close(inc_file);
        memcpy(file, &tmp_file, sizeof(tmp_file));
        return ret;
      }
      /* otherwise if no errors encoured, continue normally */
      silc_config_close(inc_file);
      continue; /* this one is handled */
    }

    /* we have a registered option (it can also be a sub-block) */
    thisopt = silc_config_find_option(ent, buf);
    if (!thisopt)
      return SILC_CONFIG_EBADOPTION;

    my_trim_spaces(file); /* prepare next char */

    /* option type is a block? */
    if (thisopt->type == SILC_CONFIG_ARG_BLOCK) {
      int ret;
      SilcConfigEntity sub_ent;

      SILC_CONFIG_DEBUG(("Entering sub-block"));
      if (*(*p)++ != '{')
	return SILC_CONFIG_EOPENBRACE;
      /* build the new entity for this sub-block */
      sub_ent = silc_config_init(ent->file);
      /* use the previous specified table to describe this block's options */
      silc_config_register_table(sub_ent, thisopt->subtable, thisopt->context);
      /* run this block! */
      ret = silc_config_main(sub_ent);
      SILC_CONFIG_DEBUG(("Returned from sub-block [ret=%d]", ret));

      if (ret) /* now check the result */
	return ret;

      /* now call block clean-up callback (if any) */
      if (thisopt->cb) {
	int ret;
	SILC_CONFIG_DEBUG(("Now calling clean-up callback"));
	ret = thisopt->cb(thisopt->type, thisopt->name, file->line, NULL,
			  thisopt->context);
	if (ret) {
	  SILC_CONFIG_DEBUG(("Callback refused the value [ret=%d]", ret));
	  return ret;
	}
      }
      /* Do we want ';' to be mandatory after close brace? */
      if (*(*p)++ != ';')
	return SILC_CONFIG_EMISSCOLON;
    }
    else if (thisopt->type == SILC_CONFIG_ARG_NONE) {
      /* before getting on, check if this row is REALLY complete */
      if (*(*p)++ != ';')
	return SILC_CONFIG_EMISSCOLON;
      SILC_CONFIG_DEBUG(("Triggering callback for none"));
      if (thisopt->cb) {
	thisopt->cb(thisopt->type, thisopt->name, file->line,
		    NULL, thisopt->context);
      }
    }
    else {
      void *pt;
      int ret = 0;	/* very important in case of no cb */

      if (*(*p)++ != '=')
	return SILC_CONFIG_EEXPECTEDEQUAL;

      my_get_string(file, buf); /* get the option argument */
      SILC_CONFIG_DEBUG(("With argument=\"%s\"", buf));

      /* before getting on, check if this row is REALLY complete */
      if (*(*p)++ != ';')
	return SILC_CONFIG_EMISSCOLON;

      /* convert the option argument to the right format */
      pt = silc_config_marshall(thisopt->type, buf);
      if (!pt)
	return SILC_CONFIG_EINVALIDTEXT;
      if (thisopt->cb)
	ret = thisopt->cb(thisopt->type, thisopt->name, file->line,
			  pt, thisopt->context);

      /* since we have to free "pt" both on failure and on success, we
         assume that ret == 0 if we didn't actually call any cb. */
      silc_free(pt);
      if (ret) {
	SILC_CONFIG_DEBUG(("Callback refused the value [ret=%d]", ret));
	return ret;
      }
    }
    continue;

 finish:
    break;
  }

  return SILC_CONFIG_OK;
}