Esempio n. 1
0
static int Paug_init(lua_State *L)
{
    augeas **a;
    struct aug_flagmap *f;
    const char *root = NULL, *loadpath = NULL;
    int flags = 0;

    if (lua_istable(L, 1)) {
        root = get_opt_string_field(L, 1, "root", NULL);
        loadpath = get_opt_string_field(L, 1, "loadpath", NULL);
        for (f = Taug_flagmap; f->name != NULL; f++)
            if (get_boolean_field(L, 1, f->name))
                flags |= f->value;
    } else {
        root = luaL_optstring(L, 1, NULL);
        loadpath = luaL_optstring(L, 2, NULL);
        flags = luaL_optinteger(L, 3, AUG_NONE);
    }

    a = (augeas **) lua_newuserdata(L, sizeof(augeas *));
    luaL_getmetatable(L, PAUG_META);
    lua_setmetatable(L, -2);

    *a = aug_init(root, loadpath, flags);
    if (*a == NULL)
        luaL_error(L, "aug_init failed");
    return 1;
}
Esempio n. 2
0
static int get_dbopts(lua_State *L, int i, struct apk_db_options *o)
{
	struct flagmap *f;
	o->root = (char *)get_opt_string_field(L, i, "root", NULL);
	o->repositories_file = (char *)get_opt_string_field(L, i, "repositories_file", NULL);
	o->keys_dir = (char *)get_opt_string_field(L, i, "keys_dir", NULL);
	o->lock_wait = get_opt_int_field(L, i, "lock_wait", 0);
	for (f = opendb_flagmap; f->name != NULL; f++)
		if (get_boolean_field(L, i, f->name))
			o->open_flags |= f->flag;
	return 0;
}
Esempio n. 3
0
JNIEXPORT jstring JNICALL SUBMIT_MESSAGE (JNIEnv *env, jobject obj) {

    const char FUNCNAME[] = "submitMessage";
    MsgObject       the_msg;
    char            *tmpstr;
    char            *msg_id;
    int             check_flag;
    int             actionCode;
    int             retry_count;
    char            *user_id;
    char            *subject;
    char            *valid_time;
    long            valid_time_long;
    char            *timeout_time;
    long            timeout_time_long;
    int             priority;
    int             type;
    char            *product;
    char            *body_file;
    char            *bodybuf	= NULL;
    size_t          bodybufsiz;
    jclass          msg_class;
    jstring         jmsg_id;
    char            buf[200];

    /* Start code ----------------------------------------------------------------------------------- */
    dwbNETsetEnv(0, (char **) NULL);

    msg_class = (*env)->GetObjectClass(env, obj);
    sprintf(buf, "%s/MhsSubmitException", PACKAGE_CLASS);
    if ((newExcCls = (*env)->FindClass(env, buf)) == NULL) {
	sprintf(statbuf, "Could not find Exception Class \"%s/MhsSubmitException\"\n", PACKAGE_CLASS);
        printf(statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    /* Note: To get the various signatures, use this command: javap -s -p com.raytheon.messaging.mhs.MhsMessage */

    /* Get the showTrace flag ----------------------------------------------------------------------- */
    if (!get_boolean_field(env, obj, msg_class, "showTrace", &show_trace)) {
        strcpy(statbuf, "Could not get boolean field \"showTrace\"");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    /* Get the message type ------------------------------------------------------------------------- */
    if (!get_message_type(env, obj, msg_class, &type)) {
        strcpy(statbuf, "Could not get message type field");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    /* Create the message object -------------------------------------------------------------------- */
    if (!(the_msg = coDDM_createMsg(type))) {
        sprintf (statbuf, "Failed createMsg type=%d\n", type);
        throw_submit_exception(env, FAIL_CREATE, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    /* Get the productID ---------------------------------------------------------------------------- */
    if (!get_string_field(env, obj, msg_class, "productId", &product)) {
        strcpy(statbuf, "Could not get product ID");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (strlen(product) > 0) {
        if (show_trace) printf ("Product ID: %s\n", product);
        if (coDDM_setProdID(the_msg, product) < 0) {
            sprintf (statbuf, "Failed setProdID '%s'\n", product);
            free(product);
            throw_submit_exception(env, FAIL_PRODID, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
    }
    free(product);

    /* Get the verifyAddressees flag ---------------------------------------------------------------- */
    if (!get_boolean_field(env, obj, msg_class, "verifyAddressees", &check_flag)) {
        strcpy(statbuf, "Could not get verifyAddressees field");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }
    if (show_trace) printf ("Verify addressees flag: %d\n", check_flag);

    /* Get the Addressees --------------------------------------------------------------------------- */
    if (!set_msg_addressees(the_msg, env, obj, msg_class)) {
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (show_trace) {
        AddrObject  addr;
        for (addr = addrListGetFirstItem(the_msg->addr_list); addr; addr = addrListGetNextItem(the_msg->addr_list)) {
            printf ("Addressee from msg object: %s %s\n", addr->addressee_name, addr->ack_required ? "(A)" : "");
        }
    }

    /* If check flag is set, don't send the message -- only verify the addressees ------------------- */
    if (check_flag) {
        int     bufsiz = 0;
        char    *addrbuf;
        char    *p_addrlist_out;

        for (tmpstr = coDDM_getFirstAddrName(the_msg); tmpstr; tmpstr = coDDM_getNextAddrName(the_msg)) {
            bufsiz += strlen(tmpstr)+1;
        }

        if (!(addrbuf = malloc(bufsiz+1))) {
            sprintf (statbuf, "Could not allocate %d bytes in %s\n", bufsiz+1, FUNCNAME);
            coDDM_destroyMsg(&the_msg);
            throw_submit_exception(env, FAIL_JNI, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }

        addrbuf[0] = '\0';
        for (tmpstr = coDDM_getFirstAddrName(the_msg); tmpstr; tmpstr = coDDM_getNextAddrName(the_msg)) {
            if (strlen(addrbuf)) {
                strcat (addrbuf, ",");
            }
            strcat(addrbuf, tmpstr);
        }

        if (show_trace) printf ("check string: %s\n", addrbuf);
        p_addrlist_out = NULL;
        if (mqc_check_addr(the_msg->prodid, addrbuf, &p_addrlist_out) < 0) {
            sprintf (statbuf, "Failed check addr list '%s'\n", addrbuf);
            free (addrbuf);
            coDDM_destroyMsg(&the_msg);
            throw_submit_exception(env, FAIL_ADDR, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }

        if (p_addrlist_out) {
            printf("Addr list: %s\n", p_addrlist_out);
        } else {
            printf("\n");
        }
        free (addrbuf);
        coDDM_destroyMsg(&the_msg);
        return((*env)->NewStringUTF(env, strlen(p_addrlist_out) ? p_addrlist_out : "\n"));
    }

    /* Get the message action code ------------------------------------------------------------------ */
    if (!get_int_field(env, obj, msg_class, "actionCode", &actionCode)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get actionCode");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (show_trace) printf ("Action Code: %d\n", actionCode);

    if (coDDM_setMsgCode(the_msg, actionCode) < 0) {
        sprintf (statbuf, "Failed setMsgCode '%d'\n", actionCode);
        coDDM_destroyMsg(&the_msg);
        throw_submit_exception(env, FAIL_CODE, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    /* Get the subject string ----------------------------------------------------------------------- */
    if (!get_string_field(env, obj, msg_class, "subject", &subject)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get subject");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (strlen(subject) > 0) {
        if (show_trace) printf ("Message subject: %s\n", subject);
        if (coDDM_setSubject(the_msg, subject) < 0) {
            sprintf (statbuf, "Failed setSubject '%s'\n", subject);
            coDDM_destroyMsg(&the_msg);
            free(subject);
            throw_submit_exception(env, FAIL_SUBJECT, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
    }
    free(subject);

    /* Get the message priority code ---------------------------------------------------------------- */
    if (!get_priority(env, obj, msg_class, &priority)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get priority");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (show_trace) printf ("Priority: %d\n", priority);

    if (coDDM_setPriority(the_msg, priority) < 0) {
        sprintf (statbuf, "Failed setPriority '%d'\n", priority);
        coDDM_destroyMsg(&the_msg);
        throw_submit_exception(env, FAIL_PRIORITY, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    /* Get the body file name ----------------------------------------------------------------------- */
    if (!get_string_field(env, obj, msg_class, "bodyFile", &body_file)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get bodyFile");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (strlen(body_file) > 0) {
        if (show_trace) printf ("Message body file name: %s\n", body_file);
        if (buffer_file((char *) body_file, &bodybuf, &bodybufsiz) < 0) {
            free(bodybuf);
            free(body_file);
            coDDM_destroyMsg(&the_msg);
            throw_submit_exception(env, FAIL_BODY, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
        if (show_trace) printf ("Message body: %s", bodybuf);

        if (coDDM_setMsgBody(the_msg, bodybuf, bodybufsiz) < 0) {
            sprintf (statbuf, "Failed setMsgBody '%s'\n", body_file);
            free(bodybuf);
            free(body_file);
            coDDM_destroyMsg(&the_msg);
            throw_submit_exception(env, FAIL_BODY, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
        free(bodybuf);
    }

    free(body_file);

    /* Set the Enclosure list ----------------------------------------------------------------------- */
    if (!set_enclosures(the_msg, env, obj, msg_class)) {
        coDDM_destroyMsg(&the_msg);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (show_trace) {
        Enclosure   encl;
        for (encl = encListGetFirstItem(the_msg->enc_list); encl; encl = encListGetNextItem(the_msg->enc_list)) {
            printf ("Enclosure file from msg object: %s\n", encl->filename);
        }
    }

    /* Get the valid time string -------------------------------------------------------------------- */
    if (!get_string_field(env, obj, msg_class, "validTimeString", &valid_time)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get validTimeString");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (strlen(valid_time) > 0) {
        if (show_trace) printf ("Valid Time String: %s\n", valid_time);
        valid_time_long = hhmmToUtime((char *) valid_time);
        if (coDDM_setValidTime(the_msg, valid_time_long) < 0) {
            sprintf (statbuf, "Failed setValidTime: %s", ctime((const time_t *)&valid_time_long));
            coDDM_destroyMsg(&the_msg);
            free(valid_time);
            throw_submit_exception(env, FAIL_VALID_TIME, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
    }

    free(valid_time);

    /* Get the timeout time string ------------------------------------------------------------------ */
    if (!get_string_field(env, obj, msg_class, "timeoutTimeString", &timeout_time)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get timeoutTimeString");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (strlen(timeout_time) > 0) {
        if (show_trace) printf ("Time Out String: %s\n", timeout_time);
        timeout_time_long = hhmmToUtime((char *) timeout_time);
        if (coDDM_setTimeoutTime(the_msg, timeout_time_long) < 0) {
            sprintf (statbuf, "Failed setTimeoutTime: %s", ctime((const time_t *)&timeout_time_long));
            coDDM_destroyMsg(&the_msg);
            free(timeout_time);
            throw_submit_exception(env, FAIL_TIMEOUT_TIME, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
    }

    free(timeout_time);

    /* Get the retry count -------------------------------------------------------------------------- */
    if (!get_int_field(env, obj, msg_class, "retryCount", &retry_count)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get retryCount");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (retry_count > 0) {
        if (show_trace) printf ("Retry count = %d\n", retry_count);
        if (coDDM_setRetryCount(the_msg, retry_count) < 0) {
            sprintf (statbuf, "Failed setRetryCount '%d'\n", retry_count);
            coDDM_destroyMsg(&the_msg);
            throw_submit_exception(env, FAIL_RETRY_COUNT, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
    }

    /* Get user ID string --------------------------------------------------------------------------- */
    if (!get_string_field(env, obj, msg_class, "userId", &user_id)) {
        coDDM_destroyMsg(&the_msg);
        strcpy(statbuf, "Could not get userId");
        throw_submit_exception(env, FAIL_JNI, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if (strlen(user_id) > 0) {
        if (show_trace) printf ("User ID: %s\n", user_id);
        if (coDDM_setUserID(the_msg, (char *) user_id) < 0) {
            sprintf (statbuf, "Failed setUserID '%s'\n", user_id);
            coDDM_destroyMsg(&the_msg);
            free(user_id);
            throw_submit_exception(env, FAIL_USER_ID, statbuf);
            return((*env)->NewStringUTF(env, statbuf));
        }
    }

    free(user_id);

    /* Submit the message  -------------------------------------------------------------------------- */
    if (coDDM_submitMsg(the_msg) < 0) {
        sprintf (statbuf, "Failed submitMsg\n");
        coDDM_destroyMsg(&the_msg);
        throw_submit_exception(env, FAIL_SUBMIT, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }

    if ((msg_id = coDDM_getMsgID(the_msg))) {
        if (show_trace) printf ("Message successfully submitted.  Message ID: %s\n", msg_id);
        jmsg_id = (*env)->NewStringUTF(env, msg_id);
        coDDM_destroyMsg(&the_msg);
        return(jmsg_id);
    } else {
        sprintf (statbuf, "Failed getMsgID\n");
        coDDM_destroyMsg(&the_msg);
        throw_submit_exception(env, FAIL_MSGID, statbuf);
        return((*env)->NewStringUTF(env, statbuf));
    }
}