mm_types.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 <string.h>
#include <errno.h>
#include <pthread.h>
#include <syslog.h>
#include <mms_list.h>
#include <mms_parser.h>
#include <mms_par_impl.h>
#include <libpq-fe.h>
#include <mms_trace.h>
#include <mms_strapp.h>
#include "mm_db.h"
#include "mm.h"
#include "mm_util.h"
#include "mm_commands.h"
#include "mm_sql.h"
#include "mm_sql_impl.h"
#include "mm_task.h"
#include "mm_path.h"
typedef struct mm_type_library mm_type_library_t;
struct mm_type_library {
};
typedef struct mm_type_data mm_type_data_t;
struct mm_type_data {
int mm_error;
int mm_level;
int mm_once;
};
static void mm_check_drive_string(char *drive_name);
static void mm_check_cartridge_string(char *cartridge_name);
static void mm_check_cartridgetype_string(char *cartridge_name);
static void mm_check_library_string(char *library_name);
static void mm_check_slottype_string(char *cartridgeshape_name,
char *cur_library_name);
static void mm_parse_type_start_elements(void *xml_type_data,
static void mm_parse_type_end_elements(void *xml_type_data,
static PGresult *drive_results;
static int num_drive;
static PGresult *cartridge_results;
static int num_cartridge;
static PGresult *library_results;
static int num_library;
static PGresult *slottype_results;
static int num_slottype;
static PGresult *carttype_results;
static int num_carttype;
static void
lib_list = next_lib_list) {
lib_list);
lib_list);
}
}
static
printf("could not allocate mem for lib struct");
exit(1);
}
return (lib);
}
int
{
"select \"DriveString\" "
"from \"DRIVELIST\";") != MM_DB_DATA) {
"db error getting drive strings");
return (1);
} else {
}
"select \"CartridgeString\" "
"from \"CARTRIDGELIST\";") != MM_DB_DATA) {
"db error getting cartridge strings");
return (1);
} else {
}
"select \"LibraryString\" "
"from \"LIBRARYLIST\";") != MM_DB_DATA) {
"db error getting library strings");
return (1);
} else {
}
"select \"SlotTypeName\", \"CartridgeShapeName\" "
"from \"SLOTTYPE\";") != MM_DB_DATA) {
"db error getting slottype strings");
return (1);
} else {
}
"select \"CartridgeTypeName\", \"CartridgeShapeName\" "
"from \"CARTRIDGETYPE\";") != MM_DB_DATA) {
"db error getting CARTRIDGETYPE strings");
return (1);
} else {
}
/* Create drive cart and library lists */
return (1);
}
"parsing types done, verify now");
if (mm_verify_types(&type_data)) {
"error verifying types");
return (1);
}
"types verified successfully, "
"type init done");
return (0);
}
static void
int found_one = 0;
"delete from \"DRIVELIST\" where ");
if (found_one != 0) {
}
found_one = 1;
}
if (found_one) {
"mm_types_delete_drive: "
"db error deleting from drivelist");
}
}
}
static void
int found_one = 0;
"delete from \"CARTRIDGELIST\" where ");
if (found_one != 0) {
}
found_one = 1;
}
if (found_one) {
"mm_types_delete_cart: "
"db error deleting from cartlist");
}
}
}
static void
char *slottype_buf = NULL;
int found_one_lib = 0;
int found_one_slottype = 0;
"delete from \"LIBRARYLIST\" where ");
"delete from \"SLOTTYPE\" where ");
lib_list = next_lib_list) {
lib_list);
node);
if (found_one_lib != 0) {
}
found_one_lib = 1;
"(\"LibraryString\" != '%s') ",
if (found_one_slottype != 0) {
}
found_one_slottype = 1;
"((\"SlotTypeName\" != '%s') and "
"(\"CartridgeShapeName\" != '%s')) ",
}
}
}
if (found_one_lib) {
"mm_types_delete_library: "
"db error deleting from librarylist");
}
}
if (found_one_slottype) {
"mm_types_delete_library: "
"db error deleting from slottype");
}
}
}
static int
{
int print = 0;
/* Print out what we have in the lists */
if (print) {
"Drive Strings:");
}
}
if (print) {
"Cartridge Strings:");
}
}
lib_list = next_lib_list) {
lib_list);
if (print) {
"Library Strings:");
"Slottype Strings:");
}
node);
}
}
}
/* Create the Side1Name column for default types */
"ALTER TABLE \"CARTRIDGETYPE\" "
"ADD \"Side1Name\" text;") != MM_DB_OK) {
/* If there is an error ignore it */
}
}
/* All strings in xml are now in db */
/* now delete any strings that are not in the xml */
return (0);
}
static int
{
}
fn,
}
}
static void
mm_check_drive_string(char *drive_name) {
int i;
char *cur_drive;
int matched_drive = 0;
for (i = 0; i < num_drive; i++) {
i, 0);
/* already have this drive name */
matched_drive = 1;
}
}
if (matched_drive == 0) {
/* Need to add this drive to drive list */
"insert into \"DRIVELIST\" "
"(\"DriveString\") values('%s');",
drive_name) != MM_DB_OK) {
"error inserting %s "
"into DRIVELIST",
}
}
}
static void
mm_check_cartridge_string(char *cartridge_name) {
int i;
char *cur_cartridge;
int matched_cartridge = 0;
for (i = 0; i < num_cartridge; i++) {
i, 0);
/* already have this cartridge name */
matched_cartridge = 1;
}
}
if (matched_cartridge == 0) {
/* Need to add this cartridge to cartridge list */
"insert into \"CARTRIDGELIST\" "
"(\"CartridgeString\") values('%s');",
cartridge_name) != MM_DB_OK) {
"error inserting %s "
"into CARTRIDGELIST",
}
}
}
static void
int i;
char *cur_carttype;
char *cur_cartshape;
int matched_cartridge = 0;
for (i = 0; i < num_carttype; i++) {
i, 0);
i, 1);
/* already have this cartridge name */
matched_cartridge = 1;
}
}
if (matched_cartridge == 0) {
/* Need to add this cartridge to cartridge list */
"insert into \"CARTRIDGETYPE\" "
"(\"CartridgeTypeName\", "
"\"CartridgeShapeName\", "
"\"Side1Name\", "
"\"CartridgeTypeMediaType\") values('%s',"
"'%s', 'side 1', 'data');",
cartridgeshape_name) != MM_DB_OK) {
"error inserting %s "
"into CARTRIDGETYPE",
}
}
}
static void
mm_check_library_string(char *library_name) {
int i;
char *cur_library;
int matched_library = 0;
for (i = 0; i < num_library; i++) {
i, 0);
/* already have this library name */
matched_library = 1;
}
}
if (matched_library == 0) {
/* Need to add this library to library list */
"insert into \"LIBRARYLIST\" "
"(\"LibraryString\") values('%s');",
library_name) != MM_DB_OK) {
"error inserting %s "
"into LIBRARYLIST",
}
}
}
static void
char *cur_library_name) {
int i;
char *cur_slottype;
char *cur_cartridgeshape;
int matched_slottype = 0;
for (i = 0; i < num_slottype; i++) {
i, 0);
i, 1);
/* already have this slottype name */
matched_slottype = 1;
}
}
if (matched_slottype == 0) {
/* Need to add this slottype to slottype list */
"insert into \"SLOTTYPE\" "
"(\"SlotTypeName\", \"CartridgeShapeName\") "
"values('%s', '%s');",
cartridgeshape_name) != MM_DB_OK) {
"error inserting %s, %s "
"into SLOTTYPE",
}
}
}
static void
{
return;
}
}
return;
}
return;
}
return;
}
return;
}
new_lib);
return;
}
return;
}
return;
}
" mm_drive_string=%s",
atts[1]);
&type_data->mm_drive_name_list)) {
"mm_parse_type_start_elements: "
"out of mem adding to drive list");
}
}
return;
}
" mm_cartridge_string=%s",
atts[1]);
&type_data->mm_cart_name_list)) {
"mm_parse_type_start_elements: "
"out of mem adding to cart list");
}
}
return;
}
" mm_slottype name=%s",
atts[1]);
"mm_parse_type_start_elements: "
"out of mem adding to library list");
}
}
return;
}
" mm_cartridgeshape name=%s",
atts[1]);
"mm_parse_type_start_elements: "
"out of mem adding to shape list");
}
}
return;
}
}
static void
{
return;
}
return;
}
return;
}
return;
}
return;
}
return;
}
}