mmsclient.c revision cee0fb94c0d4227de0a00efc162fb2739844b641
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China/*
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * CDDL HEADER START
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China *
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * The contents of this file are subject to the terms of the
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * Common Development and Distribution License (the "License").
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * You may not use this file except in compliance with the License.
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China *
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * or http://www.opensolaris.org/os/licensing.
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * See the License for the specific language governing permissions
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * and limitations under the License.
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China *
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * When distributing Covered Code, include this CDDL HEADER in each
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * If applicable, add the following below this CDDL HEADER, with the
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * fields enclosed by brackets "[]" replaced with your own identifying
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * information: Portions Copyright [yyyy] [name of copyright owner]
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China *
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * CDDL HEADER END
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China *
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China * Use is subject to license terms.
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China#include <stdio.h>
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China#include <signal.h>
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China#include <pthread.h>
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China#include <mms.h>
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China#include <mms_cores.h>
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China#include <ctype.h>
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China#define BUFSZ 1024
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinatypedef struct cli_data cli_data_t;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastruct cli_data {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *host;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *port;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *client;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *instance;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *password;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *tag;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *mm_pass;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *net_file;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_network_cfg_t net;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int exiting;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_list_t async_list;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int async_waiting;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China pthread_mutex_t cli_async_lock;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *tag_to_sync;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int wait_for_sync;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int sync_has_namevalue;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China void *ssl_data;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int waiting_to_exit;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China pthread_cond_t async_cv;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China pthread_mutex_t async_mutex;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China};
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinatypedef struct cli_cmd cli_cmd_t;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastruct cli_cmd {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_list_node_t cli_cmd_next;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int cmd_is_sync;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *cmd_text;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *cmd_task;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China void *cmd_rsp;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *cmd_root;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int cmd_namevalue;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *cmd_tag;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China};
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinacli_data_t data;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinavoid *sp;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinapthread_attr_t event_attr;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinapthread_attr_t cmd_attr;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinaextern
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinaint mms_ainit(void **, int *, mms_callbk_t *, mms_rsp_callbk_t *);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinacli_cmd_t *
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinacli_alloc_cmd() {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_cmd_t *cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cmd = (cli_cmd_t *)calloc(1, sizeof (cli_cmd_t));
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (cmd == NULL) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("could not allocate mem for new command");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China exit(1);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cmd->cmd_text = NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cmd->cmd_task = NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cmd->cmd_rsp = NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cmd->cmd_namevalue = 0;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China return (cmd);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinavoid
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinacli_destroy_cmd(cli_cmd_t *cmd) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (cmd->cmd_text != NULL) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China free(cmd->cmd_text);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (cmd->cmd_task != NULL) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China free(cmd->cmd_task);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (cmd->cmd_rsp != NULL) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_free_rsp(cmd->cmd_rsp);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (cmd->cmd_tag != NULL) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China free(cmd->cmd_tag);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (cmd->cmd_root != NULL) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_pn_destroy(cmd->cmd_root);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China free(cmd);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinavoid
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China/* LINTED: void arg is required */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinamms_catch_reader(void *ev)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer printf("mms_catch_reader: Reader shutting down\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinavoid
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinamms_client_errlog(char *prefix, char *msg)
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China{
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("mms_client_errlog: prefix - %s\nmsg - %s\n", prefix, msg);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China/*ARGSUSED*/
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastatic void
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinaclient_handle_event(void *param, void *ev)
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China{
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_rsp_ele_t *lev = (mms_rsp_ele_t *)ev;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (lev->mms_rsp_str != NULL) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Event received:\n %s\n",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China lev->mms_rsp_str);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China fflush(stdout);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastatic
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinavoid
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinaattrlist(mms_par_node_t *attrlist, int namevalue)
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China{
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *arg;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *work;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" attrlist\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China work = NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China for (arg = mms_pn_lookup_arg(attrlist, NULL, NULL, &work);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg != NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg = mms_pn_lookup_arg(attrlist, NULL, NULL, &work)) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (arg->pn_type & MMS_PN_STRING) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (namevalue) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* print 2 */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" %s",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg->pn_string);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg = mms_pn_lookup_arg(attrlist,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China NULL, NULL, &work);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" %s\n",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg->pn_string);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China } else {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* print 1 */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" %s\n",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg->pn_string);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastatic
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinavoid
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinatext_clause(mms_par_node_t *text, int namevalue)
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China{
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *arg;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *work;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" text\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China work = NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China for (arg = mms_pn_lookup_arg(text, NULL, NULL, &work);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg != NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg = mms_pn_lookup_arg(text, NULL, NULL, &work)) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if ((arg->pn_type & MMS_PN_CLAUSE) &&
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China (strcmp(arg->pn_string, "attrlist") == 0)) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China attrlist(arg, namevalue);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (arg->pn_type & MMS_PN_STRING) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (namevalue) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* print 2 */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" %s",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg->pn_string);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg = mms_pn_lookup_arg(text,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China NULL, NULL, &work);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" %s\n",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg->pn_string);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China } else {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* print 1 */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf(" %s\n",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China arg->pn_string);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastatic void
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinacli_print_async_rsp(mms_rsp_ele_t *lrsp) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* lrsp->mms_rsp_cmd is */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* the parse tree of the response */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *work;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *text;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_cmd_t *cur_cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_cmd_t *next;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int namevalue = 0;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cmd = lrsp->mms_rsp_cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("success, %s\n",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China lrsp->mms_rsp_tid);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China for (cur_cmd = mms_list_head(&data.async_list);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cur_cmd != NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cur_cmd = next) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China next = mms_list_next(&data.async_list, cur_cmd);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* Test task and remove if the same */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (strcmp(cur_cmd->cmd_task,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China lrsp->mms_rsp_tid) == 0) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China namevalue = cur_cmd->cmd_namevalue;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China work = NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* For each text clause print the results */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China for (text = mms_pn_lookup(cmd,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China "text", MMS_PN_CLAUSE, &work);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China text != NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China text = mms_pn_lookup(cmd,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China "text", MMS_PN_CLAUSE, &work)) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China text_clause(text, namevalue);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China fflush(stdout);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastatic void
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinacli_print_sync_rsp(mms_rsp_ele_t *lrsp) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* lrsp->mms_rsp_cmd is */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* the parse tree of the response */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *work;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *text;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_par_node_t *cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cmd = lrsp->mms_rsp_cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("success, %s\n",
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China lrsp->mms_rsp_tid);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China work = NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China /* For each text clause print the results */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China for (text = mms_pn_lookup(cmd,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China "text", MMS_PN_CLAUSE, &work);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China text != NULL;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China text = mms_pn_lookup(cmd,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China "text", MMS_PN_CLAUSE, &work)) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China text_clause(text, data.sync_has_namevalue);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China data.sync_has_namevalue = 0;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China fflush(stdout);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinastatic void
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinamms_client_handle_rsp(void *rsp)
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China{
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int class;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int code;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *msg;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_rsp_ele_t *lrsp = (mms_rsp_ele_t *)rsp;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China switch (mms_rsp_type(rsp)) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China case MMS_API_RSP_UNACC:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Command was not accepted\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Response - %s\n", lrsp->mms_rsp_str);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China case MMS_API_RSP_FINAL:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Command was successful\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_print_sync_rsp(lrsp);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China case MMS_API_RSP_FINAL_ERR:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Command received an error response\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Response - %s\n", lrsp->mms_rsp_str);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (mms_handle_err_rsp(rsp, &class, &code,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China &msg) != MMS_API_OK) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Error response handler failed\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Error class %d, %s\n", class,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_sym_code_to_str(class));
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Error code %d, %s\n", code,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_sym_code_to_str(code));
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (msg != NULL)
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Error message:\n%s\n", msg);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China else
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("No message clause in error rsp\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China case MMS_API_RSP_FINAL_CANC:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Command received a cancelled response\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Response - %s\n", lrsp->mms_rsp_str);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China default:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Unknow response type\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Response - %s\n", lrsp->mms_rsp_str);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China }
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China}
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinavoid
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China/* LINTED: param required */
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing Chinamms_client_handle_async_rsp(void *param, void *rsp)
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China{
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int class;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int code;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China char *msg;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China mms_rsp_ele_t *lrsp = (mms_rsp_ele_t *)rsp;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_cmd_t *cur_cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_cmd_t *next;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_cmd_t *remove_cmd;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China int found_other = 0;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China pthread_mutex_lock(&data.
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_async_lock);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China switch (mms_rsp_type(rsp)) {
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China case MMS_API_RSP_UNACC:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Command was not accepted\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Response - %s\n", lrsp->mms_rsp_str);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China case MMS_API_RSP_FINAL:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("\n\nCommand was successful\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China cli_print_async_rsp(lrsp);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("\n\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China break;
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China case MMS_API_RSP_FINAL_ERR:
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Command received an error response\n");
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China printf("Response - %s\n", lrsp->mms_rsp_str);
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China if (mms_handle_err_rsp(rsp, &class, &code,
04b6cca3fef9f6205a9aa479c48d196116193dd9lucy wang - Sun Microsystems - Beijing China &msg) != MMS_API_OK) {
printf("Error response handler failed\n");
break;
}
printf("Error class %d, %s\n", class,
mms_sym_code_to_str(class));
printf("Error code %d, %s\n", code,
mms_sym_code_to_str(code));
if (msg != NULL)
printf("Error message:\n%s\n", msg);
else
printf("No message clause in error rsp\n");
break;
case MMS_API_RSP_FINAL_CANC:
printf("Command received a cancelled response\n");
printf("Response - %s\n", lrsp->mms_rsp_str);
break;
default:
printf("Unknow response type\n");
printf("Response - %s\n", lrsp->mms_rsp_str);
break;
}
for (cur_cmd = mms_list_head(&data.async_list);
cur_cmd != NULL;
cur_cmd = next) {
next = mms_list_next(&data.async_list, cur_cmd);
/* Test task and remove if the same */
if (strcmp(cur_cmd->cmd_task,
lrsp->mms_rsp_tid) == 0) {
mms_list_remove(&data.async_list,
cur_cmd);
remove_cmd = cur_cmd;
} else {
/* there is at least one other */
/* async command waiting */
found_other = 1;
}
}
/* There are no async commands left */
if (!found_other) {
pthread_mutex_lock(&data.async_mutex);
data.async_waiting = 0;
if (data.waiting_to_exit) {
pthread_cond_signal(&data.async_cv);
}
pthread_mutex_unlock(&data.async_mutex);
}
/* If we are waiting for a sync point check if this is the response */
/* we are waiting for */
if (data.wait_for_sync == 1 && data.tag_to_sync != NULL) {
if (strstr(data.tag_to_sync, lrsp->mms_rsp_tid) != NULL) {
/* Got the response we are waiting for */
free(data.tag_to_sync);
data.tag_to_sync = NULL;
data.wait_for_sync = 0;
}
}
mms_free_rsp(rsp);
remove_cmd->cmd_rsp = NULL;
cli_destroy_cmd(remove_cmd);
pthread_mutex_unlock(&data.
cli_async_lock);
}
int
cli_need_arsp(char *buf) {
cli_cmd_t *cur_cmd;
cli_cmd_t *next;
pthread_mutex_lock(&data.
cli_async_lock);
for (cur_cmd = mms_list_head(&data.async_list);
cur_cmd != NULL;
cur_cmd = next) {
next = mms_list_next(&data.async_list, cur_cmd);
if (strstr(buf, cur_cmd->cmd_task) != NULL) {
pthread_mutex_unlock(&data.
cli_async_lock);
return (1);
}
}
pthread_mutex_unlock(&data.
cli_async_lock);
return (0);
}
static void
mms_client_signal_handler(int signo)
{
if (signo == SIGPIPE)
data.exiting = 1;
}
static void
mms_client_signal(int sig, void (*handler) ())
{
struct sigaction act, oact;
memset(&act, 0, sizeof (act));
act.sa_sigaction = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sig != SIGALRM) {
act.sa_flags |= SA_RESTART;
}
if (sigaction(sig, &act, &oact) < 0) {
(void) printf("Can't set signal handler for "
"signal %d: %s", sig, strerror(errno));
exit(1);
}
}
static void
mms_client_init()
{
int rc;
int vers;
mms_callbk_t err_callbk;
mms_rsp_callbk_t ev_callbk;
mms_err_t mms_err;
char mms_ebuf[MMS_EBUF_LEN];
sigset_t new_mask;
sigset_t old_mask;
sigemptyset(&new_mask);
sigaddset(&new_mask, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
mms_client_signal(SIGPIPE, mms_client_signal_handler);
err_callbk.mms_func = &mms_catch_reader;
err_callbk.mms_param = NULL;
ev_callbk.mms_func = &client_handle_event;
ev_callbk.mms_param = NULL;
if ((rc = mms_ainit(&sp, &vers, &err_callbk,
&ev_callbk)) != MMS_API_OK) {
printf("Error in mms_ainit(), %d, %s\n", rc,
mms_sym_code_to_str(rc));
exit(1);
}
if (vers != MMS_API_VERSION) {
printf("Mismatch of versions between client %d and API %d\n",
MMS_API_VERSION, vers);
exit(1);
}
printf("Connect to MM:\n");
printf(" Host: %s\n", data.host);
printf(" Port: %s\n", data.port);
printf(" Client: %s\n", data.client);
printf(" Instance: %s\n", data.instance);
printf(" Password:\n");
printf(" Tag: %s\n", data.tag);
#ifdef MMS_OPENSSL
if (mms_ssl_client(&data.net, &data.ssl_data, &mms_err)) {
mms_get_error_string(&mms_err, mms_ebuf, MMS_EBUF_LEN);
fprintf(stderr, "ssl init - %s\n", mms_ebuf);
fprintf(stderr, "Couldn't init ssl\n");
exit(1);
}
#endif /* MMS_OPENSSL */
if ((rc = mms_hello(sp, data.host, data.port,
data.client, data.instance, data.tag,
data.password, data.mm_pass, data.ssl_data)) != MMS_API_OK) {
printf("Error in mms_hello(), %d, %s\n", rc,
mms_sym_code_to_str(rc));
exit(1);
}
if ((rc = pthread_attr_init(&cmd_attr)) != 0) {
printf("Error in attr_init, errno - %s\n", strerror(errno));
exit(1);
}
if ((rc = pthread_attr_setdetachstate(&cmd_attr,
PTHREAD_CREATE_DETACHED)) != 0) {
printf("Error in attr setdetachstate, errno - %s\n",
strerror(errno));
pthread_attr_destroy(&cmd_attr);
exit(1);
}
if ((rc = pthread_attr_init(&event_attr)) != 0) {
printf("Error in attr_init, errno - %s\n", strerror(errno));
exit(1);
}
if ((rc = pthread_attr_setdetachstate(&event_attr,
PTHREAD_CREATE_DETACHED)) != 0) {
printf("Error in attr setdetachstate, errno - %s\n",
strerror(errno));
pthread_attr_destroy(&event_attr);
exit(1);
}
printf("Client API initialized\n");
}
void
set_default_connect_info() {
if (data.net_file != NULL) {
/* Net file was passed */
if (data.net.cli_host)
data.host =
mms_strapp(data.host,
data.net.cli_host);
if (data.net.cli_port)
data.port =
mms_strapp(data.port,
data.net.cli_port);
if (data.net.cli_name)
data.client =
mms_strapp(data.client,
data.net.cli_name);
if (data.net.cli_inst)
data.instance =
mms_strapp(data.instance,
data.net.cli_inst);
if (data.net.cli_pass)
data.password =
mms_strapp(data.password,
data.net.cli_pass);
if (data.net.mm_pass)
data.mm_pass =
mms_strapp(data.mm_pass,
data.net.mm_pass);
}
if (data.host == NULL) {
data.host = mms_strapp(data.host, "localhost");
}
if (data.port == NULL) {
data.port = mms_strapp(data.port, "7151");
}
if (data.client == NULL) {
data.client = mms_strapp(data.client, "MMS");
}
if (data.instance == NULL) {
data.instance = mms_strapp(data.instance, "admin");
}
if (data.tag == NULL) {
data.tag = mms_strapp(data.tag, "mms_client-pid=%d",
getpid());
}
}
void
usage(void)
{
fprintf(stderr, "Usage: mms_client\n");
fprintf(stderr, "-h Help\n");
fprintf(stderr, "-f File name\n");
fprintf(stderr, "-A Application name\n");
fprintf(stderr, "-i Instance name\n");
fprintf(stderr, "-s System name (MM_Host_Name)\n");
fprintf(stderr, "-P Password File\n");
fprintf(stderr, "-p Port\n");
fprintf(stderr, "-t Tag\n");
fprintf(stderr, "-n Network config file\n");
exit(2);
}
int
cli_parse_cmd(cli_cmd_t *cmd) {
int rc;
mms_list_t err_list;
mms_par_err_t *err = NULL;
rc = mms_mmp_parse(&cmd->cmd_root, &err_list, cmd->cmd_text);
mms_list_foreach(&err_list, err) {
printf("error parse, "
"line %d, col %d, near token \"%s\", err code %d, %s\n",
err->pe_line,
err->pe_col,
err->pe_token,
err->pe_code,
err->pe_msg);
}
mms_pe_destroy(&err_list);
if (rc) {
return (1);
}
return (0);
}
int
use_namevalue(cli_cmd_t *command) {
mms_par_node_t *cmd;
mms_par_node_t *reportmode;
cmd = command->cmd_root;
if ((reportmode = mms_pn_lookup(cmd, "reportmode",
MMS_PN_CLAUSE, 0)) != NULL) {
if (mms_pn_lookup(reportmode, "namevalue",
NULL, 0) != NULL) {
if (command->cmd_is_sync == 1) {
data.sync_has_namevalue = 1;
}
return (1);
}
}
if (command->cmd_is_sync == 1) {
data.sync_has_namevalue = 0;
}
return (0);
}
char *
cli_return_task(cli_cmd_t *cmd) {
mms_par_node_t *task_clause = NULL;
mms_par_node_t *work = NULL;
mms_par_node_t *task_str = NULL;
if (cmd->cmd_root == NULL) {
printf("cli_return_task: cmd->cmd_root is NULL\n");
exit(1);
}
task_clause = mms_pn_lookup(cmd->cmd_root, "task", MMS_PN_CLAUSE,
&work);
if (task_clause == NULL) {
return (NULL);
}
task_str = mms_pn_lookup(task_clause, NULL, MMS_PN_STRING, &work);
if (task_str == NULL) {
return (NULL);
}
if (cmd->cmd_task == NULL) {
cmd->cmd_task = mms_strapp(cmd->cmd_task,
task_str->pn_string);
}
/* Also set namevalue for printing later */
cmd->cmd_namevalue = use_namevalue(cmd);
return (task_str->pn_string);
}
void
cli_send_sync(cli_cmd_t *cmd) {
if (cli_return_task(cmd) == NULL) {
printf("not task found in:\n%s\n",
cmd->cmd_text);
exit(1);
}
printf("-----------------------\n");
printf("* Send Sync:\n");
printf("%s\n", cmd->cmd_text);
printf("-----------------------\n");
if (mms_send_cmd(sp, cmd->cmd_text,
&cmd->cmd_rsp) != MMS_API_OK) {
printf("error show command failed\n");
exit(1);
}
printf("* Sync Sent\n");
fflush(stdout);
mms_client_handle_rsp(cmd->cmd_rsp);
mms_free_rsp(cmd->cmd_rsp);
cmd->cmd_rsp = NULL;
}
void
cli_send_async(cli_cmd_t *cmd) {
if (cli_return_task(cmd) == NULL) {
printf("not task found in:\n%s\n",
cmd->cmd_text);
exit(1);
}
printf("-----------------------\n");
printf("@ Send Async:\n");
printf("%s\n", cmd->cmd_text);
printf("-----------------------\n");
if (mms_send_acmd(sp, cmd->cmd_text,
mms_client_handle_async_rsp,
&cmd->cmd_rsp) != MMS_API_OK) {
printf("error async command failed\n");
exit(1);
}
printf("@ Async Sent\n");
fflush(stdout);
}
static void
cli_print_events() {
char cmd_buf[BUFSZ];
printf("press any key to continue with the script\n\n");
fflush(stdout);
(void) fgets(cmd_buf, BUFSZ, stdin);
}
void
cli_mmp_prompt() {
char cmd_buf[BUFSZ];
cli_cmd_t *command1 = NULL;
int go = 0;
printf("MMP prompt, enter \"q\" to quit" \
" and continue\n");
fflush(stdout);
go = 1;
while (go) {
if (command1 == NULL) {
command1 = cli_alloc_cmd();
}
printf("\n>");
(void) fgets(cmd_buf, BUFSZ, stdin);
if (cmd_buf[0] == 'q') {
go = 0;
if (command1->cmd_text != NULL) {
memset(command1->cmd_text,
0,
sizeof (command1->cmd_text));
}
cli_destroy_cmd(command1);
command1 = NULL;
continue;
}
command1->cmd_text =
mms_strapp(command1->cmd_text, cmd_buf);
if (strrchr(command1->cmd_text, ';') != NULL) {
if (cli_parse_cmd(command1)) {
printf("could not "
"parse command, "
"check syntax\n");
memset(cmd_buf, 0,
sizeof (cmd_buf));
cli_destroy_cmd(command1);
command1 = NULL;
} else {
/* Command is sync */
command1->cmd_is_sync = 1;
cli_send_sync(command1);
cli_destroy_cmd(command1);
command1 = NULL;
}
}
}
}
void
cli_print_async() {
cli_cmd_t *cur_cmd;
cli_cmd_t *next;
pthread_mutex_lock(&data.
cli_async_lock);
printf("Outstanding async commands:\n");
for (cur_cmd = mms_list_head(&data.async_list);
cur_cmd != NULL;
cur_cmd = next) {
next = mms_list_next(&data.async_list, cur_cmd);
if (cur_cmd->cmd_task != NULL) {
printf(" %s\n", cur_cmd->cmd_task);
}
}
pthread_mutex_unlock(&data.
cli_async_lock);
}
int
main(int argc, char **argv)
{
int c;
int is_async = 0;
cli_cmd_t *command1;
FILE *fp = NULL;
FILE *pass_fp = NULL;
char buf[BUFSZ];
char *cur_cmd_text = NULL;
char *shell_cmd = NULL;
int prompt_only = 0;
const char *optflags = "A:i:s:p:t:f:n:hP:";
char *prompt = NULL;
char *corename;
int i = 0;
command1 = NULL;
data.host = NULL;
data.port = NULL;
data.client = NULL;
data.instance = NULL;
data.password = NULL;
data.tag = NULL;
data.tag_to_sync = NULL;
data.ssl_data = NULL;
data.net_file = NULL;
data.exiting = 0;
data.async_waiting = 0;
data.wait_for_sync = 0;
data.sync_has_namevalue = 0;
data.waiting_to_exit = 0;
pthread_mutex_init(&data.async_mutex, NULL);
pthread_cond_init(&data.async_cv, NULL);
if (mms_set_core(MMS_CORES_DIR, NULL)) {
fprintf(stderr, "core setup %s\n", strerror(errno));
fprintf(stderr, "Run as ROOT for cores\n");
}
corename = mms_strapp(NULL, "core.mmsclient");
/* Check to see how many core files exist */
if (mms_man_cores(MMS_CORES_DIR, corename)) {
fprintf(stderr, "core management %s\n", strerror(errno));
fprintf(stderr, "Run as ROOT for cores\n");
}
free(corename);
pthread_mutex_init(&data.cli_async_lock, NULL);
/* real optarg processing */
while ((c = getopt(argc, argv, optflags)) != EOF) {
switch (c) {
case 'A':
data.client = mms_strapp(data.client, optarg);
break;
case 'i':
data.instance = mms_strapp(data.instance, optarg);
break;
case 's':
data.host = mms_strapp(data.host, optarg);
break;
case 'P':
if ((pass_fp = fopen(optarg, "r")) == NULL) {
fprintf(stderr, "error opening file %s\n",
optarg);
return (1);
}
break;
case 'p':
data.port = mms_strapp(data.port, optarg);
break;
case 't':
data.tag = mms_strapp(data.tag, optarg);
break;
case 'f':
if ((fp = fopen(optarg, "r")) == NULL) {
fprintf(stderr, "error opening file %s\n",
optarg);
return (1);
}
break;
case 'n':
data.net_file = mms_strapp(data.net_file, optarg);
break;
case 'h':
usage();
default:
usage();
}
}
if (fp == NULL) {
prompt_only = 1;
}
/* Read the network config file */
(void) memset(&data.net, 0, sizeof (mms_network_cfg_t));
if (data.net_file != NULL) {
printf("Using net config file, %s\n",
data.net_file);
if (mms_net_cfg_read(&data.net, data.net_file)) {
fprintf(stderr, "Unable to get net info from "
"network config file, %s\n", data.net_file);
exit(1);
}
}
/* init the async command list */
mms_list_create(&data.async_list, sizeof (cli_cmd_t),
offsetof(cli_cmd_t, cli_cmd_next));
/* Set defaults for connect */
set_default_connect_info();
/* Get password */
if (data.net_file == NULL) {
if (pass_fp == NULL) {
/* Prompt for password */
prompt = mms_strapp(prompt, "MM Password for %s %s : ",
data.client, data.instance);
data.password = getpassphrase(prompt);
free(prompt);
} else {
/* Read pass word from pass_fp */
if (fgets(buf, sizeof (buf), pass_fp) == NULL) {
fprintf(stderr,
"Unable to read password from passfile\n");
exit(1);
}
for (i = 0; i < sizeof (buf); i++) {
if ((buf[i] == NULL) ||
(isspace(buf[i]) &&
!isblank(buf[i]))) {
buf[i] = '\0';
break;
}
}
data.password = mms_strapp(data.password, buf);
}
} else if (pass_fp != NULL) {
fprintf(stdout,
"WARNING: -P and -n used, "
"using password in network config file\n");
}
mms_client_init();
/* Read file and send commands, dont exit if an async command */
/* is waiting for a response */
if (prompt_only) {
while ((!data.exiting) ||
data.async_waiting) {
cli_mmp_prompt();
data.exiting = 1;
}
}
while ((!data.exiting) ||
data.async_waiting) {
if (fgets(buf, sizeof (buf), fp) == NULL) {
data.exiting = 1;
break;
}
/* If this is a blank line or a comment */
if (buf[0] == '#' || buf[0] == '\n') {
if (buf[0] == '#')
printf("%s\n",
buf);
continue; }
/* client should wait and print incomming events */
if (buf[0] == '%') {
cli_print_events();
}
/* execute a shell command */
if (buf[0] == '!') {
shell_cmd = &buf[1];
printf("Execute: \n %s\n", shell_cmd);
system(shell_cmd);
printf("Done\n");
shell_cmd = NULL;
continue;
}
/* Interactive MMP prompt */
if (buf[0] == '>') {
cli_mmp_prompt();
continue;
}
/* The next command will be async */
if (buf[0] == '@') {
is_async = 1;
continue; }
/* client should wait for the response */
/* to this command */
if (buf[0] == '$') {
printf("^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("sync point: \n %s\n",
buf);
printf("^^^^^^^^^^^^^^^^^^^^^^^\n");
if (cli_need_arsp(buf)) {
pthread_mutex_lock(&data.
cli_async_lock);
data.wait_for_sync = 1;
data.tag_to_sync =
mms_strapp(data.tag_to_sync,
buf);
pthread_mutex_unlock(&data.
cli_async_lock);
while (data.wait_for_sync) {
}
printf("=======================\n");
printf("synced with tag : %s\n",
buf);
printf("=======================\n");
} else {
printf("already got "
"response for %s",
buf);
}
continue; }
/* This is a command */
cur_cmd_text = mms_strapp(cur_cmd_text, buf);
if (strrchr(cur_cmd_text, ';') == NULL) {
continue; }
command1 = cli_alloc_cmd();
command1->cmd_text = mms_strapp(command1->cmd_text,
cur_cmd_text);
if (cli_parse_cmd(command1)) {
printf("could not parse command, "
"check syntax\n\n%s\n",
command1->cmd_text);
exit(1);
}
if (is_async) {
/* Command is async */
pthread_mutex_lock(&data.async_mutex);
data.async_waiting = 1;
pthread_mutex_unlock(&data.async_mutex);
command1->cmd_is_sync = 0;
pthread_mutex_lock(&data.
cli_async_lock);
mms_list_insert_tail(&data.async_list,
command1);
pthread_mutex_unlock(&data.
cli_async_lock);
cli_send_async(command1);
is_async = 0;
command1 = NULL;
} else {
/* Command is sync */
command1->cmd_is_sync = 1;
cli_send_sync(command1);
cli_destroy_cmd(command1);
command1 = NULL;
}
free(cur_cmd_text);
cur_cmd_text = NULL;
}
/* Wait for any remaining async commands */
pthread_mutex_lock(&data.async_mutex);
if (data.async_waiting == 1) {
data.waiting_to_exit = 1;
pthread_cond_wait(&data.async_cv,
&data.async_mutex);
}
pthread_mutex_unlock(&data.async_mutex);
printf("All Commands finished\n");
return (0);
}