DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * The contents of this file are subject to the Netscape Public License
 * Version 1.0 (the "NPL"); you may not use this file except in
 * compliance with the NPL.  You may obtain a copy of the NPL at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the NPL is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
 * for the specific language governing rights and limitations under the
 * NPL.
 *
 * The Initial Developer of this code under the NPL is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 * Reserved.
 */

#ifndef _NS_TARGET_H_
#define _NS_TARGET_H_

#include <string.h>
#include "prtypes.h"
#include "plhash.h"

#include "nsHashtable.h"
#include "nsVector.h"
#include "nsCaps.h"
#include "nsPrincipal.h"
#include "nsPrivilege.h"
#include "nsUserDialogHelper.h"

typedef nsVector nsTargetArray;

PR_BEGIN_EXTERN_C
#include "jpermission.h"
PR_PUBLIC_API(void)
java_netscape_security_getTargetDetails(const char *charSetName, char* targetName, 
                                        char** details, char **risk);
PR_END_EXTERN_C

extern int CAPS_TARGET_RISK_COLOR_HIGH;

extern PRBool CreateSystemTargets(nsPrincipal *sysPrin);

struct nsTarget {

public:

	/* Public Methods */

	virtual ~nsTarget(void);

	nsTarget(char *name, nsPrincipal *prin, 
             PRInt32 risk = JavaSecUI_targetRiskHigh(), 
             char *riskColor = JavaSecUI_getString(CAPS_TARGET_RISK_COLOR_HIGH), 
             char *description = NULL, 
             char *detailDescription = NULL,
             char *url = NULL, 
             nsTargetArray* targetArray = NULL)
    {
  		init(name, prin, targetArray, risk, riskColor, description, 
             detailDescription, url);
    }

	nsTarget(char *name, nsPrincipal *prin, 
             PRInt32 risk = JavaSecUI_targetRiskHigh(), 
             char *riskColor = JavaSecUI_getString(CAPS_TARGET_RISK_COLOR_HIGH), 
             int desc_id = 0, 
             int detail_desc_id = 0,
             int help_url_id = 0, 
             nsTargetArray* targetArray = NULL);

	nsTarget * registerTarget(void);

	nsTarget * registerTarget(void* context);

	static nsTarget * findTarget(nsTarget *target);

	static nsTarget * findTarget(char *name);

	static nsTarget * findTarget(char *name, nsPrincipal *prin);

	nsPrivilege * checkPrivilegeEnabled(nsTargetArray* prinArray, void *data);

	nsPrivilege * checkPrivilegeEnabled(nsTargetArray* prinArray);

	nsPrivilege * checkPrivilegeEnabled(nsPrincipal *p, void *data);

	virtual nsPrivilege * enablePrivilege(nsPrincipal *prin, void *data);

	nsPrivilege * getPrincipalPrivilege(nsPrincipal *prin, void *data);

	nsTargetArray* getFlattenedTargetArray(void);

	static nsTargetArray* getAllRegisteredTargets(void);

	char * getRisk(void);

	char * getRiskColor(void);

	char * getDescription(void);

	char * getDetailDescription(void);

	static nsTarget * getTargetFromDescription(char *a);

	char * getHelpURL(void);

	char * getDetailedInfo(void *a);

	nsPrincipal * getPrincipal(void);

	char * getName(void);

	PRBool equals(nsTarget *a);

	PRInt32 hashCode(void);

	char * toString(void);

	PRBool isRegistered(void);

private:

	/* Private Field Accessors */
	char * itsName;

	nsPrincipal * itsPrincipal;

	PRInt32 itsRisk;

	char * itsRiskColorStr;

	char * itsDescriptionStr;

	char * itsDetailDescriptionStr;

	char * itsURLStr;

	PRBool itsRegistered;

	nsTargetArray* itsTargetArray;

	nsTargetArray* itsExpandedTargetArray;
	
	char *itsString;

	PRUint32 itsDescriptionHash;

	static PRBool theInited;

	/* Private Methods */
	void init(char *name, nsPrincipal *prin, nsTargetArray* targetArray, PRInt32 risk, char *riskColor, char *description, char *detailDescription, char *url);

	void getFlattenedTargets(nsHashtable *targHash, nsTargetArray* expandedTargetArray);

};


class TargetKey: public nsHashKey {
public:
  nsTarget *itsTarget;
  TargetKey(nsTarget *targ) {
    itsTarget = targ;
  }
  
  PRUint32 HashValue(void) const {
    return itsTarget->hashCode();
  }

  PRBool Equals(const nsHashKey *aKey) const {
    return (itsTarget->equals(((const TargetKey *) aKey)->itsTarget));
  }

  nsHashKey *Clone(void) const {
    return new TargetKey(itsTarget);
  }
};

/* XXX: IMO, IntegerKey and StringKey should be part of xpcom */
class IntegerKey: public nsHashKey {
private:
  PRUint32 itsHash;
  
public:
  IntegerKey(PRUint32 hash) {
    itsHash = hash;
  }
  
  PRUint32 HashValue(void) const {
    return itsHash;
  }

  PRBool Equals(const nsHashKey *aKey) const {
    return (itsHash == (((const IntegerKey *) aKey)->itsHash)) ? PR_TRUE : PR_FALSE;
  }

  nsHashKey *Clone(void) const {
    return new IntegerKey(itsHash);
  }
};

class StringKey: public nsHashKey {
public:
  const char *itsString;

  StringKey(const char *string) {
    itsString = string;
  }
  
  PRUint32 HashValue(void) const {
    return PL_HashString(itsString);
  }

  PRBool Equals(const nsHashKey *aKey) const {
    return (strcmp(itsString, (((const StringKey *) aKey)->itsString)) == 0);
  }

  nsHashKey *Clone(void) const {
    return new StringKey(itsString);
  }
};

#endif /* _NS_TARGET_H_ */