示例#1
0
static int diary_handle_feed_rss(request_rec *r, diary_conf *conf)
{
    HDF *hdf;
    CSPARSE *cs;
    NEOERR *cs_err;
    STRING cs_err_str;

    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "diary_handle_feed_rss()");

    hdf_init(&hdf);
    hdf_set_value(hdf, "hdf.loadpaths.1", conf->path);
    hdf_set_value(hdf, "diary.title", conf->title);
    hdf_set_value(hdf, "diary.uri", conf->uri);

    cs_err = hdf_read_file(hdf, INDEX_HDF);
    if(cs_err){
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "cannot read index.hdf.");
        hdf_destroy(&hdf);
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    //hdf_dump(hdf, NULL);

    cs_err = cs_init(&cs, hdf);
    if(cs_err){
        string_init(&cs_err_str);
        nerr_error_string(cs_err, &cs_err_str);
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "error at cs_init(): %s", cs_err_str.buf);
        cs_destroy(&cs);
        hdf_destroy(&hdf);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    cgi_register_strfuncs(cs);

    cs_err = cs_parse_string(cs, strdup(RSS_TMPL), RSS_TMPL_LEN);
    if(cs_err){
        string_init(&cs_err_str);
        nerr_error_string(cs_err, &cs_err_str);
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "error in cs_parse_string(): %s", cs_err_str.buf);
        cs_destroy(&cs);
        hdf_destroy(&hdf);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    r->content_type = "application/rss+xml";
    cs_render(cs, r, diary_cs_render_cb);

    cs_destroy(&cs);
    hdf_destroy(&hdf);
    return OK;
}
示例#2
0
文件: hdf.cpp 项目: 292388900/hhvm
void Hdf::CheckNeoError(NEOERR *err) {
  if (err != STATUS_OK) {
    NEOSTRING str;
    string_init(&str);
    nerr_error_string(err, &str);
    throw HdfException("%s", str.buf);
  }
}
示例#3
0
文件: j_neo_util.c 项目: bigclean/moc
// Throws a runtime exception back to the Java VM appropriate for the type of
// error and frees the NEOERR that is passed in.
// TODO: throw more specific exceptions for errors like NERR_IO and NERR_NOMEM
int jNeoErr(JNIEnv *env, NEOERR *err) {
  STRING str;

  string_init(&str);
  if (nerr_match(err, NERR_PARSE)) {
    nerr_error_string(err, &str);
    throwRuntimeException(env, str.buf);
  } else if (nerr_match(err, NERR_IO)) {
    nerr_error_string(err, &str);
    throwIOException(env, str.buf);
  } else if (nerr_match(err, NERR_NOMEM)) {
    nerr_error_string(err, &str);
    throwOutOfMemoryError(env, str.buf);
  } else {
    nerr_error_traceback(err, &str);
    throwRuntimeException(env, str.buf);
  }

  nerr_ignore(&err);  // free err, otherwise it would leak
  string_clear(&str);

  return 0;
}
示例#4
0
文件: j_neo_util.c 项目: bigclean/moc
JNIEXPORT jboolean JNICALL Java_org_clearsilver_HDF__1readFile(
    JNIEnv *env, jobject objClass, jint hdf_obj_ptr, jstring j_filename,
    jboolean use_cb) {
  HDF *hdf = (HDF *)hdf_obj_ptr;
  NEOERR *err;
  const char *filename;
  jboolean retval;
  FILELOAD_INFO fl_info;

  if (use_cb == JNI_TRUE) {
    jclass hdfClass;

    fl_info.env = env;
    fl_info.fl_obj = objClass;
    fl_info.hdf = hdf;

    hdfClass = (*env)->GetObjectClass(env, objClass); 
    if (hdfClass == NULL) return JNI_FALSE;

    fl_info.fl_method = (*env)->GetMethodID(env, hdfClass,
        "fileLoad", "(Ljava/lang/String;)Ljava/lang/String;");
    if (fl_info.fl_method == NULL) return JNI_FALSE;

    hdf_register_fileload(hdf, &fl_info, jni_fileload_cb);
  }

  filename = (*env)->GetStringUTFChars(env, j_filename, 0);
  err = hdf_read_file(hdf, filename);
  (*env)->ReleaseStringUTFChars(env, j_filename, filename);
  if (use_cb == JNI_TRUE) hdf_register_fileload(hdf, NULL, NULL);
  if (err != STATUS_OK) {
    // Throw an exception.  jNeoErr handles all types of errors other than
    // NOT_FOUND, since that can mean different things in different contexts.
    // In this context, it means "file not found".
    if (nerr_match(err, NERR_NOT_FOUND)) {
      STRING str;
      string_init(&str);
      nerr_error_string(err, &str);
      throwFileNotFoundException(env, str.buf);
      string_clear(&str);
    } else {
      jNeoErr(env, err);
    }
  }
  retval = (err == STATUS_OK);
  return retval;
}
示例#5
0
PyObject * p_neo_error (NEOERR *err)
{
  STRING str;

  string_init (&str);
  if (nerr_match(err, NERR_PARSE))
  {
    nerr_error_string (err, &str);
    PyErr_SetString (NeoParseError, str.buf);
  }
  else
  {
    nerr_error_traceback (err, &str);
    PyErr_SetString (NeoError, str.buf);
  }
  string_clear (&str);
  nerr_ignore(&err);
  return NULL;
}
示例#6
0
bool Tree::RenderTemplateInternal(const std::string &tmpl,
                                  bool file_or_string,
                                  std::ostream *out,
                                  std::string *error) const
{
    if (!out) {
        return false;
    }

    CSPARSE *csparse = NULL;
    HDF *hdf = NULL;
    NEOERR *err;

    do {
        err = hdf_init(&hdf);
        if (err != STATUS_OK) {
            break;
        }

        if (!SerializeToHdfInternal(hdf, true)) {
            hdf_destroy(&hdf);
            if (error) {
                *error = "SerializationError: serializing to HDF failed";
            }
            return false;
        }

        err = cs_init(&csparse, hdf);
        if (err != STATUS_OK) {
            break;
        }

        err = cgi_register_strfuncs(csparse);
        if (err != STATUS_OK) {
            break;
        }

        if (file_or_string) {
            err = cs_parse_file(csparse, tmpl.c_str());

        } else {
            char *ctmpl = strdup(tmpl.c_str());
            if (!ctmpl) {
                cs_destroy(&csparse);
                hdf_destroy(&hdf);
                if (error) {
                    *error = "MemoryError: allocating buffer for template";
                }
                break;
            }

            err = cs_parse_string(csparse, ctmpl, tmpl.length());
        }

        if (err != STATUS_OK) {
            break;
        }

        err = cs_render(csparse, out, RenderCallback);
        if (err != STATUS_OK) {
            break;
        }

    } while (false);

    cs_destroy(&csparse);
    hdf_destroy(&hdf);

    if (err != STATUS_OK && error) {
        STRING str;
        string_init(&str);
        nerr_error_string(err, &str);
        *error = str.buf;
        string_clear(&str);
        nerr_ignore(&err);
        return false;
    }

    return true;
}
示例#7
0
static int diary_handle_index(request_rec *r, diary_conf *conf)
{
    HDF *hdf;
    CSPARSE *cs;
    NEOERR *cs_err;
    STRING cs_err_str;
    calendar_info cal;
    char *theme_path;
    char *theme_file;

    theme_path = apr_pstrcat(r->pool, conf->path, "/themes/", conf->theme, NULL);
    theme_file = apr_pstrcat(r->pool, theme_path, "/index.cst", NULL);

    hdf_init(&hdf);
    hdf_set_int_value(hdf, "index", 1);
    hdf_set_value(hdf, "hdf.loadpaths.1", conf->path);
    hdf_set_value(hdf, "hdf.loadpaths.2", theme_path);
    hdf_set_value(hdf, "diary.title", conf->title);
    hdf_set_value(hdf, "diary.uri", conf->uri);
    hdf_set_value(hdf, "diary.theme", conf->theme);

    if (conf->calendar) {
        diary_set_calendar_info(&cal, r->args);
        hdf_set_int_value(hdf, "cal.year", cal.year);
        hdf_set_value(hdf, "cal.month", cal.month);
        hdf_set_value(hdf, "cal.day", cal.day);   
        hdf_set_value(hdf, "cal.today", cal.today);
        hdf_set_int_value(hdf, "cal.lastdayofmonth", cal.lastdayofmonth);
        hdf_set_int_value(hdf, "cal.dayofweek_1stdayofmonth", cal.dayofweek_1stdayofmonth);
    }

    cs_err = hdf_read_file(hdf, INDEX_HDF);
    if(cs_err){
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "cannot read index.hdf.");
        // TODO: no need to free cs_err and cs_err_str?
        hdf_destroy(&hdf);
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    //hdf_dump(hdf, NULL);

    cs_err = cs_init(&cs, hdf);
    if(cs_err){
        string_init(&cs_err_str);
        nerr_error_string(cs_err, &cs_err_str);
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "error at cs_init(): %s", cs_err_str.buf);
        // TODO: no need to free cs_err and cs_err_str?
        cs_destroy(&cs);
        hdf_destroy(&hdf);
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    cgi_register_strfuncs(cs);

    cs_err = cs_parse_file(cs, theme_file);
    if(cs_err){
        string_init(&cs_err_str);
        nerr_error_string(cs_err, &cs_err_str);
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "hoge error in cs_parse_file(): %s", cs_err_str.buf);
        // TODO: no need to free cs_err and cs_err_str?
        cs_destroy(&cs);
        hdf_destroy(&hdf);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    r->content_type = "text/html";
    cs_render(cs, r, diary_cs_render_cb);

    cs_destroy(&cs);
    hdf_destroy(&hdf);
    return OK;
}