mmsclient.c revision cee0fb94c0d4227de0a00efc162fb2739844b641
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <mms.h>
#include <mms_cores.h>
#include <ctype.h>
#define BUFSZ 1024
typedef struct cli_data cli_data_t;
struct cli_data {
char *host;
char *port;
char *client;
char *instance;
char *password;
char *tag;
char *mm_pass;
char *net_file;
int exiting;
int async_waiting;
char *tag_to_sync;
int wait_for_sync;
int sync_has_namevalue;
void *ssl_data;
int waiting_to_exit;
};
struct cli_cmd {
int cmd_is_sync;
char *cmd_text;
char *cmd_task;
void *cmd_rsp;
int cmd_namevalue;
char *cmd_tag;
};
void *sp;
extern
cli_alloc_cmd() {
printf("could not allocate mem for new command");
exit(1);
}
cmd->cmd_namevalue = 0;
return (cmd);
}
void
}
}
}
}
}
}
void
/* LINTED: void arg is required */
mms_catch_reader(void *ev)
{
printf("mms_catch_reader: Reader shutting down\n");
}
void
{
}
/*ARGSUSED*/
static void
{
printf("Event received:\n %s\n",
lev->mms_rsp_str);
}
}
static
void
{
printf(" attrlist\n");
if (namevalue) {
/* print 2 */
printf(" %s",
printf(" %s\n",
} else {
/* print 1 */
printf(" %s\n",
}
}
}
}
static
void
{
printf(" text\n");
}
if (namevalue) {
/* print 2 */
printf(" %s",
printf(" %s\n",
} else {
/* print 1 */
printf(" %s\n",
}
}
}
}
static void
/* lrsp->mms_rsp_cmd is */
/* the parse tree of the response */
int namevalue = 0;
printf("success, %s\n",
lrsp->mms_rsp_tid);
/* Test task and remove if the same */
lrsp->mms_rsp_tid) == 0) {
break;
}
}
/* For each text clause print the results */
}
}
static void
/* lrsp->mms_rsp_cmd is */
/* the parse tree of the response */
printf("success, %s\n",
lrsp->mms_rsp_tid);
/* For each text clause print the results */
}
data.sync_has_namevalue = 0;
}
static void
mms_client_handle_rsp(void *rsp)
{
int class;
int code;
char *msg;
switch (mms_rsp_type(rsp)) {
case MMS_API_RSP_UNACC:
printf("Command was not accepted\n");
break;
case MMS_API_RSP_FINAL:
printf("Command was successful\n");
break;
case MMS_API_RSP_FINAL_ERR:
printf("Command received an error response\n");
&msg) != MMS_API_OK) {
printf("Error response handler failed\n");
break;
}
else
printf("No message clause in error rsp\n");
break;
case MMS_API_RSP_FINAL_CANC:
printf("Command received a cancelled response\n");
break;
default:
printf("Unknow response type\n");
break;
}
}
void
/* LINTED: param required */
{
int class;
int code;
char *msg;
int found_other = 0;
switch (mms_rsp_type(rsp)) {
case MMS_API_RSP_UNACC:
printf("Command was not accepted\n");
break;
case MMS_API_RSP_FINAL:
printf("\n\nCommand was successful\n");
printf("\n\n");
break;
case MMS_API_RSP_FINAL_ERR:
printf("Command received an error response\n");
&msg) != MMS_API_OK) {
printf("Error response handler failed\n");
break;
}
else
printf("No message clause in error rsp\n");
break;
case MMS_API_RSP_FINAL_CANC:
printf("Command received a cancelled response\n");
break;
default:
printf("Unknow response type\n");
break;
}
/* Test task and remove if the same */
lrsp->mms_rsp_tid) == 0) {
cur_cmd);
} else {
/* there is at least one other */
/* async command waiting */
found_other = 1;
}
}
/* There are no async commands left */
if (!found_other) {
data.async_waiting = 0;
if (data.waiting_to_exit) {
}
}
/* If we are waiting for a sync point check if this is the response */
/* we are waiting for */
/* Got the response we are waiting for */
data.wait_for_sync = 0;
}
}
}
int
cli_need_arsp(char *buf) {
return (1);
}
}
return (0);
}
static void
{
}
static void
{
}
(void) printf("Can't set signal handler for "
exit(1);
}
}
static void
{
int rc;
int vers;
char mms_ebuf[MMS_EBUF_LEN];
&ev_callbk)) != MMS_API_OK) {
exit(1);
}
if (vers != MMS_API_VERSION) {
printf("Mismatch of versions between client %d and API %d\n",
exit(1);
}
printf("Connect to MM:\n");
printf(" Password:\n");
#ifdef MMS_OPENSSL
exit(1);
}
#endif /* MMS_OPENSSL */
exit(1);
}
exit(1);
}
PTHREAD_CREATE_DETACHED)) != 0) {
printf("Error in attr setdetachstate, errno - %s\n",
exit(1);
}
exit(1);
}
PTHREAD_CREATE_DETACHED)) != 0) {
printf("Error in attr setdetachstate, errno - %s\n",
exit(1);
}
printf("Client API initialized\n");
}
void
/* Net file was passed */
}
}
}
}
}
getpid());
}
}
void
usage(void)
{
exit(2);
}
int
int rc;
printf("error parse, "
"line %d, col %d, near token \"%s\", err code %d, %s\n",
}
if (rc) {
return (1);
}
return (0);
}
int
MMS_PN_CLAUSE, 0)) != NULL) {
}
return (1);
}
}
data.sync_has_namevalue = 0;
}
return (0);
}
char *
printf("cli_return_task: cmd->cmd_root is NULL\n");
exit(1);
}
&work);
if (task_clause == NULL) {
return (NULL);
}
return (NULL);
}
}
/* Also set namevalue for printing later */
}
void
printf("not task found in:\n%s\n",
exit(1);
}
printf("-----------------------\n");
printf("* Send Sync:\n");
printf("-----------------------\n");
printf("error show command failed\n");
exit(1);
}
printf("* Sync Sent\n");
}
void
printf("not task found in:\n%s\n",
exit(1);
}
printf("-----------------------\n");
printf("@ Send Async:\n");
printf("-----------------------\n");
printf("error async command failed\n");
exit(1);
}
printf("@ Async Sent\n");
}
static void
cli_print_events() {
printf("press any key to continue with the script\n\n");
}
void
cli_mmp_prompt() {
int go = 0;
printf("MMP prompt, enter \"q\" to quit" \
" and continue\n");
go = 1;
while (go) {
command1 = cli_alloc_cmd();
}
printf("\n>");
if (cmd_buf[0] == 'q') {
go = 0;
0,
}
continue;
}
if (cli_parse_cmd(command1)) {
printf("could not "
"parse command, "
"check syntax\n");
sizeof (cmd_buf));
} else {
/* Command is sync */
}
}
}
}
void
cli_print_async() {
printf("Outstanding async commands:\n");
}
}
}
int
{
int c;
int is_async = 0;
char *cur_cmd_text = NULL;
int prompt_only = 0;
const char *optflags = "A:i:s:p:t:f:n:hP:";
char *corename;
int i = 0;
data.async_waiting = 0;
data.wait_for_sync = 0;
data.sync_has_namevalue = 0;
data.waiting_to_exit = 0;
}
/* Check to see how many core files exist */
}
/* real optarg processing */
switch (c) {
case 'A':
break;
case 'i':
break;
case 's':
break;
case 'P':
optarg);
return (1);
}
break;
case 'p':
break;
case 't':
break;
case 'f':
optarg);
return (1);
}
break;
case 'n':
break;
case 'h':
usage();
default:
usage();
}
}
prompt_only = 1;
}
/* Read the network config file */
printf("Using net config file, %s\n",
exit(1);
}
}
/* init the async command list */
/* Set defaults for connect */
/* Get password */
/* Prompt for password */
} else {
/* Read pass word from pass_fp */
"Unable to read password from passfile\n");
exit(1);
}
for (i = 0; i < sizeof (buf); i++) {
buf[i] = '\0';
break;
}
}
}
"WARNING: -P and -n used, "
"using password in network config file\n");
}
/* Read file and send commands, dont exit if an async command */
/* is waiting for a response */
if (prompt_only) {
}
}
break;
}
/* If this is a blank line or a comment */
if (buf[0] == '#')
printf("%s\n",
buf);
continue; }
/* client should wait and print incomming events */
if (buf[0] == '%') {
}
/* execute a shell command */
if (buf[0] == '!') {
printf("Done\n");
continue;
}
/* Interactive MMP prompt */
if (buf[0] == '>') {
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)) {
buf);
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 */
continue; }
command1 = cli_alloc_cmd();
if (cli_parse_cmd(command1)) {
printf("could not parse command, "
"check syntax\n\n%s\n",
exit(1);
}
if (is_async) {
/* Command is async */
command1->cmd_is_sync = 0;
command1);
is_async = 0;
} else {
/* Command is sync */
}
cur_cmd_text = NULL;
}
/* Wait for any remaining async commands */
&data.async_mutex);
}
printf("All Commands finished\n");
return (0);
}