connect.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 <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include "mms_list.h"
#include "mms_parser.h"
#include "mms_network.h"
#include <mms_sym.h>
#include <mms_trace.h>
#include <mms_strapp.h>
#include "mms_sock.h"
#include <fcntl.h>
#define MMS_OK 0
#define MMS_ERROR -1
#define MMS_WELCOME 6
#define MMS_UNWELCOME 7
/*
*
* mms_intrp()
*
* Parameters:
* rsp The response to the welcome command (XML format) that
* was sent from the MM to the client.
* err_code The error code if MMS_ERROR was returned.
*
* Globals:
* None
*
* This function will determine the type of response that was received in
* response to the client's "hello" command.
*
* Return Values:
* MMS_WELCOME If the response was a welcome
* MMS_UNWELCOME If the response was a unwelcome
* MMS_ERROR If an error was encountered while processing response
* or if the respone was a error response.
*
*/
int
{
int ret_val;
"mms_mmconnect mms_mmp_parse, line %d, "
"col %d, near token \"%s\", err code %d, %s\n",
}
return (MMS_ERROR);
}
MMS_PN_CLAUSE, NULL)) {
MMS_PN_STRING, NULL)) {
}
}
MMS_PN_CLAUSE, NULL)) {
MMS_PN_STRING, &index)) {
}
MMS_PN_STRING, &index)) {
}
}
== NULL) {
} else {
}
} else {
}
return (ret_val);
}
#define MMS_HELLO_CMD_STRING "hello client [\"%s\"] instance [\"%s\"] \
language [%s] version [\"%s\"] password [\"%s\"]; "
#define MMS_HELLO_CMD_TAG_STRING "hello client [\"%s\"] instance [\"%s\"] \
language [%s] version [\"%s\"] password [\"%s\"] tag [\"%s\"]; "
#define MMS_HELLO_CMD_CERT_STRING "hello client [\"%s\"] instance [\"%s\"] \
language [%s] version [\"%s\"] certificate [\"\n%s\n\" \"%s\"]; "
#define MMS_HELLO_CMD_CERT_TAG_STRING "hello client [\"%s\"] instance [\"%s\"] \
language [%s] version [\"%s\"] certificate [\"\n%s\n\" \"%s\"] tag [\"%s\"]; "
/*
*
* mms_mmconnect()
*
* Parameters:
* net Structure containing network information for
* connecting to the MM. This structure contains all
* necessary information needed to compose a "hello"
* command from a client module to the MM.
* conn Structure which will contain the socket connection
* information.
* err_code error code if MMS_ERROR is returned.
* error code is either MMS error code.
* tag Tag to be used for the connection.
*
* Globals:
* None.
*
* This is a general purpose routine that can be used by a client that
* need to connect to MM. All client specific information is contained in
* the mms_network_cfg structure. This routine generates a "hello" command and
* send it to the MM. It waits for a response from the MM and determines
* if a welcome or unwelcome response was sent by MM.
*
* Return Values:
* fd If a welcome response was received from MM, then
* this routine returns the file descriptor that the
* client will use to communicate with MM.
* MMS_ERROR If an error occurred while processing or if an
* unwelcome response was receieved from MM.
*
*/
int
void *ssl_data,
int *err_code,
char *tag)
{
int n;
int len;
char ebuf[MMS_EBUF_LEN];
char cmd_str[4096];
int rc;
*err_code = 0;
/*
* Connect to media manager, if ssl data is not null
* then establish a SSLv3 connection.
*/
"%s\n", ebuf);
return (MMS_ERROR);
}
/*
* Create hello command.
*/
#ifdef MMS_OPENSSL
/*
* Create auth-clause hello command using
* its private key for the signature.
*/
"mms_mmconnect: hello certificate-clause");
return (MMS_ERROR);
}
} else {
}
} else {
#endif /* MMS_OPENSSL */
/*
* Use password, client does not have
* private key for signature.
*/
"");
} else {
"", tag);
}
#ifdef MMS_OPENSSL
}
#endif /* MMS_OPENSSL */
"mms_mmconnect: Failed to write hello cmd, %d, "
"%s\n", n, ebuf);
return (MMS_ERROR);
}
"mms_mmconnect: Failed to read response to hello "
"cmd, %d, %s\n", n, ebuf);
return (MMS_ERROR);
}
case MMS_WELCOME:
/*
* Verifing welcome auth-clause is optional.
*/
"mms_mmconnect: welcome "
"password mismatch");
} else {
"mms_mmconnect: welcome "
"password matched");
}
}
#ifdef MMS_OPENSSL
"mms_mmconnect: welcome certificate-clause "
"invalid");
"mms_mmconnect: welcome "
"certificate-clause "
"password mismatch");
} else {
"mms_mmconnect: welcome "
"certificate-clause ok");
}
}
#endif /* MMS_OPENSSL */
"mms_mmconnect: welcome missing auth-clause");
}
return (MMS_OK);
}
break;
case MMS_UNWELCOME:
"mms_mmconnect: unwelcome resp - %s", rsp);
break;
case MMS_ERROR:
break;
default:
break;
}
return (MMS_ERROR);
}
/*
*
* mms_mmdisconnect()
*
* Parameters:
* conn Structure containing network information for
* connecting to the MM. This structure contains all
* necessary information needed to compose a "goodbye"
* command from a client module to the MM.
*
* Globals:
* None.
*
* This is a general purpose routine that can be used by a client that
* is disconnecting from the MM. This routine generates a "goodbye" command and
* send it to the MM. It does not wait for a response from the MM.
*
* Return Values:
* MMS_OK If the goodbye command was sent successfully.
* MMS_ERROR If an error occurred while processing
*
*/
int
{
int n;
int len;
char ebuf[MMS_EBUF_LEN];
char cmd_str[1024];
n, ebuf);
return (MMS_ERROR);
}
return (MMS_OK);
}