/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <libintl.h>
#include "pkglib.h"
#include "pkgstrct.h"
#include "pkglocale.h"
#include "pkglibmsgs.h"
/*
* Forward declarations
*/
/* from gpkgmap.c */
/*
* Module globals
*/
static int decisionTableInit = 0;
/*
* These arrays must be indexable by an unsigned char.
*/
/*
* Name: COPYPATH
* Description: copy path limiting size to destination capacity
* Arguments: DEST - (char []) - [RW]
* SRC - (char *) - [RO, *RO]
* Pointer to first byte of path to copy
* LEN - (int) - [RO]
* Number of bytes to copy
*/
{ \
/* assure return path does not overflow */ \
} \
/* copy return path to local storage */ \
}
/*
* Name: srchcfile
* Description: search contents file looking for closest match to entry,
* creating a new contents file if output contents file specified
* Arguments: ept - (struct cfent *) - [RO, *RW]
* - contents file entry, describing last item found
* path - (char *) - [RO, *RO]
* - path to search for in contents file
* - If path is "*", then the next entry is returned;
* the next entry always matches this path
* PKGserver
* - our door to the database server.
*
* Returns: int
* < 0 - error occurred
* - Use getErrstr to retrieve character-string describing
* the reason for failure
* == 0 - no match found
* - specified path not in the contents file
* == 1 - exact match found
* - specified path found in contents file
* - this value is always returned if path is "*" and the
* next entry is returned - 0 is returned when no more
* entries are left to process
* Side Effects:
* - The ept structure supplied is filled in with a description of
* the item that caused the search to terminate, except in the
* case of '0' in which case the contents of 'ept' is undefined.
* - NOTE: the ept->path item points to a path that is statically
* allocated and will be overwritten on the next call.
* - NOTE: the ept->ainfo.local item points to a path that is
* statically allocated and will be overwritten on the next call.
*/
int
{
int anypath = 0;
int c;
int cpath_len = 0;
char *p;
char *curbuf;
/*
* this code does not use nested subroutines because execution time
* of this routine is especially critical to installation and upgrade
*/
/* initialize local variables */
lpath[0] = '\0';
/* initialize ept structure values */
/*
* populate decision tables that implement fast character checking;
* this is much faster than the equivalent strpbrk() call or a
* while() loop checking for the characters. It is only faster if
* there are at least 3 characters to scan for - when checking for
* one or two characters (such as '\n' or '\0') its faster to do
* a simple while() loop.
*/
if (decisionTableInit == 0) {
/*
* any chars listed stop scan;
* scan stops on first byte found that is set to '1' below
*/
/*
* Separators for normal words
*/
/*
* Separators for list of packages, includes \\ for
* alternate ftype and : for classname
*/
decisionTableInit = 1;
}
/* if the path to scan for is empty, act like no path was specified */
}
/*
* if path to search for is "*", then we will return the first path
* we encounter as a match, otherwise we return an error
*/
return (-1);
}
anypath = 1;
}
/* attempt to narrow down the search for the specified path */
return (0);
/* determine first character of the next entry */
if (anypath == 0)
else
return (0);
/*
* current entry DOES start with absolute path
* set ept->path to point to lpath
* set cpath_start/cpath_len to point to the file name
*/
/* copy first token into path element of passed structure */
p = cpath_start + cpath_len;
/* copy path found to 'lpath' */
/* get first character following the end of the path */
c = *p++;
/*
* we want to return information about this path in
* the structure provided, so parse any local path
* and jump to code which parses rest of the input line
*/
if (c == '=') {
/* parse local path specification */
return (-1);
}
}
/*
* if an exact match and processing a new style entry, read the
* remaining information from the new style entry.
*/
while (isspace((c = *p++)))
;
switch (c) {
case '?': case 'f': case 'v': case 'e': case 'l':
case 's': case 'p': case 'c': case 'b': case 'd':
case 'x':
/* save ftype */
/* save class */
return (-1);
}
break; /* we already read the pathname */
case '\0':
/* end of line before new-line seen */
return (-1);
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return (-1);
case 'i':
return (-1);
default:
/* unknown ftype */
return (-1);
}
return (-1);
}
return (-1);
}
}
/* most types have mode, owner, group identification components */
/* mode, owner, group should be here */
ISWORDSEP) ||
ISWORDSEP)) {
return (-1);
}
}
/* i/f/v/e have size, checksum, modification time components */
/* look for content description */
BADCONT) ||
return (-1);
}
}
/* i files processing is completed - return 'exact match found' */
return (1);
}
/*
* determine list of packages which reference this entry
*/
/* if c < 0 the string was too long to fix in the buffer */
if (c < 0) {
return (-1);
}
/* a package is present - create and populate pinfo structure */
if (!pinfo) {
return (-1);
}
if (!lastpinfo) {
} else {
}
} else {
}
/* pkg/[:[ftype][:class] */
c = *p++;
if (c == '\\') {
/* get alternate ftype */
c = *p++;
}
if (c == ':') {
/* get special classname */
c = *p++;
}
/* break out of while if at end of entry */
if ((c == '\n') || (c == '\0')) {
break;
}
/* if package not separated by a space return an error */
if (!isspace(c)) {
return (-1);
}
}
/*
* parsing of the entry is complete
*/
/* if not at the end of the entry, make it so */
if ((c != '\n') && (c != '\0')) {
return (-1);
}
}
return (1);
}
static int
{
int c;
char *p = *cp;
char *p1;
if (*p == '\0') {
return (1);
}
/* leading white space ignored */
while (((c = *p) != '\0') && (isspace(*p++)))
;
if ((c == '\0') || (c == '\n')) {
p--;
*cp = p;
return (1); /* nothing there */
}
p--;
/* compute length based on delimiter found or not */
p1 = p;
p1++;
}
/* if string will fit in result buffer copy string and return success */
if (len < n) {
p += len;
*cp = p;
return (0);
}
/* result buffer too small; copy partial string, return error */
p += n;
*cp = p;
return (-1);
}
static int
{
int n;
char *p = *cp;
n = 0;
/* if at end of buffer return no more characters left */
if (*p == '\0') {
return (0);
}
while ((*p != '\0') && (*p != '\n')) {
if (n == 0) {
if (!isspace(*p)) {
n++;
}
}
p++;
}
*cp = ++p;
return (n);
}