Compare commits
5 Commits
RJCTEST_BA
...
sdr_1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4127f7ed92 | ||
|
|
fc8cd8ebd2 | ||
|
|
26ed09faf4 | ||
|
|
14e542e142 | ||
|
|
fe9b32e930 |
74
mozilla/security/psm/lib/Makefile
Executable file
74
mozilla/security/psm/lib/Makefile
Executable file
@@ -0,0 +1,74 @@
|
||||
#! gmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
@@ -26,7 +26,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src resources
|
||||
DIRS = protocol client
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
3
mozilla/security/psm/lib/client/MANIFEST
Normal file
3
mozilla/security/psm/lib/client/MANIFEST
Normal file
@@ -0,0 +1,3 @@
|
||||
cmtclist.h
|
||||
cmtcmn.h
|
||||
cmtjs.h
|
||||
74
mozilla/security/psm/lib/client/Makefile
Executable file
74
mozilla/security/psm/lib/client/Makefile
Executable file
@@ -0,0 +1,74 @@
|
||||
#! gmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
include config.mk
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
70
mozilla/security/psm/lib/client/Makefile.in
Normal file
70
mozilla/security/psm/lib/client/Makefile.in
Normal file
@@ -0,0 +1,70 @@
|
||||
#! gmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = cmt
|
||||
|
||||
EXPORTS = \
|
||||
cmtcmn.h \
|
||||
cmtjs.h \
|
||||
cmtclist.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = security
|
||||
|
||||
CSRCS = cmtinit.c \
|
||||
cmtssl.c \
|
||||
cmtutils.c \
|
||||
cmtcert.c \
|
||||
cmthash.c \
|
||||
cmtpkcs7.c \
|
||||
cmtres.c \
|
||||
cmtjs.c \
|
||||
cmtevent.c \
|
||||
cmtpasswd.c \
|
||||
cmtadvisor.c \
|
||||
cmtrng.c \
|
||||
cmtsdr.c \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lprotocol
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
99
mozilla/security/psm/lib/client/cmtadvisor.c
Normal file
99
mozilla/security/psm/lib/client/cmtadvisor.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#ifdef XP_MAC
|
||||
#include "cmtmac.h"
|
||||
#endif
|
||||
|
||||
CMTStatus CMT_SecurityAdvisor(PCMT_CONTROL control, CMTSecurityAdvisorData* data, CMUint32 *resID)
|
||||
{
|
||||
CMTItem message = {0, NULL, 0};
|
||||
SecurityAdvisorRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.infoContext = data->infoContext;
|
||||
request.resID = data->resID;
|
||||
request.hostname = data->hostname;
|
||||
request.senderAddr = data->senderAddr;
|
||||
request.encryptedP7CInfo = data->encryptedP7CInfo;
|
||||
request.signedP7CInfo = data->signedP7CInfo;
|
||||
request.decodeError = data->decodeError;
|
||||
request.verifyError = data->verifyError;
|
||||
request.encryptthis = data->encryptthis;
|
||||
request.signthis = data->signthis;
|
||||
request.numRecipients = data->numRecipients;
|
||||
request.recipients = data->recipients;
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_SECURITY_ADVISOR;
|
||||
|
||||
if (CMT_EncodeMessage(SecurityAdvisorRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SECURITY_ADVISOR)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*resID = reply.value;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
|
||||
if (message.data) {
|
||||
free(message.data);
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1362
mozilla/security/psm/lib/client/cmtcert.c
Normal file
1362
mozilla/security/psm/lib/client/cmtcert.c
Normal file
File diff suppressed because it is too large
Load Diff
111
mozilla/security/psm/lib/client/cmtclist.h
Normal file
111
mozilla/security/psm/lib/client/cmtclist.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef cmtclist_h___
|
||||
#define cmtclist_h___
|
||||
|
||||
typedef struct CMTCListStr CMTCList;
|
||||
/*
|
||||
** Circular linked list
|
||||
*/
|
||||
struct CMTCListStr {
|
||||
CMTCList *next;
|
||||
CMTCList *prev;
|
||||
};
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, before "_l".
|
||||
*/
|
||||
#define CMT_INSERT_BEFORE(_e,_l) \
|
||||
(_e)->next = (_l); \
|
||||
(_e)->prev = (_l)->prev; \
|
||||
(_l)->prev->next = (_e); \
|
||||
(_l)->prev = (_e); \
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, after "_l".
|
||||
*/
|
||||
#define CMT_INSERT_AFTER(_e,_l) \
|
||||
(_e)->next = (_l)->next; \
|
||||
(_e)->prev = (_l); \
|
||||
(_l)->next->prev = (_e); \
|
||||
(_l)->next = (_e); \
|
||||
|
||||
/*
|
||||
** Append an element "_e" to the end of the list "_l"
|
||||
*/
|
||||
#define CMT_APPEND_LINK(_e,_l) CMT_INSERT_BEFORE(_e,_l)
|
||||
|
||||
/*
|
||||
** Insert an element "_e" at the head of the list "_l"
|
||||
*/
|
||||
#define CMT_INSERT_LINK(_e,_l) CMT_INSERT_AFTER(_e,_l)
|
||||
|
||||
/* Return the head/tail of the list */
|
||||
#define CMT_LIST_HEAD(_l) (_l)->next
|
||||
#define CMT_LIST_TAIL(_l) (_l)->prev
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list.
|
||||
*/
|
||||
#define CMT_REMOVE_LINK(_e) \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list. Also initializes the
|
||||
** linkage.
|
||||
*/
|
||||
#define CMT_REMOVE_AND_INIT_LINK(_e) \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
(_e)->next = (_e); \
|
||||
(_e)->prev = (_e); \
|
||||
|
||||
/*
|
||||
** Return non-zero if the given circular list "_l" is empty, zero if the
|
||||
** circular list is not empty
|
||||
*/
|
||||
#define CMT_CLIST_IS_EMPTY(_l) \
|
||||
((_l)->next == (_l))
|
||||
|
||||
/*
|
||||
** Initialize a circular list
|
||||
*/
|
||||
#define CMT_INIT_CLIST(_l) \
|
||||
(_l)->next = (_l); \
|
||||
(_l)->prev = (_l); \
|
||||
|
||||
#define CMT_INIT_STATIC_CLIST(_l) \
|
||||
{(_l), (_l)}
|
||||
|
||||
#endif /* cmtclist_h___ */
|
||||
2264
mozilla/security/psm/lib/client/cmtcmn.h
Normal file
2264
mozilla/security/psm/lib/client/cmtcmn.h
Normal file
File diff suppressed because it is too large
Load Diff
480
mozilla/security/psm/lib/client/cmtevent.c
Normal file
480
mozilla/security/psm/lib/client/cmtevent.c
Normal file
@@ -0,0 +1,480 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include <string.h>
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
/* Typedefs */
|
||||
typedef void (*taskcompleted_handler_fn)(CMUint32 resourceID, CMUint32 numReqProcessed, CMUint32 resultCode, void* data);
|
||||
|
||||
CMTStatus CMT_SetUIHandlerCallback(PCMT_CONTROL control,
|
||||
uiHandlerCallback_fn f, void *data)
|
||||
{
|
||||
return CMT_RegisterEventHandler(control, SSM_UI_EVENT, 0,
|
||||
(void_fun)f, data);
|
||||
}
|
||||
|
||||
void CMT_SetFilePathPromptCallback(PCMT_CONTROL control,
|
||||
filePathPromptCallback_fn f, void* arg)
|
||||
{
|
||||
control->userFuncs.promptFilePath = f;
|
||||
control->userFuncs.filePromptArg = arg;
|
||||
}
|
||||
|
||||
void CMT_SetPromptCallback(PCMT_CONTROL control,
|
||||
promptCallback_fn f, void *arg)
|
||||
{
|
||||
control->userFuncs.promptCallback = f;
|
||||
control->userFuncs.promptArg = arg;
|
||||
}
|
||||
|
||||
void CMT_SetSavePrefsCallback(PCMT_CONTROL control, savePrefsCallback_fn f)
|
||||
{
|
||||
control->userFuncs.savePrefs = f;
|
||||
}
|
||||
|
||||
CMTStatus CMT_RegisterEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID, void_fun handler,
|
||||
void* data)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
/* This is the first connection */
|
||||
if (control->cmtEventHandlers == NULL) {
|
||||
control->cmtEventHandlers = ptr =
|
||||
(PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (!ptr) {
|
||||
goto loser;
|
||||
}
|
||||
} else {
|
||||
/* Look for another event handler of the same type. Make sure the
|
||||
event handler with a rsrcid of 0 is farther down the list so
|
||||
that it doesn't get chosen when there's an event handler for
|
||||
a specific rsrcid.
|
||||
*/
|
||||
for (ptr=control->cmtEventHandlers; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->type == type && resourceID != 0) {
|
||||
/* So we've got an event handler that wants to over-ride
|
||||
an existing event handler. We'll put it before the one
|
||||
that's already here.
|
||||
*/
|
||||
if (ptr->previous == NULL) {
|
||||
/* We're going to insert at the front of the list*/
|
||||
control->cmtEventHandlers = ptr->previous =
|
||||
(PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (ptr->previous == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
ptr->previous->next = ptr;
|
||||
ptr = control->cmtEventHandlers;
|
||||
} else {
|
||||
/* We want to insert in the middle of the list */
|
||||
PCMT_EVENT tmpEvent;
|
||||
|
||||
tmpEvent = (PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (tmpEvent == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
tmpEvent->previous = ptr->previous;
|
||||
ptr->previous->next = tmpEvent;
|
||||
tmpEvent->next = ptr;
|
||||
ptr->previous = tmpEvent;
|
||||
ptr = tmpEvent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ptr->next == NULL) break;
|
||||
}
|
||||
if (ptr == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
if (ptr->next == NULL) {
|
||||
/* We're adding the event handler at the end of the list. */
|
||||
ptr->next = (PCMT_EVENT)calloc(sizeof(CMT_EVENT), 1);
|
||||
if (!ptr->next) {
|
||||
goto loser;
|
||||
}
|
||||
/* Fix up the pointers */
|
||||
ptr->next->previous = ptr;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill in the data */
|
||||
ptr->type = type;
|
||||
ptr->resourceID = resourceID;
|
||||
ptr->handler = handler;
|
||||
ptr->data = data;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_UnregisterEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID)
|
||||
{
|
||||
PCMT_EVENT ptr, pptr = NULL;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL;
|
||||
pptr = ptr, ptr = ptr->next) {
|
||||
if ((ptr->type == type) && (ptr->resourceID == resourceID)) {
|
||||
if (pptr == NULL) {
|
||||
/* node is at head */
|
||||
control->cmtEventHandlers = ptr->next;
|
||||
if (control->cmtEventHandlers != NULL) {
|
||||
control->cmtEventHandlers->previous = NULL;
|
||||
}
|
||||
free(ptr);
|
||||
return CMTSuccess;
|
||||
}
|
||||
/* node is elsewhere */
|
||||
pptr->next = ptr->next;
|
||||
if (ptr->next != NULL) {
|
||||
ptr->next->previous = pptr;
|
||||
}
|
||||
free(ptr);
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
PCMT_EVENT CMT_GetEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL; ptr = ptr->next) {
|
||||
if ((ptr->type == type) && ((ptr->resourceID == resourceID) ||
|
||||
!ptr->resourceID)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PCMT_EVENT CMT_GetFirstEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL; ptr = ptr->next) {
|
||||
if ((ptr->type == type) && ((ptr->resourceID == resourceID) ||
|
||||
!ptr->resourceID)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PCMT_EVENT CMT_GetNextEventHandler(PCMT_CONTROL control, PCMT_EVENT e)
|
||||
{
|
||||
PCMT_EVENT ptr;
|
||||
|
||||
for (ptr = control->cmtEventHandlers; ptr != NULL || ptr == e;
|
||||
ptr = ptr->next) {
|
||||
}
|
||||
|
||||
for (; ptr != NULL; ptr = ptr->next) {
|
||||
if ((ptr->type == e->type) && ((ptr->resourceID == e->resourceID) ||
|
||||
!ptr->resourceID)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CMT_ProcessEvent(PCMT_CONTROL cm_control)
|
||||
{
|
||||
CMTSocket sock;
|
||||
CMTItem eventData={ 0, NULL, 0 };
|
||||
|
||||
/* Get the control socket */
|
||||
sock = cm_control->sock;
|
||||
|
||||
/* Acquire a lock on the control connection */
|
||||
CMT_LOCK(cm_control->mutex);
|
||||
/* Do another select here to be sure
|
||||
that the socket is readable */
|
||||
if (cm_control->sockFuncs.select(&sock, 1, 1) != sock) {
|
||||
/* There's no event. */
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Read the event */
|
||||
if (CMT_ReceiveMessage(cm_control, &eventData) == CMTFailure) {
|
||||
goto done;
|
||||
}
|
||||
CMT_UNLOCK(cm_control->mutex);
|
||||
/* Dispatch the event */
|
||||
CMT_DispatchEvent(cm_control, &eventData);
|
||||
return;
|
||||
done:
|
||||
/* Release the lock on the control connection */
|
||||
CMT_UNLOCK(cm_control->mutex);
|
||||
}
|
||||
|
||||
void CMT_EventLoop(PCMT_CONTROL cm_control)
|
||||
{
|
||||
CMTSocket sock;
|
||||
|
||||
/* Get the control socket */
|
||||
sock = cm_control->sock;
|
||||
CMT_ReferenceControlConnection(cm_control);
|
||||
/* Select on the control socket to see if it's readable */
|
||||
while(cm_control->sockFuncs.select(&sock, 1, 0)) {
|
||||
CMT_ProcessEvent(cm_control);
|
||||
}
|
||||
CMT_CloseControlConnection(cm_control);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
CMT_PromptUser(PCMT_CONTROL cm_control, CMTItem *eventData)
|
||||
{
|
||||
char *promptReply = NULL;
|
||||
CMTItem response={ 0, NULL, 0 };
|
||||
PromptRequest request;
|
||||
PromptReply reply;
|
||||
void * clientContext;
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(PromptRequestTemplate, &request, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Copy the client context to a pointer */
|
||||
clientContext = CMT_CopyItemToPtr(request.clientContext);
|
||||
|
||||
if (cm_control->userFuncs.promptCallback == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
promptReply =
|
||||
cm_control->userFuncs.promptCallback(cm_control->userFuncs.promptArg,
|
||||
request.prompt, clientContext, 1);
|
||||
|
||||
response.type = SSM_EVENT_MESSAGE | SSM_PROMPT_EVENT;
|
||||
if (!promptReply) {
|
||||
/* the user canceled the prompt or other errors occurred */
|
||||
reply.cancel = CM_TRUE;
|
||||
}
|
||||
else {
|
||||
/* note that this includes an empty string (zero length) password */
|
||||
reply.cancel = CM_FALSE;
|
||||
}
|
||||
reply.resID = request.resID;
|
||||
reply.promptReply = promptReply;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(PromptReplyTemplate, &response, &reply) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
CMT_TransmitMessage(cm_control, &response);
|
||||
loser:
|
||||
if (promptReply != NULL) {
|
||||
cm_control->userFuncs.userFree(promptReply);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CMT_GetFilePath(PCMT_CONTROL cm_control, CMTItem * eventData)
|
||||
{
|
||||
char *fileName=NULL;
|
||||
CMTItem response = { 0, NULL, 0 };
|
||||
FilePathRequest request;
|
||||
FilePathReply reply;
|
||||
|
||||
/* Decode the request */
|
||||
if (CMT_DecodeMessage(FilePathRequestTemplate, &request, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (cm_control->userFuncs.promptFilePath == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
fileName =
|
||||
cm_control->userFuncs.promptFilePath(cm_control->userFuncs.filePromptArg,
|
||||
request.prompt, request.fileRegEx,
|
||||
request.getExistingFile);
|
||||
|
||||
response.type = SSM_EVENT_MESSAGE | SSM_FILE_PATH_EVENT;
|
||||
reply.resID = request.resID;
|
||||
reply.filePath = fileName;
|
||||
|
||||
/* Encode the reply */
|
||||
if (CMT_EncodeMessage(FilePathReplyTemplate, &response, &reply) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
CMT_TransmitMessage(cm_control, &response);
|
||||
cm_control->userFuncs.userFree(fileName);
|
||||
loser:
|
||||
return;
|
||||
}
|
||||
|
||||
void CMT_SavePrefs(PCMT_CONTROL cm_control, CMTItem* eventData)
|
||||
{
|
||||
SetPrefListMessage request;
|
||||
int i;
|
||||
|
||||
/* decode the request */
|
||||
if (CMT_DecodeMessage(SetPrefListMessageTemplate, &request, eventData) !=
|
||||
CMTSuccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cm_control->userFuncs.savePrefs == NULL) {
|
||||
/* callback was not registered: bail */
|
||||
return;
|
||||
}
|
||||
cm_control->userFuncs.savePrefs(request.length,
|
||||
(CMTSetPrefElement*)request.list);
|
||||
|
||||
for (i = 0; i < request.length; i++) {
|
||||
if (request.list[i].key != NULL) {
|
||||
free(request.list[i].key);
|
||||
}
|
||||
if (request.list[i].value != NULL) {
|
||||
free(request.list[i].value);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CMT_DispatchEvent(PCMT_CONTROL cm_control, CMTItem * eventData)
|
||||
{
|
||||
CMUint32 eventType;
|
||||
CMTItem msgCopy;
|
||||
|
||||
/* Init the msgCopy */
|
||||
msgCopy.data = 0;
|
||||
|
||||
/* Get the event type */
|
||||
if ((eventData->type & SSM_CATEGORY_MASK) != SSM_EVENT_MESSAGE) {
|
||||
/* Somehow there was a message on the socket that was not
|
||||
* an event message. Dropping it on the floor.
|
||||
*/
|
||||
goto loser;
|
||||
}
|
||||
eventType = (eventData->type & SSM_TYPE_MASK);
|
||||
|
||||
/* We must now dispatch the event based on it's type */
|
||||
switch (eventType) {
|
||||
case SSM_UI_EVENT:
|
||||
{
|
||||
PCMT_EVENT p;
|
||||
UIEvent event;
|
||||
void * clientContext = NULL;
|
||||
|
||||
/* Copy the message to allow a second try with the old format */
|
||||
msgCopy.len = eventData->len;
|
||||
msgCopy.data = calloc(msgCopy.len, 1);
|
||||
if (msgCopy.data) {
|
||||
memcpy(msgCopy.data, eventData->data, eventData->len);
|
||||
}
|
||||
|
||||
/* Get the event data first */
|
||||
if (CMT_DecodeMessage(UIEventTemplate, &event, eventData) != CMTSuccess) {
|
||||
/* Attempt to decode using the old format. Modal is True */
|
||||
if (!msgCopy.data ||
|
||||
CMT_DecodeMessage(OldUIEventTemplate, &event, &msgCopy) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set default modal value */
|
||||
event.isModal = CM_TRUE;
|
||||
}
|
||||
|
||||
/* Convert the client context to a pointer */
|
||||
clientContext = CMT_CopyItemToPtr(event.clientContext);
|
||||
|
||||
/* Call any handlers for this event */
|
||||
p = CMT_GetEventHandler(cm_control, eventType, event.resourceID);
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
(*(uiHandlerCallback_fn)(p->handler))(event.resourceID,
|
||||
clientContext, event.width,
|
||||
event.height, event.isModal, event.url,
|
||||
p->data);
|
||||
break;
|
||||
}
|
||||
|
||||
case SSM_TASK_COMPLETED_EVENT:
|
||||
{
|
||||
PCMT_EVENT p;
|
||||
TaskCompletedEvent event;
|
||||
|
||||
/* Get the event data */
|
||||
if (CMT_DecodeMessage(TaskCompletedEventTemplate, &event, eventData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Call handler for this event */
|
||||
p = CMT_GetEventHandler(cm_control, eventType, event.resourceID);
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
(*(taskcompleted_handler_fn)(p->handler))(event.resourceID,
|
||||
event.numTasks,
|
||||
event.result, p->data);
|
||||
break;
|
||||
}
|
||||
case SSM_AUTH_EVENT:
|
||||
CMT_ServicePasswordRequest(cm_control, eventData);
|
||||
break;
|
||||
case SSM_FILE_PATH_EVENT:
|
||||
CMT_GetFilePath(cm_control, eventData);
|
||||
break;
|
||||
case SSM_PROMPT_EVENT:
|
||||
CMT_PromptUser(cm_control, eventData);
|
||||
break;
|
||||
case SSM_SAVE_PREF_EVENT:
|
||||
CMT_SavePrefs(cm_control, eventData);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
loser:
|
||||
free(eventData->data);
|
||||
free(msgCopy.data);
|
||||
return;
|
||||
}
|
||||
|
||||
216
mozilla/security/psm/lib/client/cmthash.c
Normal file
216
mozilla/security/psm/lib/client/cmthash.c
Normal file
@@ -0,0 +1,216 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#include "string.h"
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
|
||||
CMTStatus CMT_HashCreate(PCMT_CONTROL control, CMUint32 algID,
|
||||
CMUint32 * connID)
|
||||
{
|
||||
CMTItem message;
|
||||
SingleNumMessage request;
|
||||
DataConnectionReply reply;
|
||||
|
||||
/* Check passed in parameters */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.value = algID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_HASH_STREAM;
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the response */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_HASH_STREAM)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
CMTSocket sock;
|
||||
|
||||
sock = control->sockFuncs.socket(0);
|
||||
if(sock == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
/* Send the hello message */
|
||||
control->sockFuncs.send(sock, control->nonce.data, control->nonce.len);
|
||||
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the connection ID */
|
||||
*connID = reply.connID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
*connID = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_Destroy(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the cotext implementation data */
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_Begin(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_Update(PCMT_CONTROL control, CMUint32 connectionID, const unsigned char * buf, CMUint32 len)
|
||||
{
|
||||
CMTSocket sock;
|
||||
CMUint32 sent;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !buf) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the data socket */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Write the data to the socket */
|
||||
sent = CMT_WriteThisMany(control, sock, (void*)buf, len);
|
||||
if (sent != len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_HASH_End(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
unsigned char * result, CMUint32 * resultlen,
|
||||
CMUint32 maxLen)
|
||||
{
|
||||
CMTItem hash = { 0, NULL, 0 };
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !result || !resultlen) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Close the connection */
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the context info */
|
||||
if (CMT_GetStringAttribute(control, connectionID, SSM_FID_HASHCONN_RESULT,
|
||||
&hash) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
if (!hash.data) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*resultlen = hash.len;
|
||||
if (hash.len > maxLen) {
|
||||
memcpy(result, hash.data, maxLen);
|
||||
} else {
|
||||
memcpy(result, hash.data, hash.len);
|
||||
}
|
||||
|
||||
if (hash.data) {
|
||||
free(hash.data);
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (hash.data) {
|
||||
free(hash.data);
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
56
mozilla/security/psm/lib/client/cmtimpl.h
Normal file
56
mozilla/security/psm/lib/client/cmtimpl.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __CMTIMPL_H_
|
||||
#define __CMTIMPL_H_
|
||||
|
||||
typedef unsigned long CMT_HANDLE;
|
||||
|
||||
struct _CMTControl {
|
||||
CMT_HANDLE channelID;
|
||||
int socketID;
|
||||
CMTStatus (* cmtEventCallback)(struct _CMTControl * control,
|
||||
CMTItem * event, void * arg);
|
||||
void * cmtEventCallbackArg;
|
||||
struct _CMTData * cmtDataConnection;
|
||||
} _CMTControl;
|
||||
|
||||
|
||||
|
||||
struct _CMTData {
|
||||
CMT_HANDLE channelID;
|
||||
int socketID;
|
||||
struct _CMTData * next;
|
||||
struct _CMTData * previous;
|
||||
};
|
||||
|
||||
#endif /*__CMTIMPL_H_*/
|
||||
484
mozilla/security/psm/lib/client/cmtinit.c
Normal file
484
mozilla/security/psm/lib/client/cmtinit.c
Normal file
@@ -0,0 +1,484 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/tcp.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include <Events.h> // for WaitNextEvent
|
||||
#else /* Windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#include <direct.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "messages.h"
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define DIRECTORY_SEPARATOR '/'
|
||||
#elif defined WIN32
|
||||
#define DIRECTORY_SEPARATOR '\\'
|
||||
#elif defined XP_MAC
|
||||
#define DIRECTORY_SEPARATOR ':'
|
||||
#endif
|
||||
|
||||
/* Local defines */
|
||||
#define CARTMAN_PORT 11111
|
||||
#define MAX_PATH_LEN 256
|
||||
|
||||
/* write to the cmnav.log */
|
||||
#if 0
|
||||
#define LOG(x); do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, x); fclose(f); } } while(0);
|
||||
#define LOG_S(x); do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, "%s", x); fclose(f); } } while(0);
|
||||
#define ASSERT(x); if (!(x)) { LOG("ASSERT:"); LOG(#x); LOG("\n"); exit(-1); }
|
||||
#else
|
||||
#define LOG(x); ;
|
||||
#define LOG_S(x); ;
|
||||
#define ASSERT(x); ;
|
||||
#endif
|
||||
|
||||
static char*
|
||||
getCurrWorkDir(char *buf, int maxLen)
|
||||
{
|
||||
#if defined WIN32
|
||||
return _getcwd(buf, maxLen);
|
||||
#elif defined XP_UNIX
|
||||
return getcwd(buf, maxLen);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
setWorkingDir(char *path)
|
||||
{
|
||||
#if defined WIN32
|
||||
_chdir(path);
|
||||
#elif defined XP_UNIX
|
||||
chdir(path);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
launch_psm(char *executable)
|
||||
{
|
||||
char command[MAX_PATH_LEN];
|
||||
#ifdef WIN32
|
||||
STARTUPINFO sui;
|
||||
PROCESS_INFORMATION pi;
|
||||
UNALIGNED long *posfhnd;
|
||||
int i;
|
||||
char *posfile;
|
||||
|
||||
sprintf(command,"%s > psmlog", executable);
|
||||
ZeroMemory( &sui, sizeof(sui) );
|
||||
sui.cb = sizeof(sui);
|
||||
sui.cbReserved2 = (WORD)(sizeof( int ) + (3 * (sizeof( char ) +
|
||||
sizeof( long ))));
|
||||
sui.lpReserved2 = calloc( sui.cbReserved2, 1 );
|
||||
*((UNALIGNED int *)(sui.lpReserved2)) = 3;
|
||||
posfile = (char *)(sui.lpReserved2 + sizeof( int ));
|
||||
posfhnd = (UNALIGNED long *)(sui.lpReserved2 + sizeof( int ) +
|
||||
(3 * sizeof( char )));
|
||||
|
||||
for ( i = 0, posfile = (char *)(sui.lpReserved2 + sizeof( int )),
|
||||
posfhnd = (UNALIGNED long *)(sui.lpReserved2 + sizeof( int ) + (3 * sizeof( char ))) ;
|
||||
i < 3 ; i++, posfile++, posfhnd++ ) {
|
||||
|
||||
*posfile = 0;
|
||||
*posfhnd = (long)INVALID_HANDLE_VALUE;
|
||||
}
|
||||
/* Now, fire up PSM */
|
||||
if (!CreateProcess(NULL, command, NULL, NULL, TRUE, DETACHED_PROCESS,
|
||||
NULL, NULL, &sui, &pi)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
#elif defined XP_UNIX
|
||||
sprintf(command,"./%s &", executable);
|
||||
if (system(command) == -1) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
#else
|
||||
return CMTFailure;
|
||||
#endif
|
||||
}
|
||||
|
||||
PCMT_CONTROL CMT_EstablishControlConnection(char *inPath,
|
||||
CMT_SocketFuncs *sockFuncs,
|
||||
CMT_MUTEX *mutex)
|
||||
{
|
||||
PCMT_CONTROL control;
|
||||
char *executable;
|
||||
char *newWorkingDir;
|
||||
char oldWorkingDir[MAX_PATH_LEN];
|
||||
int i;
|
||||
char *path = NULL;
|
||||
size_t stringLen;
|
||||
|
||||
/* On the Mac, we do special magic in the Seamonkey PSM component, so
|
||||
if PSM isn't launched by the time we reach this point, we're not doing well. */
|
||||
#ifndef XP_MAC
|
||||
|
||||
struct stat stbuf;
|
||||
|
||||
/*
|
||||
* Create our own copy of path.
|
||||
* I'd like to do a straight strdup here, but that caused problems
|
||||
* for https.
|
||||
*/
|
||||
stringLen = strlen(inPath);
|
||||
|
||||
path = (char*) malloc(stringLen+1);
|
||||
memcpy(path, inPath, stringLen);
|
||||
path[stringLen] = '\0';
|
||||
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control != NULL) {
|
||||
return control;
|
||||
}
|
||||
/*
|
||||
* We have to try to launch it now, so it better be a valid
|
||||
* path.
|
||||
*/
|
||||
if (stat(path, &stbuf) == -1) {
|
||||
goto loser;
|
||||
}
|
||||
/*
|
||||
* Now we have to parse the path and launch the psm server.
|
||||
*/
|
||||
executable = strrchr(path, DIRECTORY_SEPARATOR);
|
||||
if (executable != NULL) {
|
||||
*executable = '\0';
|
||||
executable ++;
|
||||
newWorkingDir = path;
|
||||
} else {
|
||||
executable = path;
|
||||
newWorkingDir = NULL;
|
||||
}
|
||||
if (getCurrWorkDir(oldWorkingDir, MAX_PATH_LEN) == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
setWorkingDir(newWorkingDir);
|
||||
if (launch_psm(executable) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
setWorkingDir(oldWorkingDir);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Now try to connect to the psm server. We will try to connect
|
||||
* a maximum of 30 times and then give up.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
for (i=0; i<30; i++) {
|
||||
Sleep(1000);
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#elif defined XP_UNIX
|
||||
i = 0;
|
||||
while (i<1000) {
|
||||
i += sleep(10);
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#elif defined(XP_MAC)
|
||||
for (i=0; i<30; i++)
|
||||
{
|
||||
EventRecord theEvent;
|
||||
WaitNextEvent(0, &theEvent, 30, NULL);
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
/*
|
||||
* Figure out how to sleep for a while first
|
||||
*/
|
||||
for (i=0; i<30; i++) {
|
||||
control = CMT_ControlConnect(mutex, sockFuncs);
|
||||
if (control!= NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (control == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
if (path) {
|
||||
free (path);
|
||||
}
|
||||
return control;
|
||||
loser:
|
||||
if (control != NULL) {
|
||||
CMT_CloseControlConnection(control);
|
||||
}
|
||||
if (path) {
|
||||
free(path);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
PCMT_CONTROL CMT_ControlConnect(CMT_MUTEX *mutex, CMT_SocketFuncs *sockFuncs)
|
||||
{
|
||||
PCMT_CONTROL control = NULL;
|
||||
CMTSocket sock=NULL;
|
||||
#ifdef XP_UNIX
|
||||
int unixSock = 1;
|
||||
char path[20];
|
||||
#else
|
||||
int unixSock = 0;
|
||||
char *path=NULL;
|
||||
#endif
|
||||
|
||||
if (sockFuncs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#ifdef XP_UNIX
|
||||
sprintf(path, "/tmp/.nsmc-%d", (int)geteuid());
|
||||
#endif
|
||||
|
||||
sock = sockFuncs->socket(unixSock);
|
||||
if (sock == NULL) {
|
||||
LOG("Could not create a socket to connect to Control Connection.\n");
|
||||
goto loser;
|
||||
}
|
||||
/* Connect to the psm process */
|
||||
if (sockFuncs->connect(sock, CARTMAN_PORT, path)) {
|
||||
LOG("Could not connect to Cartman\n");
|
||||
goto loser;
|
||||
}
|
||||
|
||||
#ifdef XP_UNIX
|
||||
if (sockFuncs->verify(sock) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
#endif
|
||||
|
||||
LOG("Connected to Cartman\n");
|
||||
|
||||
/* fill in the CMTControl struct */
|
||||
control = (PCMT_CONTROL)calloc(sizeof(CMT_CONTROL), 1);
|
||||
if (control == NULL ) {
|
||||
goto loser;
|
||||
}
|
||||
control->sock = sock;
|
||||
if (mutex != NULL) {
|
||||
control->mutex = (CMT_MUTEX*)calloc(sizeof(CMT_MUTEX),1);
|
||||
if (control->mutex == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
*control->mutex = *mutex;
|
||||
}
|
||||
memcpy(&control->sockFuncs, sockFuncs, sizeof(CMT_SocketFuncs));
|
||||
control->refCount = 1;
|
||||
goto done;
|
||||
|
||||
loser:
|
||||
if (control != NULL) {
|
||||
free(control);
|
||||
}
|
||||
if (sock != NULL) {
|
||||
sockFuncs->close(sock);
|
||||
}
|
||||
control = NULL;
|
||||
|
||||
done:
|
||||
return control;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CloseControlConnection(PCMT_CONTROL control)
|
||||
{
|
||||
/* XXX Don't know what to do here yet */
|
||||
if (control != NULL) {
|
||||
CMInt32 refCount;
|
||||
CMT_LOCK(control->mutex);
|
||||
control->refCount--;
|
||||
refCount = control->refCount;
|
||||
CMT_UNLOCK(control->mutex);
|
||||
if (refCount <= 0) {
|
||||
if (control->mutex != NULL) {
|
||||
free (control->mutex);
|
||||
}
|
||||
control->sockFuncs.close(control->sock);
|
||||
free(control);
|
||||
}
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_Hello(PCMT_CONTROL control, CMUint32 version, char* profile,
|
||||
char* profileDir)
|
||||
{
|
||||
CMTItem message;
|
||||
PCMT_EVENT eventHandler;
|
||||
CMBool doesUI;
|
||||
HelloRequest request;
|
||||
HelloReply reply;
|
||||
|
||||
/* Check the passed parameters */
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
if (!profile) {
|
||||
return CMTFailure;
|
||||
}
|
||||
if (!profileDir) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
/* Create the hello message */
|
||||
eventHandler = CMT_GetEventHandler(control, SSM_UI_EVENT, 0);
|
||||
doesUI = (eventHandler == NULL) ? CM_FALSE : CM_TRUE;
|
||||
|
||||
/* Setup the request struct */
|
||||
request.version = version;
|
||||
request.policy = 0; /* no more policy */
|
||||
request.doesUI = doesUI;
|
||||
request.profile = profile;
|
||||
request.profileDir = profileDir;
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_HELLO_MESSAGE;
|
||||
|
||||
if (CMT_EncodeMessage(HelloRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_HELLO_MESSAGE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(HelloReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Successful response */
|
||||
if (reply.result == 0) {
|
||||
/* Save the nonce value */
|
||||
control->sessionID = reply.sessionID;
|
||||
control->protocolVersion = reply.version;
|
||||
control->port = reply.httpPort;
|
||||
control->nonce = reply.nonce;
|
||||
control->policy = reply.policy;
|
||||
control->serverStringVersion = reply.stringVersion;
|
||||
|
||||
/* XXX Free the messages */
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
/* XXX Free the messages */
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PassAllPrefs(PCMT_CONTROL control, int num,
|
||||
CMTSetPrefElement* list)
|
||||
{
|
||||
SetPrefListMessage request;
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
|
||||
if ((control == NULL) || (list == NULL)) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
/* pack the request */
|
||||
request.length = num;
|
||||
request.list = (SetPrefElement*)list;
|
||||
|
||||
if (CMT_EncodeMessage(SetPrefListMessageTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PREF_ACTION;
|
||||
|
||||
/* send the message */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PREF_ACTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* don't really need to check the return value */
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
char* CMT_GetServerStringVersion(PCMT_CONTROL control)
|
||||
{
|
||||
if (control == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return control->serverStringVersion;
|
||||
}
|
||||
556
mozilla/security/psm/lib/client/cmtjs.c
Normal file
556
mozilla/security/psm/lib/client/cmtjs.c
Normal file
@@ -0,0 +1,556 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "cmtutils.h"
|
||||
#include "cmtjs.h"
|
||||
#include "messages.h"
|
||||
|
||||
CMTStatus
|
||||
CMT_GenerateKeyPair(PCMT_CONTROL control, CMUint32 keyGenContext,
|
||||
CMUint32 mechType, CMTItem *param, CMUint32 keySize,
|
||||
CMUint32 *keyPairId)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
KeyPairGenRequest request = {0, 0, 0, {0, NULL, 0}};
|
||||
SingleNumMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.keyGenCtxtID = keyGenContext;
|
||||
request.genMechanism = mechType;
|
||||
if (param) {
|
||||
request.params = *param;
|
||||
}
|
||||
request.keySize = keySize;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(KeyPairGenRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_CREATE_KEY_PAIR;
|
||||
|
||||
/* Send the message and get the response */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_CREATE_KEY_PAIR)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*keyPairId = reply.value;
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
*keyPairId = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus
|
||||
CMT_CreateNewCRMFRequest(PCMT_CONTROL control, CMUint32 keyPairID,
|
||||
SSMKeyGenType keyGenType, CMUint32 *reqID)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleNumMessage request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.value = keyPairID;
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION |
|
||||
SSM_CREATE_CRMF_REQ;
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_CREATE_CRMF_REQ)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*reqID = reply.value;
|
||||
|
||||
rv = CMT_SetNumericAttribute(control, *reqID, SSM_FID_CRMFREQ_KEY_TYPE,
|
||||
keyGenType);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_EncodeCRMFRequest(PCMT_CONTROL control, CMUint32 *crmfReqID,
|
||||
CMUint32 numRequests, char ** der)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
EncodeCRMFReqRequest request;
|
||||
SingleItemMessage reply;
|
||||
|
||||
if (!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.numRequests = numRequests;
|
||||
request.reqIDs = (long *) crmfReqID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(EncodeCRMFReqRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION | SSM_DER_ENCODE_REQ;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_DER_ENCODE_REQ)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* XXX Should this be a string? Decode the message */
|
||||
if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*der = (char *) reply.item.data;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_ProcessCMMFResponse(PCMT_CONTROL control, char *nickname,
|
||||
char *certRepString, CMBool doBackup,
|
||||
void *clientContext)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CMMFCertResponseRequest request;
|
||||
|
||||
if(!control) {
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
request.nickname = nickname;
|
||||
request.base64Der = certRepString;
|
||||
request.doBackup = doBackup;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CMMFCertResponseRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION | SSM_PROCESS_CMMF_RESP;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_PROCESS_CMMF_RESP)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_CreateResource(PCMT_CONTROL control, SSMResourceType resType,
|
||||
CMTItem *params, CMUint32 *rsrcId, CMUint32 *errorCode)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CreateResourceRequest request = {0, {0, NULL, 0}};
|
||||
CreateResourceReply reply;
|
||||
|
||||
request.type = resType;
|
||||
if (params) {
|
||||
request.params = *params;
|
||||
}
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CreateResourceRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_CREATE_RESOURCE;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_CREATE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
if (CMT_DecodeMessage(CreateResourceReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*rsrcId = reply.resID;
|
||||
*errorCode = reply.result;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_SignText(PCMT_CONTROL control, CMUint32 resID, char* stringToSign, char* hostName, char* caOption, CMInt32 numCAs, char** caNames)
|
||||
{
|
||||
CMTItem message;
|
||||
SignTextRequest request;
|
||||
|
||||
|
||||
/* So some basic parameter checking */
|
||||
if (!control || !stringToSign) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resID;
|
||||
request.stringToSign = stringToSign;
|
||||
request.hostName = hostName;
|
||||
request.caOption = caOption;
|
||||
request.numCAs = numCAs;
|
||||
request.caNames = caNames;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(SignTextRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_FORMSIGN_ACTION | SSM_SIGN_TEXT;
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_FORMSIGN_ACTION | SSM_SIGN_TEXT)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_ProcessChallengeResponse(PCMT_CONTROL control, char *challengeString,
|
||||
char **responseString)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleStringMessage request;
|
||||
SingleStringMessage reply;
|
||||
|
||||
/* Set the request */
|
||||
request.string = challengeString;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleStringMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_CRMF_ACTION | SSM_CHALLENGE;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CRMF_ACTION | SSM_CHALLENGE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleStringMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*responseString = reply.string;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_FinishGeneratingKeys(PCMT_CONTROL control, CMUint32 keyGenContext)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleNumMessage request;
|
||||
|
||||
/* Set up the request */
|
||||
request.value = keyGenContext;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_FINISH_KEY_GEN;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the reply */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_FINISH_KEY_GEN)) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_GetLocalizedString(PCMT_CONTROL control,
|
||||
SSMLocalizedString whichString,
|
||||
char **localizedString)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleNumMessage request;
|
||||
GetLocalizedTextReply reply;
|
||||
|
||||
/* Set up the request */
|
||||
request.value = whichString;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_LOCALIZED_TEXT;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_LOCALIZED_TEXT)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(GetLocalizedTextReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (reply.whichString != whichString) {
|
||||
goto loser;
|
||||
}
|
||||
*localizedString = reply.localizedString;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
*localizedString = NULL;
|
||||
return rv;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_AddNewModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
char *libraryPath,
|
||||
unsigned long pubMechFlags,
|
||||
unsigned long pubCipherFlags)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
AddNewSecurityModuleRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Set up the request */
|
||||
request.moduleName = moduleName;
|
||||
request.libraryPath = libraryPath;
|
||||
request.pubMechFlags = pubMechFlags;
|
||||
request.pubCipherFlags = pubCipherFlags;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(AddNewSecurityModuleRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_ADD_NEW_MODULE;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_ADD_NEW_MODULE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the response */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return (CMTStatus) reply.value;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_DeleteModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
int *moduleType)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
SingleStringMessage request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Set up the request */
|
||||
request.string = moduleName;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleStringMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_DEL_MODULE;
|
||||
|
||||
/* Send the message */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION | SSM_DEL_MODULE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*moduleType = reply.value;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_LogoutAllTokens(PCMT_CONTROL control)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION | SSM_LOGOUT_ALL;
|
||||
message.data = NULL;
|
||||
message.len = 0;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) {
|
||||
return rv;
|
||||
}
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION |
|
||||
SSM_LOGOUT_ALL)) {
|
||||
return CMTFailure;
|
||||
}
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetSSLCapabilities(PCMT_CONTROL control, CMInt32 *capabilites)
|
||||
{
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
|
||||
message.type = (SSM_REQUEST_MESSAGE | SSM_PKCS11_ACTION |
|
||||
SSM_ENABLED_CIPHERS);
|
||||
message.data = NULL;
|
||||
message.len = 0;
|
||||
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_PKCS11_ACTION |
|
||||
SSM_ENABLED_CIPHERS)) {
|
||||
goto loser;
|
||||
}
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply,
|
||||
&message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*capabilites = reply.value;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
555
mozilla/security/psm/lib/client/cmtjs.h
Normal file
555
mozilla/security/psm/lib/client/cmtjs.h
Normal file
@@ -0,0 +1,555 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef _CMTJS_H_
|
||||
#define _CMTJS_H_
|
||||
#include "cmtcmn.h"
|
||||
#include "ssmdefs.h"
|
||||
#include "rsrcids.h"
|
||||
/*
|
||||
* Define some constants.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These defines are used in conjuction with the function
|
||||
* CMT_AddNewModule.
|
||||
*/
|
||||
#define PUBLIC_MECH_RSA_FLAG 0x00000001ul
|
||||
#define PUBLIC_MECH_DSA_FLAG 0x00000002ul
|
||||
#define PUBLIC_MECH_RC2_FLAG 0x00000004ul
|
||||
#define PUBLIC_MECH_RC4_FLAG 0x00000008ul
|
||||
#define PUBLIC_MECH_DES_FLAG 0x00000010ul
|
||||
#define PUBLIC_MECH_DH_FLAG 0x00000020ul
|
||||
#define PUBLIC_MECH_FORTEZZA_FLAG 0x00000040ul
|
||||
#define PUBLIC_MECH_RC5_FLAG 0x00000080ul
|
||||
#define PUBLIC_MECH_SHA1_FLAG 0x00000100ul
|
||||
#define PUBLIC_MECH_MD5_FLAG 0x00000200ul
|
||||
#define PUBLIC_MECH_MD2_FLAG 0x00000400ul
|
||||
|
||||
#define PUBLIC_MECH_RANDOM_FLAG 0x08000000ul
|
||||
#define PUBLIC_MECH_FRIENDLY_FLAG 0x10000000ul
|
||||
#define PUBLIC_OWN_PW_DEFAULTS 0X20000000ul
|
||||
#define PUBLIC_DISABLE_FLAG 0x40000000ul
|
||||
|
||||
|
||||
/*
|
||||
* This is the lone supported constant for the Cipher flag
|
||||
* for CMT_AddNewModule
|
||||
*/
|
||||
#define PUBLIC_CIPHER_FORTEZZA_FLAG 0x00000001ul
|
||||
|
||||
CMT_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_GenerateKeyPair
|
||||
* -----------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* keyGenContext
|
||||
* The Resource ID of a key gen context to use for creating the
|
||||
* key pair.
|
||||
* mechType
|
||||
* A PKCS11 mechanism used to generate the key pair. Valid values are:
|
||||
* CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000
|
||||
* CKM_DSA_KEY_PAIR_GEN 0x00000010
|
||||
* The definition of these values can be found at
|
||||
* http://www.rsa.com/rsalabs/pubs/pkcs11.html
|
||||
* The psm module currently supports v2.01 of PKCS11
|
||||
* params
|
||||
* This parameter will be used to pass parameters to the Key Pair
|
||||
* generation process. Currently this feature is not supported, so
|
||||
* pass in NULL for this parameter.
|
||||
* keySize
|
||||
* The size (in bits) of the key to generate.
|
||||
* keyPairId
|
||||
* A pointer to pre-allocated memory where the function can place
|
||||
* the value of the resource ID of the key pair that gets created.
|
||||
*
|
||||
* NOTES:
|
||||
* This function will send a message to the psm server requesting that
|
||||
* a public/private key pair be generated. The key gen context will queue
|
||||
* the request. You can send as many key gen requests as you want with a
|
||||
* given key gen context. After sending all the key gen requests, the user
|
||||
* must call CMT_FinishGeneratingKeys so that the key gen context actually
|
||||
* generates the keys.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates the request for key generation
|
||||
* was queued successfully and the corresponding resource ID can be found
|
||||
* at *keyPairId. Any other return value indicates an error and the value
|
||||
* at *keyPairId should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_GenerateKeyPair(PCMT_CONTROL control, CMUint32 keyGenContext,
|
||||
CMUint32 mechType, CMTItem *params, CMUint32 keySize,
|
||||
CMUint32 *keyPairId);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_FinishGeneratingKeys
|
||||
* ----------------------------------
|
||||
* INPUTS
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* keyGenContext
|
||||
* The resource ID of the key gen context which should finish
|
||||
* generating its key pairs.
|
||||
* NOTES
|
||||
* This function will send a message to the psm server notifying the key
|
||||
* gen context with the resource ID of keyGenContext to finish generating
|
||||
* all of the key gen requests it has queued up. After each key gen has
|
||||
* finished, the psm server will send a SSM_TASK_COMPLETED_EVENT. So in order
|
||||
* to detect when all of the key gens are done, the user should register
|
||||
* an event handler. See comments for CMT_RegisterEventHandler for information
|
||||
* on how to successfully register event handler callbacks. You must register
|
||||
* the event handler with keyGenContext as the target resource ID for this
|
||||
* to work correctly.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates the key gen context has started to
|
||||
* generate the key pairs in its queue. Any other return value indicates an
|
||||
* error and the key pairs will not be generated.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_FinishGeneratingKeys(PCMT_CONTROL control, CMUint32 keyGenContext);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_CreateNewCRMFRequest
|
||||
* ----------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* keyPairID
|
||||
* The resource ID of the key pair that should be associated with
|
||||
* the CRMF request created. At the time this function is called,
|
||||
* key pair should have already been created.
|
||||
* keyGenType
|
||||
* An enumeration that explains how the key pair will be used.
|
||||
* Look at the definition of SSMKeyGenType in ssmdefs.h for valid
|
||||
* values and their affects on the request.
|
||||
* reqID
|
||||
* A pointer to a pre-allocatd chunk of memory where the library
|
||||
* can place the resource ID of the new CRMF request.
|
||||
* NOTES:
|
||||
* This function sends a message to the psm server requesting that a new
|
||||
* CRMF resource object be created. Each CRMF request must be associated with
|
||||
* a public/private key pair, that is why the keyPairID parameter exists.
|
||||
* The keyGenType parameter is used to initialize the request, eg set the
|
||||
* correct keyUsage extension.
|
||||
*
|
||||
* Before encoding a CRMF request, the user will want to set the appropriate
|
||||
* attributes to build up the request. The supported attributes are:
|
||||
*
|
||||
* Attribute Enumeration Attribute Type What value means
|
||||
* --------------------- -------------- ----------------
|
||||
* SSM_FID_CRMFREQ_REGTOKEN String The value to encode as
|
||||
* the registration token
|
||||
* value for the request.
|
||||
*
|
||||
* SSM_FID_CRMFREQ_AUTHENTICATOR String The value to encode as
|
||||
* authenticator control
|
||||
* in the request.
|
||||
*
|
||||
* SSM_FID_DN String The RFC1485 formatted
|
||||
* DN to include in the
|
||||
* CRMF request.
|
||||
*
|
||||
* For information on how to properly set the attribute of a resource, refer
|
||||
* to the comments for the functions CMT_SetNumericAttribute and
|
||||
* CMT_SetStringAttribute.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates a new CRMF resource was created by
|
||||
* the psm server and has the resource ID placed at *reqID. Any other return
|
||||
* value indicates an error and the value at *reqID should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_CreateNewCRMFRequest(PCMT_CONTROL control, CMUint32 keyPairID,
|
||||
SSMKeyGenType keyGenType, CMUint32 *reqID);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_EncodeCRMFRequest
|
||||
* ------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* crmfReqID
|
||||
* An array of resource ID's for CRMF objects to be encoded.
|
||||
* numRequests
|
||||
* The length of the array crmfReqID that is passed in.
|
||||
* der
|
||||
* A pointer to a pre-allocated pointer for a char* where the library
|
||||
* can place the final DER-encoding of the requests.
|
||||
* NOTES
|
||||
* This function will send a message to the psm server requesting that
|
||||
* a number of CRMF requests be encoded into their appropriate DER
|
||||
* representation. The DER that is sent back will be of the type
|
||||
* CertReqMessages as define in the internet draft for CRMF. To look at the
|
||||
* draft, visit the following URL:
|
||||
* http://search.ietf.org/internet-drafts/internet-draft-ietf-pkix-crmf-01.txt
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates psm successfully encoded the requests
|
||||
* and placed the base64 DER encoded request at *der. Any other return value
|
||||
* indicates an error and the value at *der should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_EncodeCRMFRequest(PCMT_CONTROL control, CMUint32 *crmfReqID,
|
||||
CMUint32 numRequests, char ** der);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_ProcessCMMFResponse
|
||||
* ---------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* nickname
|
||||
* The nickname that should be associated with the certificate
|
||||
* contained in the CMMF Response.
|
||||
* certRepString
|
||||
* This is the base 64 encoded CertRepContent that issues a certificate.
|
||||
* The psm server will decode the base 64 data and then parse the
|
||||
* CertRepContent.
|
||||
* doBackup
|
||||
* A boolean value indicating whether or not psm should initiate the
|
||||
* process of backing up the newly issued certificate into a PKCS-12
|
||||
* file.
|
||||
* clientContext
|
||||
* Client supplied data pointer that is returned to the client during
|
||||
* a UI event.
|
||||
* NOTES:
|
||||
* This function takes a CertRepContent as defined in the CMMF internet draft
|
||||
* (http://search.ietf.org/internet-drafts/draft-ietf-pkix-cmmf-02.txt) and
|
||||
* imports the certificate into the user's database. The certificate will have
|
||||
* the string value of nickanme as it's nickname when added to the database
|
||||
* unless another certificate with that same Distinguished Name (DN) already
|
||||
* exists in the database, in which case the nickname of the certificate that
|
||||
* already exists will be used. If the value passed in for doBackup is
|
||||
* non-zero, then the psm server will initiate the process of backing up the
|
||||
* certificate(s) that were just imported.
|
||||
*
|
||||
* RETURN:
|
||||
* A return value of CMTSuccess indicates the certificate(s) were successfully
|
||||
* added to the database. Any other return value means the certificate(s) could
|
||||
* not be successfully added to the database.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_ProcessCMMFResponse(PCMT_CONTROL control, char *nickname,
|
||||
char *certRepString, CMBool doBackup,
|
||||
void *clientContext);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_CreateResource
|
||||
* ----------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* resType
|
||||
* The enumeration representing the resource type to create.
|
||||
* params
|
||||
* A resource dependent binary string that will be sent to the psm
|
||||
* server. Each resource will expect a binary string it defines.
|
||||
* rsrcId
|
||||
* A pointer to a pre-allocated chunk of memory where the library
|
||||
* can place the resource ID of the newly created resource.
|
||||
* errorCode
|
||||
* A pointer to a pre-allocated chunk of memory where the library
|
||||
* can place the errorCode returned by the psm server after creating
|
||||
* the resource.
|
||||
* NOTES:
|
||||
* This function sends a message to the psm server requesting that a new
|
||||
* resource be created. The params parameter depends on the type of resource
|
||||
* being created. Below is a table detailing the format of the params for
|
||||
* a given resource type. Only the resource types listed below can be created
|
||||
* by calling this function.
|
||||
*
|
||||
* Resource Type constant Value for params
|
||||
* ------------------------------ ----------------
|
||||
* SSM_RESTYPE_KEYGEN_CONTEXT NULL
|
||||
* SSM_RESTYPE_SECADVISOR_CONTEXT NULL
|
||||
* SSM_RESTYPE_SIGNTEXT NULL
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess means the psm server received the request and
|
||||
* processed the create resource create. If the value at *errorCode is zero,
|
||||
* then the value at *rsrcId is the resource ID of the newly created resource.
|
||||
* Otherwise, creating the new resource failed and *errorCode contains the
|
||||
* error code returned by the psm server. ???What are the return values and
|
||||
* what do they mean. Any other return value indicates there was an error
|
||||
* in the communication with the psm server and the values at *rsrcId and
|
||||
* *errorCode should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_CreateResource(PCMT_CONTROL control, SSMResourceType resType,
|
||||
CMTItem *params, CMUint32 *rsrcId, CMUint32 *errorCode);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_SignText
|
||||
* ----------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* resID
|
||||
* The resource ID of an SSMSignTextResource.
|
||||
* stringToSign
|
||||
* The string that the psm server should sign.
|
||||
* hostName
|
||||
* The host name of the site that is requesting a string to be
|
||||
* signed. This is used for displaying the UI that tells the user
|
||||
* a web site has requested the use sign some text.
|
||||
* caOption
|
||||
* If the value is "auto" then psm will select the certificate
|
||||
* to use for signing automatically.
|
||||
* If the value is "ask" then psm will display a list of
|
||||
* certificates for signing.
|
||||
* numCAs
|
||||
* The number of CA names included in the array caNames passed in as
|
||||
* the last parameter to this function.
|
||||
* caNames
|
||||
* An array of CA Names to use for filtering the user certs to use
|
||||
* for signing the text.
|
||||
* NOTES
|
||||
* This function will sign the text passed via the parameter stringToSign.
|
||||
* The function will also cause the psm server to send some UI notifying the
|
||||
* user that a site has requested the user sign some text. The hostName
|
||||
* parameter is used in the UI to inform the user which site is requesting
|
||||
* the signed text. The caOption is used to determine if the psm server
|
||||
* should automatically select which personal cert to use in signing the
|
||||
* text. The caNames array is ussed to narrow down the field of personal
|
||||
* certs to use when signing the text. In other words, only personal certs
|
||||
* trusted by the CA's passed in will be used.
|
||||
*
|
||||
* RETURN
|
||||
* If the function returns CMTSuccess, that indicates the psm server
|
||||
* successfully signed the text. The signed text can be retrieved by
|
||||
* calling CMT_GetStringResource and passing in SSM_FID_SIGNTEXT_RESULT
|
||||
* as the field ID. Any other return value indicates an error meaning the
|
||||
* string was not signed successfully.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_SignText(PCMT_CONTROL control, CMUint32 resID, char* stringToSign,
|
||||
char* hostName, char *caOption, CMInt32 numCAs, char** caNames);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_ProcessChallengeResponse
|
||||
* --------------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* challengeString
|
||||
* The base64 encoded Challenge string received as the
|
||||
* Proof-Of-Possession Challenge in response to CRMF request that
|
||||
* specified Challenge-Reponse as the method for Proof-Of-Possession.
|
||||
* responseString
|
||||
* A pointer to pre-allocated char* where the library can place a
|
||||
* copy of the bas64 encoded response to the challenge presented.
|
||||
* NOTES
|
||||
* This function takes the a challenge--that is encrypted with the public key
|
||||
* of a certificate we created--and decrypts it with the private key we
|
||||
* generated. The format of the challenge is as follows:
|
||||
*
|
||||
* Challenge ::= SEQUENCE {
|
||||
* owf AlgorithmIdentifier OPTIONAL,
|
||||
* -- MUST be present in the first Challenge; MAY be omitted in any
|
||||
* -- subsequent Challenge in POPODecKeyChallContent (if omitted,
|
||||
* -- then the owf used in the immediately preceding Challenge is
|
||||
* -- to be used).
|
||||
* witness OCTET STRING,
|
||||
* -- the result of applying the one-way function (owf) to a
|
||||
* -- randomly-generated INTEGER, A. [Note that a different
|
||||
* -- INTEGER MUST be used for each Challenge.]
|
||||
* sender GeneralName,
|
||||
* -- the name of the sender.
|
||||
* key OCTET STRING,
|
||||
* -- the public key used to encrypt the challenge. This will allow
|
||||
* -- the client to find the appropriate key to do the decryption.
|
||||
* challenge OCTET STRING
|
||||
* -- the encryption (under the public key for which the cert.
|
||||
* -- request is being made) of Rand, where Rand is specified as
|
||||
* -- Rand ::= SEQUENCE {
|
||||
* -- int INTEGER,
|
||||
* -- - the randomly-generated INTEGER A (above)
|
||||
* -- senderHash OCTET STRING
|
||||
* -- - the result of applying the one-way function (owf) to
|
||||
* -- - the sender's general name
|
||||
* -- }
|
||||
* -- the size of "int" must be small enough such that "Rand" can be
|
||||
* -- contained within a single PKCS #1 encryption block.
|
||||
* }
|
||||
* This challenge is based on the Challenge initially defined in the CMMF
|
||||
* internet draft, but differs in that this structure includes the sender
|
||||
* as part of the challenge along with the public key and includes a has
|
||||
* of the sender in the encrypted Rand structure. The reason for including
|
||||
* the key is to facilitate looking up the key that should be used to
|
||||
* decipher the challenge. Including the hash of the sender in the encrypted
|
||||
* Rand structure makes the challenge smaller and allows it to fit in
|
||||
* one RSA block.
|
||||
*
|
||||
* The response is of the type POPODecKeyRespContent as defined in the CMMF
|
||||
* internet draft.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates psm successfully parsed and processed
|
||||
* the challenge and created a response. The base64 encoded response to the
|
||||
* challenge is placed at *responseString. Any other return value indicates
|
||||
* an error and the value at *responseString should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_ProcessChallengeResponse(PCMT_CONTROL control, char *challengeString,
|
||||
char **responseString);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_GetLocalizedString
|
||||
* --------------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* whichString
|
||||
* The enumerated value corresponding to the localized string to
|
||||
* retrieve from the psm server
|
||||
* localizedString
|
||||
* A pointer to a pre-allocated char* where the library can place
|
||||
* copy of the localized string retrieved from the psm server.
|
||||
* NOTES
|
||||
* This function retrieves a localized string from the psm server. These
|
||||
* strings are useful for strings that aren't localized in the client
|
||||
* making use of the psm server, but need to be displayed by the user. Look
|
||||
* in protocol.h for the enumerations of the localized strings that can
|
||||
* be fetched from psm via this method.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates the localized string was retrieved
|
||||
* successfully and the localized value is located at *localizedString. Any
|
||||
* other return value indicates an error and the value at *localizedString
|
||||
* should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_GetLocalizedString(PCMT_CONTROL control,
|
||||
SSMLocalizedString whichString,
|
||||
char **localizedString);
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_DeleteModule
|
||||
* --------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* moduleName
|
||||
* The name of the PKCS11 module to delete.
|
||||
* moduleType
|
||||
* A pointer to a pre-allocated integer where the library can place
|
||||
* a value that tells what the type of module was deleted.
|
||||
* NOTES
|
||||
* This function will send a message to the psm server requesting the server
|
||||
* delete a PKCS-11 module stored in psm's security module database. moduleName
|
||||
* is the value passed in as moduleName when the module was added to the
|
||||
* security module database of psm.
|
||||
* The values that may be returned by psm for moduleType are:
|
||||
*
|
||||
* 0 The module was an external module developped by a third party
|
||||
* that was added to the psm security module.
|
||||
*
|
||||
* 1 The module deleted was the internal PKCS-11 module that comes
|
||||
* built in with the psm server.
|
||||
*
|
||||
* 2 The module that was deleted was the FIPS internal module.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates the security module was successfully
|
||||
* delete from the psm security module database and the value at *moduleType
|
||||
* will tell what type of module was deleted.
|
||||
* Any other return value indicates an error and the value at *moduleType
|
||||
* should be ignored.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_DeleteModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
int *moduleType);
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION: CMT_AddNewModule
|
||||
* --------------------------
|
||||
* INPUTS:
|
||||
* control
|
||||
* The Control Connection that has already established a connection
|
||||
* with the psm server.
|
||||
* moduleName
|
||||
* The name to be associated with the module once it is added to
|
||||
* the psm security module database.
|
||||
* libraryPath
|
||||
* The path to the library to be loaded. The library should be
|
||||
* loadable at run-time.
|
||||
* pubMechFlags
|
||||
* A bit vector indicating all cryptographic mechanisms that should
|
||||
* be turned on by default. This module will become the default
|
||||
* handler for the mechanisms that are set by this bit vector.
|
||||
* pubCipherFlags
|
||||
* A bit vector indicating all SSL or S/MIME cipher functions
|
||||
* supported by the module. Most modules will pas in 0x0 for this
|
||||
* parameter.
|
||||
* NOTES:
|
||||
* This function sends a message to the psm server and requests the .so
|
||||
* file on UNIX or .dll file on Windows be loaded as a PKCS11 module and
|
||||
* be stored in the psm security module database. The module will be stored
|
||||
* with the name moduleName that is passed in and will always expect the
|
||||
* library to live at the path passed in via the parameter libraryPath.
|
||||
* The pubMechFlags tell the psm server how this module should be used.
|
||||
* Valid values are the #define constants defined at the beginning of
|
||||
* this file.
|
||||
*
|
||||
* RETURN
|
||||
* A return value of CMTSuccess indicates the module was successfully loaded
|
||||
* and placed in the security module database of psm. Any other return value
|
||||
* indicates an error and means the module was not loaded successfully and
|
||||
* not stored in the psm server's security module database.
|
||||
*/
|
||||
CMTStatus
|
||||
CMT_AddNewModule(PCMT_CONTROL control,
|
||||
char *moduleName,
|
||||
char *libraryPath,
|
||||
unsigned long pubMechFlags,
|
||||
unsigned long pubCipherFlags);
|
||||
|
||||
CMT_END_EXTERN_C
|
||||
|
||||
#endif /*_CMTJS_H_*/
|
||||
75
mozilla/security/psm/lib/client/cmtmac.c
Normal file
75
mozilla/security/psm/lib/client/cmtmac.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
|
||||
#include "cmtmac.h"
|
||||
#include "macsocket.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifndef XP_MAC
|
||||
#error Link with the builtin strdup() on your platform.
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
my_strcpy(char *dest, const char *source)
|
||||
{
|
||||
char *i = dest;
|
||||
const char *j = source;
|
||||
while(*j)
|
||||
*i++ = *j++;
|
||||
*i = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
my_strlen(const char *str)
|
||||
{
|
||||
const char *c = str;
|
||||
int i = 0;
|
||||
|
||||
while(*c++ != '\0')
|
||||
i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
char * strdup(const char *oldstr)
|
||||
{
|
||||
/* used to keep the mac client library from referring to strdup elsewhere */
|
||||
char *newstr;
|
||||
|
||||
newstr = (char *) malloc(my_strlen(oldstr)+1);
|
||||
if (newstr)
|
||||
my_strcpy(newstr, oldstr);
|
||||
return newstr;
|
||||
}
|
||||
|
||||
40
mozilla/security/psm/lib/client/cmtmac.h
Normal file
40
mozilla/security/psm/lib/client/cmtmac.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
|
||||
#ifndef __CMTMAC_H__
|
||||
#define __CMTMAC_H__
|
||||
|
||||
char * strdup(const char *str);
|
||||
|
||||
#endif
|
||||
119
mozilla/security/psm/lib/client/cmtpasswd.c
Normal file
119
mozilla/security/psm/lib/client/cmtpasswd.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/************************************************************************
|
||||
* Code to handle password requests from the the PSM module.
|
||||
*
|
||||
************************************************************************
|
||||
*/
|
||||
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
|
||||
void CMT_SetAppFreeCallback(PCMT_CONTROL control,
|
||||
applicationFreeCallback_fn f)
|
||||
{
|
||||
control->userFuncs.userFree = f;
|
||||
}
|
||||
|
||||
void CMT_ServicePasswordRequest(PCMT_CONTROL cm_control, CMTItem * requestData)
|
||||
{
|
||||
CMTItem response = {0, NULL, 0};
|
||||
PasswordRequest request;
|
||||
PasswordReply reply;
|
||||
void * clientContext;
|
||||
|
||||
/********************************************
|
||||
* What we trying to do here:
|
||||
* 1) Throw up a dialog box and request a password.
|
||||
* 2) Create a message and send it to the PSM module.
|
||||
********************************************
|
||||
*/
|
||||
|
||||
/* Decode the request */
|
||||
if (CMT_DecodeMessage(PasswordRequestTemplate, &request, requestData) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Copy the client context to a pointer */
|
||||
clientContext = CMT_CopyItemToPtr(request.clientContext);
|
||||
|
||||
if (cm_control->userFuncs.promptCallback == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
reply.passwd =
|
||||
cm_control->userFuncs.promptCallback(cm_control->userFuncs.promptArg,
|
||||
request.prompt, clientContext, 1);
|
||||
reply.tokenID = request.tokenKey;
|
||||
if (!reply.passwd) {
|
||||
/* the user cancelled the prompt or other errors occurred */
|
||||
reply.result = -1;
|
||||
}
|
||||
else {
|
||||
/* note that this includes an empty string (zero length password) */
|
||||
reply.result = 0;
|
||||
}
|
||||
|
||||
/* Encode the reply */
|
||||
if (CMT_EncodeMessage(PasswordReplyTemplate, &response, &reply) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message response type */
|
||||
response.type = SSM_EVENT_MESSAGE | SSM_AUTH_EVENT;
|
||||
CMT_TransmitMessage(cm_control, &response);
|
||||
goto done;
|
||||
loser:
|
||||
/* something has gone wrong */
|
||||
|
||||
done:
|
||||
/*clean up anyway */
|
||||
/* We can't just free up memory allocated by the host
|
||||
application because the versions of free may not match up.
|
||||
When you run the plug-in with an optimized older browser,
|
||||
you'll see tons of Asserts (why they still have asserts in an
|
||||
optimized build is a different question, but without them
|
||||
I wouldn't have figured out this problem) about a pointer not
|
||||
being a valid heap pointer and eventually crash. This was
|
||||
the offending free line.
|
||||
So we need to call a function within the browser that
|
||||
calls the free linked in with it. js_free is
|
||||
such a function. But this is extremely ugly.
|
||||
*/
|
||||
if (reply.passwd)
|
||||
cm_control->userFuncs.userFree(reply.passwd);
|
||||
if (request.prompt)
|
||||
free(request.prompt);
|
||||
return;
|
||||
}
|
||||
|
||||
636
mozilla/security/psm/lib/client/cmtpkcs7.c
Normal file
636
mozilla/security/psm/lib/client/cmtpkcs7.c
Normal file
@@ -0,0 +1,636 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#else /* Windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
|
||||
typedef struct _CMTP7Private {
|
||||
CMTPrivate priv;
|
||||
CMTP7ContentCallback cb;
|
||||
void *cb_arg;
|
||||
} CMTP7Private;
|
||||
|
||||
CMTStatus CMT_PKCS7DecoderStart(PCMT_CONTROL control, void* clientContext, CMUint32 * connectionID, CMInt32 * result,
|
||||
CMTP7ContentCallback cb, void *cb_arg)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CMTP7Private *priv=NULL;
|
||||
SingleItemMessage request;
|
||||
DataConnectionReply reply;
|
||||
|
||||
/* Check passed in parameters */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.item = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* Encode message */
|
||||
if (CMT_EncodeMessage(SingleItemMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7DECODE_STREAM;
|
||||
|
||||
/* Send the message. */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7DECODE_STREAM)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
CMTSocket sock;
|
||||
|
||||
priv = (CMTP7Private *)malloc(sizeof(CMTP7Private));
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
priv->priv.dest = (CMTReclaimFunc) free;
|
||||
priv->cb = cb;
|
||||
priv->cb_arg = cb_arg;
|
||||
sock = control->sockFuncs.socket(0);
|
||||
if (sock == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (control->sockFuncs.connect(sock, (short)reply.port,
|
||||
NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (control->sockFuncs.send(sock, control->nonce.data,
|
||||
control->nonce.len) != control->nonce.len){
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*connectionID = reply.connID;
|
||||
|
||||
rv = CMT_SetPrivate(control, reply.connID, &priv->priv);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
if (priv) {
|
||||
free(priv);
|
||||
}
|
||||
|
||||
*result = reply.result;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7DecoderUpdate(PCMT_CONTROL control, CMUint32 connectionID, const char * buf, CMUint32 len)
|
||||
{
|
||||
CMUint32 sent;
|
||||
CMTP7Private *priv;
|
||||
unsigned long nbytes;
|
||||
char read_buf[128];
|
||||
CMTSocket sock, ctrlsock, selSock, sockArr[2];
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !buf) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the data socket */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
/* Write the data to the socket */
|
||||
sent = CMT_WriteThisMany(control, sock, (void*)buf, len);
|
||||
if (sent != len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
ctrlsock = control->sock;
|
||||
sockArr[0] = ctrlsock;
|
||||
sockArr[1] = sock;
|
||||
while ((selSock = control->sockFuncs.select(sockArr,2,1)))
|
||||
{
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else {
|
||||
nbytes = control->sockFuncs.recv(sock, read_buf, sizeof(read_buf));
|
||||
if (nbytes == -1) {
|
||||
goto loser;
|
||||
}
|
||||
if (nbytes == 0) {
|
||||
break;
|
||||
}
|
||||
priv->cb(priv->cb_arg, read_buf, nbytes);
|
||||
}
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7DecoderFinish(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
CMUint32 * resourceID)
|
||||
{
|
||||
CMTP7Private *priv;
|
||||
long nbytes;
|
||||
char buf[128];
|
||||
CMTSocket sock, ctrlsock, selSock, sockArr[2];
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
ctrlsock = control->sock;
|
||||
/* drain socket before we close it */
|
||||
control->sockFuncs.shutdown(sock);
|
||||
sockArr[0] = sock;
|
||||
sockArr[1] = ctrlsock;
|
||||
/* Let's see if doing a poll first gets rid of a weird bug where we
|
||||
* lock up the client.
|
||||
*/
|
||||
#ifndef XP_MAC
|
||||
if (control->sockFuncs.select(sockArr,2,1) != NULL)
|
||||
#endif
|
||||
{
|
||||
while (1) {
|
||||
selSock = control->sockFuncs.select(sockArr,2,0);
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else if (selSock == sock) {
|
||||
nbytes = control->sockFuncs.recv(sock, buf, sizeof(buf));
|
||||
if (nbytes < 0) {
|
||||
goto loser;
|
||||
} else if (nbytes == 0) {
|
||||
break;
|
||||
}
|
||||
priv->cb(priv->cb_arg, buf, nbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the PKCS7 content info */
|
||||
if (CMT_GetRIDAttribute(control, connectionID, SSM_FID_P7CONN_CONTENT_INFO,
|
||||
resourceID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (control) {
|
||||
CMT_CloseDataConnection(control, connectionID);
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7DestroyContentInfo(PCMT_CONTROL control, CMUint32 resourceID)
|
||||
{
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Delete the resource */
|
||||
if (CMT_DestroyResource(control, resourceID, SSM_FID_P7CONN_CONTENT_INFO) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7VerifyDetachedSignature(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 certUsage, CMUint32 hashAlgID, CMUint32 keepCerts, CMTItem* digest, CMInt32 * result)
|
||||
{
|
||||
CMTItem message;
|
||||
VerifyDetachedSigRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !digest || !result) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.pkcs7ContentID = resourceID;
|
||||
request.certUsage = certUsage;
|
||||
request.hashAlgID = hashAlgID;
|
||||
request.keepCert = (CMBool) keepCerts;
|
||||
request.hash = *digest;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(VerifyDetachedSigRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_VERIFY_DETACHED_SIG;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING |SSM_VERIFY_DETACHED_SIG)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*result = reply.value;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
*result = reply.value;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7VerifySignature(PCMT_CONTROL control, CMUint32 pubKeyAlgID,
|
||||
CMTItem *pubKeyParams, CMTItem *signerPubKey,
|
||||
CMTItem *computedHash, CMTItem *signature,
|
||||
CMInt32 *result)
|
||||
{
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CreateSigned(PCMT_CONTROL control, CMUint32 scertRID,
|
||||
CMUint32 ecertRID, CMUint32 dig_alg,
|
||||
CMTItem *digest, CMUint32 *ciRID, CMInt32 *errCode)
|
||||
{
|
||||
CMTItem message;
|
||||
CreateSignedRequest request;
|
||||
CreateContentInfoReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !scertRID || !ecertRID || !digest || !ciRID) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.scertRID = scertRID;
|
||||
request.ecertRID = ecertRID;
|
||||
request.dig_alg = dig_alg;
|
||||
request.digest = *digest;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CreateSignedRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_SIGNED;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_SIGNED)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*ciRID = reply.ciRID;
|
||||
if (reply.result == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) == CMTSuccess) {
|
||||
*errCode = reply.errorCode;
|
||||
} else {
|
||||
*errCode = 0;
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CreateEncrypted(PCMT_CONTROL control, CMUint32 scertRID,
|
||||
CMUint32 *rcertRIDs, CMUint32 *ciRID)
|
||||
{
|
||||
CMTItem message;
|
||||
CMInt32 nrcerts;
|
||||
CreateEncryptedRequest request;
|
||||
CreateContentInfoReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !scertRID || !rcertRIDs || !ciRID) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Calculate the number of certs */
|
||||
for (nrcerts =0; rcertRIDs[nrcerts] != 0; nrcerts++) {
|
||||
/* Nothing */
|
||||
;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.scertRID = scertRID;
|
||||
request.nrcerts = nrcerts;
|
||||
request.rcertRIDs = (long *) rcertRIDs;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(CreateEncryptedRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_ENCRYPTED;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message response type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_ENCRYPTED)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*ciRID = reply.ciRID;
|
||||
if (reply.result == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7EncoderStart(PCMT_CONTROL control, CMUint32 ciRID,
|
||||
CMUint32 *connectionID, CMTP7ContentCallback cb,
|
||||
void *cb_arg)
|
||||
{
|
||||
CMTItem message;
|
||||
CMTStatus rv;
|
||||
CMTP7Private *priv;
|
||||
PKCS7DataConnectionRequest request;
|
||||
DataConnectionReply reply;
|
||||
|
||||
/* Check passed in parameters */
|
||||
if (!control || !ciRID) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = ciRID;
|
||||
request.clientContext.len = 0;
|
||||
request.clientContext.data = NULL;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(PKCS7DataConnectionRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7ENCODE_STREAM;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7ENCODE_STREAM)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
CMTSocket sock;
|
||||
|
||||
priv = (CMTP7Private *)malloc(sizeof(CMTP7Private));
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
priv->priv.dest = (CMTReclaimFunc) free;
|
||||
priv->cb = cb;
|
||||
priv->cb_arg = cb_arg;
|
||||
|
||||
sock = control->sockFuncs.socket(0);
|
||||
if (sock == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
if (control->sockFuncs.connect(sock, (short)reply.port,
|
||||
NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
if (control->sockFuncs.send(sock, control->nonce.data,
|
||||
control->nonce.len) != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
*connectionID = reply.connID;
|
||||
|
||||
rv = CMT_SetPrivate(control, reply.connID, &priv->priv);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7EncoderUpdate(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
const char *buf, CMUint32 len)
|
||||
{
|
||||
CMUint32 sent;
|
||||
CMTP7Private *priv;
|
||||
unsigned long nbytes;
|
||||
char read_buf[128];
|
||||
CMTSocket sock, ctrlsock, sockArr[2], selSock;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !connectionID || !buf) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Get the data socket */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
/* Write the data to the socket */
|
||||
sent = CMT_WriteThisMany(control, sock, (void*)buf, len);
|
||||
if (sent != len) {
|
||||
goto loser;
|
||||
}
|
||||
ctrlsock = control->sock;
|
||||
sockArr[0] = ctrlsock;
|
||||
sockArr[1] = sock;
|
||||
while ((selSock = control->sockFuncs.select(sockArr, 2, 1)) != NULL)
|
||||
{
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else {
|
||||
nbytes = control->sockFuncs.recv(sock, read_buf, sizeof(read_buf));
|
||||
if (nbytes == -1) {
|
||||
goto loser;
|
||||
} else if (nbytes == 0) {
|
||||
break;
|
||||
} else {
|
||||
priv->cb(priv->cb_arg, read_buf, nbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PKCS7EncoderFinish(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
CMTP7Private *priv;
|
||||
unsigned long nbytes;
|
||||
char buf[128];
|
||||
CMTSocket sock, ctrlsock, sockArr[2], selSock;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);
|
||||
if (priv == NULL)
|
||||
goto loser;
|
||||
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
ctrlsock = control->sock;
|
||||
sockArr[0] = ctrlsock;
|
||||
sockArr[1] = sock;
|
||||
control->sockFuncs.shutdown(sock);
|
||||
while (1) {
|
||||
selSock = control->sockFuncs.select(sockArr, 2, 0);
|
||||
if (selSock == ctrlsock) {
|
||||
CMT_ProcessEvent(control);
|
||||
} else if (selSock == sock) {
|
||||
nbytes = control->sockFuncs.recv(sock, buf, sizeof(buf));
|
||||
if (nbytes < 0) {
|
||||
goto loser;
|
||||
} else if (nbytes == 0) {
|
||||
break;
|
||||
} else {
|
||||
priv->cb(priv->cb_arg, buf, nbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (control) {
|
||||
CMT_CloseDataConnection(control, connectionID);
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
479
mozilla/security/psm/lib/client/cmtres.c
Normal file
479
mozilla/security/psm/lib/client/cmtres.c
Normal file
@@ -0,0 +1,479 @@
|
||||
/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include <string.h>
|
||||
|
||||
CMTStatus CMT_GetNumericAttribute(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 fieldID, CMInt32 *value)
|
||||
{
|
||||
CMTItem message;
|
||||
GetAttribRequest request;
|
||||
GetAttribReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(GetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(GetAttribReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*value = reply.value.u.numeric;
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_SetNumericAttribute(PCMT_CONTROL control, CMUint32 resourceID,
|
||||
CMUint32 fieldID, CMInt32 value)
|
||||
{
|
||||
CMTItem message;
|
||||
SetAttribRequest request;
|
||||
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
request.value.type = SSM_NUMERIC_ATTRIBUTE;
|
||||
request.value.u.numeric = value;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(SetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE;
|
||||
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_NUMERIC_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_PadStringValue(CMTItem *dest, CMTItem src)
|
||||
{
|
||||
dest->data = NewArray(unsigned char, src.len+1);
|
||||
if (dest->data == NULL) {
|
||||
return CMTFailure;
|
||||
}
|
||||
memcpy(dest->data, src.data, src.len);
|
||||
dest->data[src.len] = '\0';
|
||||
dest->len = src.len;
|
||||
free(src.data);
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetStringAttribute(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 fieldID, CMTItem *value)
|
||||
{
|
||||
CMTItem message;
|
||||
GetAttribRequest request;
|
||||
GetAttribReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(GetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_STRING_ATTRIBUTE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_STRING_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the response */
|
||||
if (CMT_DecodeMessage(GetAttribReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
return CMT_PadStringValue(value, reply.value.u.string);
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_SetStringAttribute(PCMT_CONTROL control, CMUint32 resourceID,
|
||||
CMUint32 fieldID, CMTItem *value)
|
||||
{
|
||||
CMTItem message;
|
||||
SetAttribRequest request;
|
||||
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
request.value.type = SSM_STRING_ATTRIBUTE;
|
||||
request.value.u.string = *value;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_STRING_ATTRIBUTE;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message request type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_SET_ATTRIBUTE | SSM_STRING_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_DuplicateResource(PCMT_CONTROL control, CMUint32 resourceID,
|
||||
CMUint32 *newResID)
|
||||
{
|
||||
CMTItem message;
|
||||
SingleNumMessage request;
|
||||
DupResourceReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.value = resourceID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_DUPLICATE_RESOURCE;
|
||||
|
||||
/* Send the mesage */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_DUPLICATE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(DupResourceReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*newResID = reply.resID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
*newResID = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_DestroyResource(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 resourceType)
|
||||
{
|
||||
CMTItem message;
|
||||
DestroyResourceRequest request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resID = resourceID;
|
||||
request.resType = resourceType;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(DestroyResourceRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_DESTROY_RESOURCE;
|
||||
|
||||
/* Send the message */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_DESTROY_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.value == 0) {
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_PickleResource(PCMT_CONTROL control, CMUint32 resourceID, CMTItem * pickledResource)
|
||||
{
|
||||
CMTItem message;
|
||||
SingleNumMessage request;
|
||||
PickleResourceReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.value = resourceID;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_PICKLE_RESOURCE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_PICKLE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(PickleResourceReplyTemplate, &reply,&message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*pickledResource = reply.blob;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_UnpickleResource(PCMT_CONTROL control, CMUint32 resourceType, CMTItem pickledResource, CMUint32 * resourceID)
|
||||
{
|
||||
CMTItem message;
|
||||
UnpickleResourceRequest request;
|
||||
UnpickleResourceReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set up the request */
|
||||
request.resourceType = resourceType;
|
||||
request.resourceData = pickledResource;
|
||||
|
||||
/* Encode the request */
|
||||
if (CMT_EncodeMessage(UnpickleResourceRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_UNPICKLE_RESOURCE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_CONSERVE_RESOURCE | SSM_UNPICKLE_RESOURCE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(UnpickleResourceReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*resourceID = reply.resID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
*resourceID = 0;
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetRIDAttribute(PCMT_CONTROL control, CMUint32 resourceID, CMUint32 fieldID, CMUint32 *value)
|
||||
{
|
||||
CMTItem message;
|
||||
GetAttribRequest request;
|
||||
GetAttribReply reply;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the request */
|
||||
request.resID = resourceID;
|
||||
request.fieldID = fieldID;
|
||||
|
||||
/* Encode the message */
|
||||
if (CMT_EncodeMessage(GetAttribRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_RID_ATTRIBUTE;
|
||||
|
||||
/* Send the mesage and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message response type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION | SSM_GET_ATTRIBUTE | SSM_RID_ATTRIBUTE)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode the reply */
|
||||
if (CMT_DecodeMessage(GetAttribReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
*value = reply.value.u.rid;
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
270
mozilla/security/psm/lib/client/cmtrng.c
Normal file
270
mozilla/security/psm/lib/client/cmtrng.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*
|
||||
cmtrng.c -- Support for PSM random number generator and the seeding
|
||||
thereof with data from the client.
|
||||
|
||||
Created by mwelch 1999 Oct 21
|
||||
*/
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
#include <string.h>
|
||||
|
||||
CMTStatus
|
||||
CMT_EnsureInitializedRNGBuf(PCMT_CONTROL control)
|
||||
{
|
||||
if (control->rng.outBuf == NULL)
|
||||
{
|
||||
control->rng.outBuf = (char *) calloc(RNG_OUT_BUFFER_LEN, sizeof(char));
|
||||
if (control->rng.outBuf == NULL)
|
||||
goto loser;
|
||||
|
||||
control->rng.validOutBytes = 0;
|
||||
control->rng.out_cur = control->rng.outBuf;
|
||||
control->rng.out_end = control->rng.out_cur + RNG_OUT_BUFFER_LEN;
|
||||
|
||||
control->rng.inBuf = (char *) calloc(RNG_IN_BUFFER_LEN, sizeof(char));
|
||||
if (control->rng.outBuf == NULL)
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
if (control->rng.outBuf != NULL)
|
||||
{
|
||||
free(control->rng.outBuf);
|
||||
control->rng.outBuf = NULL;
|
||||
}
|
||||
if (control->rng.inBuf != NULL)
|
||||
{
|
||||
free(control->rng.inBuf);
|
||||
control->rng.inBuf = NULL;
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CMT_RequestPSMRandomData(PCMT_CONTROL control,
|
||||
void *buf, CMUint32 maxbytes)
|
||||
{
|
||||
SingleNumMessage req;
|
||||
SingleItemMessage reply;
|
||||
CMTItem message;
|
||||
size_t rv = 0;
|
||||
|
||||
/* Parameter checking */
|
||||
if (!control || !buf || (maxbytes == 0))
|
||||
goto loser;
|
||||
|
||||
/* Initialization. */
|
||||
memset(&reply, 0, sizeof(SingleItemMessage));
|
||||
|
||||
/* Ask PSM for the data. */
|
||||
req.value = maxbytes;
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &req) != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_MISC_ACTION | SSM_MISC_GET_RNG_DATA;
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure)
|
||||
goto loser;
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_MISC_ACTION | SSM_MISC_GET_RNG_DATA))
|
||||
goto loser;
|
||||
|
||||
/* Decode message */
|
||||
if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
/* Success - fill the return buf with what we got */
|
||||
if (reply.item.len > maxbytes)
|
||||
reply.item.len = maxbytes;
|
||||
|
||||
memcpy(buf, reply.item.data, reply.item.len);
|
||||
rv = reply.item.len;
|
||||
|
||||
loser:
|
||||
if (reply.item.data)
|
||||
free(reply.item.data);
|
||||
if (message.data)
|
||||
free(message.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
size_t
|
||||
CMT_GenerateRandomBytes(PCMT_CONTROL control,
|
||||
void *buf, CMUint32 maxbytes)
|
||||
{
|
||||
CMUint32 remaining = maxbytes;
|
||||
CMT_RNGState *rng = &(control->rng);
|
||||
char *walk = (char *) buf;
|
||||
|
||||
/* Is there already enough in the incoming cache? */
|
||||
while(remaining > rng->validInBytes)
|
||||
{
|
||||
/* Get what we have on hand. */
|
||||
memcpy(walk, rng->in_cur, rng->validInBytes);
|
||||
walk += rng->validInBytes;
|
||||
remaining -= rng->validInBytes;
|
||||
|
||||
/* Request a buffer from PSM. */
|
||||
rng->validInBytes = CMT_RequestPSMRandomData(control,
|
||||
rng->inBuf,
|
||||
RNG_IN_BUFFER_LEN);
|
||||
if (rng->validInBytes == 0)
|
||||
return (maxbytes - remaining); /* call failed */
|
||||
rng->in_cur = rng->inBuf;
|
||||
}
|
||||
if (remaining > 0)
|
||||
{
|
||||
memcpy(walk, rng->in_cur, remaining);
|
||||
rng->in_cur += remaining;
|
||||
rng->validInBytes -= remaining;
|
||||
}
|
||||
return maxbytes;
|
||||
}
|
||||
|
||||
void
|
||||
cmt_rng_xor(void *dstBuf, void *srcBuf, int len)
|
||||
{
|
||||
unsigned char *s = (unsigned char*) srcBuf;
|
||||
unsigned char *d = (unsigned char*) dstBuf;
|
||||
unsigned char tmp;
|
||||
int i;
|
||||
|
||||
for(i=0; i<len; i++, s++, d++)
|
||||
{
|
||||
tmp = *d;
|
||||
/* I wish C had circular shift operators. So do others on the team. */
|
||||
tmp = ((tmp << 1) | (tmp >> 7));
|
||||
*d = tmp ^ *s;
|
||||
}
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_RandomUpdate(PCMT_CONTROL control, void *data, size_t numbytes)
|
||||
{
|
||||
size_t dataLeft = numbytes, cacheLeft;
|
||||
char *walk = (char *) data;
|
||||
|
||||
if (CMT_EnsureInitializedRNGBuf(control) != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
/* If we have more than what the buffer can handle, wrap around. */
|
||||
cacheLeft = (control->rng.out_end - control->rng.out_cur);
|
||||
while (dataLeft >= cacheLeft)
|
||||
{
|
||||
cmt_rng_xor(control->rng.out_cur, walk, cacheLeft);
|
||||
walk += cacheLeft;
|
||||
dataLeft -= cacheLeft;
|
||||
|
||||
control->rng.out_cur = control->rng.outBuf;
|
||||
|
||||
/* Max out used space */
|
||||
control->rng.validOutBytes = cacheLeft = RNG_OUT_BUFFER_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
We now have less seed data available than we do space in the buf.
|
||||
Write what we have and update validOutBytes if we're not looping already.
|
||||
*/
|
||||
cmt_rng_xor(control->rng.out_cur, walk, dataLeft);
|
||||
control->rng.out_cur += dataLeft;
|
||||
if (control->rng.validOutBytes < RNG_OUT_BUFFER_LEN)
|
||||
control->rng.validOutBytes += dataLeft;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
size_t
|
||||
CMT_GetNoise(PCMT_CONTROL control, void *buf, CMUint32 maxbytes)
|
||||
{
|
||||
/* ### mwelch - GetNoise and GenerateRandomBytes can be the
|
||||
same function now, because presumably the RNG is being
|
||||
seeded with environmental noise on the PSM end before we
|
||||
make any of these requests */
|
||||
return CMT_GenerateRandomBytes(control, buf, maxbytes);
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_FlushPendingRandomData(PCMT_CONTROL control)
|
||||
{
|
||||
CMTItem message;
|
||||
|
||||
memset(&message, 0, sizeof(CMTItem));
|
||||
|
||||
if (CMT_EnsureInitializedRNGBuf(control) != CMTSuccess)
|
||||
return CMTFailure; /* couldn't initialize RNG buffer */
|
||||
|
||||
if (control->rng.validOutBytes == 0)
|
||||
return CMTSuccess; /* no random data available == we're flushed */
|
||||
|
||||
/* We have random data available. Send this to PSM.
|
||||
We're sending an event, so no reply is needed. */
|
||||
message.type = SSM_EVENT_MESSAGE
|
||||
| SSM_MISC_ACTION
|
||||
| SSM_MISC_PUT_RNG_DATA;
|
||||
message.len = control->rng.validOutBytes;
|
||||
message.data = (unsigned char *) calloc(message.len, sizeof(char));
|
||||
if (!message.data)
|
||||
goto loser;
|
||||
memcpy(message.data, control->rng.outBuf, message.len);
|
||||
|
||||
if (CMT_TransmitMessage(control, &message) == CMTFailure)
|
||||
goto loser;
|
||||
|
||||
/* Clear the RNG ring buffer, we've used that data */
|
||||
control->rng.out_cur = control->rng.outBuf;
|
||||
control->rng.validOutBytes = 0;
|
||||
/* zero the buffer, because we XOR in new data */
|
||||
memset(control->rng.outBuf, 0, RNG_OUT_BUFFER_LEN);
|
||||
|
||||
goto done;
|
||||
loser:
|
||||
if (message.data)
|
||||
free(message.data);
|
||||
return CMTFailure;
|
||||
done:
|
||||
return CMTSuccess;
|
||||
}
|
||||
237
mozilla/security/psm/lib/client/cmtsdr.c
Normal file
237
mozilla/security/psm/lib/client/cmtsdr.c
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*
|
||||
cmtsdr.c -- Support for the Secret Decoder Ring, which provides
|
||||
encryption and decryption using stored keys.
|
||||
|
||||
Created by thayes 18 April 2000
|
||||
*/
|
||||
#include "stddef.h"
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "protocolshr.h"
|
||||
#include "rsrcids.h"
|
||||
#include <string.h>
|
||||
|
||||
#undef PROCESS_LOCALLY
|
||||
|
||||
/* Encryption result - contains the key id and the resulting data */
|
||||
/* An empty key id indicates that NO encryption was performed */
|
||||
typedef struct EncryptionResult
|
||||
{
|
||||
CMTItem keyid;
|
||||
CMTItem data;
|
||||
} EncryptionResult;
|
||||
|
||||
/* Constants for testing */
|
||||
static const char *kPrefix = "Encrypted:";
|
||||
|
||||
static CMTItem
|
||||
CMT_CopyDataToItem(const unsigned char *data, CMUint32 len)
|
||||
{
|
||||
CMTItem item;
|
||||
|
||||
item.data = (unsigned char*) calloc(len, 1);
|
||||
item.len = len;
|
||||
memcpy(item.data, data, len);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
static CMTStatus
|
||||
tmp_SendMessage(PCMT_CONTROL control, CMTItem *message)
|
||||
{
|
||||
#ifndef PROCESS_LOCALLY
|
||||
return CMT_SendMessage(control, message);
|
||||
#else
|
||||
if (message->type == SSM_SDR_ENCRYPT_REQUEST)
|
||||
return CMT_DoEncryptionRequest(message);
|
||||
else if (message->type == SSM_SDR_DECRYPT_REQUEST)
|
||||
return CMT_DoDecryptionRequest(message);
|
||||
|
||||
return CMTFailure;
|
||||
#endif
|
||||
}
|
||||
/* End test code */
|
||||
|
||||
CMTStatus
|
||||
CMT_SDREncrypt(PCMT_CONTROL control, void *ctx,
|
||||
const unsigned char *key, CMUint32 keyLen,
|
||||
const unsigned char *data, CMUint32 dataLen,
|
||||
unsigned char **result, CMUint32 *resultLen)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTItem message;
|
||||
EncryptRequestMessage request;
|
||||
SingleItemMessage reply;
|
||||
|
||||
/* Fill in the request */
|
||||
request.keyid = CMT_CopyDataToItem(key, keyLen);
|
||||
request.data = CMT_CopyDataToItem(data, dataLen);
|
||||
request.ctx = CMT_CopyPtrToItem(ctx);
|
||||
|
||||
reply.item.data = 0;
|
||||
reply.item.len = 0;
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
rv = CMT_EncodeMessage(EncryptRequestTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_SDR_ENCRYPT_REQUEST;
|
||||
|
||||
/* Send */
|
||||
/* if (CMT_SendMessage(control, &message) != CMTSuccess) goto loser; */
|
||||
rv = tmp_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type != SSM_SDR_ENCRYPT_REPLY) { rv = CMTFailure; goto loser; }
|
||||
|
||||
rv = CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
*result = reply.item.data;
|
||||
*resultLen = reply.item.len;
|
||||
|
||||
reply.item.data = 0;
|
||||
|
||||
loser:
|
||||
if (message.data) free(message.data);
|
||||
if (request.keyid.data) free(request.keyid.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv; /* need return value */
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_SDRDecrypt(PCMT_CONTROL control, void *ctx,
|
||||
const unsigned char *data, CMUint32 dataLen,
|
||||
unsigned char **result, CMUint32 *resultLen)
|
||||
{
|
||||
CMTStatus rv;
|
||||
CMTItem message;
|
||||
DecryptRequestMessage request;
|
||||
SingleItemMessage reply;
|
||||
|
||||
/* Fill in the request */
|
||||
request.data = CMT_CopyDataToItem(data, dataLen);
|
||||
request.ctx = CMT_CopyPtrToItem(ctx);
|
||||
|
||||
reply.item.data = 0;
|
||||
reply.item.len = 0;
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
rv = CMT_EncodeMessage(DecryptRequestTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = SSM_SDR_DECRYPT_REQUEST;
|
||||
|
||||
/* Send */
|
||||
/* if (CMT_SendMessage(control, &message) != CMTSuccess) goto loser; */
|
||||
rv = tmp_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type != SSM_SDR_DECRYPT_REPLY) { rv = CMTFailure; goto loser; }
|
||||
|
||||
rv = CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
*result = reply.item.data;
|
||||
*resultLen = reply.item.len;
|
||||
|
||||
reply.item.data = 0;
|
||||
|
||||
loser:
|
||||
if (message.data) free(message.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv; /* need return value */
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
CMT_SDRChangePassword(PCMT_CONTROL control, void *ctx)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTItem message;
|
||||
SingleItemMessage request;
|
||||
SingleNumMessage reply;
|
||||
|
||||
/* Fill in the request */
|
||||
request.item = CMT_CopyPtrToItem(ctx);
|
||||
|
||||
message.data = 0;
|
||||
message.len = 0;
|
||||
|
||||
/* Encode */
|
||||
rv = CMT_EncodeMessage(SingleItemMessageTemplate, &message, &request);
|
||||
if (rv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
message.type = (SSM_REQUEST_MESSAGE|SSM_MISC_ACTION|SSM_MISC_UI|SSM_UI_CHANGE_PASSWORD);
|
||||
|
||||
/* Send */
|
||||
rv = CMT_SendMessage(control, &message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
if (message.type !=
|
||||
(SSM_REPLY_OK_MESSAGE|SSM_MISC_ACTION|SSM_MISC_UI|SSM_UI_CHANGE_PASSWORD)) {
|
||||
rv = CMTFailure;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
|
||||
loser:
|
||||
if (request.item.data) free(request.item.data);
|
||||
if (message.data) free(message.data);
|
||||
|
||||
return rv; /* need return value */
|
||||
}
|
||||
467
mozilla/security/psm/lib/client/cmtssl.c
Normal file
467
mozilla/security/psm/lib/client/cmtssl.c
Normal file
@@ -0,0 +1,467 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#else /* windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "messages.h"
|
||||
#include "rsrcids.h"
|
||||
|
||||
|
||||
|
||||
CMTStatus CMT_OpenSSLConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
SSMSSLConnectionRequestType flags,
|
||||
CMUint32 port, char * hostIP,
|
||||
char * hostName, CMBool forceHandshake, void* clientContext)
|
||||
{
|
||||
CMTItem message;
|
||||
SSLDataConnectionRequest request;
|
||||
DataConnectionReply reply;
|
||||
CMUint32 sent;
|
||||
|
||||
/* Do some parameter checking */
|
||||
if (!control || !hostIP || !hostName) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.flags = flags;
|
||||
request.port = port;
|
||||
request.hostIP = hostIP;
|
||||
request.hostName = hostName;
|
||||
request.forceHandshake = forceHandshake;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* Encode message */
|
||||
if (CMT_EncodeMessage(SSLDataConnectionRequestTemplate, &message, &request) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_SSL_CONNECTION;
|
||||
|
||||
/* Send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_SSL_CONNECTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Decode message */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
if (reply.result == 0) {
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
sent = CMT_WriteThisMany(control, sock, control->nonce.data,
|
||||
control->nonce.len);
|
||||
if (sent != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetSSLDataErrorCode(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMInt32* errorCode)
|
||||
{
|
||||
CMUint32 connID;
|
||||
|
||||
if (!control || !errorCode) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the PR error */
|
||||
if (CMT_GetNumericAttribute(control, connID, SSM_FID_SSLDATA_ERROR_VALUE,
|
||||
errorCode) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_ReleaseSSLSocketStatus(PCMT_CONTROL control, CMTSocket sock)
|
||||
{
|
||||
CMUint32 connectionID;
|
||||
|
||||
if (!control || !sock) {
|
||||
goto loser;
|
||||
}
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
if (CMT_SetNumericAttribute(control, connectionID,
|
||||
SSM_FID_SSLDATA_DISCARD_SOCKET_STATUS,
|
||||
0) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetSSLSocketStatus(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMTItem* pickledStatus, CMInt32* level)
|
||||
{
|
||||
CMUint32 connectionID;
|
||||
SingleNumMessage request;
|
||||
CMTItem message;
|
||||
PickleSecurityStatusReply reply;
|
||||
|
||||
if (!control || !pickledStatus || !level) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set up the request */
|
||||
request.value = connectionID;
|
||||
|
||||
/* encode the request */
|
||||
if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_CONSERVE_RESOURCE | SSM_PICKLE_SECURITY_STATUS;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_CONSERVE_RESOURCE | SSM_PICKLE_SECURITY_STATUS)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the reply */
|
||||
if (CMT_DecodeMessage(PickleSecurityStatusReplyTemplate, &reply, &message)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* success */
|
||||
if (reply.result == 0) {
|
||||
*pickledStatus = reply.blob;
|
||||
*level = reply.securityLevel;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_OpenTLSConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMUint32 port, char* hostIP, char* hostName)
|
||||
{
|
||||
TLSDataConnectionRequest request;
|
||||
CMTItem message;
|
||||
DataConnectionReply reply;
|
||||
CMUint32 sent;
|
||||
|
||||
/* do some parameter checking */
|
||||
if (!control || !hostIP || !hostName) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.port = port;
|
||||
request.hostIP = hostIP;
|
||||
request.hostName = hostName;
|
||||
|
||||
/* encode the message */
|
||||
if (CMT_EncodeMessage(TLSDataConnectionRequestTemplate, &message, &request)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_TLS_CONNECTION;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_TLS_CONNECTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the message */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* success */
|
||||
if (reply.result == 0) {
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
sent = CMT_WriteThisMany(control, sock, control->nonce.data,
|
||||
control->nonce.len);
|
||||
if (sent != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_TLSStepUp(PCMT_CONTROL control, CMTSocket sock,
|
||||
void* clientContext)
|
||||
{
|
||||
TLSStepUpRequest request;
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
CMUint32 connectionID;
|
||||
|
||||
/* check arguments */
|
||||
if (!control || !sock) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection ID */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set up the request */
|
||||
request.connID = connectionID;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
|
||||
/* encode the request */
|
||||
if (CMT_EncodeMessage(TLSStepUpRequestTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION | SSM_TLS_STEPUP;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_TLS_STEPUP)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return (CMTStatus) reply.value;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_OpenSSLProxyConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMUint32 port, char* hostIP,
|
||||
char* hostName)
|
||||
{
|
||||
TLSDataConnectionRequest request;
|
||||
CMTItem message;
|
||||
DataConnectionReply reply;
|
||||
CMUint32 sent;
|
||||
|
||||
/* do some parameter checking */
|
||||
if (!control || !hostIP || !hostName) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
request.port = port;
|
||||
request.hostIP = hostIP;
|
||||
request.hostName = hostName;
|
||||
|
||||
/* encode the message */
|
||||
if (CMT_EncodeMessage(TLSDataConnectionRequestTemplate, &message, &request)
|
||||
!= CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_PROXY_CONNECTION;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION |
|
||||
SSM_PROXY_CONNECTION)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the message */
|
||||
if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* success */
|
||||
if (reply.result == 0) {
|
||||
if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
sent = CMT_WriteThisMany(control, sock, control->nonce.data,
|
||||
control->nonce.len);
|
||||
if (sent != control->nonce.len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* save connection info */
|
||||
if (CMT_AddDataConnection(control, sock, reply.connID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
}
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_ProxyStepUp(PCMT_CONTROL control, CMTSocket sock,
|
||||
void* clientContext, char* remoteUrl)
|
||||
{
|
||||
ProxyStepUpRequest request;
|
||||
SingleNumMessage reply;
|
||||
CMTItem message;
|
||||
CMUint32 connectionID;
|
||||
|
||||
/* check arguments */
|
||||
if (!control || !sock || !remoteUrl) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* get the data connection ID */
|
||||
if (CMT_GetDataConnectionID(control, sock, &connectionID) != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set up the request */
|
||||
request.connID = connectionID;
|
||||
request.clientContext = CMT_CopyPtrToItem(clientContext);
|
||||
request.url = remoteUrl;
|
||||
|
||||
/* encode the request */
|
||||
if (CMT_EncodeMessage(ProxyStepUpRequestTemplate, &message, &request) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the message request type */
|
||||
message.type = SSM_REQUEST_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_PROXY_STEPUP;
|
||||
|
||||
/* send the message and get the response */
|
||||
if (CMT_SendMessage(control, &message) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* validate the message reply type */
|
||||
if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_RESOURCE_ACTION |
|
||||
SSM_PROXY_STEPUP)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* decode the reply */
|
||||
if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) !=
|
||||
CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return (CMTStatus) reply.value;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
636
mozilla/security/psm/lib/client/cmtutils.c
Normal file
636
mozilla/security/psm/lib/client/cmtutils.c
Normal file
@@ -0,0 +1,636 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#else /* Windows */
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtutils.h"
|
||||
#include "newproto.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Local defines */
|
||||
#if 0
|
||||
#define PSM_WAIT_BEFORE_SLEEP (CM_TicksPerSecond() * 60)
|
||||
#define PSM_SPINTIME PSM_WAIT_BEFORE_SLEEP
|
||||
#define PSM_KEEP_CONNECTION_ALIVE (PSM_WAIT_BEFORE_SLEEP * 900)
|
||||
#endif
|
||||
|
||||
/* If you want to dump the messages sent between the plug-in and the PSM
|
||||
* server, then remove the comment for the appropriate define.
|
||||
*/
|
||||
#if 0
|
||||
#define PRINT_SEND_MESSAGES
|
||||
#define PRINT_RECEIVE_MESSAGES
|
||||
#endif
|
||||
|
||||
#ifdef PRINT_SEND_MESSAGES
|
||||
#ifndef DEBUG_MESSAGES
|
||||
#define DEBUG_MESSAGES
|
||||
#endif /*DEBUG_MESSAGES*/
|
||||
#endif /*PRINT_SEND_MESSAGES*/
|
||||
|
||||
#ifdef PRINT_RECEIVE_MESSAGES
|
||||
#ifndef DEBUG_MESSAGES
|
||||
#define DEBUG_MESSAGES
|
||||
#endif /*DEBUG_MESSAGES*/
|
||||
#endif /*PRINT_RECEIVE_MESSAGES*/
|
||||
|
||||
#ifdef DEBUG_MESSAGES
|
||||
#define LOG(x) do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, x); fclose(f); } } while(0);
|
||||
#define LOG_S(x) do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \
|
||||
fprintf(f, "%s", x); fclose(f); } } while(0);
|
||||
#define ASSERT(x) if (!(x)) { LOG("ASSERT:"); LOG(#x); LOG("\n"); exit(-1); }
|
||||
#else
|
||||
#define LOG(x)
|
||||
#define LOG_S(x)
|
||||
#define ASSERT(x)
|
||||
#endif
|
||||
|
||||
CMUint32
|
||||
cmt_Strlen(char *str)
|
||||
{
|
||||
CMUint32 len = strlen(str);
|
||||
return sizeof(CMInt32) + (((len + 3)/4)*4);
|
||||
}
|
||||
|
||||
CMUint32
|
||||
cmt_Bloblen(CMTItem *blob)
|
||||
{
|
||||
return sizeof(CMInt32) + (((blob->len +3)/4)*4);
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_PackString(char *buf, char *str)
|
||||
{
|
||||
CMUint32 len = strlen(str);
|
||||
CMUint32 networkLen = htonl(len);
|
||||
CMUint32 padlen = ((len + 3)/4)*4;
|
||||
|
||||
memcpy(buf, &networkLen, sizeof(CMUint32));
|
||||
memcpy(buf + sizeof(CMUint32), str, len);
|
||||
memset(buf + sizeof(CMUint32) + len, 0, padlen - len);
|
||||
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_PackBlob(char *buf, CMTItem *blob)
|
||||
{
|
||||
CMUint32 len = blob->len;
|
||||
CMUint32 networkLen = htonl(len);
|
||||
CMUint32 padlen = (((blob->len + 3)/4)*4);
|
||||
|
||||
*((CMUint32*)buf) = networkLen;
|
||||
memcpy(buf + sizeof(CMUint32), blob->data, len);
|
||||
memset(buf + sizeof(CMUint32) + len, 0, padlen - len);
|
||||
|
||||
return buf + sizeof(CMUint32) + padlen;
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_UnpackString(char *buf, char **str)
|
||||
{
|
||||
char *p = NULL;
|
||||
CMUint32 len, padlen;
|
||||
|
||||
/* Get the string length */
|
||||
len = ntohl(*(CMUint32*)buf);
|
||||
|
||||
/* Get the padded length */
|
||||
padlen = ((len + 3)/4)*4;
|
||||
|
||||
/* Allocate the string and copy the data */
|
||||
p = (char *) malloc(len + 1);
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
/* Copy the data and NULL terminate */
|
||||
memcpy(p, buf+sizeof(CMUint32), len);
|
||||
p[len] = 0;
|
||||
|
||||
*str = p;
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
loser:
|
||||
*str = NULL;
|
||||
if (p) {
|
||||
free(p);
|
||||
}
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
}
|
||||
|
||||
char *
|
||||
cmt_UnpackBlob(char *buf, CMTItem **blob)
|
||||
{
|
||||
CMTItem *p = NULL;
|
||||
CMUint32 len, padlen;
|
||||
|
||||
/* Get the blob length */
|
||||
len = ntohl(*(CMUint32*)buf);
|
||||
|
||||
/* Get the padded length */
|
||||
padlen = ((len + 3)/4)*4;
|
||||
|
||||
/* Allocate the CMTItem for the blob */
|
||||
p = (CMTItem*)malloc(sizeof(CMTItem));
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
p->len = len;
|
||||
p->data = (unsigned char *) malloc(len);
|
||||
if (!p->data) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Copy that data across */
|
||||
memcpy(p->data, buf+sizeof(CMUint32), len);
|
||||
*blob = p;
|
||||
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
|
||||
loser:
|
||||
*blob = NULL;
|
||||
CMT_FreeMessage(p);
|
||||
|
||||
return buf+sizeof(CMUint32)+padlen;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MESSAGES
|
||||
void prettyPrintMessage(CMTItem *msg)
|
||||
{
|
||||
int numLines = ((msg->len+7)/8);
|
||||
char curBuffer[9], *cursor, string[2], hexVal[8];
|
||||
char hexArray[25];
|
||||
int i, j, numToCopy;
|
||||
|
||||
/*Try printing out 8 bytes at a time. */
|
||||
LOG("\n**********************************************************\n");
|
||||
LOG("About to pretty Print Message\n\n");
|
||||
curBuffer[9] = '\0';
|
||||
hexArray[24] = '\0';
|
||||
hexVal[2] = '\0';
|
||||
string[1] = '\0';
|
||||
LOG("Header Info\n");
|
||||
LOG("Message Type: ");
|
||||
sprintf(hexArray, "%lx\n", msg->type);
|
||||
LOG(hexArray);
|
||||
LOG("Message Length: ");
|
||||
sprintf (hexArray, "%ld\n\n", msg->len);
|
||||
LOG(hexArray);
|
||||
LOG("Body of Message\n");
|
||||
for (i=0, cursor=msg->data; i<numLines; i++, cursor+=8) {
|
||||
/* First copy over the buffer to our local array */
|
||||
numToCopy = ((msg->len - (unsigned int)((unsigned long)cursor-(unsigned long)msg->data)) < 8) ?
|
||||
msg->len - (unsigned int)((unsigned long)cursor-(unsigned long)msg->data) : 8;
|
||||
memcpy(curBuffer, cursor, 8);
|
||||
for (j=0;j<numToCopy;j++) {
|
||||
string[0] = curBuffer[j];
|
||||
if (isprint(curBuffer[j])) {
|
||||
string[0] = curBuffer[j];
|
||||
} else {
|
||||
string[0] = ' ';
|
||||
}
|
||||
LOG(string);
|
||||
}
|
||||
string[0] = ' ';
|
||||
for (;j<8;j++) {
|
||||
LOG(string);
|
||||
}
|
||||
LOG("\t");
|
||||
for (j=0; j<numToCopy; j++) {
|
||||
sprintf (hexVal,"%.2x", 0x0ff & (unsigned short)curBuffer[j]);
|
||||
LOG(hexVal);
|
||||
LOG(" ");
|
||||
}
|
||||
LOG("\n");
|
||||
}
|
||||
LOG("Done Pretty Printing Message\n");
|
||||
LOG("**********************************************************\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
CMTStatus CMT_SendMessage(PCMT_CONTROL control, CMTItem* message)
|
||||
{
|
||||
CMTStatus status;
|
||||
CMUint32 msgCategory;
|
||||
CMBool done = CM_FALSE;
|
||||
#ifdef PRINT_SEND_MESSAGES
|
||||
LOG("About to print message sent to PSM\n");
|
||||
prettyPrintMessage(message);
|
||||
#endif
|
||||
|
||||
/* Acquire lock on the control connection */
|
||||
CMT_LOCK(control->mutex);
|
||||
|
||||
/* Try to send pending random data */
|
||||
if (message->type != (SSM_REQUEST_MESSAGE | SSM_HELLO_MESSAGE))
|
||||
{
|
||||
/* If we've already said hello, then flush random data
|
||||
just before sending the request. */
|
||||
status = CMT_FlushPendingRandomData(control);
|
||||
if (status != CMTSuccess)
|
||||
goto loser;
|
||||
}
|
||||
|
||||
status = CMT_TransmitMessage(control, message);
|
||||
if (status != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* We have to deal with other types of data on the socket and */
|
||||
/* handle them accordingly */
|
||||
while (!done) {
|
||||
status = CMT_ReceiveMessage(control, message);
|
||||
if (status != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
msgCategory = (message->type & SSM_CATEGORY_MASK);
|
||||
switch (msgCategory) {
|
||||
case SSM_REPLY_OK_MESSAGE:
|
||||
done = CM_TRUE;
|
||||
break;
|
||||
case SSM_REPLY_ERR_MESSAGE:
|
||||
done = CM_TRUE;
|
||||
break;
|
||||
case SSM_EVENT_MESSAGE:
|
||||
CMT_DispatchEvent(control, message);
|
||||
break;
|
||||
/* XXX FIX THIS!!! For the moment I'm ignoring all other types */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Release the control connection lock */
|
||||
CMT_UNLOCK(control->mutex);
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
/* Release the control connection lock */
|
||||
CMT_UNLOCK(control->mutex);
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_TransmitMessage(PCMT_CONTROL control, CMTItem * message)
|
||||
{
|
||||
CMTMessageHeader header;
|
||||
CMUint32 sent, rv;
|
||||
|
||||
/* Set up the message header */
|
||||
header.type = htonl(message->type);
|
||||
header.len = htonl(message->len);
|
||||
|
||||
/* Send the message header */
|
||||
sent = CMT_WriteThisMany(control, control->sock,
|
||||
(void *)&header, sizeof(CMTMessageHeader));
|
||||
if (sent != sizeof(CMTMessageHeader)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Send the message body */
|
||||
sent = CMT_WriteThisMany(control, control->sock, (void *)message->data,
|
||||
message->len);
|
||||
if (sent != message->len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Free the buffer */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
return CMTSuccess;
|
||||
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_ReceiveMessage(PCMT_CONTROL control, CMTItem * response)
|
||||
{
|
||||
CMTMessageHeader header;
|
||||
CMUint32 numread, rv;
|
||||
|
||||
/* Get the message header */
|
||||
numread = CMT_ReadThisMany(control, control->sock,
|
||||
(void *)&header, sizeof(CMTMessageHeader));
|
||||
if (numread != sizeof(CMTMessageHeader)) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
response->type = ntohl(header.type);
|
||||
response->len = ntohl(header.len);
|
||||
response->data = (unsigned char *) malloc(response->len);
|
||||
if (response->data == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
numread = CMT_ReadThisMany(control, control->sock,
|
||||
(void *)(response->data), response->len);
|
||||
if (numread != response->len) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
#ifdef PRINT_RECEIVE_MESSAGES
|
||||
LOG("About to print message received from PSM.\n");
|
||||
prettyPrintMessage(response);
|
||||
#endif /*PRINT_RECEIVE_MESSAGES*/
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
if (response->data) {
|
||||
free(response->data);
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMUint32 CMT_ReadThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany)
|
||||
{
|
||||
CMUint32 total = 0;
|
||||
|
||||
while (total < thisMany) {
|
||||
int got;
|
||||
got = control->sockFuncs.recv(sock, (void*)((char*)buffer + total),
|
||||
thisMany-total);
|
||||
if (got < 0 ) {
|
||||
break;
|
||||
}
|
||||
total += got;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
CMUint32 CMT_WriteThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany)
|
||||
{
|
||||
CMUint32 total = 0;
|
||||
|
||||
while (total < thisMany) {
|
||||
CMInt32 got;
|
||||
got = control->sockFuncs.send(sock, (void*)((char*)buffer+total),
|
||||
thisMany-total);
|
||||
if (got < 0) {
|
||||
break;
|
||||
}
|
||||
total += got;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
CMTItem* CMT_ConstructMessage(CMUint32 type, CMUint32 length)
|
||||
{
|
||||
CMTItem * p;
|
||||
|
||||
p = (CMTItem*)malloc(sizeof(CMTItem));
|
||||
if (!p) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
p->type = type;
|
||||
p->len = length;
|
||||
p->data = (unsigned char *) malloc(length);
|
||||
if (!p->data) {
|
||||
goto loser;
|
||||
}
|
||||
return p;
|
||||
|
||||
loser:
|
||||
CMT_FreeMessage(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CMT_FreeMessage(CMTItem * p)
|
||||
{
|
||||
if (p != NULL) {
|
||||
if (p->data != NULL) {
|
||||
free(p->data);
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
CMTStatus CMT_AddDataConnection(PCMT_CONTROL control, CMTSocket sock,
|
||||
CMUint32 connectionID)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
/* This is the first connection */
|
||||
if (control->cmtDataConnections == NULL) {
|
||||
control->cmtDataConnections = ptr =
|
||||
(PCMT_DATA)calloc(sizeof(CMT_DATA), 1);
|
||||
if (!ptr) {
|
||||
goto loser;
|
||||
}
|
||||
} else {
|
||||
/* Position at the last entry */
|
||||
for (ptr = control->cmtDataConnections; (ptr != NULL && ptr->next
|
||||
!= NULL); ptr = ptr->next);
|
||||
ptr->next = (PCMT_DATA)calloc(sizeof(CMT_DATA), 1);
|
||||
if (!ptr->next) {
|
||||
goto loser;
|
||||
}
|
||||
/* Fix up the pointers */
|
||||
ptr->next->previous = ptr;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
/* Fill in the data */
|
||||
ptr->sock = sock;
|
||||
ptr->connectionID = connectionID;
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
int
|
||||
CMT_DestroyDataConnection(PCMT_CONTROL control, CMTSocket sock)
|
||||
{
|
||||
PCMT_DATA ptr, pptr = NULL;
|
||||
int rv=CMTSuccess;
|
||||
|
||||
control->sockFuncs.close(sock);
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL;
|
||||
pptr = ptr, ptr = ptr->next) {
|
||||
if (ptr->sock == sock) {
|
||||
if (pptr == NULL) {
|
||||
/* node is at head */
|
||||
control->cmtDataConnections = ptr->next;
|
||||
if (ptr->priv != NULL)
|
||||
ptr->priv->dest(ptr->priv);
|
||||
free(ptr);
|
||||
return rv;
|
||||
}
|
||||
/* node is elsewhere */
|
||||
pptr->next = ptr->next;
|
||||
if (ptr->priv != NULL)
|
||||
ptr->priv->dest(ptr->priv);
|
||||
free(ptr);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
CMTStatus CMT_CloseDataConnection(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
/* PCMT_DATA ptr, pptr = NULL; */
|
||||
CMTSocket sock;
|
||||
/* int rv;*/
|
||||
|
||||
/* Get the socket for this connection */
|
||||
if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Free data connection associated with this socket */
|
||||
if (CMT_DestroyDataConnection(control, sock) == CMTFailure) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetDataConnectionID(PCMT_CONTROL control, CMTSocket sock, CMUint32 * connectionID)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->sock == sock) {
|
||||
*connectionID = ptr->connectionID;
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus CMT_GetDataSocket(PCMT_CONTROL control, CMUint32 connectionID, CMTSocket * sock)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->connectionID == connectionID) {
|
||||
*sock = ptr->sock;
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus CMT_SetPrivate(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
CMTPrivate *cmtpriv)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->connectionID == connectionID) {
|
||||
ptr->priv = cmtpriv;
|
||||
return CMTSuccess;
|
||||
}
|
||||
}
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTPrivate *CMT_GetPrivate(PCMT_CONTROL control, CMUint32 connectionID)
|
||||
{
|
||||
PCMT_DATA ptr;
|
||||
|
||||
for (ptr = control->cmtDataConnections; ptr != NULL; ptr = ptr->next) {
|
||||
if (ptr->connectionID == connectionID) {
|
||||
return ptr->priv;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CMT_FreeItem(CMTItem *p)
|
||||
{
|
||||
CMT_FreeMessage(p);
|
||||
}
|
||||
|
||||
CMTItem CMT_CopyPtrToItem(void* p)
|
||||
{
|
||||
CMTItem value = {0, NULL, 0};
|
||||
|
||||
if (!p) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value.len = sizeof(p);
|
||||
value.data = (unsigned char *) malloc(value.len);
|
||||
memcpy(value.data, &p, value.len);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void * CMT_CopyItemToPtr(CMTItem value)
|
||||
{
|
||||
void * p = NULL;
|
||||
|
||||
if (value.len == sizeof(void*)) {
|
||||
memcpy(&p, value.data, value.len);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
CMTStatus CMT_ReferenceControlConnection(PCMT_CONTROL control)
|
||||
{
|
||||
CMT_LOCK(control->mutex);
|
||||
control->refCount++;
|
||||
CMT_UNLOCK(control->mutex);
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
void
|
||||
CMT_LockConnection(PCMT_CONTROL control)
|
||||
{
|
||||
CMT_LOCK(control->mutex);
|
||||
}
|
||||
|
||||
void
|
||||
CMT_UnlockConnection(PCMT_CONTROL control)
|
||||
{
|
||||
CMT_UNLOCK(control->mutex);
|
||||
}
|
||||
75
mozilla/security/psm/lib/client/cmtutils.h
Normal file
75
mozilla/security/psm/lib/client/cmtutils.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __CMTUTILS_H__
|
||||
#define __CMTUTILS_H__
|
||||
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#define New(type) (type*)malloc(sizeof(type))
|
||||
#define NewArray(type, size) (type*)malloc(sizeof(type)*(size))
|
||||
|
||||
PCMT_EVENT CMT_GetEventHandler(PCMT_CONTROL control, CMUint32 type,
|
||||
CMUint32 resourceID);
|
||||
|
||||
CMUint32 cmt_Strlen(char *str);
|
||||
char *cmt_PackString(char *buf, char *str);
|
||||
char *cmt_UnpackString(char *buf, char **str);
|
||||
|
||||
CMUint32 cmt_Bloblen(CMTItem* len);
|
||||
char *cmt_PackBlob(char *buf, CMTItem * blob);
|
||||
char *cmt_UnpackBlob(char *buf, CMTItem **blob);
|
||||
|
||||
CMTStatus CMT_SendMessage(PCMT_CONTROL control, CMTItem* message);
|
||||
CMTStatus CMT_TransmitMessage(PCMT_CONTROL control, CMTItem * message);
|
||||
CMTStatus CMT_ReceiveMessage(PCMT_CONTROL control, CMTItem * response);
|
||||
CMUint32 CMT_ReadThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany);
|
||||
CMUint32 CMT_WriteThisMany(PCMT_CONTROL control, CMTSocket sock,
|
||||
void * buffer, CMUint32 thisMany);
|
||||
CMTItem* CMT_ConstructMessage(CMUint32 type, CMUint32 length);
|
||||
void CMT_FreeMessage(CMTItem * p);
|
||||
CMTStatus CMT_AddDataConnection(PCMT_CONTROL control, CMTSocket sock, CMUint32 connectionID);
|
||||
CMTStatus CMT_GetDataConnectionID(PCMT_CONTROL control, CMTSocket sock, CMUint32 * connectionID);
|
||||
CMTStatus CMT_GetDataSocket(PCMT_CONTROL control, CMUint32 connectionID, CMTSocket * sock);
|
||||
CMTStatus CMT_CloseDataConnection(PCMT_CONTROL control, CMUint32 connectionID);
|
||||
CMTStatus CMT_SetPrivate(PCMT_CONTROL control, CMUint32 connectionID,
|
||||
CMTPrivate *cmtpriv);
|
||||
CMTPrivate *CMT_GetPrivate(PCMT_CONTROL control, CMUint32 connectionID);
|
||||
void CMT_ServicePasswordRequest(PCMT_CONTROL cm_control, CMTItem * requestData);
|
||||
void CMT_ProcessEvent(PCMT_CONTROL cm_control);
|
||||
void CMT_DispatchEvent(PCMT_CONTROL cm_control, CMTItem * eventData);
|
||||
CMTItem CMT_CopyPtrToItem(void* p);
|
||||
void * CMT_CopyItemToPtr(CMTItem value);
|
||||
|
||||
#endif /* __CMTUTILS_H__ */
|
||||
|
||||
44
mozilla/security/psm/lib/client/config.mk
Normal file
44
mozilla/security/psm/lib/client/config.mk
Normal file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
SHARED_LIBRARY =
|
||||
IMPORT_LIBRARY =
|
||||
PURE_LIBRARY =
|
||||
PROGRAM =
|
||||
|
||||
125
mozilla/security/psm/lib/client/makefile.win
Normal file
125
mozilla/security/psm/lib/client/makefile.win
Normal file
@@ -0,0 +1,125 @@
|
||||
#//
|
||||
#// The contents of this file are subject to the Mozilla Public
|
||||
#// License Version 1.1 (the "License"); you may not use this file
|
||||
#// except in compliance with the License. You may obtain a copy of
|
||||
#// the License at http://www.mozilla.org/MPL/
|
||||
#//
|
||||
#// Software distributed under the License is distributed on an "AS
|
||||
#// IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
#// implied. See the License for the specific language governing
|
||||
#// rights and limitations under the License.
|
||||
#//
|
||||
#// The Original Code is the Netscape security libraries.
|
||||
#//
|
||||
#// The Initial Developer of the Original Code is Netscape
|
||||
#// Communications Corporation. Portions created by Netscape are
|
||||
#// Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
#// Rights Reserved.
|
||||
#//
|
||||
#// Contributor(s):
|
||||
#//
|
||||
#// Alternatively, the contents of this file may be used under the
|
||||
#// terms of the GNU General Public License Version 2 or later (the
|
||||
#// "GPL"), in which case the provisions of the GPL are applicable
|
||||
#// instead of those above. If you wish to allow use of your
|
||||
#// version of this file only under the terms of the GPL and not to
|
||||
#// allow others to use your version of this file under the MPL,
|
||||
#// indicate your decision by deleting the provisions above and
|
||||
#// replace them with the notice and other provisions required by
|
||||
#// the GPL. If you do not delete the provisions above, a recipient
|
||||
#// may use your version of this file under either the MPL or the
|
||||
#// GPL.
|
||||
#//
|
||||
IGNORE_MANIFEST=1
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Makefile to build the ssl library
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
!if "$(MOZ_BITS)" == "16"
|
||||
!ifndef MOZ_DEBUG
|
||||
OPTIMIZER=-Os -UDEBUG -DNDEBUG
|
||||
!endif
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\..\..
|
||||
|
||||
!ifndef MAKE_OBJ_TYPE
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBNAME=cmt
|
||||
PDBFILE=$(LIBNAME).pdb
|
||||
|
||||
LINCS = -I$(PUBLIC)\security \
|
||||
-I$(PUBLIC)\nspr \
|
||||
-I$(DEPTH)\include \
|
||||
-I..\include
|
||||
|
||||
!ifndef OS_CONFIG
|
||||
OS_CONFIG = WIN$(MOZ_BITS)
|
||||
!endif
|
||||
|
||||
LCFLAGS = -DEXPORT_VERSION -DLIB_BUILD
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\cmtinit.obj \
|
||||
.\$(OBJDIR)\cmtssl.obj \
|
||||
.\$(OBJDIR)\cmtutils.obj \
|
||||
.\$(OBJDIR)\cmtpkcs7.obj \
|
||||
.\$(OBJDIR)\cmthash.obj \
|
||||
.\$(OBJDIR)\cmtcert.obj \
|
||||
.\$(OBJDIR)\cmtres.obj \
|
||||
.\$(OBJDIR)\cmtjs.obj \
|
||||
.\$(OBJDIR)\cmtevent.obj \
|
||||
.\$(OBJDIR)\cmtpasswd.obj \
|
||||
.\$(OBJDIR)\cmtadvisor.obj \
|
||||
.\$(OBJDIR)\cmtrng.obj \
|
||||
.\$(OBJDIR)\cmtsdr.obj \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBRARY=.\$(OBJDIR)\$(LIBNAME).lib
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// install headers
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
INSTALL_DIR=$(PUBLIC)\security
|
||||
INSTALL_FILE_LIST=cmtcmn.h cmtjs.h cmtclist.h
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
export:: INSTALL_FILES
|
||||
|
||||
64
mozilla/security/psm/lib/client/manifest.mn
Normal file
64
mozilla/security/psm/lib/client/manifest.mn
Normal file
@@ -0,0 +1,64 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
CORE_DEPTH = ../../..
|
||||
DEPTH = ../../..
|
||||
|
||||
EXPORTS = \
|
||||
cmtcmn.h \
|
||||
cmtjs.h \
|
||||
cmtclist.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = security
|
||||
|
||||
CSRCS = cmtinit.c \
|
||||
cmtssl.c \
|
||||
cmtutils.c \
|
||||
cmtcert.c \
|
||||
cmthash.c \
|
||||
cmtpkcs7.c \
|
||||
cmtres.c \
|
||||
cmtjs.c \
|
||||
cmtevent.c \
|
||||
cmtpasswd.c \
|
||||
cmtadvisor.c \
|
||||
cmtrng.c \
|
||||
cmtsdr.c \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = nspr security
|
||||
|
||||
LIBRARY_NAME = cmt
|
||||
|
||||
INCLUDES += -I$(CORE_DEPTH)/include
|
||||
128
mozilla/security/psm/lib/client/sample/Makefile
Normal file
128
mozilla/security/psm/lib/client/sample/Makefile
Normal file
@@ -0,0 +1,128 @@
|
||||
#! gmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
ifneq ($(OS_ARCH), WINNT)
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
# On linux, we link with libstdc++
|
||||
CPLUSPLUSRUNTIME = -L /usr/lib -lstdc++ -lm
|
||||
else
|
||||
# libC, presumably, is what we must link with elsewhere
|
||||
CPLUSPLUSRUNTIME = -lC -lm
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), SunOS)
|
||||
ifeq ($(OS_RELEASE), 5.5.1)
|
||||
OS_LIBS += -ldl -lsocket -lnsl -lthread -lposix4
|
||||
endif
|
||||
ifeq ($(OS_RELEASE), 5.6)
|
||||
OS_LIBS += -ldl -lsocket -lnsl -lthread -lposix4
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
ifdef USE_PTHREADS
|
||||
# Replace OS_LIBS, because the order of libpthread, libdl, and libc are
|
||||
# very important. Otherwise you get horrible crashes.
|
||||
OS_LIBS = -lpthread -ldl -lc
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
LDFLAGS += /NODEFAULTLIB:library
|
||||
endif
|
||||
|
||||
EXTRA_LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)cmt.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)protocol.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
EXTRA_LIBS += wsock32.lib \
|
||||
winmm.lib \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
link:
|
||||
if test -f $(PROGRAM); then \
|
||||
echo "rm $(PROGRAM)"; \
|
||||
rm $(PROGRAM); \
|
||||
fi; \
|
||||
gmake \
|
||||
|
||||
build_sample:
|
||||
ifneq ($(OS_ARCH),WINNT)
|
||||
cd $(CORE_DEPTH)/coreconf; gmake
|
||||
endif
|
||||
cd $(CORE_DEPTH)/security; gmake import; gmake export
|
||||
cd ../../protocol; gmake
|
||||
cd ..; gmake
|
||||
gmake
|
||||
|
||||
250
mozilla/security/psm/lib/client/sample/appsock.c
Normal file
250
mozilla/security/psm/lib/client/sample/appsock.c
Normal file
@@ -0,0 +1,250 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "cmtcmn.h"
|
||||
#include "appsock.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <netinet/tcp.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
CMT_SocketFuncs socketFuncs = {
|
||||
APP_GetSocket,
|
||||
APP_Connect,
|
||||
APP_VerifyUnixSocket,
|
||||
APP_Send,
|
||||
APP_Select,
|
||||
APP_Receive,
|
||||
APP_Shutdown,
|
||||
APP_Close
|
||||
};
|
||||
|
||||
CMTSocket APP_GetSocket(int unixSock)
|
||||
{
|
||||
APPSocket *sock;
|
||||
int on = 1;
|
||||
|
||||
#ifndef XP_UNIX
|
||||
if (unixSock) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
sock = malloc(sizeof(APPSocket));
|
||||
if (sock == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (unixSock) {
|
||||
sock->sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
} else {
|
||||
sock->sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
if (sock->sock < 0) {
|
||||
free(sock);
|
||||
return NULL;
|
||||
}
|
||||
if (!unixSock &&
|
||||
setsockopt(sock->sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&on,
|
||||
sizeof(on))) {
|
||||
free(sock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->isUnix = unixSock;
|
||||
#ifdef XP_UNIX
|
||||
memset (&sock->servAddr, 0, sizeof(struct sockaddr_un));
|
||||
#endif
|
||||
return (CMTSocket)sock;
|
||||
}
|
||||
|
||||
CMTStatus APP_Connect(CMTSocket sock, short port, char *path)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
struct sockaddr_in iServAddr;
|
||||
const struct sockaddr *servAddr;
|
||||
size_t addrLen;
|
||||
int error;
|
||||
|
||||
if (cmSock->isUnix){
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
cmSock->servAddr.sun_family = AF_UNIX;
|
||||
memcpy(&cmSock->servAddr.sun_path, path, strlen(path)+1);
|
||||
servAddr = (const struct sockaddr*)&cmSock->servAddr;
|
||||
addrLen = sizeof(cmSock->servAddr);
|
||||
#endif
|
||||
} else {
|
||||
iServAddr.sin_family = AF_INET;
|
||||
iServAddr.sin_port = htons(port);
|
||||
iServAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
servAddr = (const struct sockaddr*)&iServAddr;
|
||||
addrLen = sizeof(struct sockaddr_in);
|
||||
}
|
||||
while (connect(cmSock->sock, servAddr, addrLen) != 0) {
|
||||
#ifdef WIN32
|
||||
error = WSAGetLastError();
|
||||
if (error == WSAEISCONN) {
|
||||
break;
|
||||
}
|
||||
if ((error != WSAEINPROGRESS) && (error != WSAEWOULDBLOCK) &&
|
||||
(error!= WSAEINVAL)) {
|
||||
goto loser;
|
||||
}
|
||||
#else
|
||||
error = errno;
|
||||
if (error == EISCONN) {
|
||||
break;
|
||||
}
|
||||
if (error != EINPROGRESS) {
|
||||
goto loser;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus APP_VerifyUnixSocket(CMTSocket sock)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
int rv;
|
||||
struct stat statbuf;
|
||||
|
||||
if (!cmSock->isUnix) {
|
||||
return CMTFailure;
|
||||
}
|
||||
rv = stat(cmSock->servAddr.sun_path, &statbuf);
|
||||
if (rv < 0) {
|
||||
goto loser;
|
||||
}
|
||||
if (statbuf.st_uid != geteuid()) {
|
||||
goto loser;
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
close(cmSock->sock);
|
||||
free(cmSock);
|
||||
return CMTFailure;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t APP_Send(CMTSocket sock, void *buffer, size_t length)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*) sock;
|
||||
|
||||
return send(cmSock->sock, buffer, length, 0);
|
||||
}
|
||||
|
||||
CMTSocket APP_Select(CMTSocket *socks, int numsocks, int poll)
|
||||
{
|
||||
APPSocket **sockArr = (APPSocket**)socks;
|
||||
SOCKET nsocks = 0;
|
||||
int i, rv;
|
||||
struct timeval timeout;
|
||||
fd_set readfds;
|
||||
|
||||
#ifdef WIN32
|
||||
win_startover:
|
||||
#endif
|
||||
FD_ZERO(&readfds);
|
||||
for (i=0; i<numsocks; i++) {
|
||||
FD_SET(sockArr[i]->sock, &readfds);
|
||||
if (sockArr[i]->sock > nsocks) {
|
||||
nsocks = sockArr[i]->sock;
|
||||
}
|
||||
}
|
||||
if (poll) {
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
}
|
||||
rv = select(nsocks+1, &readfds, NULL, NULL, (poll) ? &timeout : NULL);
|
||||
|
||||
#ifdef WIN32
|
||||
/* XXX Win95/98 Bug (Q177346)
|
||||
* select() with no timeout might return even if there is no data
|
||||
* pending or no error has occurred. To get around this problem,
|
||||
* we loop if these erroneous conditions happen.
|
||||
*/
|
||||
if (poll == 0 && rv == 0) {
|
||||
goto win_startover;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Figure out which socket was selected */
|
||||
if (rv == -1 || rv == 0) {
|
||||
goto loser;
|
||||
}
|
||||
for (i=0; i<numsocks; i++) {
|
||||
if (FD_ISSET(sockArr[i]->sock, &readfds)) {
|
||||
return (CMTSocket)sockArr[i];
|
||||
}
|
||||
}
|
||||
loser:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t APP_Receive(CMTSocket sock, void *buffer, size_t bufSize)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
|
||||
return recv(cmSock->sock, buffer, bufSize, 0);
|
||||
}
|
||||
|
||||
CMTStatus APP_Shutdown(CMTSocket sock)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
int rv;
|
||||
|
||||
rv = shutdown(cmSock->sock, 1);
|
||||
return (rv == 0) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus APP_Close(CMTSocket sock)
|
||||
{
|
||||
APPSocket *cmSock = (APPSocket*)sock;
|
||||
int rv;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
rv = close(cmSock->sock);
|
||||
#else
|
||||
rv = closesocket(cmSock->sock);
|
||||
#endif
|
||||
free(cmSock);
|
||||
return (rv == 0) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
69
mozilla/security/psm/lib/client/sample/appsock.h
Normal file
69
mozilla/security/psm/lib/client/sample/appsock.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef _APPSOCK_H_
|
||||
#define _APPSOCK_H_
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
typedef int SOCKET;
|
||||
#endif
|
||||
|
||||
typedef struct APPSocketStr {
|
||||
SOCKET sock;
|
||||
int isUnix;
|
||||
#ifdef XP_UNIX
|
||||
struct sockaddr_un servAddr;
|
||||
#endif
|
||||
} APPSocket;
|
||||
|
||||
extern CMT_SocketFuncs socketFuncs;
|
||||
|
||||
CMTStatus APP_Close(CMTSocket sock);
|
||||
CMTStatus APP_Shutdown(CMTSocket sock);
|
||||
size_t APP_Receive(CMTSocket sock, void *buffer, size_t bufSize);
|
||||
CMTSocket APP_Select(CMTSocket *socks, int numsocks, int poll);
|
||||
size_t APP_Send(CMTSocket sock, void *buffer, size_t length);
|
||||
CMTStatus APP_VerifyUnixSocket(CMTSocket sock);
|
||||
CMTStatus APP_Connect(CMTSocket sock, short port, char *path);
|
||||
CMTSocket APP_GetSocket(int unixSock);
|
||||
|
||||
|
||||
#endif /* _APPSOCK_H_ */
|
||||
44
mozilla/security/psm/lib/client/sample/config.mk
Normal file
44
mozilla/security/psm/lib/client/sample/config.mk
Normal file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
TARGETS = $(PROGRAM)
|
||||
SHARED_LIBRARY =
|
||||
IMPORT_LIBRARY =
|
||||
PURE_LIBRARY =
|
||||
LIBRARY =
|
||||
|
||||
52
mozilla/security/psm/lib/client/sample/manifest.mn
Normal file
52
mozilla/security/psm/lib/client/sample/manifest.mn
Normal file
@@ -0,0 +1,52 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
CORE_DEPTH = ../../../../..
|
||||
|
||||
# MODULE public and private header directories are implicitly REQUIRED.
|
||||
MODULE = cmtsample
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
sample.c \
|
||||
appsock.c \
|
||||
$(NULL)
|
||||
INCLUDES += -I../../protocol -I..
|
||||
|
||||
# The MODULE is always implicitly required.
|
||||
# Listing it here in REQUIRES makes it appear twice in the cc command line.
|
||||
REQUIRES = security
|
||||
|
||||
PROGRAM = cmtsample
|
||||
|
||||
346
mozilla/security/psm/lib/client/sample/sample.c
Normal file
346
mozilla/security/psm/lib/client/sample/sample.c
Normal file
@@ -0,0 +1,346 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtjs.h"
|
||||
#include "appsock.h"
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <netdb.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is a simple program that tries to detect if the psm server is loaded.
|
||||
* If the server is not loaded, it will start it. The program will then
|
||||
* connect to the server and fetch an HTML page from an SSL server.
|
||||
*
|
||||
* NOTE: This sample program does not implement a mutex for the libraries.
|
||||
* If implementing a threaded application, then pass in a mutex structure
|
||||
* so that connections to the psm server happen in a thread safe manner.
|
||||
*/
|
||||
|
||||
#define NUM_CONNECT_TRIES 10
|
||||
#define READ_BUFFER_SIZE 1024
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
printf("Usage:\n"
|
||||
"\tcmtsample <secure site>\n\n"
|
||||
"This program will then echo the retrieved HTML to the screen\n");
|
||||
}
|
||||
|
||||
void
|
||||
errorMessage(int err,char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
fprintf (stderr, "cmtSample%s: ", (err) ? " error" : "");
|
||||
vfprintf (stderr, msg, args);
|
||||
fprintf (stderr, "\n");
|
||||
va_end(args);
|
||||
if (err) {
|
||||
exit (err);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define FILE_PATH_SEPARATOR '/'
|
||||
#elif defined (WIN32)
|
||||
#define FILE_PATH_SEPARATOR '\\'
|
||||
#else
|
||||
#error Tell me what the file path separator is.
|
||||
#endif
|
||||
|
||||
PCMT_CONTROL
|
||||
connect_to_psm(void)
|
||||
{
|
||||
PCMT_CONTROL control=NULL;
|
||||
char path[256], *tmp;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
if (getcwd(path,256) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#elif defined(WIN32)
|
||||
if (_getcwd(path,256) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
#error Teach me how to get the current working directory.
|
||||
#endif
|
||||
tmp = &path[strlen(path)];
|
||||
sprintf(tmp,"%c%s", FILE_PATH_SEPARATOR, "psm");
|
||||
return CMT_EstablishControlConnection(path, &socketFuncs, NULL);
|
||||
}
|
||||
|
||||
#define HTTPS_STRING "https://"
|
||||
|
||||
char*
|
||||
extract_host_from_url(char *url)
|
||||
{
|
||||
char *start, *end, *retString=NULL;
|
||||
|
||||
while(isspace(*url)) {
|
||||
url++;
|
||||
}
|
||||
url = strdup(url);
|
||||
start = strstr(url, HTTPS_STRING);
|
||||
if (start == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
start += strlen(HTTPS_STRING);
|
||||
/*
|
||||
* Figure out the end of the host name.
|
||||
*/
|
||||
end = strchr(start, ':');
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
} else {
|
||||
end = strchr(start, '/');
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
} else {
|
||||
end = strchr(start, ' ');
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
retString = strdup(start);
|
||||
return retString;
|
||||
}
|
||||
|
||||
CMUint32
|
||||
get_port_from_url(char *url)
|
||||
{
|
||||
char *colon, *port;
|
||||
|
||||
url = strdup(url);
|
||||
colon = strrchr(url, ':');
|
||||
if (colon == NULL ||
|
||||
!isdigit(colon[1])) {
|
||||
/* Return the default SSL port. */
|
||||
free(url);
|
||||
return 443;
|
||||
}
|
||||
colon++;
|
||||
port = colon;
|
||||
while(isdigit(*colon))
|
||||
colon++;
|
||||
colon[1] = '\0';
|
||||
free(url);
|
||||
return (CMUint32)atol(port);
|
||||
}
|
||||
|
||||
char*
|
||||
extract_get_target(char *url)
|
||||
{
|
||||
char *slash;
|
||||
|
||||
slash = strstr(url, "//");
|
||||
slash += 2;
|
||||
slash = strchr(slash, '/');
|
||||
if (slash != NULL)
|
||||
return strdup (slash);
|
||||
else
|
||||
return strdup ("/");
|
||||
}
|
||||
|
||||
/*
|
||||
* We'll use this function for prompting for a password.
|
||||
*/
|
||||
char*
|
||||
passwordCallback(void *arg, char *prompt, void *cotext, int isPaswd)
|
||||
{
|
||||
char input[256];
|
||||
|
||||
printf(prompt);
|
||||
fgets(input, 256, stdin);
|
||||
|
||||
return strdup(input);
|
||||
}
|
||||
|
||||
void
|
||||
freeCallback(char *userInput)
|
||||
{
|
||||
free (userInput);
|
||||
}
|
||||
|
||||
#define NUM_PREFS 2
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
PCMT_CONTROL control;
|
||||
CMTSocket sock, selSock;
|
||||
char *hostname;
|
||||
struct hostent *host;
|
||||
char *ipAddress;
|
||||
char buffer[READ_BUFFER_SIZE];
|
||||
size_t bytesRead;
|
||||
struct sockaddr_in destAddr;
|
||||
char *getString;
|
||||
char requestString[256];
|
||||
char *profile;
|
||||
CMTSetPrefElement prefs[NUM_PREFS];
|
||||
char profileDir[256];
|
||||
|
||||
#ifdef WIN32
|
||||
WORD WSAVersion = 0x0101;
|
||||
WSADATA WSAData;
|
||||
|
||||
WSAStartup (WSAVersion, &WSAData);
|
||||
#endif
|
||||
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
errorMessage (0,"cmtsample v1.0");
|
||||
errorMessage (0,"Will try connecting to site %s", argv[1]);
|
||||
if (strstr(argv[1], "https://") == NULL) {
|
||||
errorMessage(2,"%s is not a secure site", argv[1]);
|
||||
}
|
||||
control = connect_to_psm();
|
||||
if (control == NULL) {
|
||||
errorMessage(3, "Could not connect to the psm server");
|
||||
}
|
||||
/*
|
||||
* Now we have to send the hello message.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
profile = strdup("default");
|
||||
sprintf(profileDir,"%s", "c:\\default");
|
||||
#elif defined (XP_UNIX)
|
||||
profile = getenv("LOGNAME");
|
||||
sprintf(profileDir, "%s/.netscape", getenv("HOME"));
|
||||
#else
|
||||
#error Teach me how to fill in the user profile.
|
||||
#endif
|
||||
if (CMT_Hello(control, PROTOCOL_VERSION,
|
||||
profile, profileDir) != CMTSuccess)
|
||||
{
|
||||
errorMessage(10, "Failed to send the Hello Message.");
|
||||
}
|
||||
CMT_SetPromptCallback(control, passwordCallback, NULL);
|
||||
CMT_SetAppFreeCallback(control, freeCallback);
|
||||
/*
|
||||
* Now pass along some preferences to psm. We'll pass hard coded
|
||||
* ones here, but apps should figure out a way to manage their user's
|
||||
* preferences.
|
||||
*/
|
||||
prefs[0].key = "security.enable_ssl2";
|
||||
prefs[0].value = "true";
|
||||
prefs[0].type = CMT_PREF_BOOL;
|
||||
prefs[1].key = "security.enable_ssl3";
|
||||
prefs[1].value = "true";
|
||||
prefs[1].type = CMT_PREF_BOOL;
|
||||
CMT_PassAllPrefs(control, NUM_PREFS, prefs);
|
||||
hostname = extract_host_from_url(argv[1]);
|
||||
host = gethostbyname(hostname);
|
||||
if (host == NULL) {
|
||||
errorMessage(11, "gethostbyname for %s failed", hostname);
|
||||
}
|
||||
if (host->h_length != 4) {
|
||||
errorMessage(4, "Site %s uses IV v6 socket. Not supported by psm.");
|
||||
}
|
||||
|
||||
/* Create the socket we will use to get the decrypted data back from
|
||||
* the psm server.
|
||||
*/
|
||||
sock = APP_GetSocket(0);
|
||||
if (sock == NULL) {
|
||||
errorMessage(5, "Could not create new socket for communication with "
|
||||
"the psm server.");
|
||||
}
|
||||
memcpy(&(destAddr.sin_addr.s_addr), host->h_addr, host->h_length);
|
||||
ipAddress = inet_ntoa(destAddr.sin_addr);
|
||||
errorMessage(0, "Mapped %s to the following IP address: %s", argv[1],
|
||||
ipAddress);
|
||||
|
||||
if (CMT_OpenSSLConnection(control, sock, SSM_REQUEST_SSL_DATA_SSL,
|
||||
get_port_from_url(argv[1]), ipAddress,
|
||||
hostname, CM_FALSE, NULL) != CMTSuccess) {
|
||||
errorMessage(6, "Could not open SSL connection to %s.", argv[1]);
|
||||
}
|
||||
|
||||
getString = extract_get_target(argv[1]);
|
||||
sprintf(requestString,
|
||||
"GET %s HTTP/1.0\r\n"
|
||||
"\r\n", getString, hostname);
|
||||
APP_Send(sock, requestString, strlen(requestString));
|
||||
/*
|
||||
* Now all we have to do is sit here and fetch the data from the
|
||||
* socket.
|
||||
*/
|
||||
errorMessage (0, "About to print out the fetched page.");
|
||||
while ((selSock=APP_Select(&sock, 1, 0)) != NULL) {
|
||||
if (selSock == sock) {
|
||||
bytesRead = APP_Receive(sock, buffer, READ_BUFFER_SIZE-1);
|
||||
if (bytesRead == -1 || bytesRead == 0) {
|
||||
break;
|
||||
}
|
||||
buffer[bytesRead] = '\0';
|
||||
fprintf(stderr, buffer);
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"\n");
|
||||
if (bytesRead == -1) {
|
||||
errorMessage(7, "Error receiving decrypted data from psm.");
|
||||
}
|
||||
errorMessage(0, "Successfully read the entire page.");
|
||||
if (CMT_DestroyDataConnection(control, sock) != CMTSuccess) {
|
||||
errorMessage(8, "Error destroygin the SSL data connection "
|
||||
"with the psm server.");
|
||||
}
|
||||
if (CMT_CloseControlConnection(control) != CMTSuccess) {
|
||||
errorMessage(9, "Error closing the control connection.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
99
mozilla/security/psm/lib/client/test.c
Normal file
99
mozilla/security/psm/lib/client/test.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "cmt.h"
|
||||
|
||||
CMTStatus myCallback(CMTControl * control, CMTItem * event, void * arg);
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
CMTItem * msg, * event = NULL;
|
||||
CMTStatus status;
|
||||
int socket, datasocket;
|
||||
int sent;
|
||||
CMTControl * connect;
|
||||
char * buffer = "some weird text that I feel like passing to server";
|
||||
|
||||
connect = CMT_ControlConnect(myCallback, event);
|
||||
|
||||
msg = CMT_ConstructMessage(10);
|
||||
|
||||
msg->type = (int)CMTClientMessage;
|
||||
sprintf((char *)msg->data, "first msg!");
|
||||
|
||||
status = CMT_SendMessage(connect, msg, event);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_SendMessage");
|
||||
|
||||
CMT_FreeEvent(event);
|
||||
event = NULL;
|
||||
|
||||
sprintf((char *)msg->data, "second msg");
|
||||
status = CMT_SendMessage(connect, msg, event);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_SendMessage");
|
||||
|
||||
datasocket = CMT_DataConnect(connect, NULL);
|
||||
if (datasocket < 0)
|
||||
perror("CMT_DataConnect");
|
||||
|
||||
sent = write(datasocket, (void *)buffer, strlen(buffer));
|
||||
sent = write(datasocket, (void *)buffer, strlen(buffer));
|
||||
|
||||
close(datasocket);
|
||||
|
||||
msg->type = (int)CMTClientMessage;
|
||||
sprintf((char *)msg->data, "third msg!");
|
||||
status = CMT_SendMessage(connect, msg, event);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_SendMessage");
|
||||
|
||||
status = CMT_CloseControlConnection(connect);
|
||||
if (status != SECSuccess)
|
||||
perror("CMT_CloseControl");
|
||||
|
||||
CMT_FreeMessage(msg);
|
||||
CMT_FreeEvent(event);
|
||||
}
|
||||
|
||||
CMTStatus myCallback(CMTControl * control, CMTItem * event, void * arg)
|
||||
{
|
||||
if (event)
|
||||
printf("Event received is : type %d, data %s\n", event->type, event->data);
|
||||
else printf("No event!\n");
|
||||
if (arg)
|
||||
printf("Arg is %s\n", (char *)arg);
|
||||
else printf("No arg!\n");
|
||||
|
||||
|
||||
return SECSuccess;
|
||||
}
|
||||
BIN
mozilla/security/psm/lib/macbuild/PSMClient.mcp
Normal file
BIN
mozilla/security/psm/lib/macbuild/PSMClient.mcp
Normal file
Binary file not shown.
3
mozilla/security/psm/lib/macbuild/PSMPrefix.h
Normal file
3
mozilla/security/psm/lib/macbuild/PSMPrefix.h
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
#include "MacPrefix.h"
|
||||
2
mozilla/security/psm/lib/macbuild/PSMPrefix_debug.h
Normal file
2
mozilla/security/psm/lib/macbuild/PSMPrefix_debug.h
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
#include "MacPrefix_debug.h"
|
||||
BIN
mozilla/security/psm/lib/macbuild/PSMProtocol.mcp
Normal file
BIN
mozilla/security/psm/lib/macbuild/PSMProtocol.mcp
Normal file
Binary file not shown.
@@ -20,7 +20,8 @@
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
DIRS=public src resources
|
||||
DIRS = client protocol
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
43
mozilla/security/psm/lib/manifest.mn
Normal file
43
mozilla/security/psm/lib/manifest.mn
Normal file
@@ -0,0 +1,43 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
#
|
||||
|
||||
CORE_DEPTH = ../..
|
||||
DEPTH = ../..
|
||||
|
||||
DIRS = protocol client
|
||||
|
||||
#
|
||||
# these dirs are not built at the moment
|
||||
#
|
||||
#NOBUILD_DIRS = jar
|
||||
3
mozilla/security/psm/lib/protocol/MANIFEST
Normal file
3
mozilla/security/psm/lib/protocol/MANIFEST
Normal file
@@ -0,0 +1,3 @@
|
||||
obscure.h
|
||||
rsrcids.h
|
||||
ssmdefs.h
|
||||
74
mozilla/security/psm/lib/protocol/Makefile
Executable file
74
mozilla/security/psm/lib/protocol/Makefile
Executable file
@@ -0,0 +1,74 @@
|
||||
#! gmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
include config.mk
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
64
mozilla/security/psm/lib/protocol/Makefile.in
Normal file
64
mozilla/security/psm/lib/protocol/Makefile.in
Normal file
@@ -0,0 +1,64 @@
|
||||
#! gmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = protocol
|
||||
MODULE = security
|
||||
|
||||
EXPORTS = \
|
||||
protocol.h \
|
||||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
CSRCS = newproto.c \
|
||||
templates.c \
|
||||
protocolshr.c \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
44
mozilla/security/psm/lib/protocol/config.mk
Normal file
44
mozilla/security/psm/lib/protocol/config.mk
Normal file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
SHARED_LIBRARY =
|
||||
IMPORT_LIBRARY =
|
||||
PURE_LIBRARY =
|
||||
PROGRAM =
|
||||
|
||||
124
mozilla/security/psm/lib/protocol/makefile.win
Normal file
124
mozilla/security/psm/lib/protocol/makefile.win
Normal file
@@ -0,0 +1,124 @@
|
||||
#//
|
||||
#// The contents of this file are subject to the Mozilla Public
|
||||
#// License Version 1.1 (the "License"); you may not use this file
|
||||
#// except in compliance with the License. You may obtain a copy of
|
||||
#// the License at http://www.mozilla.org/MPL/
|
||||
#//
|
||||
#// Software distributed under the License is distributed on an "AS
|
||||
#// IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
#// implied. See the License for the specific language governing
|
||||
#// rights and limitations under the License.
|
||||
#//
|
||||
#// The Original Code is the Netscape security libraries.
|
||||
#//
|
||||
#// The Initial Developer of the Original Code is Netscape
|
||||
#// Communications Corporation. Portions created by Netscape are
|
||||
#// Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
#// Rights Reserved.
|
||||
#//
|
||||
#// Contributor(s):
|
||||
#//
|
||||
#// Alternatively, the contents of this file may be used under the
|
||||
#// terms of the GNU General Public License Version 2 or later (the
|
||||
#// "GPL"), in which case the provisions of the GPL are applicable
|
||||
#// instead of those above. If you wish to allow use of your
|
||||
#// version of this file only under the terms of the GPL and not to
|
||||
#// allow others to use your version of this file under the MPL,
|
||||
#// indicate your decision by deleting the provisions above and
|
||||
#// replace them with the notice and other provisions required by
|
||||
#// the GPL. If you do not delete the provisions above, a recipient
|
||||
#// may use your version of this file under either the MPL or the
|
||||
#// GPL.
|
||||
#//
|
||||
IGNORE_MANIFEST=1
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Makefile to build the ssl library
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
!if "$(MOZ_BITS)" == "16"
|
||||
!ifndef MOZ_DEBUG
|
||||
OPTIMIZER=-Os -UDEBUG -DNDEBUG
|
||||
!endif
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\..\..
|
||||
|
||||
!ifndef MAKE_OBJ_TYPE
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBNAME=protocol
|
||||
PDBFILE=$(LIBNAME).pdb
|
||||
|
||||
LINCS = -I$(PUBLIC)\security \
|
||||
-I$(PUBLIC)\nspr \
|
||||
-I$(DEPTH)\include \
|
||||
-I..\include
|
||||
|
||||
!ifndef OS_CONFIG
|
||||
OS_CONFIG = WIN$(MOZ_BITS)
|
||||
!endif
|
||||
|
||||
LCFLAGS = -DEXPORT_VERSION -DLIB_BUILD
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\newproto.obj \
|
||||
.\$(OBJDIR)\templates.obj \
|
||||
.\$(OBJDIR)\protocolshr.obj \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBRARY=.\$(OBJDIR)\$(LIBNAME).lib
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// install headers
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
INSTALL_DIR=$(PUBLIC)\security
|
||||
INSTALL_FILE_LIST= protocol.h \
|
||||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
export:: INSTALL_FILES
|
||||
|
||||
65
mozilla/security/psm/lib/protocol/manifest.mn
Normal file
65
mozilla/security/psm/lib/protocol/manifest.mn
Normal file
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU General Public License Version 2 or later (the
|
||||
# "GPL"), in which case the provisions of the GPL are applicable
|
||||
# instead of those above. If you wish to allow use of your
|
||||
# version of this file only under the terms of the GPL and not to
|
||||
# allow others to use your version of this file under the MPL,
|
||||
# indicate your decision by deleting the provisions above and
|
||||
# replace them with the notice and other provisions required by
|
||||
# the GPL. If you do not delete the provisions above, a recipient
|
||||
# may use your version of this file under either the MPL or the
|
||||
# GPL.
|
||||
#
|
||||
|
||||
CORE_DEPTH = ../../..
|
||||
|
||||
EXPORTS = \
|
||||
protocol.h \
|
||||
protocolf.h \
|
||||
protocolport.h \
|
||||
protocolnspr20.h \
|
||||
protocolshr.h \
|
||||
ssmdefs.h \
|
||||
rsrcids.h \
|
||||
messages.h \
|
||||
newproto.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = security
|
||||
CSRCS = newproto.c \
|
||||
protocolshr.c \
|
||||
templates.c \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(subst /,_,$(shell uname -s)),OS2)
|
||||
CSRCS += os2_rand.c
|
||||
endif
|
||||
|
||||
# mac_rand.c
|
||||
# unix_rand.c
|
||||
# win_rand.c
|
||||
# prelib.c
|
||||
|
||||
REQUIRES = security dbm nspr
|
||||
|
||||
LIBRARY_NAME = protocol
|
||||
620
mozilla/security/psm/lib/protocol/messages.h
Normal file
620
mozilla/security/psm/lib/protocol/messages.h
Normal file
@@ -0,0 +1,620 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __MESSAGES_H__
|
||||
#define __MESSAGES_H__
|
||||
|
||||
#include "newproto.h"
|
||||
|
||||
typedef struct SingleNumMessage {
|
||||
CMInt32 value;
|
||||
} SingleNumMessage;
|
||||
|
||||
extern CMTMessageTemplate SingleNumMessageTemplate[];
|
||||
|
||||
typedef struct SingleStringMessage {
|
||||
char *string;
|
||||
} SingleStringMessage;
|
||||
|
||||
extern CMTMessageTemplate SingleStringMessageTemplate[];
|
||||
|
||||
typedef struct SingleItemMessage {
|
||||
CMTItem item;
|
||||
} SingleItemMessage;
|
||||
|
||||
extern CMTMessageTemplate SingleItemMessageTemplate[];
|
||||
|
||||
typedef struct HelloRequest {
|
||||
CMInt32 version;
|
||||
CMInt32 policy;
|
||||
CMBool doesUI;
|
||||
char *profile;
|
||||
char* profileDir;
|
||||
} HelloRequest;
|
||||
|
||||
extern CMTMessageTemplate HelloRequestTemplate[];
|
||||
|
||||
typedef struct HelloReply {
|
||||
CMInt32 result;
|
||||
CMInt32 sessionID;
|
||||
CMInt32 version;
|
||||
CMInt32 httpPort;
|
||||
CMInt32 policy;
|
||||
CMTItem nonce;
|
||||
char *stringVersion;
|
||||
} HelloReply;
|
||||
|
||||
extern CMTMessageTemplate HelloReplyTemplate[];
|
||||
|
||||
typedef struct SSLDataConnectionRequest {
|
||||
CMInt32 flags;
|
||||
CMInt32 port;
|
||||
char *hostIP;
|
||||
char *hostName;
|
||||
CMBool forceHandshake;
|
||||
CMTItem clientContext;
|
||||
} SSLDataConnectionRequest;
|
||||
|
||||
extern CMTMessageTemplate SSLDataConnectionRequestTemplate[];
|
||||
|
||||
typedef struct TLSDataConnectionRequest {
|
||||
CMInt32 port;
|
||||
char* hostIP;
|
||||
char* hostName;
|
||||
} TLSDataConnectionRequest;
|
||||
|
||||
extern CMTMessageTemplate TLSDataConnectionRequestTemplate[];
|
||||
|
||||
typedef struct TLSStepUpRequest {
|
||||
CMUint32 connID;
|
||||
CMTItem clientContext;
|
||||
} TLSStepUpRequest;
|
||||
|
||||
extern CMTMessageTemplate TLSStepUpRequestTemplate[];
|
||||
|
||||
typedef struct ProxyStepUpRequest {
|
||||
CMUint32 connID;
|
||||
CMTItem clientContext;
|
||||
char* url;
|
||||
} ProxyStepUpRequest;
|
||||
|
||||
extern CMTMessageTemplate ProxyStepUpRequestTemplate[];
|
||||
|
||||
typedef struct PKCS7DataConnectionRequest {
|
||||
CMUint32 resID;
|
||||
CMTItem clientContext;
|
||||
} PKCS7DataConnectionRequest;
|
||||
|
||||
extern CMTMessageTemplate PKCS7DataConnectionRequestTemplate[];
|
||||
|
||||
typedef struct DataConnectionReply {
|
||||
CMInt32 result;
|
||||
CMInt32 connID;
|
||||
CMInt32 port;
|
||||
} DataConnectionReply;
|
||||
|
||||
extern CMTMessageTemplate DataConnectionReplyTemplate[];
|
||||
|
||||
typedef struct UIEvent {
|
||||
CMInt32 resourceID;
|
||||
CMInt32 width;
|
||||
CMInt32 height;
|
||||
CMBool isModal;
|
||||
char *url;
|
||||
CMTItem clientContext;
|
||||
} UIEvent;
|
||||
|
||||
extern CMTMessageTemplate UIEventTemplate[];
|
||||
extern CMTMessageTemplate OldUIEventTemplate[];
|
||||
|
||||
typedef struct TaskCompletedEvent {
|
||||
CMInt32 resourceID;
|
||||
CMInt32 numTasks;
|
||||
CMInt32 result;
|
||||
} TaskCompletedEvent;
|
||||
|
||||
extern CMTMessageTemplate TaskCompletedEventTemplate[];
|
||||
|
||||
typedef struct VerifyDetachedSigRequest {
|
||||
CMInt32 pkcs7ContentID;
|
||||
CMInt32 certUsage;
|
||||
CMInt32 hashAlgID;
|
||||
CMBool keepCert;
|
||||
CMTItem hash;
|
||||
} VerifyDetachedSigRequest;
|
||||
|
||||
extern CMTMessageTemplate VerifyDetachedSigRequestTemplate[];
|
||||
|
||||
typedef struct CreateSignedRequest {
|
||||
CMInt32 scertRID;
|
||||
CMInt32 ecertRID;
|
||||
CMInt32 dig_alg;
|
||||
CMTItem digest;
|
||||
} CreateSignedRequest;
|
||||
|
||||
extern CMTMessageTemplate CreateSignedRequestTemplate[];
|
||||
|
||||
typedef struct CreateContentInfoReply {
|
||||
CMInt32 ciRID;
|
||||
CMInt32 result;
|
||||
CMInt32 errorCode;
|
||||
} CreateContentInfoReply;
|
||||
|
||||
extern CMTMessageTemplate CreateContentInfoReplyTemplate[];
|
||||
|
||||
typedef struct CreateEncryptedRequest {
|
||||
CMInt32 scertRID;
|
||||
CMInt32 nrcerts;
|
||||
CMInt32 *rcertRIDs;
|
||||
} CreateEncryptedRequest;
|
||||
|
||||
extern CMTMessageTemplate CreateEncryptedRequestTemplate[];
|
||||
|
||||
typedef struct CreateResourceRequest {
|
||||
CMInt32 type;
|
||||
CMTItem params;
|
||||
} CreateResourceRequest;
|
||||
|
||||
extern CMTMessageTemplate CreateResourceRequestTemplate[];
|
||||
|
||||
typedef struct CreateResourceReply {
|
||||
CMInt32 result;
|
||||
CMInt32 resID;
|
||||
} CreateResourceReply;
|
||||
|
||||
extern CMTMessageTemplate CreateResourceReplyTemplate[];
|
||||
|
||||
typedef struct GetAttribRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 fieldID;
|
||||
} GetAttribRequest;
|
||||
|
||||
extern CMTMessageTemplate GetAttribRequestTemplate[];
|
||||
|
||||
typedef struct GetAttribReply {
|
||||
CMInt32 result;
|
||||
SSMAttributeValue value;
|
||||
} GetAttribReply;
|
||||
|
||||
extern CMTMessageTemplate GetAttribReplyTemplate[];
|
||||
|
||||
typedef struct SetAttribRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 fieldID;
|
||||
SSMAttributeValue value;
|
||||
} SetAttribRequest;
|
||||
|
||||
extern CMTMessageTemplate SetAttribRequestTemplate[];
|
||||
|
||||
typedef struct PickleResourceReply {
|
||||
CMInt32 result;
|
||||
CMTItem blob;
|
||||
} PickleResourceReply;
|
||||
|
||||
extern CMTMessageTemplate PickleResourceReplyTemplate[];
|
||||
|
||||
typedef struct UnpickleResourceRequest {
|
||||
CMInt32 resourceType;
|
||||
CMTItem resourceData;
|
||||
} UnpickleResourceRequest;
|
||||
|
||||
extern CMTMessageTemplate UnpickleResourceRequestTemplate[];
|
||||
|
||||
typedef struct UnpickleResourceReply {
|
||||
CMInt32 result;
|
||||
CMInt32 resID;
|
||||
} UnpickleResourceReply;
|
||||
|
||||
extern CMTMessageTemplate UnpickleResourceReplyTemplate[];
|
||||
|
||||
typedef struct PickleSecurityStatusReply {
|
||||
CMInt32 result;
|
||||
CMInt32 securityLevel;
|
||||
CMTItem blob;
|
||||
} PickleSecurityStatusReply;
|
||||
|
||||
extern CMTMessageTemplate PickleSecurityStatusReplyTemplate[];
|
||||
|
||||
typedef struct DupResourceReply {
|
||||
CMInt32 result;
|
||||
CMUint32 resID;
|
||||
} DupResourceReply;
|
||||
|
||||
extern CMTMessageTemplate DupResourceReplyTemplate[];
|
||||
|
||||
typedef struct DestroyResourceRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 resType;
|
||||
} DestroyResourceRequest;
|
||||
|
||||
extern CMTMessageTemplate DestroyResourceRequestTemplate[];
|
||||
|
||||
typedef struct VerifyCertRequest {
|
||||
CMInt32 resID;
|
||||
CMInt32 certUsage;
|
||||
} VerifyCertRequest;
|
||||
|
||||
extern CMTMessageTemplate VerifyCertRequestTemplate[];
|
||||
|
||||
typedef struct AddTempCertToDBRequest {
|
||||
CMInt32 resID;
|
||||
char *nickname;
|
||||
CMInt32 sslFlags;
|
||||
CMInt32 emailFlags;
|
||||
CMInt32 objSignFlags;
|
||||
} AddTempCertToDBRequest;
|
||||
|
||||
extern CMTMessageTemplate AddTempCertToDBRequestTemplate[];
|
||||
|
||||
typedef struct MatchUserCertRequest {
|
||||
CMInt32 certType;
|
||||
CMInt32 numCANames;
|
||||
char **caNames;
|
||||
} MatchUserCertRequest;
|
||||
|
||||
extern CMTMessageTemplate MatchUserCertRequestTemplate[];
|
||||
|
||||
typedef struct MatchUserCertReply {
|
||||
CMInt32 numCerts;
|
||||
CMInt32 *certs;
|
||||
} MatchUserCertReply;
|
||||
|
||||
extern CMTMessageTemplate MatchUserCertReplyTemplate[];
|
||||
|
||||
typedef struct EncodeCRMFReqRequest {
|
||||
CMInt32 numRequests;
|
||||
CMInt32 * reqIDs;
|
||||
} EncodeCRMFReqRequest;
|
||||
|
||||
extern CMTMessageTemplate EncodeCRMFReqRequestTemplate[];
|
||||
|
||||
typedef struct CMMFCertResponseRequest {
|
||||
char *nickname;
|
||||
char *base64Der;
|
||||
CMBool doBackup;
|
||||
CMTItem clientContext;
|
||||
} CMMFCertResponseRequest;
|
||||
|
||||
extern CMTMessageTemplate CMMFCertResponseRequestTemplate[];
|
||||
|
||||
typedef struct PasswordRequest {
|
||||
CMInt32 tokenKey;
|
||||
char *prompt;
|
||||
CMTItem clientContext;
|
||||
} PasswordRequest;
|
||||
|
||||
extern CMTMessageTemplate PasswordRequestTemplate[];
|
||||
|
||||
typedef struct PasswordReply {
|
||||
CMInt32 result;
|
||||
CMInt32 tokenID;
|
||||
char * passwd;
|
||||
} PasswordReply;
|
||||
|
||||
extern CMTMessageTemplate PasswordReplyTemplate[];
|
||||
|
||||
typedef struct KeyPairGenRequest {
|
||||
CMInt32 keyGenCtxtID;
|
||||
CMInt32 genMechanism;
|
||||
CMInt32 keySize;
|
||||
CMTItem params;
|
||||
} KeyPairGenRequest;
|
||||
|
||||
extern CMTMessageTemplate KeyPairGenRequestTemplate[];
|
||||
|
||||
typedef struct DecodeAndCreateTempCertRequest {
|
||||
CMInt32 type;
|
||||
CMTItem cert;
|
||||
} DecodeAndCreateTempCertRequest;
|
||||
|
||||
extern CMTMessageTemplate DecodeAndCreateTempCertRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStyleRequest {
|
||||
char *choiceString;
|
||||
char *challenge;
|
||||
char *typeString;
|
||||
char *pqgString;
|
||||
} GenKeyOldStyleRequest;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStyleRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStyleTokenRequest {
|
||||
CMInt32 rid;
|
||||
CMInt32 numtokens;
|
||||
char ** tokenNames;
|
||||
} GenKeyOldStyleTokenRequest;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStyleTokenRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStyleTokenReply {
|
||||
CMInt32 rid;
|
||||
CMBool cancel;
|
||||
char * tokenName;
|
||||
} GenKeyOldStyleTokenReply;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStyleTokenReplyTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStylePasswordRequest {
|
||||
CMInt32 rid;
|
||||
char * tokenName;
|
||||
CMBool internal;
|
||||
CMInt32 minpwdlen;
|
||||
CMInt32 maxpwdlen;
|
||||
} GenKeyOldStylePasswordRequest;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStylePasswordRequestTemplate[];
|
||||
|
||||
typedef struct GenKeyOldStylePasswordReply {
|
||||
CMInt32 rid;
|
||||
CMBool cancel;
|
||||
char * password;
|
||||
} GenKeyOldStylePasswordReply;
|
||||
|
||||
extern CMTMessageTemplate GenKeyOldStylePasswordReplyTemplate[];
|
||||
|
||||
typedef struct GetKeyChoiceListRequest {
|
||||
char *type;
|
||||
char *pqgString;
|
||||
} GetKeyChoiceListRequest;
|
||||
|
||||
extern CMTMessageTemplate GetKeyChoiceListRequestTemplate[];
|
||||
|
||||
typedef struct GetKeyChoiceListReply {
|
||||
CMInt32 nchoices;
|
||||
char **choices;
|
||||
} GetKeyChoiceListReply;
|
||||
|
||||
extern CMTMessageTemplate GetKeyChoiceListReplyTemplate[];
|
||||
|
||||
typedef struct AddNewSecurityModuleRequest {
|
||||
char *moduleName;
|
||||
char *libraryPath;
|
||||
CMInt32 pubMechFlags;
|
||||
CMInt32 pubCipherFlags;
|
||||
} AddNewSecurityModuleRequest;
|
||||
|
||||
extern CMTMessageTemplate AddNewSecurityModuleRequestTemplate[];
|
||||
|
||||
typedef struct FilePathRequest {
|
||||
CMInt32 resID;
|
||||
char *prompt;
|
||||
CMBool getExistingFile;
|
||||
char *fileRegEx;
|
||||
} FilePathRequest;
|
||||
|
||||
extern CMTMessageTemplate FilePathRequestTemplate[];
|
||||
|
||||
typedef struct FilePathReply {
|
||||
CMInt32 resID;
|
||||
char *filePath;
|
||||
} FilePathReply;
|
||||
|
||||
extern CMTMessageTemplate FilePathReplyTemplate[];
|
||||
|
||||
typedef struct PasswordPromptReply {
|
||||
CMInt32 resID;
|
||||
char *promptReply;
|
||||
} PasswordPromptReply;
|
||||
|
||||
extern CMTMessageTemplate PasswordPromptReplyTemplate[];
|
||||
|
||||
typedef struct SignTextRequest {
|
||||
CMInt32 resID;
|
||||
char *stringToSign;
|
||||
char *hostName;
|
||||
char *caOption;
|
||||
CMInt32 numCAs;
|
||||
char** caNames;
|
||||
} SignTextRequest;
|
||||
|
||||
extern CMTMessageTemplate SignTextRequestTemplate[];
|
||||
|
||||
typedef struct GetLocalizedTextReply {
|
||||
CMInt32 whichString;
|
||||
char *localizedString;
|
||||
} GetLocalizedTextReply;
|
||||
|
||||
extern CMTMessageTemplate GetLocalizedTextReplyTemplate[];
|
||||
|
||||
typedef struct ImportCertReply {
|
||||
CMInt32 result;
|
||||
CMInt32 resID;
|
||||
} ImportCertReply;
|
||||
|
||||
extern CMTMessageTemplate ImportCertReplyTemplate[];
|
||||
|
||||
typedef struct PromptRequest {
|
||||
CMInt32 resID;
|
||||
char *prompt;
|
||||
CMTItem clientContext;
|
||||
} PromptRequest;
|
||||
|
||||
extern CMTMessageTemplate PromptRequestTemplate[];
|
||||
|
||||
typedef struct PromptReply {
|
||||
CMInt32 resID;
|
||||
CMBool cancel;
|
||||
char *promptReply;
|
||||
} PromptReply;
|
||||
|
||||
extern CMTMessageTemplate PromptReplyTemplate[];
|
||||
|
||||
typedef struct RedirectCompareReqeust {
|
||||
CMTItem socketStatus1Data;
|
||||
CMTItem socketStatus2Data;
|
||||
} RedirectCompareRequest;
|
||||
|
||||
extern CMTMessageTemplate RedirectCompareRequestTemplate[];
|
||||
|
||||
typedef struct DecodeAndAddCRLRequest {
|
||||
CMTItem derCrl;
|
||||
CMUint32 type;
|
||||
char *url;
|
||||
} DecodeAndAddCRLRequest;
|
||||
|
||||
extern CMTMessageTemplate DecodeAndAddCRLRequestTemplate[];
|
||||
|
||||
typedef struct SecurityAdvisorRequest {
|
||||
CMInt32 infoContext;
|
||||
CMInt32 resID;
|
||||
char * hostname;
|
||||
char * senderAddr;
|
||||
CMUint32 encryptedP7CInfo;
|
||||
CMUint32 signedP7CInfo;
|
||||
CMInt32 decodeError;
|
||||
CMInt32 verifyError;
|
||||
CMBool encryptthis;
|
||||
CMBool signthis;
|
||||
CMInt32 numRecipients;
|
||||
char ** recipients;
|
||||
} SecurityAdvisorRequest;
|
||||
|
||||
extern CMTMessageTemplate SecurityAdvisorRequestTemplate[];
|
||||
|
||||
/* "SecurityConfig" javascript related message templates */
|
||||
typedef struct SCAddTempCertToPermDBRequest {
|
||||
CMTItem certKey;
|
||||
char* trustStr;
|
||||
char* nickname;
|
||||
} SCAddTempCertToPermDBRequest;
|
||||
|
||||
extern CMTMessageTemplate SCAddTempCertToPermDBRequestTemplate[];
|
||||
|
||||
typedef struct SCDeletePermCertsRequest {
|
||||
CMTItem certKey;
|
||||
CMBool deleteAll;
|
||||
} SCDeletePermCertsRequest;
|
||||
|
||||
extern CMTMessageTemplate SCDeletePermCertsRequestTemplate[];
|
||||
|
||||
typedef struct TimeMessage {
|
||||
CMInt32 year;
|
||||
CMInt32 month;
|
||||
CMInt32 day;
|
||||
CMInt32 hour;
|
||||
CMInt32 minute;
|
||||
CMInt32 second;
|
||||
} TimeMessage;
|
||||
|
||||
extern CMTMessageTemplate TimeMessageTemplate[];
|
||||
|
||||
typedef struct CertEnumElement {
|
||||
char* name;
|
||||
CMTItem certKey;
|
||||
} CertEnumElement;
|
||||
|
||||
typedef struct SCCertIndexEnumReply {
|
||||
int length;
|
||||
CertEnumElement* list;
|
||||
} SCCertIndexEnumReply;
|
||||
|
||||
extern CMTMessageTemplate SCCertIndexEnumReplyTemplate[];
|
||||
|
||||
/* Test message */
|
||||
typedef struct TestListElement {
|
||||
char * name;
|
||||
char * value;
|
||||
} TestListElement;
|
||||
|
||||
typedef struct TestList {
|
||||
char *listName;
|
||||
int numElements;
|
||||
TestListElement *elements;
|
||||
} TestList;
|
||||
|
||||
extern CMTMessageTemplate TestListTemplate[];
|
||||
|
||||
/* Preference-related structs */
|
||||
typedef struct SetPrefElement {
|
||||
char* key;
|
||||
char* value;
|
||||
CMInt32 type;
|
||||
} SetPrefElement;
|
||||
|
||||
typedef struct SetPrefListMessage {
|
||||
int length;
|
||||
SetPrefElement* list;
|
||||
} SetPrefListMessage;
|
||||
|
||||
extern CMTMessageTemplate SetPrefListMessageTemplate[];
|
||||
|
||||
typedef struct GetPrefElement {
|
||||
char* key;
|
||||
CMInt32 type;
|
||||
} GetPrefElement;
|
||||
|
||||
typedef struct GetPrefListRequest {
|
||||
int length;
|
||||
GetPrefElement* list;
|
||||
} GetPrefListRequest;
|
||||
|
||||
extern CMTMessageTemplate GetPrefListRequestTemplate[];
|
||||
|
||||
typedef struct GetCertExtension {
|
||||
CMUint32 resID;
|
||||
CMUint32 extension;
|
||||
} GetCertExtension;
|
||||
|
||||
extern CMTMessageTemplate GetCertExtensionTemplate[];
|
||||
|
||||
typedef struct HTMLCertInfoRequest {
|
||||
CMUint32 certID;
|
||||
CMUint32 showImages;
|
||||
CMUint32 showIssuer;
|
||||
} HTMLCertInfoRequest;
|
||||
|
||||
extern CMTMessageTemplate HTMLCertInfoRequestTemplate[];
|
||||
|
||||
typedef struct EncryptRequestMessage
|
||||
{
|
||||
CMTItem keyid; /* May have length 0 for default */
|
||||
CMTItem data;
|
||||
CMTItem ctx; /* serialized void* ptr */
|
||||
} EncryptRequestMessage;
|
||||
|
||||
extern CMTMessageTemplate EncryptRequestTemplate[];
|
||||
|
||||
typedef struct SingleItemMessage EncryptReplyMessage;
|
||||
#define EncryptReplyTemplate SingleItemMessageTemplate
|
||||
|
||||
typedef struct DecryptRequestMessage
|
||||
{
|
||||
CMTItem data;
|
||||
CMTItem ctx; /* serialized void* ptr */
|
||||
} DecryptRequestMessage;
|
||||
extern CMTMessageTemplate DecryptRequestTemplate[];
|
||||
|
||||
typedef struct SingleItemMessage DecryptReplyMessage;
|
||||
#define DecryptReplyTemplate SingleItemMessageTemplate
|
||||
|
||||
#endif /* __MESSAGES_H__ */
|
||||
602
mozilla/security/psm/lib/protocol/newproto.c
Normal file
602
mozilla/security/psm/lib/protocol/newproto.c
Normal file
@@ -0,0 +1,602 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#ifdef XP_MAC
|
||||
#include "macsocket.h"
|
||||
#endif
|
||||
|
||||
#include "newproto.h"
|
||||
|
||||
char SSMVersionString[] = "1.1";
|
||||
|
||||
CMT_Alloc_fn cmt_alloc = malloc;
|
||||
CMT_Free_fn cmt_free = free;
|
||||
|
||||
#define ASSERT(x) assert(x)
|
||||
|
||||
#define CM_ntohl ntohl
|
||||
#define CM_htonl htonl
|
||||
|
||||
|
||||
/*************************************************************
|
||||
*
|
||||
* CMT_Init
|
||||
*
|
||||
*
|
||||
************************************************************/
|
||||
void
|
||||
CMT_Init(CMT_Alloc_fn allocfn, CMT_Free_fn freefn)
|
||||
{
|
||||
cmt_alloc = allocfn;
|
||||
cmt_free = freefn;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
decode_int(unsigned char **curptr, void *dest, CMInt32 *remaining)
|
||||
{
|
||||
CMInt32 datalen = sizeof(CMInt32);
|
||||
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
*(CMInt32 *)dest = ntohl(**(CMInt32 **)curptr);
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
decode_string(unsigned char **curptr, CMInt32 *len,
|
||||
unsigned char **data, CMInt32 *remaining)
|
||||
{
|
||||
CMTStatus rv;
|
||||
CMInt32 datalen;
|
||||
|
||||
rv = decode_int(curptr, len, remaining);
|
||||
if (rv != CMTSuccess)
|
||||
return CMTFailure;
|
||||
|
||||
/* NULL string */
|
||||
if (*len == 0) {
|
||||
*data = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
datalen = (*len + 3) & ~3;
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
|
||||
*data = (unsigned char *) cmt_alloc(*len + 1);
|
||||
if (*data == NULL)
|
||||
return CMTFailure;
|
||||
|
||||
memcpy(*data, *curptr, *len);
|
||||
(*data)[*len] = 0;
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
done:
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* CMT_DecodeMessage
|
||||
*
|
||||
* Decode msg into dest as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_DecodeMessage(CMTMessageTemplate *tmpl, void *dest, CMTItem *msg)
|
||||
{
|
||||
unsigned char *curptr, *destptr, *list;
|
||||
void ** ptr;
|
||||
CMInt32 remaining, len, choiceID = 0, listSize, listCount = 0;
|
||||
CMBool inChoice = CM_FALSE, foundChoice = CM_FALSE, inList = CM_FALSE;
|
||||
CMInt32 listItemSize = 0;
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTMessageTemplate *startOfList, *p;
|
||||
CMBool inStructList = CM_FALSE;
|
||||
|
||||
curptr = msg->data;
|
||||
remaining = msg->len;
|
||||
|
||||
while(tmpl->type != CMT_DT_END) {
|
||||
/* XXX Maybe this should be a more formal state machine? */
|
||||
if (inChoice) {
|
||||
if (tmpl->type == CMT_DT_END_CHOICE) {
|
||||
if (!foundChoice)
|
||||
goto loser;
|
||||
inChoice = CM_FALSE;
|
||||
foundChoice = CM_FALSE;
|
||||
tmpl++;
|
||||
continue;
|
||||
}
|
||||
if (choiceID != tmpl->choiceID) {
|
||||
tmpl++;
|
||||
continue; /* Not this option */
|
||||
} else {
|
||||
foundChoice = CM_TRUE;
|
||||
}
|
||||
}
|
||||
if (inList) {
|
||||
destptr = &list[listCount * listItemSize];
|
||||
listCount++;
|
||||
} else {
|
||||
if (inStructList) {
|
||||
destptr = tmpl->offset + list;
|
||||
} else {
|
||||
destptr = tmpl->offset + (unsigned char *)dest;
|
||||
}
|
||||
}
|
||||
switch (tmpl->type) {
|
||||
case CMT_DT_RID:
|
||||
case CMT_DT_INT:
|
||||
case CMT_DT_BOOL:
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_STRING:
|
||||
rv = decode_string(&curptr, &len, (unsigned char **)destptr,
|
||||
&remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_ITEM:
|
||||
rv = decode_string(&curptr, (long *) &((CMTItem *)destptr)->len,
|
||||
&((CMTItem *)destptr)->data, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_LIST:
|
||||
/* XXX This is too complicated */
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)destptr;
|
||||
tmpl++;
|
||||
if (tmpl->type == CMT_DT_STRING) {
|
||||
listItemSize = sizeof(unsigned char *);
|
||||
} else if (tmpl->type == CMT_DT_ITEM) {
|
||||
listItemSize = sizeof(CMTItem);
|
||||
} else {
|
||||
listItemSize = sizeof(CMInt32);
|
||||
}
|
||||
if (listSize == 0) {
|
||||
list = NULL;
|
||||
} else {
|
||||
list = (unsigned char *) cmt_alloc(listSize * listItemSize);
|
||||
}
|
||||
*(void **)(tmpl->offset + (unsigned char *)dest) = list;
|
||||
inList = CM_TRUE;
|
||||
listCount = 0;
|
||||
break;
|
||||
case CMT_DT_STRUCT_LIST:
|
||||
/* XXX This is too complicated */
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)destptr;
|
||||
tmpl++;
|
||||
if (tmpl->type != CMT_DT_STRUCT_PTR) {
|
||||
goto loser;
|
||||
}
|
||||
ptr = (void**)(tmpl->offset + (unsigned char *)dest);
|
||||
startOfList = tmpl;
|
||||
p = tmpl;
|
||||
listItemSize = 0;
|
||||
while (p->type != CMT_DT_END_STRUCT_LIST) {
|
||||
if (p->type == CMT_DT_STRING) {
|
||||
listItemSize += sizeof(unsigned char *);
|
||||
} else if (p->type == CMT_DT_ITEM) {
|
||||
listItemSize += sizeof(CMTItem);
|
||||
} else if (p->type == CMT_DT_INT) {
|
||||
listItemSize += sizeof(CMInt32);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if (listSize == 0) {
|
||||
list = NULL;
|
||||
} else {
|
||||
list = (unsigned char *) cmt_alloc(listSize * listItemSize);
|
||||
}
|
||||
*ptr = list;
|
||||
inStructList = CM_TRUE;
|
||||
listCount = 0;
|
||||
break;
|
||||
case CMT_DT_END_STRUCT_LIST:
|
||||
listCount++;
|
||||
if (listCount == listSize) {
|
||||
inStructList = CM_FALSE;
|
||||
} else {
|
||||
list += listItemSize;
|
||||
tmpl = startOfList;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_CHOICE:
|
||||
rv = decode_int(&curptr, destptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
choiceID = *(CMInt32 *)destptr;
|
||||
inChoice = CM_TRUE;
|
||||
foundChoice = CM_FALSE;
|
||||
break;
|
||||
case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */
|
||||
case CMT_DT_END:
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (inList) {
|
||||
if (listCount == listSize) {
|
||||
inList = CM_FALSE;
|
||||
tmpl++;
|
||||
}
|
||||
} else {
|
||||
tmpl++;
|
||||
}
|
||||
}
|
||||
loser:
|
||||
/* Free the data buffer */
|
||||
if (msg->data) {
|
||||
cmt_free(msg->data);
|
||||
msg->data = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
calc_msg_len(CMTMessageTemplate *tmpl, void *src, CMInt32 *len_out)
|
||||
{
|
||||
CMInt32 len = 0, choiceID = 0, listSize, listItemSize, listCount;
|
||||
unsigned char *srcptr, *list;
|
||||
CMBool inChoice = CM_FALSE, inList = CM_FALSE, foundChoice = CM_FALSE;
|
||||
CMTMessageTemplate *startOfList, *p;
|
||||
CMBool inStructList = CM_FALSE;
|
||||
|
||||
while(tmpl->type != CMT_DT_END) {
|
||||
if (inChoice) {
|
||||
if (tmpl->type == CMT_DT_END_CHOICE) {
|
||||
if (!foundChoice)
|
||||
goto loser;
|
||||
inChoice = CM_FALSE;
|
||||
foundChoice = CM_FALSE;
|
||||
tmpl++;
|
||||
continue;
|
||||
}
|
||||
if (choiceID != tmpl->choiceID) {
|
||||
tmpl++;
|
||||
continue; /* Not this option */
|
||||
} else {
|
||||
foundChoice = CM_TRUE;
|
||||
}
|
||||
}
|
||||
if (inList) {
|
||||
srcptr = &list[listCount * listItemSize];
|
||||
listCount++;
|
||||
} else if (inStructList) {
|
||||
srcptr = tmpl->offset + list;
|
||||
} else {
|
||||
srcptr = tmpl->offset + (unsigned char *)src;
|
||||
}
|
||||
switch(tmpl->type) {
|
||||
case CMT_DT_RID:
|
||||
case CMT_DT_INT:
|
||||
case CMT_DT_BOOL:
|
||||
len += sizeof(CMInt32);
|
||||
break;
|
||||
case CMT_DT_STRING:
|
||||
len += sizeof(CMInt32);
|
||||
/* Non NULL string */
|
||||
if (*(char**)srcptr) {
|
||||
len += (strlen(*(char**)srcptr) + 4) & ~3;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_ITEM:
|
||||
len += sizeof(CMInt32);
|
||||
len += (((CMTItem *)srcptr)->len + 3) & ~3;
|
||||
break;
|
||||
case CMT_DT_LIST:
|
||||
len += sizeof(CMInt32);
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type == CMT_DT_STRING) {
|
||||
listItemSize = sizeof(unsigned char *);
|
||||
} else if (tmpl->type == CMT_DT_ITEM) {
|
||||
listItemSize = sizeof(CMTItem);
|
||||
} else {
|
||||
listItemSize = sizeof(CMInt32);
|
||||
}
|
||||
list = *(unsigned char **)(tmpl->offset + (unsigned char *)src);
|
||||
listCount = 0;
|
||||
inList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_STRUCT_LIST:
|
||||
len += sizeof(CMInt32);
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type != CMT_DT_STRUCT_PTR) {
|
||||
goto loser;
|
||||
}
|
||||
list = *(unsigned char**)(tmpl->offset + (unsigned char*)src);
|
||||
startOfList = tmpl;
|
||||
p = tmpl;
|
||||
listItemSize = 0;
|
||||
while (p->type != CMT_DT_END_STRUCT_LIST) {
|
||||
if (p->type == CMT_DT_STRING) {
|
||||
listItemSize += sizeof(unsigned char *);
|
||||
} else if (p->type == CMT_DT_ITEM) {
|
||||
listItemSize += sizeof(CMTItem);
|
||||
} else if (p->type == CMT_DT_INT) {
|
||||
listItemSize += sizeof(CMInt32);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
listCount = 0;
|
||||
inStructList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_END_STRUCT_LIST:
|
||||
listCount++;
|
||||
if (listCount == listSize) {
|
||||
inStructList = CM_FALSE;
|
||||
} else {
|
||||
list += listItemSize;
|
||||
tmpl = startOfList;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_CHOICE:
|
||||
len += sizeof(CMInt32);
|
||||
choiceID = *(CMInt32 *)srcptr;
|
||||
inChoice = CM_TRUE;
|
||||
foundChoice = CM_FALSE;
|
||||
break;
|
||||
case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */
|
||||
case CMT_DT_END:
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (inList) {
|
||||
if (listCount == listSize) {
|
||||
inList = CM_FALSE;
|
||||
tmpl++;
|
||||
}
|
||||
} else {
|
||||
tmpl++;
|
||||
}
|
||||
}
|
||||
*len_out = len;
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
encode_int(unsigned char **curptr, void *src, CMInt32 *remaining)
|
||||
{
|
||||
CMInt32 datalen = sizeof(CMInt32);
|
||||
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
**(CMInt32 **)curptr = CM_htonl(*(CMInt32 *)src);
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
static CMTStatus
|
||||
encode_string(unsigned char **curptr, CMInt32 len,
|
||||
unsigned char *data, CMInt32 *remaining)
|
||||
{
|
||||
CMTStatus rv;
|
||||
CMInt32 datalen;
|
||||
|
||||
rv = encode_int(curptr, &len, remaining);
|
||||
if (rv != CMTSuccess)
|
||||
return CMTFailure;
|
||||
|
||||
/* NULL string */
|
||||
if (len == 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
datalen = (len + 3) & ~3;
|
||||
if (*remaining < datalen)
|
||||
return CMTFailure;
|
||||
|
||||
memcpy(*curptr, data, len);
|
||||
*remaining -= datalen;
|
||||
*curptr += datalen;
|
||||
done:
|
||||
return CMTSuccess;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* CMT_EncodeMessage
|
||||
*
|
||||
* Encode src into msg as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_EncodeMessage(CMTMessageTemplate *tmpl, CMTItem *msg, void *src)
|
||||
{
|
||||
CMInt32 choiceID = 0, listSize, listItemSize, listCount, remaining;
|
||||
unsigned char *srcptr, *curptr, *list;
|
||||
CMBool inChoice = CM_FALSE, inList = CM_FALSE, foundChoice = CM_FALSE;
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTMessageTemplate *startOfList, *p;
|
||||
CMBool inStructList = CM_FALSE;
|
||||
|
||||
rv = calc_msg_len(tmpl, src, (long *) &msg->len);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
curptr = msg->data = (unsigned char *) cmt_alloc(msg->len);
|
||||
if(msg->data == NULL)
|
||||
goto loser;
|
||||
remaining = msg->len;
|
||||
|
||||
while(tmpl->type != CMT_DT_END) {
|
||||
if (inChoice) {
|
||||
if (tmpl->type == CMT_DT_END_CHOICE) {
|
||||
if (!foundChoice)
|
||||
goto loser;
|
||||
inChoice = CM_FALSE;
|
||||
foundChoice = CM_FALSE;
|
||||
tmpl++;
|
||||
continue;
|
||||
}
|
||||
if (choiceID != tmpl->choiceID) {
|
||||
tmpl++;
|
||||
continue; /* Not this option */
|
||||
} else {
|
||||
foundChoice = CM_TRUE;
|
||||
}
|
||||
}
|
||||
if (inList) {
|
||||
srcptr = &list[listCount * listItemSize];
|
||||
listCount++;
|
||||
} else {
|
||||
if (inStructList) {
|
||||
srcptr = tmpl->offset + list;
|
||||
} else {
|
||||
srcptr = tmpl->offset + (unsigned char *)src;
|
||||
}
|
||||
}
|
||||
switch(tmpl->type) {
|
||||
case CMT_DT_RID:
|
||||
case CMT_DT_INT:
|
||||
case CMT_DT_BOOL:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_STRING:
|
||||
if (*(char**)srcptr) {
|
||||
/* Non NULL string */
|
||||
rv = encode_string(&curptr, (long) strlen(*(char**)srcptr),
|
||||
*(unsigned char**)srcptr, &remaining);
|
||||
} else {
|
||||
/* NULL string */
|
||||
rv = encode_string(&curptr, 0L, *(unsigned char**)srcptr, &remaining);
|
||||
}
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_ITEM:
|
||||
rv = encode_string(&curptr, ((CMTItem *)srcptr)->len,
|
||||
((CMTItem *)srcptr)->data, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
break;
|
||||
case CMT_DT_LIST:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type == CMT_DT_STRING) {
|
||||
listItemSize = sizeof(unsigned char *);
|
||||
} else if (tmpl->type == CMT_DT_ITEM) {
|
||||
listItemSize = sizeof(CMTItem);
|
||||
} else {
|
||||
listItemSize = sizeof(CMInt32);
|
||||
}
|
||||
list = *(unsigned char **)(tmpl->offset + (unsigned char *)src);
|
||||
listCount = 0;
|
||||
inList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_STRUCT_LIST:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
listSize = *(CMInt32 *)srcptr;
|
||||
tmpl++;
|
||||
if (tmpl->type != CMT_DT_STRUCT_PTR) {
|
||||
goto loser;
|
||||
}
|
||||
list = *(unsigned char**)(tmpl->offset + (unsigned char*)src);
|
||||
startOfList = tmpl;
|
||||
p = tmpl;
|
||||
listItemSize = 0;
|
||||
while (p->type != CMT_DT_END_STRUCT_LIST) {
|
||||
if (p->type == CMT_DT_STRING) {
|
||||
listItemSize += sizeof(unsigned char *);
|
||||
} else if (p->type == CMT_DT_ITEM) {
|
||||
listItemSize += sizeof(CMTItem);
|
||||
} else if (p->type == CMT_DT_INT) {
|
||||
listItemSize += sizeof(CMInt32);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
listCount = 0;
|
||||
inStructList = CM_TRUE;
|
||||
break;
|
||||
case CMT_DT_END_STRUCT_LIST:
|
||||
listCount++;
|
||||
if (listCount == listSize) {
|
||||
inStructList = CM_FALSE;
|
||||
} else {
|
||||
list += listItemSize;
|
||||
tmpl = startOfList;
|
||||
}
|
||||
break;
|
||||
case CMT_DT_CHOICE:
|
||||
rv = encode_int(&curptr, srcptr, &remaining);
|
||||
if (rv != CMTSuccess)
|
||||
goto loser;
|
||||
choiceID = *(CMInt32 *)srcptr;
|
||||
inChoice = CM_TRUE;
|
||||
foundChoice = CM_FALSE;
|
||||
break;
|
||||
case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */
|
||||
case CMT_DT_END:
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (inList) {
|
||||
if (listCount == listSize) {
|
||||
inList = CM_FALSE;
|
||||
tmpl++;
|
||||
}
|
||||
} else {
|
||||
tmpl++;
|
||||
}
|
||||
}
|
||||
return CMTSuccess;
|
||||
loser:
|
||||
return CMTFailure;
|
||||
}
|
||||
102
mozilla/security/psm/lib/protocol/newproto.h
Normal file
102
mozilla/security/psm/lib/protocol/newproto.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __NEWPROTO_H__
|
||||
#define __NEWPROTO_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ssmdefs.h"
|
||||
|
||||
typedef enum CMTDataType {
|
||||
CMT_DT_END,
|
||||
CMT_DT_RID,
|
||||
CMT_DT_INT,
|
||||
CMT_DT_BOOL,
|
||||
CMT_DT_STRING,
|
||||
CMT_DT_ITEM,
|
||||
CMT_DT_LIST,
|
||||
CMT_DT_CHOICE,
|
||||
CMT_DT_END_CHOICE,
|
||||
CMT_DT_STRUCT_LIST,
|
||||
CMT_DT_END_STRUCT_LIST,
|
||||
CMT_DT_STRUCT_PTR
|
||||
} CMTDataType;
|
||||
|
||||
typedef struct CMTMessageTemplate {
|
||||
CMTDataType type;
|
||||
CMUint32 offset;
|
||||
CMInt32 validator;
|
||||
CMInt32 choiceID;
|
||||
} CMTMessageTemplate;
|
||||
|
||||
typedef struct CMTMessageHeader {
|
||||
CMInt32 type;
|
||||
CMInt32 len;
|
||||
} CMTMessageHeader;
|
||||
|
||||
typedef void *(* CMT_Alloc_fn) (size_t size);
|
||||
typedef void (* CMT_Free_fn)(void * ptr);
|
||||
|
||||
extern CMT_Alloc_fn cmt_alloc;
|
||||
extern CMT_Free_fn cmt_free;
|
||||
|
||||
/*************************************************************
|
||||
*
|
||||
* CMT_Init
|
||||
*
|
||||
*
|
||||
************************************************************/
|
||||
void
|
||||
CMT_Init(CMT_Alloc_fn allocfn, CMT_Free_fn freefn);
|
||||
|
||||
/*************************************************************
|
||||
* CMT_DecodeMessage
|
||||
*
|
||||
* Decode msg into dest as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_DecodeMessage(CMTMessageTemplate *tmpl, void *dest, CMTItem *msg);
|
||||
|
||||
|
||||
/*************************************************************
|
||||
* CMT_EncodeMessage
|
||||
*
|
||||
* Encode src into msg as specified by tmpl.
|
||||
*
|
||||
************************************************************/
|
||||
CMTStatus
|
||||
CMT_EncodeMessage(CMTMessageTemplate *tmpl, CMTItem *msg, void *src);
|
||||
|
||||
|
||||
#endif /* __NEWPROTO_H__ */
|
||||
187
mozilla/security/psm/lib/protocol/obsample.c
Normal file
187
mozilla/security/psm/lib/protocol/obsample.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/* SAMPLE CODE
|
||||
** Illustrates use of SSMObscure object methods.
|
||||
**
|
||||
** Author: Nelson Bolyard June 1999
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "obscure.h"
|
||||
|
||||
|
||||
/* On error, returns -1.
|
||||
** On success, returns non-negative number of unobscured bytes in buf
|
||||
int
|
||||
RecvInitObscureData(int fd, SSMObscureObject * obj, void * buf, int bufSize )
|
||||
{
|
||||
SSMObscureBool done = 0;
|
||||
|
||||
do {
|
||||
int cc;
|
||||
int rv;
|
||||
cc = read(fd, buf, bufSize);
|
||||
if (cc <= 0)
|
||||
return -1;
|
||||
rv = SSMObscure_RecvInit(obj, buf, cc, &done);
|
||||
} while (!done);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* returns -1 on error, 0 on success. */
|
||||
int
|
||||
SendInitObscureData(int fd, SSMObscureObject * obj)
|
||||
{
|
||||
unsigned char * initBuf = NULL;
|
||||
int rv = -1;
|
||||
|
||||
do {
|
||||
int bufLen;
|
||||
int len;
|
||||
int cc;
|
||||
|
||||
bufLen = SSMObscure_SendInit(obj, NULL);
|
||||
if (bufLen <= 0)
|
||||
break;
|
||||
|
||||
initBuf = malloc(bufLen);
|
||||
if (!initBuf)
|
||||
break;
|
||||
|
||||
len = SSMObscure_SendInit(obj, initBuf);
|
||||
if (len != bufLen)
|
||||
break;
|
||||
|
||||
cc = write(fd, initBuf, len);
|
||||
|
||||
/* Note, this code assumes a blocking socket,
|
||||
** and hence doesn't deal with short writes.
|
||||
*/
|
||||
if (cc < len)
|
||||
break;
|
||||
|
||||
rv = 0;
|
||||
|
||||
} while (0);
|
||||
|
||||
if (initBuf) {
|
||||
free(initBuf);
|
||||
initBuf = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* This is like write, but it obscures the data first. */
|
||||
/* This code assumes a blocking socket, and so it doesn't handle short
|
||||
** writes.
|
||||
*/
|
||||
int
|
||||
obscuredWrite(SSMObscureObject * obj, int fd, void * buf, int len)
|
||||
{
|
||||
int rv;
|
||||
int cc;
|
||||
|
||||
cc = SSMObscure_Send(obj, buf, len);
|
||||
if (cc <= 0)
|
||||
return cc;
|
||||
rv = write(fd, buf, cc);
|
||||
ASSERT(rv == cc || rv < 0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* This is like read, but it unobscures the data after reading it. */
|
||||
int
|
||||
obscuredRead(SSMObscureObject * obj, int fd, void * buf, int len)
|
||||
{
|
||||
int rv;
|
||||
int cc;
|
||||
|
||||
do {
|
||||
cc = read(fd, buf, len);
|
||||
if (cc <= 0)
|
||||
return cc;
|
||||
rv = SSMObscure_Recv(obj, buf, len);
|
||||
} while (rv == 0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
SSMObscureObject * sobj;
|
||||
unsigned char buf[8192];
|
||||
|
||||
/* Call this with fd for socket that has just been accepted.
|
||||
** returns -1 on error,
|
||||
** On success, returns non-negative number of bytes received in buf.
|
||||
*/
|
||||
int
|
||||
InitClientObscureObject(int fd)
|
||||
{
|
||||
int rv;
|
||||
|
||||
sobj = SSMObscure_Create(0);
|
||||
if (!sobj)
|
||||
return -1;
|
||||
|
||||
rv = SendInitObscureData(fd, sobj);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
rv = RecvInitObscureData(fd, sobj, buf, sizeof buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Call this with fd for socket that has just been connected.
|
||||
** returns -1 on error,
|
||||
** On success, returns non-negative number of bytes received in buf.
|
||||
*/
|
||||
int
|
||||
InitServerObscureObject(int fd)
|
||||
{
|
||||
int cc;
|
||||
|
||||
sobj = SSMObscure_Create(1);
|
||||
if (!sobj)
|
||||
return -1;
|
||||
|
||||
cc = RecvInitObscureData(fd, sobj, buf, sizeof buf);
|
||||
if (cc < 0)
|
||||
return cc;
|
||||
|
||||
|
||||
rv = SendInitObscureData(fd, sobj);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
136
mozilla/security/psm/lib/protocol/obscure.c
Normal file
136
mozilla/security/psm/lib/protocol/obscure.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include "obspriv.h"
|
||||
#include "newproto.h"
|
||||
|
||||
|
||||
/*
|
||||
** Create a new Obscuring object
|
||||
*/
|
||||
SSMObscureObject *
|
||||
SSMObscure_Create(SSMObscureBool IsServer)
|
||||
{
|
||||
SSMObscureObject * obj;
|
||||
void * priv;
|
||||
|
||||
obj = (SSMObscureObject *) cmt_alloc(sizeof *obj);
|
||||
if (!obj)
|
||||
return obj;
|
||||
/* This needs to be a little more elegant */
|
||||
priv = SSMObscure_InitPrivate(obj, IsServer);
|
||||
if (!priv) {
|
||||
cmt_free(obj);
|
||||
return NULL;
|
||||
}
|
||||
obj->privData = priv;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/* Prepare initial buffer with initial message to send to other side to
|
||||
** establish cryptographic * synchronization.
|
||||
**
|
||||
** If buf is NULL, function returns the size of the buffer that
|
||||
** the caller needs to allocate for sending the initial message.
|
||||
**
|
||||
** If buf is non-null, function returns the number of bytes of data filled
|
||||
** into buf, the amount that the caller should then send to the other side.
|
||||
**
|
||||
*/
|
||||
int
|
||||
SSMObscure_SendInit( SSMObscureObject * obj, void * buf)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->sendInit(obj->privData, buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
** Obscure "len" bytes in "buf" before sending it.
|
||||
*/
|
||||
int
|
||||
SSMObscure_Send( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->send(obj->privData, buf, len);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
** UnObscure "len" bytes in "buf" after receiving it.
|
||||
** This function may absorb some or all of the received bytes, leaving
|
||||
** fewer bytes (possibly none) in the buffer for the application to use
|
||||
** than were in the buffer when the function was called.
|
||||
** Function returns the number of bytes of unobscured data remaining in
|
||||
** buf. Zero means all data was used internally and no data remains
|
||||
** for application use. Negative number means error occurred.
|
||||
*/
|
||||
int
|
||||
SSMObscure_Recv( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->recv(obj->privData, buf, len);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* like _Recv, but returns a flag telling when all initialization info has
|
||||
** been received.
|
||||
*/
|
||||
int
|
||||
SSMObscure_RecvInit( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len,
|
||||
SSMObscureBool * done)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->recvInit(obj->privData, buf, len, done);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
** Destroy the Obscure Object
|
||||
*/
|
||||
int
|
||||
SSMObscure_Destroy(SSMObscureObject * obj)
|
||||
{
|
||||
int rv;
|
||||
rv = obj->destroy(obj->privData);
|
||||
cmt_free(obj);
|
||||
return rv;
|
||||
}
|
||||
|
||||
98
mozilla/security/psm/lib/protocol/obscure.h
Normal file
98
mozilla/security/psm/lib/protocol/obscure.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __obscure_h__
|
||||
#define __obscure_h__ 1
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef unsigned char SSMObscureBool;
|
||||
|
||||
typedef struct SSMObscureObjectStr SSMObscureObject;
|
||||
|
||||
/*
|
||||
** Create a new Obscuring object
|
||||
*/
|
||||
extern SSMObscureObject * SSMObscure_Create(SSMObscureBool IsServer);
|
||||
|
||||
|
||||
/* Prepare initial buffer with initial message to send to other side to
|
||||
** establish cryptographic * synchronization.
|
||||
**
|
||||
** If buf is NULL, function returns the size of the buffer that
|
||||
** the caller needs to allocate for sending the initial message.
|
||||
**
|
||||
** If buf is non-null, function returns the number of bytes of data filled
|
||||
** into buf, the amount that the caller should then send to the other side.
|
||||
**
|
||||
*/
|
||||
extern int SSMObscure_SendInit( SSMObscureObject * obj,
|
||||
void * buf);
|
||||
|
||||
/*
|
||||
** Obscure "len" bytes in "buf" before sending it.
|
||||
*/
|
||||
extern int SSMObscure_Send( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len);
|
||||
|
||||
/*
|
||||
** UnObscure "len" bytes in "buf" after receiving it.
|
||||
** This function may absorb some or all of the received bytes, leaving
|
||||
** fewer bytes (possibly none) in the buffer for the application to use
|
||||
** than were in the buffer when the function was called.
|
||||
** Function returns the number of bytes of unobscured data remaining in
|
||||
** buf. Zero means all data was used internally and no data remains
|
||||
** for application use. Negative number means error occurred.
|
||||
*/
|
||||
extern int SSMObscure_Recv( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len);
|
||||
|
||||
/* like _Recv, but returns a flag telling when all initialization info has
|
||||
** been received.
|
||||
*/
|
||||
extern int SSMObscure_RecvInit( SSMObscureObject * obj,
|
||||
void * buf,
|
||||
unsigned int len,
|
||||
SSMObscureBool * done);
|
||||
|
||||
/*
|
||||
** Destroy the Obscure Object
|
||||
*/
|
||||
extern int SSMObscure_Destroy(SSMObscureObject * obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __obscure_h__ */
|
||||
115
mozilla/security/psm/lib/protocol/obspriv.c
Normal file
115
mozilla/security/psm/lib/protocol/obspriv.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "obspriv.h"
|
||||
#include "newproto.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
/*
|
||||
Originally this code was used to obscure the control messages
|
||||
traveling between processes. With the relaxation of export rules,
|
||||
this whole step is no longer necessary, and is included for
|
||||
informational purposes only. (We need to finish removing the
|
||||
obscuring code.)
|
||||
*/
|
||||
struct obscureNOPStr {
|
||||
SSMObscureObject * obj;
|
||||
};
|
||||
|
||||
typedef struct obscureNOPStr obscureV1;
|
||||
|
||||
static int
|
||||
ssmObscure_Destroy(void * privData)
|
||||
{
|
||||
obscureV1 * priv = (obscureV1 *)privData;
|
||||
|
||||
memset(priv, 0, sizeof *priv);
|
||||
cmt_free(priv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_Send(void * privData, void * buf, unsigned int len)
|
||||
{
|
||||
/* obscureV1 * priv = (obscureV1 *)privData;*/
|
||||
|
||||
/* NOP */
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_Recv(void * privData, void * buf, unsigned int len)
|
||||
{
|
||||
/*obscureV1 * priv = (obscureV1 *)privData;*/
|
||||
|
||||
/* NOP */
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_SendInit(void * privData, void * buf)
|
||||
{
|
||||
/*obscureV1 * priv = (obscureV1 *)privData;*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ssmObscure_RecvInit(void * privData, void * buf, unsigned int len,
|
||||
SSMObscureBool * pDone)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
ssmObscure_InitPrivate(SSMObscureObject * obj, SSMObscureBool IsServer)
|
||||
{
|
||||
obscureV1 * priv = (obscureV1 *) cmt_alloc(sizeof (obscureV1));
|
||||
|
||||
if (!priv)
|
||||
return NULL;
|
||||
|
||||
priv->obj = obj;
|
||||
|
||||
obj->privData = (void *)priv;
|
||||
obj->destroy = ssmObscure_Destroy;
|
||||
obj->send = ssmObscure_Send;
|
||||
obj->recv = ssmObscure_Recv;
|
||||
obj->sendInit = ssmObscure_SendInit;
|
||||
obj->recvInit = ssmObscure_RecvInit;
|
||||
|
||||
return priv;
|
||||
}
|
||||
|
||||
obsInitFn SSMObscure_InitPrivate = ssmObscure_InitPrivate;
|
||||
63
mozilla/security/psm/lib/protocol/obspriv.h
Normal file
63
mozilla/security/psm/lib/protocol/obspriv.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "obscure.h"
|
||||
|
||||
typedef void * (* obsInitFn) (SSMObscureObject * instance,
|
||||
SSMObscureBool IsServer);
|
||||
typedef int (* obsDestroyFn) (void * priv);
|
||||
typedef int (* obsSendFn) (void * priv, void * buf, unsigned int len);
|
||||
typedef int (* obsRecvFn) (void * priv, void * buf, unsigned int len);
|
||||
typedef int (* obsSendInitFn)(void * priv, void * buf);
|
||||
typedef int (* obsRecvInitFn)(void * priv, void * buf, unsigned int len,
|
||||
SSMObscureBool * done);
|
||||
|
||||
struct SSMObscureObjectStr {
|
||||
void * privData;
|
||||
obsDestroyFn destroy;
|
||||
obsSendFn send;
|
||||
obsRecvFn recv;
|
||||
obsSendInitFn sendInit;
|
||||
obsRecvInitFn recvInit;
|
||||
};
|
||||
|
||||
|
||||
/* This is common to the beginning of all versions of the obscuring protocol */
|
||||
struct SSMInitMsgHdrStr {
|
||||
short version;
|
||||
short length;
|
||||
};
|
||||
|
||||
typedef struct SSMInitMsgHdrStr SSMInitMsgHdr;
|
||||
|
||||
extern obsInitFn SSMObscure_InitPrivate;
|
||||
|
||||
141
mozilla/security/psm/lib/protocol/protocol.h
Normal file
141
mozilla/security/psm/lib/protocol/protocol.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*
|
||||
protocol.h - Definitions of various items to support the PSM protocol.
|
||||
*/
|
||||
|
||||
#ifndef __PROTOCOL_H__
|
||||
#define __PROTOCOL_H__
|
||||
|
||||
|
||||
#include "rsrcids.h"
|
||||
|
||||
#define SSMPRStatus SSMStatus
|
||||
#define SSMPR_SUCCESS SSM_SUCCESS
|
||||
#define SSMPR_FAILURE SSM_FAILURE
|
||||
|
||||
#define SSMPR_INVALID_ARGUMENT_ERROR PR_INVALID_ARGUMENT_ERROR
|
||||
#define SSMPR_OUT_OF_MEMORY_ERROR PR_OUT_OF_MEMORY_ERROR
|
||||
|
||||
#define SSMPRInt32 PRInt32
|
||||
#define SSMPRUint32 PRUint32
|
||||
|
||||
#define SSMPR_ntohl PR_ntohl
|
||||
#define SSMPR_htonl PR_htonl
|
||||
#define SSMPORT_Free PORT_Free
|
||||
#define SSMPORT_ZAlloc PORT_ZAlloc
|
||||
|
||||
#define SSMPR_SetError PR_SetError
|
||||
#define SSMPR_GetError PR_GetError
|
||||
#define SSMPORT_SetError PORT_SetError
|
||||
#define SSMPORT_GetError PORT_GetError
|
||||
|
||||
/*
|
||||
Current version of PSM protocol.
|
||||
Increment this value when the protocol changes.
|
||||
*/
|
||||
|
||||
#define SSMSTRING_PADDED_LENGTH(x) ((((x)+3)/4)*4)
|
||||
#define SSMPORT_ZNEW(type) (type*)SSMPORT_ZAlloc(sizeof(type))
|
||||
#define SSMPORT_ZNewArray(type,size) (type*)SSMPORT_ZAlloc(sizeof(type)*(size))
|
||||
/* Various message structs */
|
||||
|
||||
struct _SSMHelloRequest {
|
||||
CMUint32 m_version; /* Protocol version supported by client */
|
||||
struct _SSMString m_profileName; /* Name of user profile (where to find
|
||||
certs etc) */
|
||||
};
|
||||
|
||||
struct _SSMHelloReply {
|
||||
CMInt32 m_result; /* Error, if any, which occurred
|
||||
(0 == success) */
|
||||
CMUint32 m_version; /* Protocol version supported by PSM */
|
||||
struct _SSMString m_nonce; /* Session nonce -- must be written to data channels */
|
||||
};
|
||||
|
||||
struct _SSMRequestSSLDataConnection
|
||||
{
|
||||
CMUint32 m_flags; /* Flags to indicate to SSM what to do with
|
||||
the connection */
|
||||
CMUint32 m_port; /* Port number to connect to */
|
||||
struct _SSMString m_hostIP; /* IP address of final target machine (not proxy) */
|
||||
/* struct _SSMString m_hostName; Host name of target machine (for server auth) -- not accessed directly */
|
||||
};
|
||||
|
||||
struct _SSMReplySSLDataConnection {
|
||||
CMInt32 m_result; /* Error, if any, which occurred (0 == success) */
|
||||
CMUint32 m_connectionID; /* Connection ID of newly opened channel */
|
||||
CMUint32 m_port; /* Port number to which to connect on PSM */
|
||||
};
|
||||
|
||||
|
||||
struct _SSMRequestSecurityStatus {
|
||||
CMUint32 m_connectionID; /* ID of connection of which to stat */
|
||||
};
|
||||
|
||||
struct _SSMReplySecurityStatus {
|
||||
CMInt32 m_result; /* Error, if any, which occurred (0 == success) */
|
||||
CMUint32 m_keySize; /* Key size */
|
||||
CMUint32 m_secretKeySize; /* Secret key size */
|
||||
struct _SSMString m_cipherName; /* Name of cipher in use */
|
||||
/* SSMString m_certificate; -- DER encoded cert
|
||||
We do not access this as a field, we have to skip over m_cipherName */
|
||||
};
|
||||
|
||||
/*
|
||||
Use this macro to jump over strings.
|
||||
For example, if you wanted to access m_certificate above,
|
||||
use a line like the following:
|
||||
|
||||
char *ptr = &(reply->m_cipherName) + SSM_SIZEOF_STRING(reply->m_cipherName);
|
||||
*/
|
||||
#define SSM_SIZEOF_STRING(str) (SSMSTRING_PADDED_LENGTH(PR_ntohl((str).m_length)) + sizeof(CMUint32))
|
||||
|
||||
|
||||
typedef struct _SSMHelloRequest SSMHelloRequest;
|
||||
typedef struct _SSMHelloReply SSMHelloReply;
|
||||
typedef struct _SSMRequestSSLDataConnection SSMRequestSSLDataConnection;
|
||||
typedef struct _SSMReplySSLDataConnection SSMReplySSLDataConnection;
|
||||
typedef struct _SSMRequestSecurityStatus SSMRequestSecurityStatus;
|
||||
typedef struct _SSMReplySecurityStatus SSMReplySecurityStatus;
|
||||
|
||||
/*
|
||||
Functions to convert between an SSMString and a C string.
|
||||
Return values are allocated using PR_Malloc (which means that
|
||||
SSMPR_Free must be used to free up the memory after use).
|
||||
*/
|
||||
CMTStatus SSM_StringToSSMString(SSMString ** ssmString, int len, char * string);
|
||||
CMTStatus SSM_SSMStringToString(char ** string,int *len, SSMString * ssmString);
|
||||
|
||||
|
||||
#endif /* __PROTOCOL_H__ */
|
||||
2260
mozilla/security/psm/lib/protocol/protocolf.c
Normal file
2260
mozilla/security/psm/lib/protocol/protocolf.c
Normal file
File diff suppressed because it is too large
Load Diff
359
mozilla/security/psm/lib/protocol/protocolf.h
Normal file
359
mozilla/security/psm/lib/protocol/protocolf.h
Normal file
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __PROTOCOLF_H__
|
||||
#define __PROTOCOLF_H__
|
||||
/*************************************************************************
|
||||
* For each type of message, parse and pack function is provided.
|
||||
*
|
||||
* Parse functions accept a ptr to the "blob" of data received from the
|
||||
* network and fill in fields of the message, numbers in host-order, strings
|
||||
* as C-style NULL-terminated strings. Return SSMPRStatus.
|
||||
*
|
||||
* Pack functions take all the info to construct a message and fill in a
|
||||
* ptr to the "blob" of data to be sent. Return length of the data blob, or
|
||||
* a zero in case of an error
|
||||
*
|
||||
* All functions set NSPR errors when necessary.
|
||||
************************************************************************/
|
||||
#include "protocol.h"
|
||||
#include "cert.h"
|
||||
|
||||
SSMPRStatus SSM_ParseHelloRequest(void * helloRequest,
|
||||
SSMPRUint32 * version,
|
||||
PRBool * doesUI,
|
||||
PRInt32 * policyType,
|
||||
SSMPRUint32 * profileLen,
|
||||
char ** profile);
|
||||
SSMPRInt32 SSM_PackHelloReply(void ** helloReply, SSMPRInt32 result,
|
||||
SSMPRUint32 sessionID, SSMPRUint32 version,
|
||||
SSMPRUint32 httpPort, SSMPRUint32 nonceLen,
|
||||
char * nonce, SSMPolicyType policy);
|
||||
|
||||
/* Parse data connections requests */
|
||||
SSMPRStatus SSM_ParseSSLDataConnectionRequest(void *sslRequest,
|
||||
SSMPRUint32 * flags,
|
||||
SSMPRUint32 * port,
|
||||
SSMPRUint32 * hostIPLen,
|
||||
char ** hostIP,
|
||||
SSMPRUint32 * hostNameLen,
|
||||
char ** hostName);
|
||||
SSMPRStatus SSM_ParseHashStreamRequest(void * hashStreamRequest,
|
||||
SSMPRUint32 * type);
|
||||
SSMPRStatus SSM_ParseP7EncodeConnectionRequest(void *request,
|
||||
SSMPRUint32 *ciRID);
|
||||
/* Messages to initiate PKCS7 data connection */
|
||||
/* PKCS7DecodeRequest message has no data */
|
||||
|
||||
/* Single data connection reply */
|
||||
SSMPRInt32 SSM_PackDataConnectionReply(void ** sslReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 connID,
|
||||
SSMPRUint32 port);
|
||||
|
||||
SSMPRStatus SSM_ParseSSLSocketStatusRequest(void * statusRequest,
|
||||
SSMPRUint32 * connID);
|
||||
SSMPRInt32 SSM_PackSSLSocketStatusReply(void ** statusReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 resourceID);
|
||||
|
||||
/*
|
||||
* UI event is an asynchroneous message sent from PSM server to the client
|
||||
* NOTE: (context) is the actual context pointer, it is NOT a ptr-to-ptr.
|
||||
* The value of (context) is copied into the packet.
|
||||
*/
|
||||
SSMPRInt32 SSM_PackUIEvent(void ** eventRequest, SSMPRUint32 resourceID,
|
||||
SSMPRUint32 width, SSMPRUint32 height,
|
||||
SSMPRUint32 urlLen, char * url);
|
||||
|
||||
SSMPRInt32 SSM_PackTaskCompletedEvent(void **event, SSMPRUint32 resourceID,
|
||||
SSMPRUint32 numTasks, SSMPRUint32 result);
|
||||
|
||||
/* Verify raw signature */
|
||||
|
||||
SSMPRStatus SSM_ParseVerifyRawSigRequest(void * verifyRawSigRequest,
|
||||
SSMPRUint32 * algorithmID,
|
||||
SSMPRUint32 * paramsLen,
|
||||
unsigned char ** params,
|
||||
SSMPRUint32 * pubKeyLen,
|
||||
unsigned char ** pubKey,
|
||||
SSMPRUint32 * hashLen,
|
||||
unsigned char ** hash,
|
||||
SSMPRUint32 * signatureLen,
|
||||
unsigned char ** signature);
|
||||
SSMPRInt32 SSM_PackVerifyRawSigReply(void ** verifyRawSigReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
/* Verify detached signature */
|
||||
SSMPRStatus SSM_ParseVerifyDetachedSigRequest(void * request,
|
||||
SSMPRInt32 * pkcs7ContentID,
|
||||
SSMPRInt32 * certUsage,
|
||||
SSMPRInt32 * hashAlgID,
|
||||
SSMPRUint32 * keepCert,
|
||||
SSMPRUint32 * digestLen,
|
||||
unsigned char ** hash);
|
||||
|
||||
SSMPRInt32 SSM_PackVerifyDetachedSigReply(void ** verifyDetachedSigReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
/* PKCS#7 functions */
|
||||
SSMPRStatus SSM_ParseCreateSignedRequest(void *request,
|
||||
SSMPRInt32 *scertRID,
|
||||
SSMPRInt32 *ecertRID,
|
||||
SSMPRUint32 *dig_alg,
|
||||
SECItem **digest);
|
||||
|
||||
SSMPRInt32 SSM_PackCreateSignedReply(void **reply, SSMPRInt32 ciRID,
|
||||
SSMPRUint32 result);
|
||||
|
||||
SSMPRStatus SSM_ParseCreateEncryptedRequest(void *request,
|
||||
SSMPRInt32 *scertRID,
|
||||
SSMPRInt32 *nrcerts,
|
||||
SSMPRInt32 **rcertRIDs);
|
||||
|
||||
SSMPRInt32 SSM_PackCreateEncryptedReply(void **reply, SSMPRInt32 ciRID,
|
||||
SSMPRUint32 result);
|
||||
|
||||
/* Resource functions */
|
||||
SSMPRStatus SSM_ParseCreateResourceRequest(void *request,
|
||||
SSMPRUint32 *type,
|
||||
unsigned char **params,
|
||||
SSMPRUint32 *paramLen);
|
||||
|
||||
SSMPRStatus SSM_PackCreateResourceReply(void **reply, SSMPRStatus rv,
|
||||
SSMPRUint32 resID);
|
||||
|
||||
SSMPRStatus SSM_ParseGetAttribRequest(void * getAttribRequest,
|
||||
SSMPRUint32 * resourceID,
|
||||
SSMPRUint32 * fieldID);
|
||||
|
||||
void SSM_DestroyAttrValue(SSMAttributeValue *value, PRBool freeit);
|
||||
|
||||
SSMPRInt32 SSM_PackGetAttribReply(void **getAttribReply,
|
||||
SSMPRInt32 result,
|
||||
SSMAttributeValue *value);
|
||||
SSMPRStatus SSM_ParseSetAttribRequest(SECItem *msg,
|
||||
SSMPRInt32 *resourceID,
|
||||
SSMPRInt32 *fieldID,
|
||||
SSMAttributeValue *value);
|
||||
/* Currently, there is no need for a pack version. There is nothing to send
|
||||
* back except for the notice that the operation was successful.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* Pickle and unpickle resources. */
|
||||
SSMPRStatus SSM_ParsePickleResourceRequest(void * pickleResourceRequest,
|
||||
SSMPRUint32 * resourceID);
|
||||
SSMPRInt32 SSM_PackPickleResourceReply(void ** pickleResourceReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 resourceLen,
|
||||
void * resource);
|
||||
SSMPRStatus SSM_ParseUnpickleResourceRequest(void * unpickleResourceRequest,
|
||||
SSMPRUint32 blobSize,
|
||||
SSMPRUint32 * resourceType,
|
||||
SSMPRUint32 * resourceLen,
|
||||
void ** resource);
|
||||
SSMPRInt32 SSM_PackUnpickleResourceReply(void ** unpickleResourceReply,
|
||||
SSMPRInt32 result,
|
||||
SSMPRUint32 resourceID);
|
||||
|
||||
/* Destroy resource */
|
||||
SSMPRStatus SSM_ParseDestroyResourceRequest(void * destroyResourceRequest,
|
||||
SSMPRUint32 * resourceID,
|
||||
SSMPRUint32 * resourceType);
|
||||
SSMPRInt32 SSM_PackDestroyResourceReply(void ** destroyResourceReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
/* Duplicate resource */
|
||||
SSMPRStatus SSM_ParseDuplicateResourceRequest(void * request,
|
||||
SSMPRUint32 * resourceID);
|
||||
SSMPRInt32 SSM_PackDuplicateResourceReply(void ** reply, SSMPRInt32 result,
|
||||
SSMPRUint32 resID);
|
||||
|
||||
/* Cert actions */
|
||||
typedef struct MatchUserCertRequestData {
|
||||
PRUint32 certType;
|
||||
PRInt32 numCANames;
|
||||
char ** caNames;
|
||||
} MatchUserCertRequestData;
|
||||
|
||||
typedef struct SSMCertList {
|
||||
PRCList certs;
|
||||
PRInt32 count;
|
||||
} SSMCertList;
|
||||
|
||||
typedef struct SSMCertListElement {
|
||||
PRCList links;
|
||||
PRUint32 certResID;
|
||||
} SSMCertListElement;
|
||||
|
||||
#define SSM_CERT_LIST_ELEMENT_PTR(_q) (SSMCertListElement*)(_q);
|
||||
|
||||
SSMPRStatus SSM_ParseVerifyCertRequest(void * verifyCertRequest,
|
||||
SSMPRUint32 * resourceID,
|
||||
SSMPRInt32 * certUsage);
|
||||
SSMPRInt32 SSM_PackVerifyCertReply(void ** verifyCertReply,
|
||||
SSMPRInt32 result);
|
||||
|
||||
SSMPRStatus SSM_ParseImportCertRequest(void * importCertRequest,
|
||||
SSMPRUint32 * blobLen,
|
||||
void ** certBlob);
|
||||
SSMPRInt32 SSM_PackImportCertReply(void ** importCertReply, SSMPRInt32 result,
|
||||
SSMPRUint32 resourceID);
|
||||
PRStatus SSM_ParseFindCertByNicknameRequest(void *request, char ** nickname);
|
||||
PRInt32 SSM_PackFindCertByNicknameReply(void ** reply, PRUint32 resourceID);
|
||||
PRStatus SSM_ParseFindCertByKeyRequest(void *request, SECItem ** key);
|
||||
PRInt32 SSM_PackFindCertByKeyReply(void ** reply, PRUint32 resourceID);
|
||||
PRStatus SSM_ParseFindCertByEmailAddrRequest(void *request, char ** emailAddr);
|
||||
PRInt32 SSM_PackFindCertByEmailAddrReply(void ** reply, PRUint32 resourceID);
|
||||
PRStatus SSM_ParseAddTempCertToDBRequest(void *request, PRUint32 *resourceID, char ** nickname, PRInt32 *ssl, PRInt32 *email, PRInt32 *objectSigning);
|
||||
PRInt32 SSM_PackAddTempCertToDBReply(void ** reply);
|
||||
PRStatus SSM_ParseMatchUserCertRequest(void *request, MatchUserCertRequestData** data);
|
||||
PRInt32 SSM_PackMatchUserCertReply(void **reply, SSMCertList * certList);
|
||||
|
||||
SSMPRInt32 SSM_PackErrorMessage(void ** errorReply, SSMPRInt32 result);
|
||||
|
||||
|
||||
/* PKCS11 actions */
|
||||
SSMPRStatus SSM_ParseKeyPairGenRequest(void *keyPairGenRequest,
|
||||
SSMPRInt32 requestLen,
|
||||
SSMPRUint32 *keyPairCtxtID,
|
||||
SSMPRUint32 *genMechanism,
|
||||
SSMPRUint32 *keySize,
|
||||
unsigned char **params,
|
||||
SSMPRUint32 *paramLen);
|
||||
|
||||
SSMPRInt32 SSM_PackKeyPairGenResponse(void ** keyPairGenResponse,
|
||||
SSMPRUint32 keyPairId);
|
||||
|
||||
PRStatus
|
||||
SSM_ParseFinishKeyGenRequest(void *finishKeyGenRequest,
|
||||
PRInt32 requestLen,
|
||||
PRInt32 *keyGenContext);
|
||||
|
||||
/* CMMF/CRMF Actions */
|
||||
SSMPRStatus SSM_ParseCreateCRMFReqRequest(void *crmfReqRequest,
|
||||
SSMPRInt32 requestLen,
|
||||
SSMPRUint32 *keyPairId);
|
||||
|
||||
SSMPRInt32 SSM_PackCreateCRMFReqReply(void **crmfReqReply,
|
||||
SSMPRUint32 crmfReqId);
|
||||
|
||||
SSMPRStatus SSM_ParseEncodeCRMFReqRequest(void *encodeReq,
|
||||
SSMPRInt32 requestLen,
|
||||
SSMPRUint32 **crmfReqId,
|
||||
SSMPRInt32 *numRequests);
|
||||
|
||||
SSMPRInt32 SSM_PackEncodeCRMFReqReply(void **encodeReply,
|
||||
char *crmfDER,
|
||||
SSMPRUint32 derLen);
|
||||
|
||||
SSMPRStatus SSM_ParseCMMFCertResponse(void *encodedRes,
|
||||
SSMPRInt32 encodeLen,
|
||||
char **nickname,
|
||||
char **base64Der,
|
||||
PRBool *doBackup);
|
||||
|
||||
PRStatus SSM_ParsePOPChallengeRequest(void *challenge,
|
||||
PRInt32 len,
|
||||
char **responseString);
|
||||
PRInt32 SSM_PackPOPChallengeResponse(void **response,
|
||||
char *responseString,
|
||||
PRInt32 responseStringLen);
|
||||
|
||||
PRInt32 SSM_PackPasswdRequest(void ** passwdRequest, PRInt32 tokenID,
|
||||
char * prompt, PRInt32 promptLen);
|
||||
PRStatus SSM_ParsePasswordReply(void * passwdReply, PRInt32 * result,
|
||||
PRInt32 * tokenID,
|
||||
char ** passwd, PRInt32 * passwdLen);
|
||||
|
||||
/* Sign Text Actions */
|
||||
typedef struct {
|
||||
char *stringToSign;
|
||||
char *hostName;
|
||||
char *caOption;
|
||||
PRInt32 numCAs;
|
||||
char **caNames;
|
||||
} signTextRequestData;
|
||||
|
||||
PRStatus SSM_ParseSignTextRequest(void* signTextRequest, PRInt32 len, PRUint32* resID, signTextRequestData ** data);
|
||||
|
||||
PRStatus SSM_ParseGetLocalizedTextRequest(void *data,
|
||||
SSMLocalizedString *whichString);
|
||||
|
||||
PRInt32 SSM_PackGetLocalizedTextResponse(void **data,
|
||||
SSMLocalizedString whichString,
|
||||
char *retString);
|
||||
|
||||
PRStatus SSM_ParseAddNewSecurityModuleRequest(void *data,
|
||||
char **moduleName,
|
||||
char **libraryPath,
|
||||
unsigned long *pubMechFlags,
|
||||
unsigned long *pubCipherFlags);
|
||||
|
||||
PRInt32 SSM_PackAddNewModuleResponse(void **data, PRInt32 rv);
|
||||
|
||||
PRStatus SSM_ParseDeleteSecurityModuleRequest(void *data, char **moduleName);
|
||||
|
||||
PRInt32 SSM_PackDeleteModuleResponse(void **data, PRInt32 moduleType);
|
||||
|
||||
PRInt32 SSM_PackFilePathRequest(void **data, PRInt32 resID, char *prompt,
|
||||
PRBool shouldFileExist, char *fileSuffix);
|
||||
|
||||
PRStatus SSM_ParseFilePathReply(void *message, char **filePath,
|
||||
PRInt32 *rid);
|
||||
|
||||
PRInt32 SSM_PackPromptRequestEvent(void **data, PRInt32 resID, char *prompt);
|
||||
PRStatus SSM_ParsePasswordPromptReply(void *data, PRInt32 *resID,
|
||||
char **reply);
|
||||
|
||||
/* messages for importing certs *the traditional way* */
|
||||
PRInt32 SSM_PackDecodeCertReply(void ** data, PRInt32 certID);
|
||||
PRStatus SSM_ParseDecodeCertRequest(void * data, PRInt32 * len,
|
||||
char ** buffer);
|
||||
PRStatus SSM_ParseGetKeyChoiceListRequest(void * data, PRUint32 dataLen,
|
||||
char ** type, PRUint32 *typeLen,
|
||||
char ** pqgString, PRUint32 *pqgLen);
|
||||
PRInt32 SSM_PackGetKeyChoiceListReply(void **data, char ** list);
|
||||
|
||||
PRStatus SSM_ParseGenKeyOldStyleRequest(void * data, PRUint32 datalen,
|
||||
char ** choiceString,
|
||||
char ** challenge,
|
||||
char ** typeString,
|
||||
char ** pqgString);
|
||||
PRInt32 SSM_PackGenKeyOldStyleReply(void ** data, char * keydata);
|
||||
|
||||
PRStatus SSM_ParseDecodeAndCreateTempCertRequest(void * data,
|
||||
char ** certbuf, PRUint32 * certlen, int * certClass);
|
||||
|
||||
#endif /*PROTOCOLF_H_*/
|
||||
74
mozilla/security/psm/lib/protocol/protocolnspr20.h
Normal file
74
mozilla/security/psm/lib/protocol/protocolnspr20.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0x00000000
|
||||
#endif
|
||||
|
||||
#define SSMPR_BYTES_PER_INT 4
|
||||
#define SSMPR_BYTES_PER_LONG 4
|
||||
|
||||
/******************************************************************
|
||||
* No NSPR - define all the SSMPR values and functions here
|
||||
******************************************************************
|
||||
*/
|
||||
|
||||
#define SSMPRStatus PRStatus
|
||||
#define SSMPR_SUCCESS PR_SUCCESS
|
||||
#define SSMPR_FAILURE PR_FAILURE
|
||||
|
||||
#define SSMPR_INVALID_ARGUMENT_ERROR PR_INVALID_ARGUMENT_ERROR
|
||||
#define SSMPR_OUT_OF_MEMORY_ERROR PR_OUT_OF_MEMORY_ERROR
|
||||
|
||||
#define SSMPRInt32 PRInt32
|
||||
#define SSMPRUint32 PRUint32
|
||||
|
||||
#define SSMPR_ntohl PR_ntohl
|
||||
#define SSMPR_htonl PR_htonl
|
||||
#define SSMPORT_Free PORT_Free
|
||||
#define SSMPORT_ZAlloc PORT_ZAlloc
|
||||
|
||||
#define SSMPR_SetError PR_SetError
|
||||
#define SSMPR_GetError PR_GetError
|
||||
#define SSMPORT_SetError PORT_SetError
|
||||
#define SSMPORT_GetError PORT_GetError
|
||||
|
||||
|
||||
|
||||
|
||||
49
mozilla/security/psm/lib/protocol/protocolport.c
Normal file
49
mozilla/security/psm/lib/protocol/protocolport.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*************************************************************************
|
||||
*
|
||||
* PSM portable run-time. (Used when NSPR20 is not available.)
|
||||
*
|
||||
*************************************************************************
|
||||
*/
|
||||
|
||||
SSMPRInt32 ssmprErrno;
|
||||
|
||||
void SSMPORT_SetError(SSMPRInt32 errorcode)
|
||||
{ ssmprErrno = errorcode; }
|
||||
|
||||
|
||||
SSMPRInt32 SSMPORT_GetError(void)
|
||||
{ return ssmprErrno; }
|
||||
|
||||
|
||||
93
mozilla/security/psm/lib/protocol/protocolport.h
Normal file
93
mozilla/security/psm/lib/protocol/protocolport.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0x00000000
|
||||
#endif
|
||||
|
||||
#define SSMPR_BYTES_PER_INT 4
|
||||
#define SSMPR_BYTES_PER_LONG 4
|
||||
|
||||
/******************************************************************
|
||||
* No NSPR - define all the SSMPR values and functions here
|
||||
******************************************************************
|
||||
*/
|
||||
|
||||
typedef enum { SSMPR_SUCCESS = 0, SSMPR_FAILURE = -1 } SSMPRStatus;
|
||||
enum {
|
||||
SSMPR_INVALID_ARGUMENT_ERROR = -6000,
|
||||
SSMPR_OUT_OF_MEMORY_ERROR = -5987
|
||||
};
|
||||
|
||||
#if SSMPR_BYTES_PER_INT == 4
|
||||
typedef unsigned int SSMPRUint32;
|
||||
typedef int SSMPRInt32;
|
||||
#elif SSMPR_BYTES_PER_LONG == 4
|
||||
typedef unsigned long SSMPRUint32;
|
||||
typedef long SSMPRInt32;
|
||||
#else
|
||||
#error No suitable type for SSMPRInt32/SSMPRUint32
|
||||
#endif
|
||||
|
||||
/*******************************************************************
|
||||
* Use libc functions instead
|
||||
*******************************************************************
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#define SSMPR_ntohl ntohl
|
||||
#define SSMPR_htonl htonl
|
||||
|
||||
#include <stdlib.h>
|
||||
#define SSMPORT_Free free
|
||||
#define SSMPR_sprint printf
|
||||
#define SSMPORT_ZAlloc malloc
|
||||
|
||||
extern SSMPRInt32 ssmprErrno;
|
||||
#define SSMPR_SetError(x, y) SSMPORT_SetError(x)
|
||||
#define SSMPR_GetError SSMPORT_GetError
|
||||
void SSMPORT_SetError(SSMPRInt32 errorcode);
|
||||
|
||||
|
||||
|
||||
|
||||
169
mozilla/security/psm/lib/protocol/protocolshr.c
Normal file
169
mozilla/security/psm/lib/protocol/protocolshr.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "string.h"
|
||||
#include "protocol.h"
|
||||
#include "protocolshr.h"
|
||||
#include "messages.h"
|
||||
|
||||
/* Forward ref */
|
||||
static void encrypt(CMTItem *data);
|
||||
static void decrypt(CMTItem *data);
|
||||
|
||||
const char *kPrefix = "Encrypted";
|
||||
|
||||
/* encryption request */
|
||||
CMTStatus
|
||||
CMT_DoEncryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
EncryptRequestMessage request;
|
||||
EncryptReplyMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.keyid.data = 0;
|
||||
request.data.data = 0;
|
||||
reply.item.data = 0;
|
||||
|
||||
/* Decode incoming message */
|
||||
rv = CMT_DecodeMessage(EncryptRequestTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser; /* Protocol error */
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Encrypt" by prefixing the data */
|
||||
reply.item.len = request.data.len + pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) {
|
||||
rv = CMTFailure;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (pLen) memcpy(reply.item.data, kPrefix, pLen);
|
||||
encrypt(&request.data);
|
||||
memcpy(&reply.item.data[pLen], request.data.data, request.data.len);
|
||||
|
||||
/* Generate response */
|
||||
message->type = SSM_SDR_ENCRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(EncryptReplyTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser; /* Unknown error */
|
||||
|
||||
loser:
|
||||
if (request.keyid.data) free(request.keyid.data);
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* decryption request */
|
||||
CMTStatus
|
||||
CMT_DoDecryptionRequest(CMTItem *message)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
DecryptRequestMessage request;
|
||||
DecryptReplyMessage reply;
|
||||
CMUint32 pLen = strlen(kPrefix);
|
||||
|
||||
/* Initialize */
|
||||
request.data.data = 0;
|
||||
request.ctx.data = 0;
|
||||
reply.item.data = 0;
|
||||
|
||||
/* Decode the message */
|
||||
rv = CMT_DecodeMessage(DecryptRequestTemplate, &request, message);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
/* Free incoming message */
|
||||
free(message->data);
|
||||
message->data = NULL;
|
||||
|
||||
/* "Decrypt" the message by removing the key */
|
||||
if (pLen && memcmp(request.data.data, kPrefix, pLen) != 0) {
|
||||
rv = CMTFailure; /* Invalid format */
|
||||
goto loser;
|
||||
}
|
||||
|
||||
reply.item.len = request.data.len - pLen;
|
||||
reply.item.data = calloc(reply.item.len, 1);
|
||||
if (!reply.item.data) { rv = CMTFailure; goto loser; }
|
||||
|
||||
memcpy(reply.item.data, &request.data.data[pLen], reply.item.len);
|
||||
decrypt(&reply.item);
|
||||
|
||||
/* Create reply message */
|
||||
message->type = SSM_SDR_DECRYPT_REPLY;
|
||||
rv = CMT_EncodeMessage(DecryptReplyTemplate, message, &reply);
|
||||
if (rv != CMTSuccess) goto loser;
|
||||
|
||||
loser:
|
||||
if (request.data.data) free(request.data.data);
|
||||
if (request.ctx.data) free(request.ctx.data);
|
||||
if (reply.item.data) free(reply.item.data);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* "encrypt" */
|
||||
static unsigned char mask[64] = {
|
||||
0x73, 0x46, 0x1a, 0x05, 0x24, 0x65, 0x43, 0xb4, 0x24, 0xee, 0x79, 0xc1, 0xcc,
|
||||
0x49, 0xc7, 0x27, 0x11, 0x91, 0x2e, 0x8f, 0xaa, 0xf7, 0x62, 0x75, 0x41, 0x7e,
|
||||
0xb2, 0x42, 0xde, 0x1b, 0x42, 0x7b, 0x1f, 0x33, 0x49, 0xca, 0xd1, 0x6a, 0x85,
|
||||
0x05, 0x6c, 0xf9, 0x0e, 0x3e, 0x72, 0x02, 0xf2, 0xd8, 0x9d, 0xa1, 0xb8, 0x6e,
|
||||
0x03, 0x18, 0x3e, 0x82, 0x86, 0x34, 0x1a, 0x61, 0xd9, 0x65, 0xb6, 0x7f
|
||||
};
|
||||
|
||||
static void
|
||||
encrypt(CMTItem *data)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
j = 0;
|
||||
for(i = 0;i < data->len;i++)
|
||||
{
|
||||
data->data[i] ^= mask[j];
|
||||
|
||||
if (++j >= 64) j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
decrypt(CMTItem *data)
|
||||
{
|
||||
encrypt(data);
|
||||
}
|
||||
|
||||
|
||||
48
mozilla/security/psm/lib/protocol/protocolshr.h
Normal file
48
mozilla/security/psm/lib/protocol/protocolshr.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
/*
|
||||
protocolshr.h - Definitions of shared routines for both client and server
|
||||
These are mostly for testing.
|
||||
*/
|
||||
|
||||
#ifndef __PROTOCOLSHR_H__
|
||||
#define __PROTOCOLSHR_H__
|
||||
|
||||
CMTStatus
|
||||
CMT_DoEncryptionRequest(CMTItem *message);
|
||||
|
||||
CMTStatus
|
||||
CMT_DoDecryptionRequest(CMTItem *meessage);
|
||||
|
||||
|
||||
#endif /* __PROTOCOLSHR_H__ */
|
||||
207
mozilla/security/psm/lib/protocol/protocoltest.c
Normal file
207
mozilla/security/psm/lib/protocol/protocoltest.c
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "protocolf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
void * blob, * recvd;
|
||||
int blobSize;
|
||||
SSMPRUint32 version, flags, port, connID, keySize, secretKeySize;
|
||||
SSMPRUint32 sessionID, httpPort;
|
||||
SSMPRInt32 result;
|
||||
char *profile, * nonce, * hostIP, * hostName, * cipher, * CA;
|
||||
SSMPRStatus rv;
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to pack and parse HelloRequest message
|
||||
*/
|
||||
version = 3;
|
||||
profile = (char *)SSMPORT_ZAlloc(strlen("profile"));
|
||||
sprintf(profile, "profile");
|
||||
printf("HelloRequest, packing version #%d, profile %s\n",
|
||||
version, profile);
|
||||
blobSize = SSM_PackHelloRequest(&blob, version, profile);
|
||||
if (!blobSize)
|
||||
printf("Error in PackHelloRequest: %d\n", SSMPR_GetError());
|
||||
SSMPORT_Free(profile);
|
||||
version = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseHelloRequest(recvd, &version, &profile);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseHelloRequest: %d\n", SSMPR_GetError());
|
||||
printf("HelloRequest, parsing version #%d, profile %s\n",
|
||||
version, profile);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack HelloReply message
|
||||
*/
|
||||
version = 5;
|
||||
result = 2;
|
||||
sessionID = 34567;
|
||||
httpPort = 87654;
|
||||
nonce = (char *)SSMPORT_ZAlloc(strlen("some secret nonce"));
|
||||
sprintf(nonce, "some secret nonce");
|
||||
printf("HelloReply, packing result %d, sessionID %d, version #%d, httpPort %d,\n nonce %s\n",
|
||||
result, sessionID, version, httpPort, nonce);
|
||||
blobSize = SSM_PackHelloReply(&blob, result, sessionID, version, httpPort,
|
||||
nonce);
|
||||
if (!blobSize)
|
||||
printf("Error in PackHelloReply: %d\n", SSMPR_GetError());
|
||||
memset(nonce, 0, strlen(nonce));
|
||||
SSMPORT_Free(nonce);
|
||||
version = result = sessionID = httpPort = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseHelloReply(recvd, &result, &sessionID, &version, &httpPort,
|
||||
&nonce);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseHelloReply: %d\n", SSMPR_GetError());
|
||||
printf("HelloReply, parsing result %d, sessionID %d, version #%d, httpPort %d, \n nonce %s\n",
|
||||
result, sessionID, version, httpPort, nonce);
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SSLDataConnectionRequest message
|
||||
*/
|
||||
flags = 0x00044000;
|
||||
port = 34567;
|
||||
hostIP = (char *)SSMPORT_ZAlloc(strlen("somehostIP"));
|
||||
sprintf(hostIP, "somehostIP");
|
||||
hostName = (char *)SSMPORT_ZAlloc(strlen("somehostName"));
|
||||
sprintf(hostName, "somehostName");
|
||||
printf("SSLDataConnRequest, packing flags %x, port %d, hostIP %s, hostName %s\n",
|
||||
flags, port, hostIP, hostName);
|
||||
blobSize = SSM_PackSSLDataConnectionRequest(&blob, flags, port, hostIP,
|
||||
hostName);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSSLDataConnectionRequest: %d\n", SSMPR_GetError());
|
||||
SSMPORT_Free(hostIP);
|
||||
SSMPORT_Free(hostName);
|
||||
flags = port = 0;
|
||||
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
|
||||
rv = SSM_ParseSSLDataConnectionRequest(recvd, &flags, &port, &hostIP,
|
||||
&hostName);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSSLDataConnectionRequest: %d\n", SSMPR_GetError());
|
||||
printf(
|
||||
"SSLDataConnRequest, parsing flags %x, port %d, hostIP %s, hostName %s\n",
|
||||
flags, port, hostIP, hostName);
|
||||
SSMPORT_Free(hostIP);
|
||||
SSMPORT_Free(hostName);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SSLDataConnectionReply message
|
||||
*/
|
||||
result = 2;
|
||||
connID = 713259;
|
||||
port = 57402;
|
||||
printf("SSLDataConnReply, packing result %d, connectionID %d, port %d\n",
|
||||
result, connID, port);
|
||||
blobSize = SSM_PackSSLDataConnectionReply(&blob, result, connID, port);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSSLDataConnReply: %d\n", SSMPR_GetError());
|
||||
result = connID = port = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseSSLDataConnectionReply(recvd, &result, &connID, &port);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSSLDataConnectionReply: %d\n", SSMPR_GetError());
|
||||
printf("SSLDataConnReply, parsing result %d, connectionID %d, port %d\n",
|
||||
result, connID, port);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SecurityStatusRequest message
|
||||
*/
|
||||
connID = 45375;
|
||||
printf("SecurityStatusRequest, packing connection ID %d\n", connID);
|
||||
blobSize = SSM_PackSecurityStatusRequest(&blob, connID);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSecurityStatusRequest: %d\n", SSMPR_GetError());
|
||||
connID = 0;
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseSecurityStatusRequest(recvd, &connID);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSecurityStatusRequest: %d\n", SSMPR_GetError());
|
||||
printf("SecurityStatusRequest, parsing connection ID %d\n", connID);
|
||||
|
||||
|
||||
/*
|
||||
* Test functions to parse and pack SecurityStatusReply message
|
||||
*/
|
||||
result = 2;
|
||||
keySize = 256;
|
||||
secretKeySize = 511;
|
||||
cipher = (char *)SSMPORT_ZAlloc(strlen("My Cipher"));
|
||||
sprintf(cipher, "My Cipher");
|
||||
CA = (char *)SSMPORT_ZAlloc(strlen("My CA issuer"));
|
||||
sprintf(CA, "My CA issuer");
|
||||
printf("SecurityStatusReply, packing result %d, keysize %d, secretKeySize %d, cipher %s, CA %s\n", result, keySize, secretKeySize, cipher, CA);
|
||||
blobSize = SSM_PackSecurityStatusReply(&blob, result, keySize, secretKeySize, cipher, CA);
|
||||
if (!blobSize)
|
||||
printf("Error in PackSecurityStatusReply: %d\n", SSMPR_GetError());
|
||||
result = keySize = secretKeySize = 0;
|
||||
SSMPORT_Free(cipher);
|
||||
SSMPORT_Free(CA);
|
||||
recvd = (void *)SSMPORT_ZAlloc(blobSize);
|
||||
if (!recvd) printf("Can't allocate %d bytes of memory!\n", blobSize);
|
||||
memcpy(recvd, blob, blobSize);
|
||||
SSMPORT_Free(blob);
|
||||
rv = SSM_ParseSecurityStatusReply(recvd, &result, &keySize, &secretKeySize,
|
||||
&cipher, &CA);
|
||||
if (rv != SSMPR_SUCCESS)
|
||||
printf("Error in ParseSecurityStatusReply: %d\n", SSMPR_GetError());
|
||||
printf("SecurityStatusReply, parsing result %d, keysize %d, secretKeySize %d, cipher %s, CA %s\n", result, keySize, secretKeySize, cipher, CA);
|
||||
}
|
||||
|
||||
|
||||
|
||||
130
mozilla/security/psm/lib/protocol/protocolutil.c
Normal file
130
mozilla/security/psm/lib/protocol/protocolutil.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#include "protocol.h"
|
||||
#include "prmem.h"
|
||||
#include "prnetdb.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef NSPR20
|
||||
#include "protocolport.c"
|
||||
#endif
|
||||
|
||||
CMStatus SSM_SSMStringToString(char ** string,
|
||||
int *len,
|
||||
SSMString * ssmString)
|
||||
{
|
||||
char * str = NULL;
|
||||
int realLen;
|
||||
PRStatus rv =PR_SUCCESS;
|
||||
|
||||
if (!ssmString || !string ) {
|
||||
rv = PR_INVALID_ARGUMENT_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* in case we fail */
|
||||
*string = NULL;
|
||||
if (len) *len = 0;
|
||||
|
||||
/* Convert from net byte order */
|
||||
realLen = SSMPR_ntohl(ssmString->m_length);
|
||||
|
||||
str = (char *)PR_CALLOC(realLen+1); /* add 1 byte for end 0 */
|
||||
if (!str) {
|
||||
rv = PR_OUT_OF_MEMORY_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
memcpy(str, (char *) &(ssmString->m_data), realLen);
|
||||
/* str[realLen]=0; */
|
||||
|
||||
if (len) *len = realLen;
|
||||
*string = str;
|
||||
return rv;
|
||||
|
||||
loser:
|
||||
if (str)
|
||||
PR_Free(str);
|
||||
if (string && *string) {
|
||||
PR_Free(*string);
|
||||
*string = NULL;
|
||||
}
|
||||
if (rv == PR_SUCCESS)
|
||||
rv = PR_FAILURE;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
CMStatus SSM_StringToSSMString(SSMString ** ssmString, int length,
|
||||
char * string)
|
||||
{
|
||||
SSMPRUint32 len;
|
||||
SSMString *result = NULL;
|
||||
PRStatus rv = PR_SUCCESS;
|
||||
|
||||
if (!string || !ssmString) {
|
||||
rv = PR_INVALID_ARGUMENT_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*ssmString = NULL; /* in case we fail */
|
||||
|
||||
if (length) len = length;
|
||||
else len = strlen(string);
|
||||
if (len <= 0) {
|
||||
rv = PR_INVALID_ARGUMENT_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
result = (SSMString *) PR_CALLOC(sizeof(PRUint32) +
|
||||
SSMSTRING_PADDED_LENGTH(len));
|
||||
if (!result) {
|
||||
rv = PR_OUT_OF_MEMORY_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
result->m_length = SSMPR_htonl(len);
|
||||
memcpy((char *) (&(result->m_data)), string, len);
|
||||
|
||||
*ssmString = result;
|
||||
goto done;
|
||||
|
||||
loser:
|
||||
if (result)
|
||||
PR_Free(result);
|
||||
*ssmString = NULL;
|
||||
if (rv == PR_SUCCESS)
|
||||
rv = PR_FAILURE;
|
||||
done:
|
||||
return rv;
|
||||
}
|
||||
|
||||
165
mozilla/security/psm/lib/protocol/rsrcids.h
Normal file
165
mozilla/security/psm/lib/protocol/rsrcids.h
Normal file
@@ -0,0 +1,165 @@
|
||||
/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __SSM_RSRCIDS_H__
|
||||
#define __SSM_RSRCIDS_H__
|
||||
|
||||
#include "ssmdefs.h"
|
||||
|
||||
/*
|
||||
* IMPORTANT:
|
||||
*
|
||||
* To preserve backward compatibility as much as possible, always add new
|
||||
* values to either one of the enumeration tables at the end of the table.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SSM_RESTYPE_NULL = 0L,
|
||||
SSM_RESTYPE_RESOURCE,
|
||||
SSM_RESTYPE_CONNECTION,
|
||||
SSM_RESTYPE_CONTROL_CONNECTION,
|
||||
SSM_RESTYPE_DATA_CONNECTION,
|
||||
SSM_RESTYPE_SSL_DATA_CONNECTION,
|
||||
SSM_RESTYPE_PKCS7_DECODE_CONNECTION,
|
||||
SSM_RESTYPE_PKCS7_ENCODE_CONNECTION,
|
||||
SSM_RESTYPE_HASH_CONNECTION,
|
||||
|
||||
SSM_RESTYPE_CERTIFICATE,
|
||||
SSM_RESTYPE_SSL_SOCKET_STATUS,
|
||||
SSM_RESTYPE_PKCS7_CONTENT_INFO,
|
||||
SSM_RESTYPE_KEY_PAIR,
|
||||
SSM_RESTYPE_CRMF_REQUEST,
|
||||
SSM_RESTYPE_KEYGEN_CONTEXT,
|
||||
SSM_RESTYPE_SECADVISOR_CONTEXT,
|
||||
SSM_RESTYPE_SIGNTEXT,
|
||||
SSM_RESTYPE_PKCS12_CONTEXT,
|
||||
SSM_RESTYPE_MAX
|
||||
} SSMResourceType;
|
||||
|
||||
/* Attribute/resource types */
|
||||
|
||||
/* Attribute IDs */
|
||||
typedef enum
|
||||
{
|
||||
SSM_FID_NULL = (CMUint32) 0, /* placeholder */
|
||||
|
||||
/* Connection attributes */
|
||||
SSM_FID_CONN_ALIVE,
|
||||
SSM_FID_CONN_PARENT,
|
||||
|
||||
/* Data connection attributes */
|
||||
SSM_FID_CONN_DATA_PENDING,
|
||||
|
||||
/* SSL data connection attributes */
|
||||
SSM_FID_SSLDATA_SOCKET_STATUS,
|
||||
SSM_FID_SSLDATA_ERROR_VALUE,
|
||||
|
||||
/* PKCS7 decode connection attributes */
|
||||
SSM_FID_P7CONN_CONTENT_INFO,
|
||||
SSM_FID_P7CONN_RETURN_VALUE,
|
||||
SSM_FID_P7CONN_ERROR_VALUE,
|
||||
|
||||
/* Hash connection attributes */
|
||||
SSM_FID_HASHCONN_RESULT,
|
||||
|
||||
/* Certificate attributes */
|
||||
SSM_FID_CERT_SUBJECT_NAME,
|
||||
SSM_FID_CERT_ISSUER_NAME,
|
||||
SSM_FID_CERT_SERIAL_NUMBER,
|
||||
SSM_FID_CERT_EXP_DATE,
|
||||
SSM_FID_CERT_FINGERPRINT,
|
||||
SSM_FID_CERT_COMMON_NAME,
|
||||
SSM_FID_CERT_NICKNAME,
|
||||
SSM_FID_CERT_ORG_NAME,
|
||||
SSM_FID_CERT_HTML_CERT,
|
||||
SSM_FID_CERT_PICKLE_CERT,
|
||||
SSM_FID_CERT_CERTKEY,
|
||||
SSM_FID_CERT_FIND_CERT_ISSUER,
|
||||
SSM_FID_CERT_EMAIL_ADDRESS,
|
||||
SSM_FID_CERT_ISPERM,
|
||||
|
||||
/* SSL socket status attributes */
|
||||
SSM_FID_SSS_KEYSIZE,
|
||||
SSM_FID_SSS_SECRET_KEYSIZE,
|
||||
SSM_FID_SSS_CERT_ID,
|
||||
SSM_FID_SSS_CIPHER_NAME,
|
||||
SSM_FID_SSS_SECURITY_LEVEL,
|
||||
SSM_FID_SSS_HTML_STATUS,
|
||||
|
||||
/* PKCS7 content info attributes */
|
||||
SSM_FID_P7CINFO_IS_SIGNED,
|
||||
SSM_FID_P7CINFO_IS_ENCRYPTED,
|
||||
SSM_FID_P7CINFO_SIGNER_CERT,
|
||||
|
||||
/* CRMF ID's */
|
||||
SSM_FID_CRMFREQ_REGTOKEN,
|
||||
SSM_FID_CRMFREQ_AUTHENTICATOR,
|
||||
SSM_FID_CRMFREQ_EXTENSIONS,
|
||||
SSM_FID_CRMFREQ_KEY_TYPE,
|
||||
SSM_FID_CRMFREQ_DN,
|
||||
|
||||
/* Security advisor context */
|
||||
SSM_FID_SECADVISOR_URL,
|
||||
SSM_FID_SECADVISOR_WIDTH,
|
||||
SSM_FID_SECADVISOR_HEIGHT,
|
||||
|
||||
/* Sign Text */
|
||||
SSM_FID_SIGNTEXT_RESULT,
|
||||
|
||||
/* Key Gen ID's */
|
||||
SSM_FID_KEYGEN_ESCROW_AUTHORITY,
|
||||
|
||||
/* Key Pair ID's */
|
||||
SSM_FID_KEYPAIR_KEY_GEN_TYPE,
|
||||
|
||||
/* Session Attributes */
|
||||
SSM_FID_DEFAULT_EMAIL_RECIPIENT_CERT,
|
||||
SSM_FID_DEFAULT_EMAIL_SIGNER_CERT,
|
||||
|
||||
/* Client Context Attribute */
|
||||
SSM_FID_CLIENT_CONTEXT,
|
||||
|
||||
/* Resource Error */
|
||||
SSM_FID_RESOURCE_ERROR,
|
||||
|
||||
SSM_FID_KEYGEN_SLOT_NAME,
|
||||
SSM_FID_DISABLE_ESCROW_WARN,
|
||||
SSM_FID_KEYGEN_TOKEN_NAME,
|
||||
|
||||
SSM_FID_SSLDATA_DISCARD_SOCKET_STATUS,
|
||||
|
||||
SSM_FID_MAX /* placeholder */
|
||||
} SSMAttributeID;
|
||||
|
||||
#endif
|
||||
324
mozilla/security/psm/lib/protocol/ssmdefs.h
Normal file
324
mozilla/security/psm/lib/protocol/ssmdefs.h
Normal file
@@ -0,0 +1,324 @@
|
||||
/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
#ifndef __SSMDEFS_H__
|
||||
#define __SSMDEFS_H__
|
||||
|
||||
/* Basic type definitions for both client and server. */
|
||||
typedef long CMInt32;
|
||||
typedef unsigned long CMUint32;
|
||||
typedef long SSMResourceID;
|
||||
|
||||
typedef int SSMStatus;
|
||||
|
||||
#define PSM_PORT 11111
|
||||
#define PSM_DATA_PORT 11113 /* needs to be removed */
|
||||
|
||||
typedef enum _CMTStatus {
|
||||
CMTFailure = -1,
|
||||
CMTSuccess = 0
|
||||
} CMTStatus;
|
||||
|
||||
typedef enum {
|
||||
CM_FALSE = 0,
|
||||
CM_TRUE = 1
|
||||
} CMBool;
|
||||
|
||||
typedef struct CMTItemStr {
|
||||
CMUint32 type;
|
||||
unsigned char *data;
|
||||
unsigned int len;
|
||||
} CMTItem;
|
||||
|
||||
/* A length-encoded string. */
|
||||
struct _SSMString {
|
||||
CMUint32 m_length;
|
||||
char m_data;
|
||||
};
|
||||
typedef struct _SSMString SSMString;
|
||||
|
||||
#define SSM_PROTOCOL_VERSION 0x00000051
|
||||
|
||||
#define SSM_INVALID_RESOURCE 0x00000000
|
||||
#define SSM_GLOBAL_RESOURCE 0x00000001
|
||||
#define SSM_SESSION_RESOURCE 0x00000002
|
||||
|
||||
/* Message category flags */
|
||||
#define SSM_REQUEST_MESSAGE 0x10000000
|
||||
#define SSM_REPLY_OK_MESSAGE 0x20000000
|
||||
#define SSM_REPLY_ERR_MESSAGE 0x30000000
|
||||
#define SSM_EVENT_MESSAGE 0x40000000
|
||||
|
||||
/* Message types */
|
||||
#define SSM_DATA_CONNECTION 0x00001000
|
||||
#define SSM_OBJECT_SIGNING 0x00002000
|
||||
#define SSM_RESOURCE_ACTION 0x00003000
|
||||
#define SSM_CERT_ACTION 0x00004000
|
||||
#define SSM_PKCS11_ACTION 0x00005000
|
||||
#define SSM_CRMF_ACTION 0x00006000
|
||||
#define SSM_FORMSIGN_ACTION 0x00007000
|
||||
#define SSM_LOCALIZED_TEXT 0x00008000
|
||||
#define SSM_HELLO_MESSAGE 0x00009000
|
||||
#define SSM_SECURITY_ADVISOR 0x0000a000
|
||||
#define SSM_SEC_CFG_ACTION 0x0000b000
|
||||
#define SSM_KEYGEN_TAG 0x0000c000
|
||||
#define SSM_PREF_ACTION 0x0000d000
|
||||
#define SSM_MISC_ACTION 0x0000f000
|
||||
|
||||
/* Data connection messages subtypes */
|
||||
#define SSM_SSL_CONNECTION 0x00000100
|
||||
#define SSM_PKCS7DECODE_STREAM 0x00000200
|
||||
#define SSM_PKCS7ENCODE_STREAM 0x00000300
|
||||
#define SSM_HASH_STREAM 0x00000400
|
||||
#define SSM_TLS_CONNECTION 0x00000500
|
||||
#define SSM_PROXY_CONNECTION 0x00000600
|
||||
|
||||
/* Object signing message subtypes */
|
||||
#define SSM_VERIFY_RAW_SIG 0x00000100
|
||||
#define SSM_VERIFY_DETACHED_SIG 0x00000200
|
||||
#define SSM_CREATE_SIGNED 0x00000300
|
||||
#define SSM_CREATE_ENCRYPTED 0x00000400
|
||||
|
||||
/* Resource access messages subtypes */
|
||||
#define SSM_CREATE_RESOURCE 0x00000100
|
||||
#define SSM_DESTROY_RESOURCE 0x00000200
|
||||
#define SSM_GET_ATTRIBUTE 0x00000300
|
||||
#define SSM_CONSERVE_RESOURCE 0x00000400
|
||||
#define SSM_DUPLICATE_RESOURCE 0x00000500
|
||||
#define SSM_SET_ATTRIBUTE 0x00000600
|
||||
#define SSM_TLS_STEPUP 0x00000700
|
||||
#define SSM_PROXY_STEPUP 0x00000800
|
||||
|
||||
/* Further specification for resource access messages */
|
||||
#define SSM_SSLSocket_Status 0x00000010
|
||||
|
||||
#define SSM_NO_ATTRIBUTE 0x00000000
|
||||
#define SSM_NUMERIC_ATTRIBUTE 0x00000010
|
||||
#define SSM_STRING_ATTRIBUTE 0x00000020
|
||||
#define SSM_RID_ATTRIBUTE 0x00000030
|
||||
|
||||
#define SSM_PICKLE_RESOURCE 0x00000010
|
||||
#define SSM_UNPICKLE_RESOURCE 0x00000020
|
||||
#define SSM_PICKLE_SECURITY_STATUS 0x00000030
|
||||
|
||||
/* Certificate access message subtypes */
|
||||
#define SSM_IMPORT_CERT 0x00000100
|
||||
#define SSM_VERIFY_CERT 0x00000200
|
||||
#define SSM_FIND_BY_NICKNAME 0x00000300
|
||||
#define SSM_FIND_BY_KEY 0x00000400
|
||||
#define SSM_FIND_BY_EMAILADDR 0x00000500
|
||||
#define SSM_ADD_TO_DB 0x00000600
|
||||
#define SSM_DECODE_CERT 0x00000700
|
||||
#define SSM_MATCH_USER_CERT 0x00000800
|
||||
#define SSM_DESTROY_CERT 0x00000900
|
||||
#define SSM_DECODE_TEMP_CERT 0x00000a00
|
||||
#define SSM_REDIRECT_COMPARE 0x00000b00
|
||||
#define SSM_DECODE_CRL 0x00000c00
|
||||
#define SSM_EXTENSION_VALUE 0x00000d00
|
||||
#define SSM_HTML_INFO 0x00000e00
|
||||
|
||||
/* message subtypes used for KEYGEN form tag */
|
||||
#define SSM_GET_KEY_CHOICE 0x00000100
|
||||
#define SSM_KEYGEN_START 0x00000200
|
||||
#define SSM_KEYGEN_TOKEN 0x00000300
|
||||
#define SSM_KEYGEN_PASSWORD 0x00000400
|
||||
#define SSM_KEYGEN_DONE 0x00000500
|
||||
|
||||
#define SSM_CREATE_KEY_PAIR 0x00000100
|
||||
#define SSM_FINISH_KEY_GEN 0x00000200
|
||||
#define SSM_ADD_NEW_MODULE 0x00000300
|
||||
#define SSM_DEL_MODULE 0x00000400
|
||||
#define SSM_LOGOUT_ALL 0x00000500
|
||||
#define SSM_ENABLED_CIPHERS 0x00000600
|
||||
|
||||
#define SSM_CREATE_CRMF_REQ 0x00000100
|
||||
#define SSM_DER_ENCODE_REQ 0x00000200
|
||||
#define SSM_PROCESS_CMMF_RESP 0x00000300
|
||||
#define SSM_CHALLENGE 0x00000400
|
||||
|
||||
#define SSM_SIGN_TEXT 0x00000100
|
||||
|
||||
/* Security Config subtypes */
|
||||
#define SSM_ADD_CERT_TO_TEMP_DB 0x00000100
|
||||
#define SSM_ADD_TEMP_CERT_TO_DB 0x00000200
|
||||
#define SSM_DELETE_PERM_CERTS 0x00000300
|
||||
#define SSM_FIND_CERT_KEY 0x00000400
|
||||
#define SSM_GET_CERT_PROP_BY_KEY 0x00000500
|
||||
#define SSM_CERT_INDEX_ENUM 0x00000600
|
||||
|
||||
/* subcategories for SSM_FIND_CERT_KEY and SSM_CERT_INDEX_ENUM */
|
||||
#define SSM_FIND_KEY_BY_NICKNAME 0x00000010
|
||||
#define SSM_FIND_KEY_BY_EMAIL_ADDR 0x00000020
|
||||
#define SSM_FIND_KEY_BY_DN 0x00000030
|
||||
|
||||
/* subcategories for SSM_GET_CERT_PROP_BY_KEY */
|
||||
#define SSM_SECCFG_GET_NICKNAME 0x00000010
|
||||
#define SSM_SECCFG_GET_EMAIL_ADDR 0x00000020
|
||||
#define SSM_SECCFG_GET_DN 0x00000030
|
||||
#define SSM_SECCFG_GET_TRUST 0x00000040
|
||||
#define SSM_SECCFG_CERT_IS_PERM 0x00000050
|
||||
#define SSM_SECCFG_GET_NOT_BEFORE 0x00000060
|
||||
#define SSM_SECCFG_GET_NOT_AFTER 0x00000070
|
||||
#define SSM_SECCFG_GET_SERIAL_NO 0x00000080
|
||||
#define SSM_SECCFG_GET_ISSUER 0x00000090
|
||||
#define SSM_SECCFG_GET_ISSUER_KEY 0x000000a0
|
||||
#define SSM_SECCFG_GET_SUBJECT_NEXT 0x000000b0
|
||||
#define SSM_SECCFG_GET_SUBJECT_PREV 0x000000c0
|
||||
|
||||
/* Misc requests */
|
||||
#define SSM_MISC_GET_RNG_DATA 0x00000100
|
||||
#define SSM_MISC_PUT_RNG_DATA 0x00000200
|
||||
#define SSM_MISC_SDR_ENCRYPT 0x00000300
|
||||
#define SSM_MISC_SDR_DECRYPT 0x00000400
|
||||
#define SSM_MISC_UI 0x00000500
|
||||
|
||||
/* specific UI requests */
|
||||
#define SSM_UI_CHANGE_PASSWORD 0x00000010
|
||||
|
||||
#define SSM_SDR_ENCRYPT_REQUEST \
|
||||
(SSM_REQUEST_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_ENCRYPT)
|
||||
#define SSM_SDR_ENCRYPT_REPLY \
|
||||
(SSM_REPLY_OK_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_ENCRYPT)
|
||||
#define SSM_SDR_DECRYPT_REQUEST \
|
||||
(SSM_REQUEST_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_DECRYPT)
|
||||
#define SSM_SDR_DECRYPT_REPLY \
|
||||
(SSM_REPLY_OK_MESSAGE|SSM_MISC_ACTION|SSM_MISC_SDR_DECRYPT)
|
||||
|
||||
/* Type masks for message types */
|
||||
#define SSM_CATEGORY_MASK 0xF0000000
|
||||
#define SSM_TYPE_MASK 0x0000F000
|
||||
#define SSM_SUBTYPE_MASK 0x00000F00
|
||||
#define SSM_SPECIFIC_MASK 0x000000F0
|
||||
|
||||
typedef struct SSMAttributeValue {
|
||||
CMUint32 type;
|
||||
union {
|
||||
SSMResourceID rid;
|
||||
CMTItem string;
|
||||
CMInt32 numeric;
|
||||
} u;
|
||||
} SSMAttributeValue;
|
||||
|
||||
typedef enum {
|
||||
rsaEnc, rsaDualUse, rsaSign, rsaNonrepudiation, rsaSignNonrepudiation,
|
||||
dhEx, dsaSignNonrepudiation, dsaSign, dsaNonrepudiation, invalidKeyGen
|
||||
} SSMKeyGenType;
|
||||
|
||||
typedef enum {
|
||||
ssmUnknownPolicy= -1,ssmDomestic=0, ssmExport=1, ssmFrance=2
|
||||
} SSMPolicyType;
|
||||
|
||||
/* These are the localized strings that PSM can feed back to
|
||||
* the plug-in. These will initially be used by the plug-in for
|
||||
* JavaScript purposes to pop up alert/confirm dialogs that would
|
||||
* cause nightmares to do if we sent UI events.
|
||||
*/
|
||||
typedef enum {
|
||||
SSM_STRING_BAD_PK11_LIB_PARAM,
|
||||
SSM_STRING_BAD_PK11_LIB_PATH,
|
||||
SSM_STRING_ADD_MOD_SUCCESS,
|
||||
SSM_STRING_DUP_MOD_FAILURE,
|
||||
SSM_STRING_ADD_MOD_FAILURE,
|
||||
SSM_STRING_BAD_MOD_NAME,
|
||||
SSM_STRING_EXT_MOD_DEL,
|
||||
SSM_STRING_INT_MOD_DEL,
|
||||
SSM_STRING_MOD_DEL_FAIL,
|
||||
SSM_STRING_ADD_MOD_WARN,
|
||||
SSM_STRING_MOD_PROMPT,
|
||||
SSM_STRING_DLL_PROMPT,
|
||||
SSM_STRING_DEL_MOD_WARN,
|
||||
SSM_STRING_INVALID_CRL,
|
||||
SSM_STRING_INVALID_CKL,
|
||||
SSM_STRING_ROOT_CKL_CERT_NOT_FOUND,
|
||||
SSM_STRING_BAD_CRL_SIGNATURE,
|
||||
SSM_STRING_BAD_CKL_SIGNATURE,
|
||||
SSM_STRING_ERR_ADD_CRL,
|
||||
SSM_STRING_ERR_ADD_CKL,
|
||||
SSM_STRING_JAVASCRIPT_DISABLED
|
||||
} SSMLocalizedString;
|
||||
|
||||
/* Event types */
|
||||
#define SSM_UI_EVENT 0x00001000
|
||||
#define SSM_TASK_COMPLETED_EVENT 0x00002000
|
||||
#define SSM_FILE_PATH_EVENT 0x00003000
|
||||
#define SSM_PROMPT_EVENT 0x00004000
|
||||
#define SSM_AUTH_EVENT 0x00007000
|
||||
#define SSM_SAVE_PREF_EVENT 0x00008000
|
||||
#define SSM_MISC_EVENT 0x0000f000
|
||||
|
||||
/* Flags used in Create SSL Data request */
|
||||
#define SSM_REQUEST_SSL_DATA_SSL 0x00000001
|
||||
#define SSM_REQUEST_SSL_DATA_PROXY 0x00000002
|
||||
#define SSM_REQUEST_SSL_CONNECTION_MASK 0x00000003
|
||||
|
||||
/* Create typedefs for the various #defines */
|
||||
typedef CMUint32 SSMMessageCategory;
|
||||
typedef CMUint32 SSMMessageType;
|
||||
typedef CMUint32 SSMDataConnectionSType;
|
||||
typedef CMUint32 SSMObjSignSType;
|
||||
typedef CMUint32 SSMResourceAccessSType;
|
||||
typedef CMUint32 SSMCreateResource;
|
||||
typedef CMUint32 SSMResourceAttrType;
|
||||
typedef CMUint32 SSMResourceConsv;
|
||||
typedef CMUint32 SSMCertAccessSType;
|
||||
typedef CMUint32 SSMKeyGenTagProcessType;
|
||||
typedef CMUint32 SSMPKCS11Actions;
|
||||
typedef CMUint32 SSMCRMFAction;
|
||||
typedef CMUint32 SSMFormSignAction;
|
||||
typedef CMUint32 SSMSecCfgAction;
|
||||
typedef CMUint32 SSMSecCfgFindByType;
|
||||
typedef CMUint32 SSMSecCfgGetCertPropType;
|
||||
typedef CMUint32 SSMMiscRequestType;
|
||||
typedef CMUint32 SSMMessageMaskType;
|
||||
typedef CMUint32 SSMEventType;
|
||||
typedef CMUint32 SSMSSLConnectionRequestType;
|
||||
|
||||
/*
|
||||
* This string is version that can be used to assemble any
|
||||
* version information by the apllication using the protocol
|
||||
* library.
|
||||
*/
|
||||
extern char SSMVersionString[];
|
||||
|
||||
/* What type of client */
|
||||
typedef enum
|
||||
{
|
||||
SSM_NOINFO,
|
||||
SSM_COMPOSE,
|
||||
SSM_MAIL_MESSAGE,
|
||||
SSM_NEWS_MESSAGE,
|
||||
SSM_SNEWS_MESSAGE,
|
||||
SSM_BROWSER
|
||||
} SSMClientType;
|
||||
|
||||
#endif /* __SSMDEFS_H__ */
|
||||
628
mozilla/security/psm/lib/protocol/templates.c
Normal file
628
mozilla/security/psm/lib/protocol/templates.c
Normal file
@@ -0,0 +1,628 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License Version 2 or later (the
|
||||
* "GPL"), in which case the provisions of the GPL are applicable
|
||||
* instead of those above. If you wish to allow use of your
|
||||
* version of this file only under the terms of the GPL and not to
|
||||
* allow others to use your version of this file under the MPL,
|
||||
* indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by
|
||||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*/
|
||||
|
||||
#include "stddef.h"
|
||||
#include "messages.h"
|
||||
|
||||
CMTMessageTemplate SingleNumMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SingleNumMessage, value) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SingleStringMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(SingleStringMessage, string) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SingleItemMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(SingleItemMessage, item) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate HelloRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(HelloRequest, version) },
|
||||
{ CMT_DT_INT, offsetof(HelloRequest, policy) },
|
||||
{ CMT_DT_BOOL, offsetof(HelloRequest, doesUI) },
|
||||
{ CMT_DT_STRING, offsetof(HelloRequest, profile) },
|
||||
{ CMT_DT_STRING, offsetof(HelloRequest, profileDir) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate HelloReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(HelloReply, result) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, sessionID) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, version) },
|
||||
{ CMT_DT_STRING, offsetof(HelloReply, stringVersion) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, httpPort) },
|
||||
{ CMT_DT_INT, offsetof(HelloReply, policy) },
|
||||
{ CMT_DT_ITEM, offsetof(HelloReply, nonce) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SSLDataConnectionRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SSLDataConnectionRequest, flags) },
|
||||
{ CMT_DT_INT, offsetof(SSLDataConnectionRequest, port) },
|
||||
{ CMT_DT_STRING, offsetof(SSLDataConnectionRequest, hostIP) },
|
||||
{ CMT_DT_STRING, offsetof(SSLDataConnectionRequest, hostName) },
|
||||
{ CMT_DT_BOOL, offsetof(SSLDataConnectionRequest, forceHandshake) },
|
||||
{ CMT_DT_ITEM, offsetof(SSLDataConnectionRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TLSDataConnectionRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TLSDataConnectionRequest, port) },
|
||||
{ CMT_DT_STRING, offsetof(TLSDataConnectionRequest, hostIP) },
|
||||
{ CMT_DT_STRING, offsetof(TLSDataConnectionRequest, hostName) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TLSStepUpRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TLSStepUpRequest, connID) },
|
||||
{ CMT_DT_ITEM, offsetof(TLSStepUpRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate ProxyStepUpRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(ProxyStepUpRequest, connID) },
|
||||
{ CMT_DT_ITEM, offsetof(ProxyStepUpRequest, clientContext) },
|
||||
{ CMT_DT_STRING, offsetof(ProxyStepUpRequest, url) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PKCS7DataConnectionRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PKCS7DataConnectionRequest, resID) },
|
||||
{ CMT_DT_ITEM, offsetof(PKCS7DataConnectionRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DataConnectionReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DataConnectionReply, result) },
|
||||
{ CMT_DT_INT, offsetof(DataConnectionReply, connID) },
|
||||
{ CMT_DT_INT, offsetof(DataConnectionReply, port) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate UIEventTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UIEvent, resourceID) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, width) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, height) },
|
||||
{ CMT_DT_BOOL, offsetof(UIEvent, isModal) },
|
||||
{ CMT_DT_STRING, offsetof(UIEvent, url) },
|
||||
{ CMT_DT_ITEM, offsetof(UIEvent, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
/*
|
||||
* The old UI Event was missing the modal indication.
|
||||
* As a transition aid, we use the old template if the
|
||||
* "modern" version doesn't work. Model is true in that case
|
||||
*/
|
||||
CMTMessageTemplate OldUIEventTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UIEvent, resourceID) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, width) },
|
||||
{ CMT_DT_INT, offsetof(UIEvent, height) },
|
||||
{ CMT_DT_STRING, offsetof(UIEvent, url) },
|
||||
{ CMT_DT_ITEM, offsetof(UIEvent, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TaskCompletedEventTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TaskCompletedEvent, resourceID) },
|
||||
{ CMT_DT_INT, offsetof(TaskCompletedEvent, numTasks) },
|
||||
{ CMT_DT_INT, offsetof(TaskCompletedEvent, result) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate VerifyDetachedSigRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(VerifyDetachedSigRequest, pkcs7ContentID) },
|
||||
{ CMT_DT_INT, offsetof(VerifyDetachedSigRequest, certUsage) },
|
||||
{ CMT_DT_INT, offsetof(VerifyDetachedSigRequest, hashAlgID) },
|
||||
{ CMT_DT_BOOL, offsetof(VerifyDetachedSigRequest, keepCert) },
|
||||
{ CMT_DT_ITEM, offsetof(VerifyDetachedSigRequest, hash) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateSignedRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateSignedRequest, scertRID) },
|
||||
{ CMT_DT_INT, offsetof(CreateSignedRequest, ecertRID) },
|
||||
{ CMT_DT_INT, offsetof(CreateSignedRequest, dig_alg) },
|
||||
{ CMT_DT_ITEM, offsetof(CreateSignedRequest, digest) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateContentInfoReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateContentInfoReply, ciRID) },
|
||||
{ CMT_DT_INT, offsetof(CreateContentInfoReply, result) },
|
||||
{ CMT_DT_INT, offsetof(CreateContentInfoReply, errorCode) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateEncryptedRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateEncryptedRequest, scertRID) },
|
||||
{ CMT_DT_LIST, offsetof(CreateEncryptedRequest, nrcerts) },
|
||||
{ CMT_DT_INT, offsetof(CreateEncryptedRequest, rcertRIDs) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateResourceRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateResourceRequest, type) },
|
||||
{ CMT_DT_ITEM, offsetof(CreateResourceRequest, params) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CreateResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(CreateResourceReply, result) },
|
||||
{ CMT_DT_INT, offsetof(CreateResourceReply, resID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetAttribRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetAttribRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(GetAttribRequest, fieldID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetAttribReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetAttribReply, result) },
|
||||
{ CMT_DT_CHOICE, offsetof(GetAttribReply, value.type) },
|
||||
{ CMT_DT_RID, offsetof(GetAttribReply, value.u.rid), 0, SSM_RID_ATTRIBUTE },
|
||||
{ CMT_DT_INT, offsetof(GetAttribReply, value.u.numeric), 0,
|
||||
SSM_NUMERIC_ATTRIBUTE },
|
||||
{ CMT_DT_ITEM, offsetof(GetAttribReply, value.u.string), 0,
|
||||
SSM_STRING_ATTRIBUTE},
|
||||
{ CMT_DT_END_CHOICE },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SetAttribRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SetAttribRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(SetAttribRequest, fieldID) },
|
||||
{ CMT_DT_CHOICE, offsetof(SetAttribRequest, value.type) },
|
||||
{ CMT_DT_RID, offsetof(SetAttribRequest, value.u.rid), 0, SSM_RID_ATTRIBUTE },
|
||||
{ CMT_DT_INT, offsetof(SetAttribRequest, value.u.numeric), 0,
|
||||
SSM_NUMERIC_ATTRIBUTE },
|
||||
{ CMT_DT_ITEM, offsetof(SetAttribRequest, value.u.string), 0,
|
||||
SSM_STRING_ATTRIBUTE},
|
||||
{ CMT_DT_END_CHOICE },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PickleResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PickleResourceReply, result) },
|
||||
{ CMT_DT_ITEM, offsetof(PickleResourceReply, blob) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate UnpickleResourceRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UnpickleResourceRequest, resourceType) },
|
||||
{ CMT_DT_ITEM, offsetof(UnpickleResourceRequest, resourceData) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate UnpickleResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(UnpickleResourceReply, result) },
|
||||
{ CMT_DT_INT, offsetof(UnpickleResourceReply, resID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PickleSecurityStatusReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PickleSecurityStatusReply, result) },
|
||||
{ CMT_DT_INT, offsetof(PickleSecurityStatusReply, securityLevel) },
|
||||
{ CMT_DT_ITEM, offsetof(PickleSecurityStatusReply, blob) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DupResourceReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DupResourceReply, result) },
|
||||
{ CMT_DT_RID, offsetof(DupResourceReply, resID), 0, SSM_RID_ATTRIBUTE },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DestroyResourceRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DestroyResourceRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(DestroyResourceRequest, resType) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate VerifyCertRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(VerifyCertRequest, resID) },
|
||||
{ CMT_DT_INT, offsetof(VerifyCertRequest, certUsage) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate AddTempCertToDBRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(AddTempCertToDBRequest, nickname) },
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, sslFlags) },
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, emailFlags) },
|
||||
{ CMT_DT_INT, offsetof(AddTempCertToDBRequest, objSignFlags) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate MatchUserCertRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(MatchUserCertRequest, certType) },
|
||||
{ CMT_DT_LIST, offsetof(MatchUserCertRequest, numCANames) },
|
||||
{ CMT_DT_STRING, offsetof(MatchUserCertRequest, caNames) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate MatchUserCertReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_LIST, offsetof(MatchUserCertReply, numCerts) },
|
||||
{ CMT_DT_INT, offsetof(MatchUserCertReply, certs) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate EncodeCRMFReqRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_LIST, offsetof(EncodeCRMFReqRequest, numRequests) },
|
||||
{ CMT_DT_INT, offsetof(EncodeCRMFReqRequest, reqIDs) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate CMMFCertResponseRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(CMMFCertResponseRequest, nickname) },
|
||||
{ CMT_DT_STRING, offsetof(CMMFCertResponseRequest, base64Der) },
|
||||
{ CMT_DT_INT, offsetof(CMMFCertResponseRequest, doBackup) },
|
||||
{ CMT_DT_ITEM, offsetof(CMMFCertResponseRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PasswordRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PasswordRequest, tokenKey) },
|
||||
{ CMT_DT_STRING, offsetof(PasswordRequest, prompt) },
|
||||
{ CMT_DT_ITEM, offsetof(PasswordRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PasswordReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PasswordReply, result) },
|
||||
{ CMT_DT_INT, offsetof(PasswordReply, tokenID) },
|
||||
{ CMT_DT_STRING, offsetof(PasswordReply, passwd) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate KeyPairGenRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(KeyPairGenRequest, keyGenCtxtID) },
|
||||
{ CMT_DT_INT, offsetof(KeyPairGenRequest, genMechanism) },
|
||||
{ CMT_DT_INT, offsetof(KeyPairGenRequest, keySize) },
|
||||
{ CMT_DT_ITEM, offsetof(KeyPairGenRequest, params) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DecodeAndCreateTempCertRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(DecodeAndCreateTempCertRequest, type) },
|
||||
{ CMT_DT_ITEM, offsetof(DecodeAndCreateTempCertRequest, cert) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStyleRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, choiceString) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, challenge) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, typeString) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleRequest, pqgString) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStyleTokenRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStyleTokenRequest, rid) },
|
||||
{ CMT_DT_LIST, offsetof(GenKeyOldStyleTokenRequest, numtokens) },
|
||||
{ CMT_DT_STRING,offsetof(GenKeyOldStyleTokenRequest, tokenNames)},
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStyleTokenReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStyleTokenReply, rid) },
|
||||
{ CMT_DT_BOOL, offsetof(GenKeyOldStyleTokenReply, cancel) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStyleTokenReply, tokenName) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStylePasswordRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordRequest, rid) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStylePasswordRequest, tokenName) },
|
||||
{ CMT_DT_BOOL, offsetof(GenKeyOldStylePasswordRequest, internal) },
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordRequest, minpwdlen) },
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordRequest, maxpwdlen) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GenKeyOldStylePasswordReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GenKeyOldStylePasswordReply, rid) },
|
||||
{ CMT_DT_BOOL, offsetof(GenKeyOldStylePasswordReply, cancel) },
|
||||
{ CMT_DT_STRING, offsetof(GenKeyOldStylePasswordReply, password) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
|
||||
CMTMessageTemplate GetKeyChoiceListRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(GetKeyChoiceListRequest, type) },
|
||||
{ CMT_DT_STRING, offsetof(GetKeyChoiceListRequest, pqgString) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetKeyChoiceListReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_LIST, offsetof(GetKeyChoiceListReply, nchoices) },
|
||||
{ CMT_DT_STRING, offsetof(GetKeyChoiceListReply, choices) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate AddNewSecurityModuleRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(AddNewSecurityModuleRequest, moduleName) },
|
||||
{ CMT_DT_STRING, offsetof(AddNewSecurityModuleRequest, libraryPath) },
|
||||
{ CMT_DT_INT, offsetof(AddNewSecurityModuleRequest, pubMechFlags) },
|
||||
{ CMT_DT_INT, offsetof(AddNewSecurityModuleRequest, pubCipherFlags) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate FilePathRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(FilePathRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(FilePathRequest, prompt) },
|
||||
{ CMT_DT_BOOL, offsetof(FilePathRequest, getExistingFile) },
|
||||
{ CMT_DT_STRING, offsetof(FilePathRequest, fileRegEx) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate FilePathReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(FilePathReply, resID) },
|
||||
{ CMT_DT_STRING, offsetof(FilePathReply, filePath) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PasswordPromptReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PasswordPromptReply, resID) },
|
||||
{ CMT_DT_STRING, offsetof(PasswordPromptReply, promptReply) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SignTextRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SignTextRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, stringToSign) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, hostName) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, caOption) },
|
||||
{ CMT_DT_LIST, offsetof(SignTextRequest, numCAs) },
|
||||
{ CMT_DT_STRING, offsetof(SignTextRequest, caNames) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetLocalizedTextReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetLocalizedTextReply, whichString) },
|
||||
{ CMT_DT_STRING, offsetof(GetLocalizedTextReply, localizedString) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate ImportCertReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(ImportCertReply, result) },
|
||||
{ CMT_DT_INT, offsetof(ImportCertReply, resID) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PromptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PromptRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(PromptRequest, prompt) },
|
||||
{ CMT_DT_ITEM, offsetof(PromptRequest, clientContext) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate PromptReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(PromptReply, resID) },
|
||||
{ CMT_DT_BOOL, offsetof(PromptReply, cancel) },
|
||||
{ CMT_DT_STRING, offsetof(PromptReply, promptReply) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate RedirectCompareRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(RedirectCompareRequest, socketStatus1Data) },
|
||||
{ CMT_DT_ITEM, offsetof(RedirectCompareRequest, socketStatus2Data) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DecodeAndAddCRLRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(DecodeAndAddCRLRequest, derCrl) },
|
||||
{ CMT_DT_INT, offsetof(DecodeAndAddCRLRequest, type) },
|
||||
{ CMT_DT_STRING, offsetof(DecodeAndAddCRLRequest, url) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SecurityAdvisorRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, infoContext) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, resID) },
|
||||
{ CMT_DT_STRING, offsetof(SecurityAdvisorRequest, hostname) },
|
||||
{ CMT_DT_STRING, offsetof(SecurityAdvisorRequest, senderAddr) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, encryptedP7CInfo) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, signedP7CInfo) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, decodeError) },
|
||||
{ CMT_DT_INT, offsetof(SecurityAdvisorRequest, verifyError) },
|
||||
{ CMT_DT_BOOL, offsetof(SecurityAdvisorRequest, encryptthis) },
|
||||
{ CMT_DT_BOOL, offsetof(SecurityAdvisorRequest, signthis) },
|
||||
{ CMT_DT_LIST, offsetof(SecurityAdvisorRequest, numRecipients) },
|
||||
{ CMT_DT_STRING, offsetof(SecurityAdvisorRequest, recipients) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SCAddTempCertToPermDBRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(SCAddTempCertToPermDBRequest, certKey) },
|
||||
{ CMT_DT_STRING, offsetof(SCAddTempCertToPermDBRequest, trustStr) },
|
||||
{ CMT_DT_STRING, offsetof(SCAddTempCertToPermDBRequest, nickname) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SCDeletePermCertsRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(SCDeletePermCertsRequest, certKey) },
|
||||
{ CMT_DT_BOOL, offsetof(SCDeletePermCertsRequest, deleteAll) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate TimeMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, year) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, month) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, day) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, hour) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, minute) },
|
||||
{ CMT_DT_INT, offsetof(TimeMessage, second) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate SCCertIndexEnumReplyTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(SCCertIndexEnumReply, length) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(SCCertIndexEnumReply, list) },
|
||||
{ CMT_DT_STRING, offsetof(CertEnumElement, name) },
|
||||
{ CMT_DT_ITEM, offsetof(CertEnumElement, certKey) },
|
||||
{ CMT_DT_END_STRUCT_LIST },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
/* Test template */
|
||||
|
||||
CMTMessageTemplate TestListTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRING, offsetof(TestList, listName) },
|
||||
{ CMT_DT_STRUCT_LIST, offsetof(TestList, numElements) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(TestList, elements) },
|
||||
{ CMT_DT_STRING, offsetof(TestListElement, name) },
|
||||
{ CMT_DT_STRING, offsetof(TestListElement, value) },
|
||||
{ CMT_DT_END_STRUCT_LIST},
|
||||
{ CMT_DT_END}
|
||||
};
|
||||
|
||||
CMTMessageTemplate SetPrefListMessageTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRUCT_LIST, offsetof(SetPrefListMessage, length) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(SetPrefListMessage, list) },
|
||||
{ CMT_DT_STRING, offsetof(SetPrefElement, key) },
|
||||
{ CMT_DT_STRING, offsetof(SetPrefElement, value) },
|
||||
{ CMT_DT_INT, offsetof(SetPrefElement, type) },
|
||||
{ CMT_DT_END_STRUCT_LIST },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetPrefListRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_STRUCT_LIST, offsetof(GetPrefListRequest, length) },
|
||||
{ CMT_DT_STRUCT_PTR, offsetof(GetPrefListRequest, list) },
|
||||
{ CMT_DT_STRING, offsetof(GetPrefElement, key) },
|
||||
{ CMT_DT_INT, offsetof(GetPrefElement, type) },
|
||||
{ CMT_DT_END_STRUCT_LIST },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate GetCertExtensionTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(GetCertExtension, resID) },
|
||||
{ CMT_DT_INT, offsetof(GetCertExtension, extension) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate HTMLCertInfoRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_INT, offsetof(HTMLCertInfoRequest, certID) },
|
||||
{ CMT_DT_INT, offsetof(HTMLCertInfoRequest, showImages) },
|
||||
{ CMT_DT_INT, offsetof(HTMLCertInfoRequest, showIssuer) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate EncryptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, keyid) },
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, data) },
|
||||
{ CMT_DT_ITEM, offsetof(EncryptRequestMessage, ctx) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
|
||||
CMTMessageTemplate DecryptRequestTemplate[] =
|
||||
{
|
||||
{ CMT_DT_ITEM, offsetof(DecryptRequestMessage, data) },
|
||||
{ CMT_DT_ITEM, offsetof(DecryptRequestMessage, ctx) },
|
||||
{ CMT_DT_END }
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,26 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/* Defining the following causes NS_APPSHELL to be defined as NS_EXPORT. */
|
||||
#define _IMPL_NS_APPSHELL
|
||||
|
||||
#include "MacSharedPrefix.h"
|
||||
@@ -1,26 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/* Defining the following causes NS_APPSHELL to be defined as NS_EXPORT. */
|
||||
#define _IMPL_NS_APPSHELL
|
||||
|
||||
#include "MacSharedPrefix_debug.h"
|
||||
@@ -1 +0,0 @@
|
||||
nsIBookmarksService.idl
|
||||
@@ -1,35 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = appcomps
|
||||
XPIDL_MODULE = bookmarks
|
||||
|
||||
XPIDLSRCS = nsIBookmarksService.idl
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
MODULE=bookmarks
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\nsIBookmarksService.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* The Browser Bookmarks service
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIRDFResource;
|
||||
|
||||
[scriptable, uuid(a82e9300-e4af-11d2-8fdf-0008c70adc7b)]
|
||||
interface nsIBookmarksService : nsISupports
|
||||
{
|
||||
const unsigned long BOOKMARK_DEFAULT_TYPE = 0;
|
||||
const unsigned long BOOKMARK_SEARCH_TYPE = 1;
|
||||
const unsigned long BOOKMARK_FIND_TYPE = 2;
|
||||
|
||||
boolean ReadBookmarks();
|
||||
boolean IsBookmarked(in string aURI);
|
||||
|
||||
void addBookmarkImmediately(in string aURI, in wstring aTitle, in long bmType, in wstring docCharset);
|
||||
|
||||
nsIRDFResource createFolder(in wstring aName, in nsIRDFResource aParentFolder);
|
||||
nsIRDFResource createFolderWithDetails(in wstring aName, in nsIRDFResource aParentFolder,
|
||||
in long aIndex);
|
||||
|
||||
nsIRDFResource createGroup(in wstring aName, in nsIRDFResource aParentFolder);
|
||||
nsIRDFResource createGroupWithDetails(in wstring aName, in nsIRDFResource aParentFolder,
|
||||
in long aIndex);
|
||||
|
||||
nsIRDFResource createBookmark(in wstring aName, in string aURL, in nsIRDFResource aParentFolder);
|
||||
nsIRDFResource createBookmarkWithDetails(in wstring aName, in string aURI, in wstring docCharSet,
|
||||
in nsIRDFResource aFolder, in long aIndex);
|
||||
|
||||
void updateBookmarkIcon(in string aURL, in wstring iconURL);
|
||||
void removeBookmarkIcon(in string aURL, in wstring iconURL);
|
||||
|
||||
void updateLastVisitedDate(in string aURL, in wstring docCharset);
|
||||
|
||||
string resolveKeyword(in wstring aName);
|
||||
|
||||
wstring getLastCharset(in string aURI);
|
||||
|
||||
void importSystemBookmarks(in nsIRDFResource aParentFolder);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
// {E638D760-8687-11d2-B530-000000000000}
|
||||
#define NS_BOOKMARKS_SERVICE_CID \
|
||||
{ 0xe638d760, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
#define NS_BOOKMARKS_SERVICE_CONTRACTID \
|
||||
"@mozilla.org/browser/bookmarks-service;1"
|
||||
|
||||
#define NS_BOOKMARKS_DATASOURCE_CONTRACTID \
|
||||
"@mozilla.org/rdf/datasource;1?name=bookmarks"
|
||||
|
||||
%}
|
||||
@@ -1,9 +0,0 @@
|
||||
bm-find.js
|
||||
bm-find.xul
|
||||
bm-panel.js
|
||||
bm-panel.xul
|
||||
bm-props.js
|
||||
bm-props.xul
|
||||
bookmarks.js
|
||||
bookmarksDD.js
|
||||
bookmarks.xul
|
||||
@@ -1,30 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -1,348 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Add Bookmark Dialog.
|
||||
* ====================
|
||||
*
|
||||
* This is a generic bookmark dialog that allows for bookmark addition
|
||||
* and folder selection. It can be opened with various parameters that
|
||||
* result in appearance/purpose differences and initial state.
|
||||
*
|
||||
* Use: Open with 'openDialog', with the flags
|
||||
* 'centerscreen,chrome,dialog=no,resizable=yes'
|
||||
*
|
||||
* Parameters:
|
||||
* Apart from the standard openDialog parameters, this dialog can
|
||||
* be passed additional information, which gets mapped to the
|
||||
* window.arguments array:
|
||||
*
|
||||
* window.arguments[0]: Bookmark Name. The value to be prefilled
|
||||
* into the "Name: " field (if visible).
|
||||
* window.arguments[1]: Bookmark URL: The location of the bookmark.
|
||||
* The value to be filled in the "Location: "
|
||||
* field (if visible).
|
||||
* window.arguments[2]: Bookmark Folder. The RDF Resource URI of the
|
||||
* folder that this bookmark should be created in.
|
||||
* window.arguments[3]: Bookmark Charset. The charset that should be
|
||||
* used when adding a bookmark to the specified
|
||||
* URL. (Usually the charset of the current
|
||||
* document when launching this window).
|
||||
* window.arguments[4]: The mode of operation. See notes for details.
|
||||
* window.arguments[5]: If the mode is "addGroup", this is an array
|
||||
* of objects with name, URL and charset
|
||||
* properties, one for each group member.
|
||||
*
|
||||
* Mode of Operation Notes:
|
||||
* ------------------------
|
||||
* This dialog can be opened in four different ways by using a parameter
|
||||
* passed through the call to openDialog. The 'mode' of operation
|
||||
* of the window is expressed in window.arguments[4]. The valid modes are:
|
||||
*
|
||||
* 1) <default> (no fifth open parameter).
|
||||
* Opens this dialog with the bookmark Name, URL and folder selection
|
||||
* components visible.
|
||||
* 2) "newBookmark" (fifth open parameter = String("newBookmark"))
|
||||
* Opens the dialog as in (1) above except the folder selection tree
|
||||
* is hidden. This type of mode is useful when the creation folder
|
||||
* is pre-determined.
|
||||
* 3) "selectFolder" (fifth open parameter = String("selectFolder"))
|
||||
* Opens the dialog as in (1) above except the Name/Location section
|
||||
* is hidden, and the dialog takes on the utility of a Folder chooser.
|
||||
* Used when the user must select a Folder for some purpose.
|
||||
* 4) "addGroup" (fifth open parameter = String("addGroup"))
|
||||
* Opens the dialog like <default>, with a checkbox to select between
|
||||
* filing a single bookmark or a group. For the single bookmark the
|
||||
* values are taken from the name, URL and charset arguments.
|
||||
* For the group, the values are taken from the sixth argument.
|
||||
* This parameter can also be String("addGroup,group") where "group"
|
||||
* specifies that the dialog starts in filing as a group.
|
||||
*/
|
||||
|
||||
var gFld_Name = null;
|
||||
var gFld_URL = null;
|
||||
var gFolderTree = null;
|
||||
var gCB_AddGroup = null;
|
||||
|
||||
var gBookmarkCharset = null;
|
||||
|
||||
const kRDFSContractID = "@mozilla.org/rdf/rdf-service;1";
|
||||
const kRDFSIID = Components.interfaces.nsIRDFService;
|
||||
const kRDF = Components.classes[kRDFSContractID].getService(kRDFSIID);
|
||||
|
||||
var gSelectItemObserver = null;
|
||||
|
||||
var gCreateInFolder = "NC:NewBookmarkFolder";
|
||||
|
||||
function Startup()
|
||||
{
|
||||
gFld_Name = document.getElementById("name");
|
||||
gFld_URL = document.getElementById("url");
|
||||
gCB_AddGroup = document.getElementById("addgroup");
|
||||
var bookmarkView = document.getElementById("bookmarks-view");
|
||||
|
||||
var shouldSetOKButton = true;
|
||||
var dialogElement = document.documentElement;
|
||||
if ("arguments" in window) {
|
||||
var ind;
|
||||
var folderItem = null;
|
||||
var arg;
|
||||
if (window.arguments.length < 5)
|
||||
arg = null;
|
||||
else
|
||||
arg = window.arguments[4];
|
||||
switch (arg) {
|
||||
case "selectFolder":
|
||||
// If we're being opened as a folder selection window
|
||||
document.getElementById("bookmarknamegrid").setAttribute("hidden", "true");
|
||||
document.getElementById("createinseparator").setAttribute("hidden", "true");
|
||||
document.getElementById("nameseparator").setAttribute("hidden", "true");
|
||||
sizeToContent();
|
||||
dialogElement.setAttribute("title", dialogElement.getAttribute("title-selectFolder"));
|
||||
shouldSetOKButton = false;
|
||||
if (window.arguments[2])
|
||||
folderItem = bookmarkView.rdf.GetResource(window.arguments[2]);
|
||||
if (folderItem) {
|
||||
ind = bookmarkView.treeBuilder.getIndexOfResource(folderItem);
|
||||
bookmarkView.treeBoxObject.selection.select(ind);
|
||||
}
|
||||
break;
|
||||
case "newBookmark":
|
||||
setupFields();
|
||||
if (window.arguments[2])
|
||||
gCreateInFolder = window.arguments[2];
|
||||
document.getElementById("folderbox").setAttribute("hidden", "true");
|
||||
sizeToFit();
|
||||
break;
|
||||
case "addGroup":
|
||||
document.getElementById("showaddgroup").setAttribute("hidden", "false");
|
||||
setupFields();
|
||||
sizeToFit();
|
||||
break;
|
||||
case "addGroup,group":
|
||||
document.getElementById("showaddgroup").setAttribute("hidden", "false");
|
||||
gCB_AddGroup.setAttribute("checked", "true");
|
||||
setupFields();
|
||||
toggleGroup();
|
||||
sizeToFit();
|
||||
break;
|
||||
default:
|
||||
// Regular Add Bookmark
|
||||
setupFields();
|
||||
if (window.arguments[2]) {
|
||||
gCreateInFolder = window.arguments[2];
|
||||
folderItem = bookmarkView.rdf.GetResource(gCreateInFolder);
|
||||
if (folderItem) {
|
||||
ind = bookmarkView.treeBuilder.getIndexOfResource(folderItem);
|
||||
bookmarkView.treeBoxObject.selection.select(ind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSetOKButton)
|
||||
onFieldInput();
|
||||
if (document.getElementById("bookmarknamegrid").hasAttribute("hidden")) {
|
||||
bookmarkView.tree.focus();
|
||||
if (bookmarkView.currentIndex == -1)
|
||||
bookmarkView.treeBoxObject.selection.select(0);
|
||||
}
|
||||
else {
|
||||
gFld_Name.select();
|
||||
gFld_Name.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function sizeToFit()
|
||||
{
|
||||
var dialogElement = document.documentElement;
|
||||
dialogElement.removeAttribute("persist");
|
||||
dialogElement.removeAttribute("height");
|
||||
dialogElement.removeAttribute("width");
|
||||
dialogElement.setAttribute("style", dialogElement.getAttribute("style"));
|
||||
sizeToContent();
|
||||
}
|
||||
|
||||
function setupFields()
|
||||
{
|
||||
// New bookmark in predetermined folder.
|
||||
gFld_Name.value = window.arguments[0] || "";
|
||||
gFld_URL.value = window.arguments[1] || "";
|
||||
onFieldInput();
|
||||
gFld_Name.select();
|
||||
gFld_Name.focus();
|
||||
gBookmarkCharset = window.arguments[3] || null;
|
||||
}
|
||||
|
||||
function onFieldInput()
|
||||
{
|
||||
const ok = document.documentElement.getButton("accept");
|
||||
ok.disabled = gFld_URL.value == "" && !addingGroup() ||
|
||||
gFld_Name.value == "";
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
if (!document.getElementById("folderbox").hasAttribute("hidden")) {
|
||||
var bookmarkView = document.getElementById("bookmarks-view");
|
||||
var currentIndex = bookmarkView.currentIndex;
|
||||
if (currentIndex != -1)
|
||||
gCreateInFolder = bookmarkView.treeBuilder.getResourceAtIndex(currentIndex).Value;
|
||||
}
|
||||
// In Select Folder Mode, do nothing but tell our caller what
|
||||
// folder was selected.
|
||||
if (window.arguments.length > 4 && window.arguments[4] == "selectFolder")
|
||||
window.arguments[5].selectedFolder = gCreateInFolder;
|
||||
else {
|
||||
// Otherwise add a bookmark to the selected folder.
|
||||
|
||||
const kBMDS = kRDF.GetDataSource("rdf:bookmarks");
|
||||
const kBMSContractID = "@mozilla.org/browser/bookmarks-service;1";
|
||||
const kBMSIID = Components.interfaces.nsIBookmarksService;
|
||||
const kBMS = Components.classes[kBMSContractID].getService(kBMSIID);
|
||||
var rFolder = kRDF.GetResource(gCreateInFolder, true);
|
||||
const kRDFCContractID = "@mozilla.org/rdf/container;1";
|
||||
const kRDFIID = Components.interfaces.nsIRDFContainer;
|
||||
const kRDFC = Components.classes[kRDFCContractID].getService(kRDFIID);
|
||||
try {
|
||||
kRDFC.Init(kBMDS, rFolder);
|
||||
}
|
||||
catch (e) {
|
||||
// No "NC:NewBookmarkFolder" exists, just append to the root.
|
||||
rFolder = kRDF.GetResource("NC:BookmarksRoot", true);
|
||||
kRDFC.Init(kBMDS, rFolder);
|
||||
}
|
||||
|
||||
// if no URL was provided and we're not filing as a group, do nothing
|
||||
if (!gFld_URL.value && !addingGroup())
|
||||
return;
|
||||
|
||||
var url;
|
||||
if (addingGroup()) {
|
||||
const group = kBMS.createGroup(gFld_Name.value, rFolder);
|
||||
const groups = window.arguments[5];
|
||||
for (var i = 0; i < groups.length; ++i) {
|
||||
url = getNormalizedURL(groups[i].url);
|
||||
kBMS.createBookmarkWithDetails(groups[i].name, url,
|
||||
groups[i].charset, group, -1);
|
||||
}
|
||||
} else {
|
||||
url = getNormalizedURL(gFld_URL.value);
|
||||
var newBookmark = kBMS.createBookmarkWithDetails(gFld_Name.value, url, gBookmarkCharset, rFolder, -1);
|
||||
if (window.arguments.length > 4 && window.arguments[4] == "newBookmark") {
|
||||
window.arguments[5].newBookmark = newBookmark;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getNormalizedURL(url)
|
||||
{
|
||||
// Check to see if the item is a local directory path, and if so, convert
|
||||
// to a file URL so that aggregation with rdf:files works
|
||||
try {
|
||||
const kLF = Components.classes["@mozilla.org/file/local;1"]
|
||||
.createInstance(Components.interfaces.nsILocalFile);
|
||||
kLF.initWithPath(url);
|
||||
if (kLF.exists()) {
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.classes.nsIIOService);
|
||||
|
||||
url = ioService.getURLSpecFromFile(kLF);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
var gBookmarksShell = null;
|
||||
function createNewFolder ()
|
||||
{
|
||||
var bookmarksView = document.getElementById("bookmarks-view");
|
||||
bookmarksView.createNewFolder();
|
||||
}
|
||||
|
||||
function useDefaultFolder ()
|
||||
{
|
||||
const kBMDS = kRDF.GetDataSource("rdf:bookmarks");
|
||||
var bookmarkView = document.getElementById("bookmarks-view");
|
||||
var sources = kBMDS.GetSources(bookmarkView.rdf.GetResource(NC_NS + "FolderType"), bookmarkView.rdf.GetResource("NC:NewBookmarkFolder"), true);
|
||||
var folder = null;
|
||||
if (sources.hasMoreElements()) {
|
||||
folder = sources.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
}
|
||||
var ind = bookmarkView.treeBuilder.getIndexOfResource(folder);
|
||||
if (ind != -1) {
|
||||
bookmarkView.tree.focus();
|
||||
bookmarkView.treeBoxObject.selection.select(ind);
|
||||
gCreateInFolder = folder.Value;
|
||||
}
|
||||
else {
|
||||
bookmarkView.treeBoxObject.selection.clearSelection();
|
||||
gCreateInFolder = "NC:BookmarksRoot";
|
||||
}
|
||||
}
|
||||
|
||||
var gOldNameValue = "";
|
||||
var gOldURLValue = "";
|
||||
|
||||
function toggleGroup()
|
||||
{
|
||||
// swap between single bookmark and group name
|
||||
var temp = gOldNameValue;
|
||||
gOldNameValue = gFld_Name.value;
|
||||
gFld_Name.value = temp;
|
||||
|
||||
// swap between single bookmark and group url
|
||||
temp = gOldURLValue;
|
||||
gOldURLValue = gFld_URL.value;
|
||||
gFld_URL.value = temp;
|
||||
gFld_URL.disabled = gCB_AddGroup.getAttribute("checked") == "true";
|
||||
|
||||
gFld_Name.select();
|
||||
gFld_Name.focus();
|
||||
onFieldInput();
|
||||
}
|
||||
|
||||
function addingGroup()
|
||||
{
|
||||
const showAddGroup = document.getElementById("showaddgroup");
|
||||
return showAddGroup.getAttribute("hidden") != "true" && gCB_AddGroup.getAttribute("checked") == "true";
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- -*- Mode: HTML; indent-tabs-mode: nil; -*- -->
|
||||
<!--
|
||||
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com> (Original Author)
|
||||
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/"?>
|
||||
<?xml-stylesheet href="chrome://communicator/skin/bookmarks/bookmarks.css"?>
|
||||
<?xml-stylesheet href="chrome://communicator/content/bookmarks/bookmarks.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
|
||||
%brandDTD;
|
||||
<!ENTITY % addBookmarkDTD SYSTEM "chrome://communicator/locale/bookmarks/addBookmark.dtd">
|
||||
%addBookmarkDTD;
|
||||
]>
|
||||
|
||||
<dialog id="newBookmarkDialog" style="width: 36em;"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
ondialogaccept="return onOK(event)"
|
||||
title="&newBookmark.title;" title-selectFolder="&selectFolder.label;"
|
||||
onload="Startup();"
|
||||
persist="screenX screenY width height"
|
||||
screenX="24" screenY="24">
|
||||
|
||||
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksOverlay.js"/>
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksTree.js"/>
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/addBookmark.js"/>
|
||||
|
||||
<stringbundle id="bookmarksbundle"
|
||||
src="chrome://communicator/locale/bookmarks/bookmark.properties"/>
|
||||
|
||||
<broadcaster id="showaddgroup" hidden="true"/>
|
||||
|
||||
<separator id="nameseparator" class="thin"/>
|
||||
|
||||
<grid id="bookmarknamegrid">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="5"/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row align="center">
|
||||
<label value="&name.label;" accesskey="&name.accesskey;" control="name"/>
|
||||
<textbox id="name" oninput="onFieldInput();"/>
|
||||
<spacer/>
|
||||
</row>
|
||||
<row>
|
||||
<separator class="thin"/>
|
||||
<separator class="thin"/>
|
||||
<spacer/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label value="&url.label;" accesskey="&url.accesskey;" control="url"/>
|
||||
<textbox id="url" oninput="onFieldInput();"/>
|
||||
<spacer/>
|
||||
</row>
|
||||
<row observes="showaddgroup">
|
||||
<separator class="thin"/>
|
||||
<separator class="thin"/>
|
||||
<spacer/>
|
||||
</row>
|
||||
<row observes="showaddgroup">
|
||||
<spacer/>
|
||||
<hbox pack="start">
|
||||
<checkbox id="addgroup" label="&addGroup.label;"
|
||||
accesskey="&addGroup.accesskey;" oncommand="toggleGroup();"/>
|
||||
</hbox>
|
||||
<spacer/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
<separator id="createinseparator"/>
|
||||
|
||||
<vbox id="folderbox" flex="1">
|
||||
<separator/>
|
||||
<hbox flex="1">
|
||||
<label id="createinlabel" value="&createin.label;"/>
|
||||
<hbox flex="1">
|
||||
<bookmarks-tree id="bookmarks-view" flex="1" type="folders"/>
|
||||
<vbox>
|
||||
<button label="&button.newfolder.label;" accesskey="&button.newfolder.accesskey;"
|
||||
oncommand="createNewFolder();"/>
|
||||
<button label="&button.defaultfolder.label;"
|
||||
accesskey="&button.defaultfolder.accesskey;"
|
||||
oncommand="useDefaultFolder();"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
||||
<separator/>
|
||||
|
||||
</dialog>
|
||||
@@ -1,87 +0,0 @@
|
||||
<?xml version="1.0"?> <!-- -*- Mode: SGML; indent-tabs-mode: nil; -*- -->
|
||||
<!--
|
||||
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com> (Original Author, v2.0)
|
||||
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://communicator/skin/sidebar/sidebarListView.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://communicator/skin/bookmarks/bookmarksWindow.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://communicator/content/bookmarks/bookmarks.css" type="text/css"?>
|
||||
|
||||
<?xul-overlay href="chrome://communicator/content/utilityOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://global/content/globalOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://communicator/content/bookmarks/bookmarksOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://communicator/content/tasksOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://communicator/content/communicatorOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://communicator/locale/bookmarks/bookmarks.dtd">
|
||||
|
||||
<page id="bookmarksPanel"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="Startup();" elementtofocus="bookmarks-view">
|
||||
|
||||
<!-- XXX - would like to cut this dependency out -->
|
||||
<script type="application/x-javascript" src="chrome://global/content/strres.js"/>
|
||||
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
|
||||
<!-- Bookmarks Shell -->
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksOverlay.js"/>
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksPanel.js"/>
|
||||
|
||||
<!-- Drag and Drop -->
|
||||
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
<script type="application/x-javascript" src="chrome://global/content/nsTransferable.js"/>
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksDD.js"/>
|
||||
|
||||
|
||||
<!-- context menu, tooltips, etc -->
|
||||
<popupset id="bookmarksPopupset"/>
|
||||
|
||||
<!-- bookmarks string bundle -->
|
||||
<stringbundleset id="stringbundleset"/>
|
||||
|
||||
<!-- bookmarks & edit commands -->
|
||||
<commands id="commands">
|
||||
<commandset id="CommandUpdate_Bookmarks"
|
||||
commandupdater="true"
|
||||
events="click,focus"
|
||||
oncommandupdate="document.getElementById('bookmarks-view').onCommandUpdate();">
|
||||
</commandset>
|
||||
<commandset id="bookmarksItems"/>
|
||||
</commands>
|
||||
|
||||
<hbox id="panel-bar" class="toolbar">
|
||||
<toolbarbutton id="btnAddBookmark" label="&command.addBookmark.label;"
|
||||
oncommand="addBookmark();"/>
|
||||
<toolbarbutton id="btnManageBookmarks" label="&command.manageBookmarks.label;"
|
||||
oncommand="manageBookmarks();"/>
|
||||
<spacer flex="1"/>
|
||||
<toolbarseparator/>
|
||||
<toolbarbutton id="btnFindBookmarks" label="&command.findBookmarks.label;"
|
||||
oncommand="document.getElementById('bookmarks-view').openFindDialog();"/>
|
||||
</hbox>
|
||||
|
||||
<bookmarks-tree id="bookmarks-view" class="sidebar" type="single-column" flex="1"/>
|
||||
|
||||
</page>
|
||||
@@ -1,387 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var NC_NAMESPACE_URI = "http://home.netscape.com/NC-rdf#";
|
||||
|
||||
// XXX MAKE SURE that the "url" field is LAST!
|
||||
// This is important for what happens if/when the URL itself is changed.
|
||||
// Ask rjc@netscape.com if you want to know why exactly this is.
|
||||
|
||||
// This is the set of fields that are visible in the window.
|
||||
var gFields = ["name", "shortcut", "description", "url"];
|
||||
|
||||
// ...and this is a parallel array that contains the RDF properties
|
||||
// that they are associated with.
|
||||
var gProperties = [NC_NAMESPACE_URI + "Name",
|
||||
NC_NAMESPACE_URI + "ShortcutURL",
|
||||
NC_NAMESPACE_URI + "Description",
|
||||
NC_NAMESPACE_URI + "URL"];
|
||||
|
||||
var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
|
||||
var RDFC = Components.classes["@mozilla.org/rdf/container-utils;1"]
|
||||
.getService(Components.interfaces.nsIRDFContainerUtils);
|
||||
|
||||
var Bookmarks = RDF.GetDataSource("rdf:bookmarks");
|
||||
|
||||
var gBookmarkURL = "";
|
||||
|
||||
function Init()
|
||||
{
|
||||
var x;
|
||||
gBookmarkURL = window.arguments[0];
|
||||
|
||||
// Initialize the properties panel by copying the values from the
|
||||
// RDF graph into the fields on screen.
|
||||
|
||||
for (var i = 0; i < gFields.length; ++i) {
|
||||
var field = document.getElementById(gFields[i]);
|
||||
|
||||
var value = Bookmarks.GetTarget(RDF.GetResource(gBookmarkURL),
|
||||
RDF.GetResource(gProperties[i]),
|
||||
true);
|
||||
|
||||
if (value)
|
||||
value = value.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
|
||||
if (value) //make sure were aren't stuffing null into any fields
|
||||
field.value = value;
|
||||
}
|
||||
|
||||
var propsWindow = document.getElementById("bmPropsWindow");
|
||||
var nameNode = document.getElementById("name");
|
||||
var title = propsWindow.getAttribute("title");
|
||||
title = title.replace(/\*\*bm_title\*\*/gi, nameNode.value);
|
||||
propsWindow.setAttribute("title", title);
|
||||
|
||||
// check bookmark schedule
|
||||
value = Bookmarks.GetTarget(RDF.GetResource(gBookmarkURL),
|
||||
RDF.GetResource("http://home.netscape.com/WEB-rdf#Schedule"),
|
||||
true);
|
||||
|
||||
if (value) {
|
||||
value = value.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
|
||||
if (value) {
|
||||
var values = value.split("|");
|
||||
if (values.length == 4) {
|
||||
// get day range
|
||||
var days = values[0];
|
||||
var dayNode = document.getElementById("dayRange");
|
||||
var dayItems = dayNode.childNodes[0].childNodes;
|
||||
for (x=0; x < dayItems.length; ++x) {
|
||||
if (dayItems[x].getAttribute("value") == days) {
|
||||
dayNode.selectedItem = dayItems[x];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// get hour range
|
||||
var hours = values[1].split("-");
|
||||
var startHour = "";
|
||||
var endHour = "";
|
||||
|
||||
if (hours.length == 2) {
|
||||
startHour = hours[0];
|
||||
endHour = hours[1];
|
||||
}
|
||||
|
||||
// set start hour
|
||||
var startHourNode = document.getElementById("startHourRange");
|
||||
var startHourItems = startHourNode.childNodes[0].childNodes;
|
||||
for (x=0; x < startHourItems.length; ++x) {
|
||||
if (startHourItems[x].getAttribute("value") == startHour) {
|
||||
startHourNode.selectedItem = startHourItems[x];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// set end hour
|
||||
var endHourNode = document.getElementById("endHourRange");
|
||||
var endHourItems = endHourNode.childNodes[0].childNodes;
|
||||
for (x=0; x < endHourItems.length; ++x) {
|
||||
if (endHourItems[x].getAttribute("value") == endHour) {
|
||||
endHourNode.selectedItem = endHourItems[x];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// get duration
|
||||
var duration = values[2];
|
||||
var durationNode = document.getElementById("duration");
|
||||
durationNode.value = duration;
|
||||
|
||||
// get notification method
|
||||
var method = values[3];
|
||||
if (method.indexOf("icon") >= 0)
|
||||
document.getElementById("bookmarkIcon").checked = true;
|
||||
|
||||
if (method.indexOf("sound") >= 0)
|
||||
document.getElementById("playSound").checked = true;
|
||||
|
||||
if (method.indexOf("alert") >= 0)
|
||||
document.getElementById("showAlert").checked = true;
|
||||
|
||||
if (method.indexOf("open") >= 0)
|
||||
document.getElementById("openWindow").checked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if its a container, disable some things
|
||||
var isContainerFlag = RDFC.IsContainer(Bookmarks, RDF.GetResource(gBookmarkURL));
|
||||
if (!isContainerFlag) {
|
||||
// XXX To do: the "RDFC.IsContainer" call above only works for RDF sequences;
|
||||
// if its not a RDF sequence, we should to more checking to see if
|
||||
// the item in question is really a container of not. A good example
|
||||
// of this is the "File System" container.
|
||||
}
|
||||
|
||||
if (isContainerFlag) {
|
||||
// If it is a folder, it has no URL or Keyword
|
||||
document.getElementById("locationrow").setAttribute("hidden", "true");
|
||||
document.getElementById("shortcutrow").setAttribute("hidden", "true");
|
||||
}
|
||||
|
||||
if (gBookmarkURL.substr(0, 7).toLowerCase() != "http://" &&
|
||||
gBookmarkURL.substr(0, 8).toLowerCase() != "https://") {
|
||||
// only allow scheduling of http/https URLs
|
||||
document.getElementById("ScheduleTab").setAttribute("hidden", "true");
|
||||
document.getElementById("NotifyTab").setAttribute("hidden", "true");
|
||||
}
|
||||
|
||||
sizeToContent();
|
||||
|
||||
// Set up the enabled of controls on the scheduling panels
|
||||
dayRangeChange(document.getElementById("dayRange"));
|
||||
|
||||
// set initial focus
|
||||
var name = document.getElementById("name");
|
||||
name.focus();
|
||||
name.select();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Commit()
|
||||
{
|
||||
var changed = false;
|
||||
|
||||
// Grovel through the fields to see if any of the values have
|
||||
// changed. If so, update the RDF graph and force them to be saved
|
||||
// to disk.
|
||||
for (var i = 0; i < gFields.length; ++i) {
|
||||
var field = document.getElementById(gFields[i]);
|
||||
|
||||
if (field) {
|
||||
// Get the new value as a literal, using 'null' if the value is empty.
|
||||
var newvalue = field.value;
|
||||
|
||||
var oldvalue = Bookmarks.GetTarget(RDF.GetResource(gBookmarkURL),
|
||||
RDF.GetResource(gProperties[i]),
|
||||
true);
|
||||
|
||||
if (oldvalue)
|
||||
oldvalue = oldvalue.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
|
||||
if (newvalue && gProperties[i] == (NC_NAMESPACE_URI + "ShortcutURL")) {
|
||||
// shortcuts are always lowercased internally
|
||||
newvalue = newvalue.toLowerCase();
|
||||
}
|
||||
else if (newvalue && gProperties[i] == (NC_NAMESPACE_URI + "URL")) {
|
||||
// we're dealing with the URL attribute;
|
||||
// if a scheme isn't specified, use "http://"
|
||||
if (newvalue.indexOf(":") < 0)
|
||||
newvalue = "http://" + newvalue;
|
||||
}
|
||||
|
||||
if (newvalue)
|
||||
newvalue = RDF.GetLiteral(newvalue);
|
||||
|
||||
if (updateAttribute(gProperties[i], oldvalue, newvalue)) {
|
||||
// Update gBookmarkURL if the url changed
|
||||
if (newvalue && gProperties[i] == NC_NAMESPACE_URI + "URL")
|
||||
gBookmarkURL = newvalue.Value;
|
||||
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update bookmark schedule if necessary;
|
||||
// if the tab was removed, just skip it
|
||||
var scheduleTab = document.getElementById("ScheduleTab");
|
||||
if (scheduleTab) {
|
||||
var scheduleRes = "http://home.netscape.com/WEB-rdf#Schedule";
|
||||
oldvalue = Bookmarks.GetTarget(RDF.GetResource(gBookmarkURL),
|
||||
RDF.GetResource(scheduleRes), true);
|
||||
newvalue = "";
|
||||
var dayRangeNode = document.getElementById("dayRange");
|
||||
var dayRange = dayRangeNode.selectedItem.getAttribute("value");
|
||||
|
||||
if (dayRange) {
|
||||
var startHourRangeNode = document.getElementById("startHourRange");
|
||||
var startHourRange = startHourRangeNode.selectedItem.getAttribute("value");
|
||||
|
||||
var endHourRangeNode = document.getElementById("endHourRange");
|
||||
var endHourRange = endHourRangeNode.selectedItem.getAttribute("value");
|
||||
|
||||
if (parseInt(startHourRange) > parseInt(endHourRange)) {
|
||||
var temp = startHourRange;
|
||||
startHourRange = endHourRange;
|
||||
endHourRange = temp;
|
||||
}
|
||||
|
||||
var bookmarkBundle;
|
||||
var duration = document.getElementById("duration").value;
|
||||
if (!duration) {
|
||||
bookmarkBundle = document.getElementById("bundle_bookmark");
|
||||
alert (bookmarkBundle.getString("pleaseEnterADuration"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var methods = [];
|
||||
if (document.getElementById("bookmarkIcon").checked)
|
||||
methods.push("icon");
|
||||
if (document.getElementById("playSound").checked)
|
||||
methods.push("sound");
|
||||
if (document.getElementById("showAlert").checked)
|
||||
methods.push("alert");
|
||||
if (document.getElementById("openWindow").checked)
|
||||
methods.push("open");
|
||||
|
||||
if (methods.length == 0) {
|
||||
bookmarkBundle = document.getElementById("bundle_bookmark");
|
||||
alert (bookmarkBundle.getString("pleaseSelectANotification"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var method = methods.join(); // join string in array with ","
|
||||
|
||||
newvalue = dayRange + "|" + startHourRange + "-" + endHourRange + "|" + duration + "|" + method;
|
||||
}
|
||||
|
||||
if (newvalue)
|
||||
newvalue = RDF.GetLiteral(newvalue);
|
||||
|
||||
if (updateAttribute(scheduleRes, oldvalue, newvalue))
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
var remote = Bookmarks.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
if (remote)
|
||||
remote.Flush();
|
||||
}
|
||||
|
||||
window.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
function updateAttribute(prop, oldvalue, newvalue)
|
||||
{
|
||||
var changed = false;
|
||||
|
||||
if (prop && (oldvalue || newvalue) && oldvalue != newvalue) {
|
||||
|
||||
if (oldvalue && !newvalue) {
|
||||
Bookmarks.Unassert(RDF.GetResource(gBookmarkURL),
|
||||
RDF.GetResource(prop),
|
||||
oldvalue);
|
||||
}
|
||||
else if (!oldvalue && newvalue) {
|
||||
Bookmarks.Assert(RDF.GetResource(gBookmarkURL),
|
||||
RDF.GetResource(prop),
|
||||
newvalue,
|
||||
true);
|
||||
}
|
||||
else /* if (oldvalue && newvalue) */ {
|
||||
Bookmarks.Change(RDF.GetResource(gBookmarkURL),
|
||||
RDF.GetResource(prop),
|
||||
oldvalue,
|
||||
newvalue);
|
||||
}
|
||||
|
||||
changed = true;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
function setEndHourRange()
|
||||
{
|
||||
// Get the values of the start-time and end-time as ints
|
||||
var startHourRangeNode = document.getElementById("startHourRange");
|
||||
var startHourRange = startHourRangeNode.selectedItem.getAttribute("value");
|
||||
var startHourRangeInt = parseInt(startHourRange);
|
||||
|
||||
var endHourRangeNode = document.getElementById("endHourRange");
|
||||
var endHourRange = endHourRangeNode.selectedItem.getAttribute("value");
|
||||
var endHourRangeInt = parseInt(endHourRange);
|
||||
|
||||
var endHourItemNode = endHourRangeNode.firstChild.firstChild;
|
||||
|
||||
var index = 0;
|
||||
|
||||
// disable all those end-times before the start-time
|
||||
for (; index < startHourRangeInt; ++index) {
|
||||
endHourItemNode.setAttribute("disabled", "true");
|
||||
endHourItemNode = endHourItemNode.nextSibling;
|
||||
}
|
||||
|
||||
// update the selected value if it's out of the allowed range
|
||||
if (startHourRangeInt >= endHourRangeInt)
|
||||
endHourRangeNode.selectedItem = endHourItemNode;
|
||||
|
||||
// make sure all the end-times after the start-time are enabled
|
||||
for (; index < 24; ++index) {
|
||||
endHourItemNode.removeAttribute("disabled");
|
||||
endHourItemNode = endHourItemNode.nextSibling;
|
||||
}
|
||||
}
|
||||
|
||||
function dayRangeChange (aMenuList)
|
||||
{
|
||||
var controls = ["startHourRange", "endHourRange", "duration", "bookmarkIcon",
|
||||
"showAlert", "openWindow", "playSound", "durationSubLabel",
|
||||
"durationLabel", "startHourRangeLabel", "endHourRangeLabel"];
|
||||
for (var i = 0; i < controls.length; ++i)
|
||||
document.getElementById(controls[i]).disabled = !aMenuList.value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,235 +0,0 @@
|
||||
<?xml version="1.0"?> <!-- -*- Mode: SGML; indent-tabs-mode: nil; -*- -->
|
||||
<!--
|
||||
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://communicator/skin/bookmarks/bookmarks.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
|
||||
%brandDTD;
|
||||
<!ENTITY % bmpropsDTD SYSTEM "chrome://communicator/locale/bookmarks/bm-props.dtd">
|
||||
%bmpropsDTD;
|
||||
]>
|
||||
|
||||
<dialog id="bmPropsWindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&bookmarks.windowtitle.label;"
|
||||
onload="Init()" style="width: 30em;"
|
||||
ondialogaccept="return Commit();">
|
||||
|
||||
<stringbundle id="bundle_bookmark" src="chrome://communicator/locale/bookmarks/bookmark.properties"/>
|
||||
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bm-props.js"/>
|
||||
|
||||
<keyset id="keyset"/>
|
||||
|
||||
<tabbox>
|
||||
<tabs>
|
||||
<tab label="&generalInfo.label;" accesskey="&generalInfo.accesskey;"/>
|
||||
<tab id="ScheduleTab" label="&schedule.label;" accesskey="&schedule.accesskey;"/>
|
||||
<tab id="NotifyTab" label="¬ification.label;" accesskey="¬ification.accesskey;"/>
|
||||
</tabs>
|
||||
<tabpanels>
|
||||
<vbox>
|
||||
<separator class="thin"/>
|
||||
<hbox align="start">
|
||||
<image class="message-icon"/>
|
||||
<separator class="thin" orient="vertical"/>
|
||||
<description flex="1">&generaldesc.label;</description>
|
||||
</hbox>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<vbox class="box-padded">
|
||||
<grid>
|
||||
<columns>
|
||||
<column />
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row align="center">
|
||||
<label value="&bookmarks.name.label;" control="name"/>
|
||||
<textbox id="name"/>
|
||||
</row>
|
||||
<row id="locationrow" align="center">
|
||||
<label value="&bookmarks.location.label;" control="url"/>
|
||||
<textbox id="url" />
|
||||
</row>
|
||||
<row id="shortcutrow" align="center">
|
||||
<label value="&bookmarks.shortcut.label;" control="shortcut"/>
|
||||
<textbox id="shortcut" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="&bookmarks.description.label;" control="description"/>
|
||||
<textbox multiline="true" wrap="virtual" id="description" flex="1"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
<separator/>
|
||||
</vbox>
|
||||
</vbox>
|
||||
|
||||
<vbox>
|
||||
<separator class="thin"/>
|
||||
<hbox align="center">
|
||||
<image id="schedule-icon"/>
|
||||
<separator class="thin" orient="vertical"/>
|
||||
<description flex="1">&schedule.description;</description>
|
||||
</hbox>
|
||||
<separator class="thin"/>
|
||||
<hbox class="box-padded">
|
||||
<spacer flex="1"/>
|
||||
<groupbox>
|
||||
<caption label="&checkforupdates.legend.label;"/>
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row align="center">
|
||||
<label value="&when.label;" control="dayRange"/>
|
||||
<hbox>
|
||||
<menulist id="dayRange" oncommand="dayRangeChange(this);">
|
||||
<menupopup>
|
||||
<menuitem value="" label="&checknever.label;"/>
|
||||
<menuseparator />
|
||||
<menuitem value="0123456" label="&checkeveryday.label;"/>
|
||||
<menuitem value="12345" label="&checkweekdays.label;"/>
|
||||
<menuitem value="06" label="&checkweekends.label;"/>
|
||||
<menuitem value="1" label="&checkmondays.label;"/>
|
||||
<menuitem value="2" label="&checktuesdays.label;"/>
|
||||
<menuitem value="3" label="&checkwednesdays.label;"/>
|
||||
<menuitem value="4" label="&checkthursdays.label;"/>
|
||||
<menuitem value="5" label="&checkfridays.label;"/>
|
||||
<menuitem value="6" label="&checksaturdays.label;"/>
|
||||
<menuitem value="0" label="&checksundays.label;"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</hbox>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label id="startHourRangeLabel"
|
||||
value="&from.label;" control="startHourRange"/>
|
||||
<hbox align="center">
|
||||
<menulist id="startHourRange" oncommand="setEndHourRange()">
|
||||
<menupopup>
|
||||
<menuitem value="0" label="&midnight.label;"/>
|
||||
<menuitem value="1" label="&AMone.label;"/>
|
||||
<menuitem value="2" label="&AMtwo.label;"/>
|
||||
<menuitem value="3" label="&AMthree.label;"/>
|
||||
<menuitem value="4" label="&AMfour.label;"/>
|
||||
<menuitem value="5" label="&AMfive.label;"/>
|
||||
<menuitem value="6" label="&AMsix.label;"/>
|
||||
<menuitem value="7" label="&AMseven.label;"/>
|
||||
<menuitem value="8" label="&AMeight.label;"/>
|
||||
<menuitem value="9" label="&AMnine.label;"/>
|
||||
<menuitem value="10" label="&AMten.label;"/>
|
||||
<menuitem value="11" label="&AMeleven.label;"/>
|
||||
<menuitem value="12" label="&noon.label;"/>
|
||||
<menuitem value="13" label="&PMone.label;"/>
|
||||
<menuitem value="14" label="&PMtwo.label;"/>
|
||||
<menuitem value="15" label="&PMthree.label;"/>
|
||||
<menuitem value="16" label="&PMfour.label;"/>
|
||||
<menuitem value="17" label="&PMfive.label;"/>
|
||||
<menuitem value="18" label="&PMsix.label;"/>
|
||||
<menuitem value="19" label="&PMseven.label;"/>
|
||||
<menuitem value="20" label="&PMeight.label;"/>
|
||||
<menuitem value="21" label="&PMnine.label;"/>
|
||||
<menuitem value="22" label="&PMten.label;"/>
|
||||
<menuitem value="23" label="&PMeleven.label;"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
<label id="endHourRangeLabel"
|
||||
value="&to.label;" control="endHourRange"/>
|
||||
<menulist id="endHourRange">
|
||||
<menupopup onpopupshowing="setEndHourRange()">
|
||||
<menuitem value="1" label="&AMone.label;"/>
|
||||
<menuitem value="2" label="&AMtwo.label;"/>
|
||||
<menuitem value="3" label="&AMthree.label;"/>
|
||||
<menuitem value="4" label="&AMfour.label;"/>
|
||||
<menuitem value="5" label="&AMfive.label;"/>
|
||||
<menuitem value="6" label="&AMsix.label;"/>
|
||||
<menuitem value="7" label="&AMseven.label;"/>
|
||||
<menuitem value="8" label="&AMeight.label;"/>
|
||||
<menuitem value="9" label="&AMnine.label;"/>
|
||||
<menuitem value="10" label="&AMten.label;"/>
|
||||
<menuitem value="11" label="&AMeleven.label;"/>
|
||||
<menuitem value="12" label="&noon.label;"/>
|
||||
<menuitem value="13" label="&PMone.label;"/>
|
||||
<menuitem value="14" label="&PMtwo.label;"/>
|
||||
<menuitem value="15" label="&PMthree.label;"/>
|
||||
<menuitem value="16" label="&PMfour.label;"/>
|
||||
<menuitem value="17" label="&PMfive.label;"/>
|
||||
<menuitem value="18" label="&PMsix.label;"/>
|
||||
<menuitem value="19" label="&PMseven.label;"/>
|
||||
<menuitem value="20" label="&PMeight.label;"/>
|
||||
<menuitem value="21" label="&PMnine.label;"/>
|
||||
<menuitem value="22" label="&PMten.label;"/>
|
||||
<menuitem value="23" label="&PMeleven.label;"/>
|
||||
<menuitem value="24" label="&midnight.label;"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</hbox>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label id="durationLabel"
|
||||
value="&every.label;" control="duration"/>
|
||||
<hbox align="center">
|
||||
<textbox id="duration" size="4" value="60" />
|
||||
<label id="durationSubLabel" value="&minutes.label;" />
|
||||
</hbox>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
<separator class="thin"/>
|
||||
</groupbox>
|
||||
<spacer flex="1"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
||||
<vbox>
|
||||
<separator class="thin"/>
|
||||
<hbox align="start">
|
||||
<image id="notification-icon"/>
|
||||
<separator class="thin" orient="vertical"/>
|
||||
<description flex="1">¬ification.description;</description>
|
||||
</hbox>
|
||||
<separator class="thin"/>
|
||||
<hbox class="box-padded">
|
||||
<spacer flex="1"/>
|
||||
<groupbox>
|
||||
<caption label="¬ifications.legend.label;" />
|
||||
<vbox align="start">
|
||||
<checkbox id="bookmarkIcon" label="¬ification.icon.label;" />
|
||||
<checkbox id="showAlert" label="¬ification.alert.label;" />
|
||||
<checkbox id="openWindow" label="¬ification.window.label;" />
|
||||
<checkbox id="playSound" label="¬ification.sound.label;" />
|
||||
</vbox>
|
||||
</groupbox>
|
||||
<spacer flex="1"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
</dialog>
|
||||
@@ -1,854 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
This is the old bookmarks code, included here for the sake of the bookmarks sidebar panel,
|
||||
which will be fixed to use my new code in .9. In the mean time, this file provides a
|
||||
life line to various functionality.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
var NC_NS = "http://home.netscape.com/NC-rdf#";
|
||||
var RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||
|
||||
function Init() {
|
||||
var tree = document.getElementById("bookmarksTree");
|
||||
tree.controllers.appendController(BookmarksController);
|
||||
var children = document.getElementById('treechildren-bookmarks');
|
||||
tree.selectItem(children.firstChild);
|
||||
tree.focus();
|
||||
|
||||
RefreshSort();
|
||||
}
|
||||
|
||||
var BookmarksController = {
|
||||
supportsCommand: function(command)
|
||||
{
|
||||
switch(command)
|
||||
{
|
||||
case "cmd_undo":
|
||||
case "cmd_redo":
|
||||
return false;
|
||||
case "cmd_cut":
|
||||
case "cmd_copy":
|
||||
case "cmd_paste":
|
||||
case "cmd_delete":
|
||||
case "cmd_selectAll":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
isCommandEnabled: function(command)
|
||||
{
|
||||
switch(command)
|
||||
{
|
||||
case "cmd_undo":
|
||||
case "cmd_redo":
|
||||
return false;
|
||||
case "cmd_cut":
|
||||
case "cmd_copy":
|
||||
case "cmd_paste":
|
||||
case "cmd_delete":
|
||||
case "cmd_selectAll":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
doCommand: function(command)
|
||||
{
|
||||
switch(command)
|
||||
{
|
||||
case "cmd_undo":
|
||||
case "cmd_redo":
|
||||
break;
|
||||
case "cmd_cut":
|
||||
doCut();
|
||||
break;
|
||||
case "cmd_copy":
|
||||
doCopy();
|
||||
break;
|
||||
case "cmd_paste":
|
||||
doPaste();
|
||||
break;
|
||||
case "cmd_delete":
|
||||
doDelete();
|
||||
break;
|
||||
case "cmd_selectAll":
|
||||
doSelectAll();
|
||||
break;
|
||||
}
|
||||
},
|
||||
onEvent: function(event)
|
||||
{
|
||||
// On blur events set the menu item texts back to the normal values
|
||||
/*if (event == 'blur' )
|
||||
{
|
||||
goSetMenuValue('cmd_undo', 'valueDefault');
|
||||
goSetMenuValue('cmd_redo', 'valueDefault');
|
||||
}*/
|
||||
}
|
||||
};
|
||||
|
||||
function CommandUpdate_Bookmarks()
|
||||
{
|
||||
//goUpdateCommand('button_delete');
|
||||
// get selection info from dir pane
|
||||
/*
|
||||
var oneAddressBookSelected = false;
|
||||
if ( dirTree && dirTree.selectedItems && (dirTree.selectedItems.length == 1) )
|
||||
oneAddressBookSelected = true;
|
||||
|
||||
// get selection info from results pane
|
||||
var selectedCards = GetSelectedAddresses();
|
||||
var oneOrMoreCardsSelected = false;
|
||||
if ( selectedCards )
|
||||
oneOrMoreCardsSelected = true;
|
||||
*/
|
||||
// set commands to enabled / disabled
|
||||
//goSetCommandEnabled('cmd_PrintCard', oneAddressBookSelected);
|
||||
goSetCommandEnabled('bm_cmd_find', true/*oneAddressBookSelected*/);
|
||||
}
|
||||
|
||||
function copySelectionToClipboard()
|
||||
{
|
||||
var treeNode = document.getElementById("bookmarksTree");
|
||||
if (!treeNode) return false;
|
||||
var select_list = treeNode.selectedItems;
|
||||
if (!select_list) return false;
|
||||
if (select_list.length < 1) return false;
|
||||
|
||||
var rdf_uri = "@mozilla.org/rdf/rdf-service;1"
|
||||
var RDF = Components.classes[rdf_uri].getService();
|
||||
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
if (!RDF) return false;
|
||||
|
||||
var Bookmarks = RDF.GetDataSource("rdf:bookmarks");
|
||||
if (!Bookmarks) return false;
|
||||
|
||||
var nameRes = RDF.GetResource(NC_NS + "Name");
|
||||
if (!nameRes) return false;
|
||||
|
||||
// Build a url that encodes all the select nodes
|
||||
// as well as their parent nodes
|
||||
var url = "";
|
||||
var text = "";
|
||||
var html = "";
|
||||
|
||||
for (var nodeIndex = 0; nodeIndex < select_list.length; nodeIndex++)
|
||||
{
|
||||
var node = select_list[nodeIndex];
|
||||
if (!node) continue;
|
||||
|
||||
var ID = getAbsoluteID("bookmarksTree", node);
|
||||
if (!ID) continue;
|
||||
|
||||
var IDRes = RDF.GetResource(ID);
|
||||
if (!IDRes) continue;
|
||||
var nameNode = Bookmarks.GetTarget(IDRes, nameRes, true);
|
||||
var theName = "";
|
||||
if (nameNode)
|
||||
nameNode =
|
||||
nameNode.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (nameNode) theName = nameNode.Value;
|
||||
|
||||
url += "ID:{" + ID + "};";
|
||||
url += "NAME:{" + theName + "};";
|
||||
|
||||
if (node.getAttribute("container") == "true")
|
||||
{
|
||||
var type = node.getAttribute("type");
|
||||
if (type == NC_NS + "BookmarkSeparator")
|
||||
{
|
||||
// Note: can't encode separators in text, just html
|
||||
html += "<hr><p>";
|
||||
}
|
||||
else
|
||||
{
|
||||
text += ID + "\r";
|
||||
|
||||
html += "<a href='" + ID + "'>";
|
||||
if (theName != "")
|
||||
{
|
||||
html += theName;
|
||||
}
|
||||
html += "</a><p>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (url == "") return false;
|
||||
|
||||
// get some useful components
|
||||
var trans_uri = "@mozilla.org/widget/transferable;1";
|
||||
var trans = Components.classes[trans_uri].createInstance();
|
||||
if (trans) trans = trans.QueryInterface(Components.interfaces.nsITransferable);
|
||||
if (!trans) return false;
|
||||
|
||||
var clip_uri = "@mozilla.org/widget/clipboard;1";
|
||||
var clip = Components.classes[clip_uri].getService();
|
||||
if (clip) clip = clip.QueryInterface(Components.interfaces.nsIClipboard);
|
||||
if (!clip) return false;
|
||||
clip.emptyClipboard(Components.interfaces.nsIClipboard.kGlobalClipboard);
|
||||
|
||||
// save bookmark's ID
|
||||
trans.addDataFlavor("moz/bookmarkclipboarditem");
|
||||
var data_uri = "@mozilla.org/supports-wstring;1";
|
||||
var data = Components.classes[data_uri].createInstance();
|
||||
if (data) {
|
||||
data = data.QueryInterface(Components.interfaces.nsISupportsWString);
|
||||
}
|
||||
if (!data) return false;
|
||||
data.data = url;
|
||||
// double byte data
|
||||
trans.setTransferData("moz/bookmarkclipboarditem", data, url.length*2);
|
||||
|
||||
if (text != "")
|
||||
{
|
||||
trans.addDataFlavor("text/unicode");
|
||||
|
||||
var textData_uri = "@mozilla.org/supports-wstring;1";
|
||||
var textData = Components.classes[textData_uri].createInstance();
|
||||
if (textData) textData = textData.QueryInterface(Components.interfaces.nsISupportsWString);
|
||||
if (!textData) return false;
|
||||
textData.data = text;
|
||||
// double byte data
|
||||
trans.setTransferData("text/unicode", textData, text.length*2);
|
||||
}
|
||||
if (html != "")
|
||||
{
|
||||
trans.addDataFlavor("text/html");
|
||||
|
||||
var wstring_uri = "@mozilla.org/supports-wstring;1";
|
||||
var htmlData = Components.classes[wstring_uri].createInstance();
|
||||
if (htmlData) {
|
||||
var wstring_interface = Components.interfaces.nsISupportsWString;
|
||||
htmlData = htmlData.QueryInterface(wstring_interface);
|
||||
}
|
||||
if (!htmlData) return false;
|
||||
htmlData.data = html;
|
||||
// double byte data
|
||||
trans.setTransferData("text/html", htmlData, html.length*2);
|
||||
}
|
||||
clip.setData(trans, null,
|
||||
Components.interfaces.nsIClipboard.kGlobalClipboard);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doCut()
|
||||
{
|
||||
if (copySelectionToClipboard() == true) {
|
||||
doDelete(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function doCopy()
|
||||
{
|
||||
copySelectionToClipboard();
|
||||
return true;
|
||||
}
|
||||
|
||||
function doPaste()
|
||||
{
|
||||
var treeNode = document.getElementById("bookmarksTree");
|
||||
if (!treeNode) return false;
|
||||
var select_list = treeNode.selectedItems;
|
||||
if (!select_list) return false;
|
||||
if (select_list.length != 1) return false;
|
||||
|
||||
var pasteNodeID = select_list[0].getAttribute("id");
|
||||
var isContainerFlag = (select_list[0].getAttribute("container") == "true");
|
||||
|
||||
var clip_uri = "@mozilla.org/widget/clipboard;1";
|
||||
var clip = Components.classes[clip_uri].getService();
|
||||
if (clip) clip = clip.QueryInterface(Components.interfaces.nsIClipboard);
|
||||
if (!clip) return false;
|
||||
|
||||
var trans_uri = "@mozilla.org/widget/transferable;1";
|
||||
var trans = Components.classes[trans_uri].createInstance();
|
||||
if (trans) {
|
||||
trans = trans.QueryInterface(Components.interfaces.nsITransferable);
|
||||
}
|
||||
if (!trans) return false;
|
||||
trans.addDataFlavor("moz/bookmarkclipboarditem");
|
||||
|
||||
clip.getData(trans, Components.interfaces.nsIClipboard.kGlobalClipboard);
|
||||
var data = new Object();
|
||||
var dataLen = new Object();
|
||||
trans.getTransferData("moz/bookmarkclipboarditem", data, dataLen);
|
||||
if (data) {
|
||||
var data_interface = Components.interfaces.nsISupportsWString
|
||||
data = data.value.QueryInterface(data_interface);
|
||||
}
|
||||
var url = null;
|
||||
// double byte data
|
||||
if (data) url = data.data.substring(0, dataLen.value / 2);
|
||||
if (!url) return false;
|
||||
|
||||
var strings = url.split(";");
|
||||
if (!strings) return false;
|
||||
|
||||
var rdf_uri = "@mozilla.org/rdf/rdf-service;1";
|
||||
var RDF = Components.classes[rdf_uri].getService();
|
||||
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
if (!RDF) return false;
|
||||
var rdfc_uri = "@mozilla.org/rdf/container;1";
|
||||
var RDFC = Components.classes[rdfc_uri].getService();
|
||||
RDFC = RDFC.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
if (!RDFC) return false;
|
||||
var Bookmarks = RDF.GetDataSource("rdf:bookmarks");
|
||||
if (!Bookmarks) return false;
|
||||
|
||||
var nameRes = RDF.GetResource(NC_NS + "Name");
|
||||
if (!nameRes) return false;
|
||||
|
||||
pasteNodeRes = RDF.GetResource(pasteNodeID);
|
||||
if (!pasteNodeRes) return false;
|
||||
var pasteContainerRes = null;
|
||||
var pasteNodeIndex = -1;
|
||||
if (isContainerFlag == true)
|
||||
{
|
||||
pasteContainerRes = pasteNodeRes;
|
||||
}
|
||||
else
|
||||
{
|
||||
var parID = select_list[0].parentNode.parentNode.getAttribute("ref");
|
||||
if (!parID) {
|
||||
parID = select_list[0].parentNode.parentNode.getAttribute("id");
|
||||
}
|
||||
if (!parID) return false;
|
||||
pasteContainerRes = RDF.GetResource(parID);
|
||||
if (!pasteContainerRes) return false;
|
||||
}
|
||||
RDFC.Init(Bookmarks, pasteContainerRes);
|
||||
|
||||
if (isContainerFlag == false)
|
||||
{
|
||||
pasteNodeIndex = RDFC.IndexOf(pasteNodeRes);
|
||||
if (pasteNodeIndex < 0) return false; // how did that happen?
|
||||
}
|
||||
|
||||
var typeRes = RDF.GetResource(RDF_NS + "type");
|
||||
if (!typeRes) return false;
|
||||
var bmTypeRes = RDF.GetResource(NC_NS + "Bookmark");
|
||||
if (!bmTypeRes) return false;
|
||||
|
||||
var dirty = false;
|
||||
for (var x=0; x<strings.length; x=x+2)
|
||||
{
|
||||
var theID = strings[x];
|
||||
var theName = strings[x+1];
|
||||
if ((theID.indexOf("ID:{") == 0) && (theName.indexOf("NAME:{") == 0))
|
||||
{
|
||||
theID = theID.substr(4, theID.length-5);
|
||||
theName = theName.substr(6, theName.length-7);
|
||||
|
||||
var IDRes = RDF.GetResource(theID);
|
||||
if (!IDRes) continue;
|
||||
|
||||
if (RDFC.IndexOf(IDRes) > 0)
|
||||
continue;
|
||||
|
||||
if (theName != "")
|
||||
{
|
||||
var NameLiteral = RDF.GetLiteral(theName);
|
||||
if (NameLiteral)
|
||||
{
|
||||
Bookmarks.Assert(IDRes, nameRes, NameLiteral, true);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
if (isContainerFlag == true)
|
||||
RDFC.AppendElement(IDRes);
|
||||
else
|
||||
RDFC.InsertElementAt(IDRes, pasteNodeIndex++, true);
|
||||
dirty = true;
|
||||
|
||||
// make sure appropriate bookmark type is set
|
||||
var bmTypeNode = Bookmarks.GetTarget( IDRes, typeRes, true );
|
||||
if (!bmTypeNode)
|
||||
{
|
||||
// set default bookmark type
|
||||
Bookmarks.Assert(IDRes, typeRes, bmTypeRes, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dirty == true)
|
||||
{
|
||||
var rdf_ds_interface = Components.interfaces.nsIRDFRemoteDataSource;
|
||||
var remote = Bookmarks.QueryInterface(rdf_ds_interface);
|
||||
if (remote)
|
||||
remote.Flush();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function doDelete(promptFlag)
|
||||
{
|
||||
var treeNode = document.getElementById("bookmarksTree");
|
||||
if (!treeNode) return false;
|
||||
var select_list = treeNode.selectedItems;
|
||||
if (!select_list) return false;
|
||||
if (select_list.length < 1) return false;
|
||||
|
||||
if (promptFlag == true)
|
||||
{
|
||||
var deleteStr = '';
|
||||
if (select_list.length == 1) {
|
||||
deleteStr = get_localized_string("DeleteItem");
|
||||
} else {
|
||||
deleteStr = get_localized_string("DeleteItems");
|
||||
}
|
||||
var ok = confirm(deleteStr);
|
||||
if (!ok) return false;
|
||||
}
|
||||
|
||||
var RDF_uri = "@mozilla.org/rdf/rdf-service;1";
|
||||
var RDF = Components.classes[RDF_uri].getService();
|
||||
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
if (!RDF) return false;
|
||||
|
||||
var RDFC_uri = "@mozilla.org/rdf/container;1";
|
||||
var RDFC = Components.classes[RDFC_uri].getService();
|
||||
RDFC = RDFC.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
if (!RDFC) return false;
|
||||
|
||||
var Bookmarks = RDF.GetDataSource("rdf:bookmarks");
|
||||
if (!Bookmarks) return false;
|
||||
|
||||
var dirty = false;
|
||||
|
||||
// note: backwards delete so that we handle odd deletion cases such as
|
||||
// deleting a child of a folder as well as the folder itself
|
||||
for (var nodeIndex=select_list.length-1; nodeIndex>=0; nodeIndex--)
|
||||
{
|
||||
var node = select_list[nodeIndex];
|
||||
if (!node) continue;
|
||||
var ID = node.getAttribute("id");
|
||||
if (!ID) continue;
|
||||
|
||||
// don't allow deletion of various "special" folders
|
||||
if ((ID == "NC:BookmarksRoot") || (ID == "NC:IEFavoritesRoot"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var parentID = node.parentNode.parentNode.getAttribute("ref");
|
||||
if (!parentID) parentID = node.parentNode.parentNode.getAttribute("id");
|
||||
if (!parentID) continue;
|
||||
|
||||
var IDRes = RDF.GetResource(ID);
|
||||
if (!IDRes) continue;
|
||||
var parentIDRes = RDF.GetResource(parentID);
|
||||
if (!parentIDRes) continue;
|
||||
|
||||
RDFC.Init(Bookmarks, parentIDRes);
|
||||
RDFC.RemoveElement(IDRes, true);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (dirty == true)
|
||||
{
|
||||
var remote = Bookmarks.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
if (remote)
|
||||
remote.Flush();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function doSelectAll()
|
||||
{
|
||||
var treeNode = document.getElementById("bookmarksTree");
|
||||
if (!treeNode) return false;
|
||||
treeNode.selectAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
function doUnload()
|
||||
{
|
||||
// Get the current window position/size.
|
||||
var x = window.screenX;
|
||||
var y = window.screenY;
|
||||
var h = window.outerHeight;
|
||||
var w = window.outerWidth;
|
||||
|
||||
// Store these into the window attributes (for persistence).
|
||||
var win = document.getElementById("bookmark-window");
|
||||
win.setAttribute("x", x);
|
||||
win.setAttribute("y", y);
|
||||
win.setAttribute("height", h);
|
||||
win.setAttribute("width", w);
|
||||
}
|
||||
|
||||
function BookmarkProperties()
|
||||
{
|
||||
var treeNode = document.getElementById('bookmarksTree');
|
||||
var select_list = treeNode.selectedItems;
|
||||
|
||||
if (select_list.length >= 1) {
|
||||
// don't bother showing properties on bookmark separators
|
||||
var type = select_list[0].getAttribute('type');
|
||||
if (type != NC_NS + "BookmarkSeparator") {
|
||||
window.openDialog("chrome://communicator/content/bookmarks/bm-props.xul",
|
||||
"_blank", "centerscreen,chrome,menubar",
|
||||
select_list[0].getAttribute("id"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function OpenBookmarksFind()
|
||||
{
|
||||
window.openDialog("chrome://communicator/content/bookmarks/bm-find.xul",
|
||||
"FindBookmarksWindow",
|
||||
"dialog=no,close,chrome,resizable", "bookmarks");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getAbsoluteID(root, node)
|
||||
{
|
||||
var url = node.getAttribute("ref");
|
||||
if ((url == null) || (url == ""))
|
||||
{
|
||||
url = node.getAttribute("id");
|
||||
}
|
||||
try
|
||||
{
|
||||
var rootNode = document.getElementById(root);
|
||||
var ds = null;
|
||||
if (rootNode)
|
||||
{
|
||||
ds = rootNode.database;
|
||||
}
|
||||
|
||||
// add support for anonymous resources such as Internet Search results,
|
||||
// IE favorites under Win32, and NetPositive URLs under BeOS
|
||||
var rdf_uri = "@mozilla.org/rdf/rdf-service;1";
|
||||
var rdf = Components.classes[rdf_uri].getService();
|
||||
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
if (rdf && ds)
|
||||
{
|
||||
var src = rdf.GetResource(url, true);
|
||||
var prop = rdf.GetResource(NC_NS + "URL",
|
||||
true);
|
||||
var target = ds.GetTarget(src, prop, true);
|
||||
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (target) target = target.Value;
|
||||
if (target) url = target;
|
||||
}
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function OpenURL(event, node, root)
|
||||
{
|
||||
if ((event.button != 0) || (event.detail != 2)
|
||||
|| (node.nodeName != "treeitem"))
|
||||
return false;
|
||||
|
||||
if (node.getAttribute("container") == "true")
|
||||
return false;
|
||||
|
||||
var url = getAbsoluteID(root, node);
|
||||
|
||||
// Ignore "NC:" urls.
|
||||
if (url.substring(0, 3) == "NC:")
|
||||
return false;
|
||||
|
||||
if (event.altKey)
|
||||
{
|
||||
BookmarkProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
// get right sized window
|
||||
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
|
||||
function doContextCmd(cmdName)
|
||||
{
|
||||
// Do some prompting/confirmation for various bookmark
|
||||
// commands that we know about.
|
||||
// If we have values to pass it, they are added to the arguments array
|
||||
|
||||
var nameVal = "";
|
||||
var urlVal = "";
|
||||
var promptStr;
|
||||
|
||||
var picker_uri;
|
||||
var filePicker;
|
||||
|
||||
if (cmdName == NC_NS + "command?cmd=newbookmark")
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
promptStr = get_localized_string("NewBookmarkURLPrompt");
|
||||
urlVal = prompt(promptStr, "");
|
||||
if (!urlVal || urlVal=="") return false;
|
||||
|
||||
// ensure we get a fully qualified URL (protocol colon address)
|
||||
var colonOffset = urlVal.indexOf(":");
|
||||
if (colonOffset > 0) break;
|
||||
alert(get_localized_string("NeedValidURL"));
|
||||
}
|
||||
|
||||
promptStr = get_localized_string("NewBookmarkNamePrompt");
|
||||
nameVal = prompt(promptStr, "");
|
||||
if (!nameVal || nameVal=="") return false;
|
||||
}
|
||||
else if (cmdName == NC_NS + "command?cmd=newfolder")
|
||||
{
|
||||
promptStr = get_localized_string("NewFolderNamePrompt");
|
||||
nameVal = prompt(promptStr, "");
|
||||
if (!nameVal || nameVal=="") return false;
|
||||
}
|
||||
else if ((cmdName == NC_NS + "command?cmd=deletebookmark") ||
|
||||
(cmdName == NC_NS + "command?cmd=deletebookmarkfolder") ||
|
||||
(cmdName == NC_NS + "command?cmd=deletebookmarkseparator"))
|
||||
{
|
||||
return doDelete(true);
|
||||
//var promptStr = get_localized_string("DeleteItems");
|
||||
//if (!confirm(promptStr)) return false;
|
||||
}
|
||||
else if (cmdName == NC_NS + "command?cmd=import")
|
||||
{
|
||||
try
|
||||
{
|
||||
picker_uri = "@mozilla.org/filepicker;1";
|
||||
filePicker = Components.classes[picker_uri].createInstance(nsIFilePicker);
|
||||
if (!filePicker) return false;
|
||||
|
||||
promptStr = get_localized_string("SelectImport");
|
||||
filePicker.init(window, promptStr, nsIFilePicker.modeOpen);
|
||||
filePicker.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll);
|
||||
if (filePicker.show() != nsIFilePicker.returnCancel)
|
||||
var filename = filePicker.fileURL.spec;
|
||||
if ((!filename) || (filename == "")) return false;
|
||||
|
||||
urlVal = filename;
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (cmdName == NC_NS + "command?cmd=export")
|
||||
{
|
||||
try
|
||||
{
|
||||
picker_uri = "@mozilla.org/filepicker;1";
|
||||
filePicker = Components.classes[picker_uri].createInstance(nsIFilePicker);
|
||||
if (!filePicker) return false;
|
||||
|
||||
promptStr = get_localized_string("EnterExport");
|
||||
filePicker.init(window, promptStr, nsIFilePicker.modeSave);
|
||||
filePicker.defaultString = "bookmarks.html";
|
||||
filePicker.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll);
|
||||
if (filePicker.show() != nsIFilePicker.returnCancel &&
|
||||
filePicker.fileURL.spec &&
|
||||
filePicker.fileURL.spec.length > 0) {
|
||||
urlVal = filePicker.fileURL.spec;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var treeNode = document.getElementById("bookmarksTree");
|
||||
if (!treeNode) return false;
|
||||
var db = treeNode.database;
|
||||
if (!db) return false;
|
||||
|
||||
var compositeDB = db.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
if (!compositeDB) return false;
|
||||
|
||||
var isupports_uri = "@mozilla.org/rdf/rdf-service;1";
|
||||
var isupports = Components.classes[isupports_uri].getService();
|
||||
if (!isupports) return false;
|
||||
var rdf = isupports.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
if (!rdf) return false;
|
||||
|
||||
// need a resource for the command
|
||||
var cmdResource = rdf.GetResource(cmdName);
|
||||
if (!cmdResource) return false;
|
||||
cmdResource = cmdResource.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
if (!cmdResource) return false;
|
||||
|
||||
// set up selection nsISupportsArray
|
||||
var selection_uri = "@mozilla.org/supports-array;1";
|
||||
var selectionInstance = Components.classes[selection_uri].createInstance();
|
||||
var selectionArray = selectionInstance.QueryInterface(Components.interfaces.nsISupportsArray);
|
||||
|
||||
// set up arguments nsISupportsArray
|
||||
var arguments_uri = "@mozilla.org/supports-array;1";
|
||||
var argumentsInstance = Components.classes[arguments_uri].createInstance();
|
||||
var argumentsArray = argumentsInstance.QueryInterface(Components.interfaces.nsISupportsArray);
|
||||
|
||||
// get various arguments (parent, name)
|
||||
var parentArc = rdf.GetResource(NC_NS + "parent");
|
||||
if (!parentArc) return false;
|
||||
var nameArc = rdf.GetResource(NC_NS + "Name");
|
||||
if (!nameArc) return false;
|
||||
var urlArc = rdf.GetResource(NC_NS + "URL");
|
||||
if (!urlArc) return false;
|
||||
|
||||
var select_list = treeNode.selectedItems;
|
||||
|
||||
var uri;
|
||||
var rdfNode;
|
||||
|
||||
if (select_list.length < 1)
|
||||
{
|
||||
// if nothing is selected, default to using the "ref"
|
||||
// on the root of the tree
|
||||
uri = treeNode.getAttribute("ref");
|
||||
if (!uri || uri=="") return false;
|
||||
rdfNode = rdf.GetResource(uri);
|
||||
// add node into selection array
|
||||
if (rdfNode)
|
||||
{
|
||||
selectionArray.AppendElement(rdfNode);
|
||||
}
|
||||
|
||||
// add singular arguments into arguments array
|
||||
if ((nameVal) && (nameVal != ""))
|
||||
{
|
||||
var nameLiteral = rdf.GetLiteral(nameVal);
|
||||
if (!nameLiteral) return false;
|
||||
argumentsArray.AppendElement(nameArc);
|
||||
argumentsArray.AppendElement(nameLiteral);
|
||||
}
|
||||
if ((urlVal) && (urlVal != ""))
|
||||
{
|
||||
var urlLiteral = rdf.GetLiteral(urlVal);
|
||||
if (!urlLiteral) return false;
|
||||
argumentsArray.AppendElement(urlArc);
|
||||
argumentsArray.AppendElement(urlLiteral);
|
||||
}
|
||||
}
|
||||
else for (var nodeIndex=0; nodeIndex<select_list.length; nodeIndex++)
|
||||
{
|
||||
var node = select_list[nodeIndex];
|
||||
if (!node) break;
|
||||
uri = node.getAttribute("ref");
|
||||
if ((uri) || (uri == ""))
|
||||
{
|
||||
uri = node.getAttribute("id");
|
||||
}
|
||||
if (!uri) return false;
|
||||
|
||||
rdfNode = rdf.GetResource(uri);
|
||||
if (!rdfNode) break;
|
||||
|
||||
// add node into selection array
|
||||
selectionArray.AppendElement(rdfNode);
|
||||
|
||||
// get the parent's URI
|
||||
var parentURI = "";
|
||||
var theParent = node.parentNode.parentNode;
|
||||
parentURI = theParent.getAttribute("ref");
|
||||
if ((!parentURI) || (parentURI == ""))
|
||||
{
|
||||
parentURI = theParent.getAttribute("id");
|
||||
}
|
||||
if (parentURI == "") return false;
|
||||
|
||||
var parentNode = rdf.GetResource(parentURI, true);
|
||||
if (!parentNode) return false;
|
||||
|
||||
// add multiple arguments into arguments array
|
||||
argumentsArray.AppendElement(parentArc);
|
||||
argumentsArray.AppendElement(parentNode);
|
||||
|
||||
if ((nameVal) && (nameVal != ""))
|
||||
{
|
||||
var nameLiteral2 = rdf.GetLiteral(nameVal);
|
||||
if (!nameLiteral2) return false;
|
||||
argumentsArray.AppendElement(nameArc);
|
||||
argumentsArray.AppendElement(nameLiteral2);
|
||||
}
|
||||
if ((urlVal) && (urlVal != ""))
|
||||
{
|
||||
var urlLiteral2 = rdf.GetLiteral(urlVal);
|
||||
if (!urlLiteral2) return false;
|
||||
argumentsArray.AppendElement(urlArc);
|
||||
argumentsArray.AppendElement(urlLiteral2);
|
||||
}
|
||||
}
|
||||
|
||||
// do the command
|
||||
compositeDB.DoCommand(selectionArray, cmdResource, argumentsArray);
|
||||
return true;
|
||||
}
|
||||
|
||||
function bookmarkSelect()
|
||||
{
|
||||
var tree = document.getElementById("bookmarksTree");
|
||||
var status = document.getElementById("statusbar-text");
|
||||
var val = "";
|
||||
if (tree.selectedItems.length == 1)
|
||||
{
|
||||
val = getAbsoluteID("bookmarksTree", tree.selectedItems[0]);
|
||||
|
||||
// Ignore "NC:" urls.
|
||||
if (val.substring(0, 3) == "NC:")
|
||||
{
|
||||
val = "";
|
||||
}
|
||||
}
|
||||
status.label = val;
|
||||
return true;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
bookmarks-tree, bookmarks-tree[type="multi-column"]
|
||||
{
|
||||
-moz-binding : url("chrome://communicator/content/bookmarks/bookmarks.xml#bookmarks-tree-full");
|
||||
}
|
||||
|
||||
bookmarks-tree[type="single-column"]
|
||||
{
|
||||
-moz-binding : url("chrome://communicator/content/bookmarks/bookmarks.xml#bookmarks-tree-name");
|
||||
}
|
||||
|
||||
bookmarks-tree[type="folders"]
|
||||
{
|
||||
-moz-binding : url("chrome://communicator/content/bookmarks/bookmarks.xml#bookmarks-tree-folders");
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author, v3.0)
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Initialize the command controllers, set focus, tree root,
|
||||
// window title state, etc.
|
||||
function Startup()
|
||||
{
|
||||
const windowNode = document.getElementById("bookmark-window");
|
||||
const bookmarksView = document.getElementById("bookmarks-view");
|
||||
var titleString;
|
||||
|
||||
// If we've been opened with a parameter, root the tree on it.
|
||||
if ("arguments" in window && window.arguments[0]) {
|
||||
var title;
|
||||
var uri = window.arguments[0];
|
||||
bookmarksView.tree.setAttribute("ref", uri);
|
||||
if (uri.substring(0,5) == "find:") {
|
||||
title = bookmarksView._bundle.GetStringFromName("search_results_title");
|
||||
// Update the windowtype so that future searches are directed
|
||||
// there and the window is not re-used for bookmarks.
|
||||
windowNode.setAttribute("windowtype", "bookmarks:searchresults");
|
||||
}
|
||||
else {
|
||||
const krNameArc = bookmarksView.rdf.GetResource(NC_NS + "Name");
|
||||
const krRoot = bookmarksView.rdf.GetResource(window.arguments[0]);
|
||||
var rName = bookmarksView.db.GetTarget(krRoot, krNameArc, true);
|
||||
title = rName.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
}
|
||||
titleString = bookmarksView._bundle.GetStringFromName("window_title");
|
||||
titleString = titleString.replace(/%folder_name%/gi, title);
|
||||
windowNode.setAttribute("title", titleString);
|
||||
}
|
||||
else {
|
||||
const kProfileContractID = "@mozilla.org/profile/manager;1";
|
||||
const kProfileIID = Components.interfaces.nsIProfile;
|
||||
const kProfile = Components.classes[kProfileContractID].getService(kProfileIID);
|
||||
var length = {value:0};
|
||||
var profileList = kProfile.getProfileList(length);
|
||||
// unset the default BM title if the user has more than one profile
|
||||
// or if he/she has changed the name of the default one.
|
||||
// the profile "default" is not localizable.
|
||||
if (length.value > 1 || kProfile.currentProfile.toLowerCase() != "default") {
|
||||
titleString = bookmarksView._bundle.GetStringFromName("bookmarks_root");
|
||||
titleString = titleString.replace(/%user_name%/, kProfile.currentProfile);
|
||||
windowNode.setAttribute("title", titleString);
|
||||
}
|
||||
}
|
||||
|
||||
bookmarksView.treeBoxObject.selection.select(0);
|
||||
bookmarksView.tree.focus();
|
||||
}
|
||||
|
||||
function Shutdown ()
|
||||
{
|
||||
// Store current window position and size in window attributes (for persistence).
|
||||
var win = document.getElementById("bookmark-window");
|
||||
win.setAttribute("x", screenX);
|
||||
win.setAttribute("y", screenY);
|
||||
win.setAttribute("height", outerHeight);
|
||||
win.setAttribute("width", outerWidth);
|
||||
|
||||
var bookmarksView = document.getElementById("bookmarks-view");
|
||||
bookmarksView.flushBMDatasource();
|
||||
}
|
||||
|
||||
var gConstructedViewMenuSortItems = false;
|
||||
function fillViewMenu(aEvent)
|
||||
{
|
||||
var adjacentElement = document.getElementById("fill-before-this-node");
|
||||
var popupElement = aEvent.target;
|
||||
|
||||
var bookmarksView = document.getElementById("bookmarks-view");
|
||||
var columns = bookmarksView.columns;
|
||||
|
||||
if (!gConstructedViewMenuSortItems) {
|
||||
for (var i = 0; i < columns.length; ++i) {
|
||||
var name = columns[i].name;
|
||||
var accesskey = columns[i].accesskey;
|
||||
|
||||
var menuitem = document.createElement("menuitem");
|
||||
var nameTemplate = bookmarksView._bundle.GetStringFromName("SortMenuItem");
|
||||
name = nameTemplate.replace(/%NAME%/g, columns[i].label);
|
||||
menuitem.setAttribute("label", name);
|
||||
menuitem.setAttribute("accesskey", columns[i].accesskey);
|
||||
menuitem.setAttribute("resource", columns[i].resource);
|
||||
menuitem.setAttribute("id", "sortMenuItem:" + columns[i].resource);
|
||||
menuitem.setAttribute("checked", columns[i].sortActive);
|
||||
menuitem.setAttribute("name", "sortSet");
|
||||
menuitem.setAttribute("type", "radio");
|
||||
|
||||
popupElement.insertBefore(menuitem, adjacentElement);
|
||||
}
|
||||
|
||||
gConstructedViewMenuSortItems = true;
|
||||
}
|
||||
|
||||
const kPrefSvcContractID = "@mozilla.org/preferences;1";
|
||||
const kPrefSvcIID = Components.interfaces.nsIPrefService;
|
||||
var prefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
|
||||
var bookmarksSortPrefs = prefSvc.getBranch("browser.bookmarks.sort.");
|
||||
|
||||
if (gConstructedViewMenuSortItems) {
|
||||
var resource = bookmarksSortPrefs.getCharPref("resource");
|
||||
var element = document.getElementById("sortMenuItem:" + resource);
|
||||
if (element)
|
||||
element.setAttribute("checked", "true");
|
||||
}
|
||||
|
||||
var sortAscendingMenu = document.getElementById("ascending");
|
||||
var sortDescendingMenu = document.getElementById("descending");
|
||||
var noSortMenu = document.getElementById("natural");
|
||||
|
||||
sortAscendingMenu.setAttribute("checked", "false");
|
||||
sortDescendingMenu.setAttribute("checked", "false");
|
||||
noSortMenu.setAttribute("checked", "false");
|
||||
var direction = bookmarksSortPrefs.getCharPref("direction");
|
||||
if (direction == "natural")
|
||||
sortAscendingMenu.setAttribute("checked", "true");
|
||||
else if (direction == "ascending")
|
||||
sortDescendingMenu.setAttribute("checked", "true");
|
||||
else
|
||||
noSortMenu.setAttribute("checked", "true");
|
||||
}
|
||||
|
||||
function onViewMenuSortItemSelected(aEvent)
|
||||
{
|
||||
var resource = aEvent.target.getAttribute("resource");
|
||||
|
||||
const kPrefSvcContractID = "@mozilla.org/preferences;1";
|
||||
const kPrefSvcIID = Components.interfaces.nsIPrefService;
|
||||
var prefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
|
||||
var bookmarksSortPrefs = prefSvc.getBranch("browser.bookmarks.sort.");
|
||||
|
||||
switch (resource) {
|
||||
case "":
|
||||
break;
|
||||
case "direction":
|
||||
var dirn = bookmarksSortPrefs.getCharPref("direction");
|
||||
if (aEvent.target.id == "ascending")
|
||||
bookmarksSortPrefs.setCharPref("direction", "natural");
|
||||
else if (aEvent.target.id == "descending")
|
||||
bookmarksSortPrefs.setCharPref("direction", "ascending");
|
||||
else
|
||||
bookmarksSortPrefs.setCharPref("direction", "descending");
|
||||
break;
|
||||
default:
|
||||
bookmarksSortPrefs.setCharPref("resource", resource);
|
||||
var direction = bookmarksSortPrefs.getCharPref("direction");
|
||||
if (direction == "descending")
|
||||
bookmarksSortPrefs.setCharPref("direction", "natural");
|
||||
break;
|
||||
}
|
||||
|
||||
aEvent.preventCapture();
|
||||
}
|
||||
|
||||
var gConstructedColumnsMenuItems = false;
|
||||
function fillColumnsMenu(aEvent)
|
||||
{
|
||||
var bookmarksView = document.getElementById("bookmarks-view");
|
||||
var columns = bookmarksView.columns;
|
||||
var i;
|
||||
|
||||
if (!gConstructedColumnsMenuItems) {
|
||||
for (i = 0; i < columns.length; ++i) {
|
||||
var menuitem = document.createElement("menuitem");
|
||||
menuitem.setAttribute("label", columns[i].label);
|
||||
menuitem.setAttribute("resource", columns[i].resource);
|
||||
menuitem.setAttribute("id", "columnMenuItem:" + columns[i].resource);
|
||||
menuitem.setAttribute("type", "checkbox");
|
||||
menuitem.setAttribute("checked", columns[i].hidden != "true");
|
||||
aEvent.target.appendChild(menuitem);
|
||||
}
|
||||
|
||||
gConstructedColumnsMenuItems = true;
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < columns.length; ++i) {
|
||||
var element = document.getElementById("columnMenuItem:" + columns[i].resource);
|
||||
if (element && columns[i].hidden != "true")
|
||||
element.setAttribute("checked", "true");
|
||||
}
|
||||
}
|
||||
|
||||
aEvent.preventBubble();
|
||||
}
|
||||
|
||||
function onViewMenuColumnItemSelected(aEvent)
|
||||
{
|
||||
var resource = aEvent.target.getAttribute("resource");
|
||||
if (resource != "") {
|
||||
var bookmarksView = document.getElementById("bookmarks-view");
|
||||
bookmarksView.toggleColumnVisibility(resource);
|
||||
}
|
||||
|
||||
aEvent.preventBubble();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,252 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- -*- Mode: HTML; indent-tabs-mode: nil; -*- -->
|
||||
<!--
|
||||
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com>
|
||||
Blake Ross <blakeross@telocity.com>
|
||||
Dean Tessman <dean_tessman@hotmail.com>
|
||||
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://communicator/skin/bookmarks/bookmarksWindow.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://communicator/content/bookmarks/bookmarks.css" type="text/css"?>
|
||||
<?xul-overlay href="chrome://global/content/globalOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://communicator/content/bookmarks/bookmarksOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://communicator/content/utilityOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://communicator/content/tasksOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://communicator/content/communicatorOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % utilDTD SYSTEM "chrome://communicator/locale/utilityOverlay.dtd" >
|
||||
%utilDTD;
|
||||
<!ENTITY % bmDTD SYSTEM "chrome://communicator/locale/bookmarks/bookmarks.dtd">
|
||||
%bmDTD;
|
||||
]>
|
||||
|
||||
<window id="bookmark-window" windowtype="bookmarks:manager"
|
||||
title="&bookmarksWindowTitle.label;"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:web="http://home.netscape.com/WEB-rdf#"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
width="630" height="400" screenX="20" screenY="20"
|
||||
persist="width height screenX screenY sizemode"
|
||||
onload="Startup();" onunload="Shutdown();">
|
||||
|
||||
<!-- The order of loading of these script files is IMPORTANT -->
|
||||
|
||||
<!-- Shared Libraries -->
|
||||
<script type="application/x-javascript" src="chrome://global/content/strres.js"></script>
|
||||
|
||||
<!-- XXX - This should SO become an XBL widget -->
|
||||
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"></script>
|
||||
|
||||
<!-- Shared Bookmarks Utility Library -->
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksOverlay.js"/>
|
||||
<!-- Tree-based Bookmarks UI Utility Library -->
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksTree.js"/>
|
||||
<!-- Bookmarks Window -->
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarks.js"/>
|
||||
|
||||
<!-- Bookmarks Window Drag & Drop -->
|
||||
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
<script type="application/x-javascript" src="chrome://global/content/nsTransferable.js"/>
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksDD.js"/>
|
||||
|
||||
<popupset id="bookmarksPopupset"/>
|
||||
|
||||
<commands id="commands">
|
||||
<commandset id="CommandUpdate_Bookmarks"
|
||||
commandupdater="true"
|
||||
events="focus,tree-select"
|
||||
oncommandupdate="document.getElementById('bookmarks-view').onCommandUpdate();">
|
||||
</commandset>
|
||||
|
||||
<commandset id="tasksCommands"/>
|
||||
|
||||
<!-- File Menu -->
|
||||
<command id="cmd_close" oncommand="close()"/>
|
||||
<command id="cmd_quit"/>
|
||||
<!-- Edit Menu -->
|
||||
<command id="cmd_undo"/>
|
||||
</commands>
|
||||
|
||||
<stringbundleset id="stringbundleset"/>
|
||||
|
||||
<keyset id="tasksKeys">
|
||||
<!-- File Menu -->
|
||||
<key id="key_close"/>
|
||||
<key id="key_quit"/>
|
||||
<!-- Edit Menu -->
|
||||
<key id="key_undo"/>
|
||||
|
||||
<!-- These keybindings do not have a command specified in the overlay,
|
||||
which is good, but we need to specify it ourselves here -->
|
||||
<key id="key_cut" command="cmd_bm_cut"/>
|
||||
<key id="key_copy" command="cmd_bm_copy"/>
|
||||
<key id="key_paste" command="cmd_bm_paste"/>
|
||||
<key id="key_selectAll" command="cmd_bm_selectAll"/>
|
||||
|
||||
<!-- We need to provide our own delete key binding because the key_delete
|
||||
handler in platformGlobalOverlay.xul maps command to "cmd_delete" which
|
||||
is NOT what we want! -->
|
||||
<key id="key_bm_delete" keycode="VK_DELETE" command="cmd_bm_delete"/>
|
||||
|
||||
<key id="bm_key_find"
|
||||
key="&edit.find.keybinding;"
|
||||
command="cmd_bm_find" modifiers="accel"/>
|
||||
<key id="bm_key_properties"
|
||||
key="&edit.properties.keybinding;"
|
||||
command="cmd_bm_properties" modifiers="accel"/>
|
||||
</keyset>
|
||||
|
||||
<toolbox id="bookmarks-toolbox">
|
||||
<menubar id="main-menubar" grippytooltiptext="&menuBar.tooltip;">
|
||||
<menu id="menu_File">
|
||||
<menupopup id="menu_FilePopup">
|
||||
<menu id="menu_New">
|
||||
<menupopup>
|
||||
<menuitem label="&menuitem.newBookmark.label;"
|
||||
accesskey="&command.newBookmark.accesskey;"
|
||||
observes="cmd_bm_newbookmark"/>
|
||||
<menuitem label="&menuitem.newFolder.label;"
|
||||
accesskey="&command.newFolder.accesskey;"
|
||||
observes="cmd_bm_newfolder"/>
|
||||
<menuitem label="&menuitem.newSeparator.label;"
|
||||
accesskey="&command.newSeparator.accesskey;"
|
||||
observes="cmd_bm_newseparator"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menuitem id="menu_close"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="menu_Edit">
|
||||
<menupopup>
|
||||
<menuitem id="menu_undo" disabled="true"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="menu_bm_cut"
|
||||
label="&cutCmd.label;" accesskey="&cutCmd.accesskey;"
|
||||
key="key_cut" command="cmd_bm_cut"/>
|
||||
<menuitem id="menu_bm_copy"
|
||||
label="©Cmd.label;" accesskey="©Cmd.accesskey;"
|
||||
key="key_copy" command="cmd_bm_copy"/>
|
||||
<menuitem id="menu_bm_paste"
|
||||
label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;"
|
||||
key="key_paste" command="cmd_bm_paste"/>
|
||||
<menuitem id="menu_bm_delete"
|
||||
label="&deleteCmd.label;" accesskey="&deleteCmd.label;"
|
||||
key="key_bm_delete" command="cmd_bm_delete"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="menu_bm_selectAll"
|
||||
label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;"
|
||||
key="key_selectAll" command="cmd_bm_selectAll"/>
|
||||
<menuseparator/>
|
||||
<menuitem label="&command.fileBookmark.label;"
|
||||
accesskey="&command.fileBookmark.accesskey;"
|
||||
command="cmd_bm_fileBookmark"/>
|
||||
<menuseparator/>
|
||||
<menuitem observes="cmd_bm_properties" key="bm_key_properties"
|
||||
label="&command.properties.label;"
|
||||
accesskey="&command.properties.accesskey;" />
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
<menu id="menu_View">
|
||||
<menupopup onpopupshowing="fillViewMenu(event)"
|
||||
oncommand="onViewMenuSortItemSelected(event);">
|
||||
<menuitem id="viewCommandToolbar" type="checkbox" class="menuitem-iconic"
|
||||
label="&menuitem.view.command.toolbar.label;"
|
||||
accesskey="&menuitem.view.command.toolbar.accesskey;"
|
||||
oncommand="goToggleToolbar('command-toolbar', 'viewCommandToolbar'); event.preventBubble();"
|
||||
persist="checked"/>
|
||||
<menuseparator id="fill-after-this-node"/>
|
||||
<menuitem id="natural" label="&menuitem.view.unsorted.label;"
|
||||
accesskey="&menuitem.view.unsorted.accesskey;"
|
||||
type="radio"
|
||||
resource="direction" name="sortSet"/>
|
||||
<menuseparator id="fill-before-this-node"/>
|
||||
<menuitem id="ascending" label="&menuitem.view.ascending.label;"
|
||||
accesskey="&menuitem.view.ascending.accesskey;"
|
||||
type="radio"
|
||||
resource="direction" name="sortDirectionSet"/>
|
||||
<menuitem id="descending" label="&menuitem.view.descending.label;"
|
||||
accesskey="&menuitem.view.descending.accesskey;"
|
||||
type="radio"
|
||||
resource="direction" name="sortDirectionSet"/>
|
||||
<menuseparator/>
|
||||
<menu id="descending" label="&menuitem.view.show_columns.label;"
|
||||
accesskey="&menuitem.view.show_columns.accesskey;">
|
||||
<menupopup id="columnsPopup" onpopupshowing="fillColumnsMenu(event);"
|
||||
oncommand="onViewMenuColumnItemSelected(event);"/>
|
||||
</menu>
|
||||
<menuseparator/>
|
||||
<menuitem label="&menuitem.newbookmarkfolder.label;"
|
||||
command="cmd_bm_setnewbookmarkfolder"
|
||||
accesskey="&menuitem.newbookmarkfolder.accesskey;"/>
|
||||
<menuitem label="&menuitem.newinternetsearchfolder.label;"
|
||||
command="cmd_bm_setnewsearchfolder"
|
||||
accesskey="&menuitem.newinternetsearchfolder.accesskey;"/>
|
||||
<menuitem label="&menuitem.personaltoolbarfolder.label;"
|
||||
command="cmd_bm_setpersonaltoolbarfolder"
|
||||
accesskey="&menuitem.personaltoolbarfolder.accesskey;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="tasksMenu">
|
||||
<menupopup id="taskPopup">
|
||||
<menuitem command="cmd_bm_find" key="bm_key_find"
|
||||
label="&menuitem.find.label;"
|
||||
accesskey="&menuitem.find.accesskey;"/>
|
||||
<menuitem label="&menuitem.import.label;"
|
||||
accesskey="&menuitem.import.accesskey;"
|
||||
observes="cmd_bm_import"/>
|
||||
<menuitem label="&menuitem.export.label;"
|
||||
accesskey="&menuitem.export.accesskey;"
|
||||
observes="cmd_bm_export"/>
|
||||
<menuseparator/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="windowMenu"/>
|
||||
<menu id="menu_Help"/>
|
||||
</menubar>
|
||||
|
||||
<toolbar id="command-toolbar" tbalign="stretch" grippytooltiptext="&bookmarkToolbar.tooltip;">
|
||||
<toolbarbutton id="newfolder" label="&button.newFolder.label;"
|
||||
command="cmd_bm_newfolder"/>
|
||||
<toolbarbutton id="newseparator" label="&button.newSeparator.label;"
|
||||
command="cmd_bm_newseparator"/>
|
||||
<toolbarseparator/>
|
||||
<toolbarbutton id="fileBookmark" label="&command.fileBookmark.label;"
|
||||
command="cmd_bm_fileBookmark"/>
|
||||
<toolbarseparator/>
|
||||
<toolbarbutton id="properties" label="&command.properties.label;"
|
||||
command="cmd_bm_properties"/>
|
||||
<toolbarbutton id="rename" label="&command.rename.label;"
|
||||
command="cmd_bm_rename"/>
|
||||
<toolbarbutton id="delete" label="&command.delete.label;"
|
||||
command="cmd_bm_delete"/>
|
||||
</toolbar>
|
||||
</toolbox>
|
||||
|
||||
<bookmarks-tree id="bookmarks-view" flex="1"/>
|
||||
|
||||
</window>
|
||||
|
||||
@@ -1,508 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
This is the old bookmarks code, included here for the sake of the bookmarks sidebar panel,
|
||||
which will be fixed to use my new code in .9. In the mean time, this file provides a
|
||||
life line to various functionality.
|
||||
*/
|
||||
|
||||
|
||||
var NC_NS = "http://home.netscape.com/NC-rdf#";
|
||||
var RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||
|
||||
|
||||
|
||||
function TopLevelDrag ( event )
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
function BeginDragTree ( event )
|
||||
{
|
||||
//XXX we rely on a capturer to already have determined which item the mouse was over
|
||||
//XXX and have set an attribute.
|
||||
|
||||
// if the click is on the tree proper, ignore it. We only care about clicks on items.
|
||||
|
||||
var tree = document.getElementById("bookmarksTree");
|
||||
if ( event.target == tree || event.target.localName == "treechildren" )
|
||||
return(true); // continue propagating the event
|
||||
|
||||
var childWithDatabase = tree;
|
||||
if ( ! childWithDatabase )
|
||||
return(false);
|
||||
|
||||
var dragStarted = false;
|
||||
|
||||
var trans =
|
||||
Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
|
||||
if ( !trans ) return(false);
|
||||
|
||||
var genData =
|
||||
Components.classes["@mozilla.org/supports-wstring;1"].createInstance(Components.interfaces.nsISupportsWString);
|
||||
if (!genData) return(false);
|
||||
|
||||
var genDataURL =
|
||||
Components.classes["@mozilla.org/supports-wstring;1"].createInstance(Components.interfaces.nsISupportsWString);
|
||||
if (!genDataURL) return(false);
|
||||
|
||||
trans.addDataFlavor("text/unicode");
|
||||
trans.addDataFlavor("moz/rdfitem");
|
||||
|
||||
// ref/id (url) is on the <treeitem> which is two levels above the <treecell> which is
|
||||
// the target of the event.
|
||||
var id = event.target.parentNode.parentNode.getAttribute("ref");
|
||||
if (!id || id=="")
|
||||
{
|
||||
id = event.target.parentNode.parentNode.getAttribute("id");
|
||||
}
|
||||
|
||||
var parentID = event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("ref");
|
||||
if (!parentID || parentID == "")
|
||||
{
|
||||
parentID = event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("id");
|
||||
}
|
||||
|
||||
var trueID = id;
|
||||
if (parentID != null)
|
||||
{
|
||||
trueID += "\n" + parentID;
|
||||
}
|
||||
genData.data = trueID;
|
||||
genDataURL.data = id;
|
||||
|
||||
var database = childWithDatabase.database;
|
||||
var rdf =
|
||||
Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
|
||||
if ((!rdf) || (!database)) { dump("CAN'T GET DATABASE\n"); return(false); }
|
||||
|
||||
// make sure its a bookmark, bookmark separator, or bookmark folder
|
||||
var src = rdf.GetResource(id, true);
|
||||
var prop = rdf.GetResource(RDF_NS + "type", true);
|
||||
var target = database.GetTarget(src, prop, true);
|
||||
|
||||
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
if (target) target = target.Value;
|
||||
if ((!target) || (target == "")) {dump("BAD\n"); return(false);}
|
||||
|
||||
if ((target != NC_NS + "BookmarkSeparator") &&
|
||||
(target != NC_NS + "Bookmark") &&
|
||||
(target != NC_NS + "Folder")) return(false);
|
||||
|
||||
trans.setTransferData ( "moz/rdfitem", genData, genData.data.length * 2); // double byte data
|
||||
trans.setTransferData ( "text/unicode", genDataURL, genDataURL.data.length * 2); // double byte data
|
||||
|
||||
var transArray =
|
||||
Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
|
||||
if ( !transArray ) return(false);
|
||||
|
||||
// put it into the transferable as an |nsISupports|
|
||||
var genTrans = trans.QueryInterface(Components.interfaces.nsISupports);
|
||||
transArray.AppendElement(genTrans);
|
||||
|
||||
var dragService =
|
||||
Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
|
||||
if ( !dragService ) return(false);
|
||||
|
||||
var nsIDragService = Components.interfaces.nsIDragService;
|
||||
dragService.invokeDragSession ( event.target, transArray, null, nsIDragService.DRAGDROP_ACTION_COPY +
|
||||
nsIDragService.DRAGDROP_ACTION_MOVE );
|
||||
dragStarted = true;
|
||||
|
||||
return(!dragStarted);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function DragOverTree ( event )
|
||||
{
|
||||
var validFlavor = false;
|
||||
var dragSession = null;
|
||||
var retVal = true;
|
||||
|
||||
var dragService =
|
||||
Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
|
||||
if ( !dragService ) return(false);
|
||||
|
||||
dragSession = dragService.getCurrentSession();
|
||||
if ( !dragSession ) return(false);
|
||||
|
||||
if ( dragSession.isDataFlavorSupported("moz/rdfitem") ) validFlavor = true;
|
||||
else if ( dragSession.isDataFlavorSupported("text/unicode") ) validFlavor = true;
|
||||
//XXX other flavors here...
|
||||
|
||||
// touch the attribute on the rowgroup to trigger the repaint with the drop feedback.
|
||||
if ( validFlavor )
|
||||
{
|
||||
var treeRoot = document.getElementById("bookmarksTree");
|
||||
if (!treeRoot) return(false);
|
||||
var treeDatabase = treeRoot.database;
|
||||
if (!treeDatabase) return(false);
|
||||
|
||||
//XXX this is really slow and likes to refresh N times per second.
|
||||
var rowGroup = event.target.parentNode.parentNode;
|
||||
var sortActive = treeRoot.getAttribute("sortActive");
|
||||
if (sortActive == "true")
|
||||
rowGroup.setAttribute ( "dd-triggerrepaintsorted", 0 );
|
||||
else
|
||||
rowGroup.setAttribute ( "dd-triggerrepaint", 0 );
|
||||
|
||||
dragSession.canDrop = true;
|
||||
// necessary??
|
||||
retVal = false;
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function DropOnTree ( event )
|
||||
{
|
||||
var treeRoot = document.getElementById("bookmarksTree");
|
||||
if (!treeRoot) return(false);
|
||||
var treeDatabase = treeRoot.database;
|
||||
if (!treeDatabase) return(false);
|
||||
|
||||
// for beta1, don't allow D&D if sorting is active
|
||||
var sortActive = treeRoot.getAttribute("sortActive");
|
||||
if (sortActive == "true")
|
||||
{
|
||||
dump("Sorry, drag&drop is currently disabled when sorting is active.\n");
|
||||
return(false);
|
||||
}
|
||||
|
||||
var RDF =
|
||||
Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
|
||||
if (!RDF) return(false);
|
||||
var RDFC =
|
||||
Components.classes["@mozilla.org/rdf/container;1"].getService(Components.interfaces.nsIRDFContainer);
|
||||
if (!RDFC) return(false);
|
||||
|
||||
var Bookmarks = RDF.GetDataSource("rdf:bookmarks");
|
||||
if (!Bookmarks) return(false);
|
||||
|
||||
// target is the <treecell>, and "ref/id" is on the <treeitem> two levels above
|
||||
var treeItem = event.target.parentNode.parentNode;
|
||||
if (!treeItem) return(false);
|
||||
|
||||
// get drop hint attributes
|
||||
var dropBefore = treeItem.getAttribute("dd-droplocation");
|
||||
var dropOn = treeItem.getAttribute("dd-dropon");
|
||||
|
||||
// calculate drop action
|
||||
var dropAction;
|
||||
if (dropBefore == "true") dropAction = "before";
|
||||
else if (dropOn == "true") dropAction = "on";
|
||||
else dropAction = "after";
|
||||
|
||||
// calculate parent container node
|
||||
var containerItem = treeItem;
|
||||
if (dropAction != "on")
|
||||
{
|
||||
containerItem = treeItem.parentNode.parentNode;
|
||||
}
|
||||
|
||||
// magical fix for bug # 33546: handle dropping after open container
|
||||
if (treeItem.getAttribute("container") == "true")
|
||||
{
|
||||
if (treeItem.getAttribute("open") == "true")
|
||||
{
|
||||
if (dropAction == "after")
|
||||
{
|
||||
dropAction = "before";
|
||||
containerItem = treeItem;
|
||||
|
||||
// find <treechildren>, drop before first child
|
||||
var treeChildren = treeItem;
|
||||
treeItem = null;
|
||||
for (var x = 0; x < treeChildren.childNodes.length; x++)
|
||||
{
|
||||
if (treeChildren.childNodes[x].tagName == "treechildren")
|
||||
{
|
||||
treeItem = treeChildren.childNodes[x].childNodes[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!treeItem)
|
||||
{
|
||||
dropAction = "on";
|
||||
containerItem = treeItem.parentNode.parentNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var targetID = getAbsoluteID("bookmarksTree", treeItem);
|
||||
if (!targetID) return(false);
|
||||
var targetNode = RDF.GetResource(targetID, true);
|
||||
if (!targetNode) return(false);
|
||||
|
||||
var containerID = getAbsoluteID("bookmarksTree", containerItem);
|
||||
if (!containerID) return(false);
|
||||
var containerNode = RDF.GetResource(containerID);
|
||||
if (!containerNode) return(false);
|
||||
|
||||
var dragService =
|
||||
Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
|
||||
if ( !dragService ) return(false);
|
||||
|
||||
var dragSession = dragService.getCurrentSession();
|
||||
if ( !dragSession ) return(false);
|
||||
|
||||
var trans =
|
||||
Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
|
||||
if ( !trans ) return(false);
|
||||
trans.addDataFlavor("moz/rdfitem");
|
||||
trans.addDataFlavor("text/x-moz-url");
|
||||
trans.addDataFlavor("text/unicode");
|
||||
|
||||
var typeRes = RDF.GetResource(RDF_NS + "type");
|
||||
if (!typeRes) return false;
|
||||
var bmTypeRes = RDF.GetResource(NC_NS + "Bookmark");
|
||||
if (!bmTypeRes) return false;
|
||||
|
||||
var dirty = false;
|
||||
|
||||
for ( var i = 0; i < dragSession.numDropItems; ++i )
|
||||
{
|
||||
dragSession.getData ( trans, i );
|
||||
var dataObj = new Object();
|
||||
var bestFlavor = new Object();
|
||||
var len = new Object();
|
||||
trans.getAnyTransferData ( bestFlavor, dataObj, len );
|
||||
if ( dataObj ) dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsWString);
|
||||
if ( !dataObj ) continue;
|
||||
|
||||
var sourceID = null;
|
||||
var parentID = null;
|
||||
var checkNameHack = false;
|
||||
var name=null;
|
||||
|
||||
if (bestFlavor.value == "moz/rdfitem")
|
||||
{
|
||||
// pull the URL out of the data object
|
||||
var data = dataObj.data.substring(0, len.value / 2);
|
||||
|
||||
// moz/rdfitem allows parent ID specified on next line; check for it
|
||||
var cr = data.indexOf("\n");
|
||||
if (cr >= 0)
|
||||
{
|
||||
sourceID = data.substr(0, cr);
|
||||
parentID = data.substr(cr+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceID = data;
|
||||
}
|
||||
}
|
||||
else if (bestFlavor.value == "text/x-moz-url")
|
||||
{
|
||||
// pull the URL out of the data object
|
||||
data = dataObj.data.substring(0, len.value / 2);
|
||||
sourceID = data;
|
||||
|
||||
// we may need to synthesize a name (just use the URL)
|
||||
checkNameHack = true;
|
||||
}
|
||||
else if (bestFlavor.value == "text/unicode")
|
||||
{
|
||||
sourceID = dataObj.data;
|
||||
|
||||
// we may need to synthesize a name (just use the URL)
|
||||
checkNameHack = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown flavor, skip
|
||||
continue;
|
||||
}
|
||||
|
||||
// pull the (optional) name out of the URL
|
||||
var separator = sourceID.indexOf("\n");
|
||||
if (separator >= 0)
|
||||
{
|
||||
name = sourceID.substr(separator+1);
|
||||
sourceID = sourceID.substr(0, separator);
|
||||
}
|
||||
|
||||
var sourceNode = RDF.GetResource(sourceID, true);
|
||||
if (!sourceNode) continue;
|
||||
|
||||
var parentNode = null;
|
||||
if (parentID != null)
|
||||
{
|
||||
parentNode = RDF.GetResource(parentID, true);
|
||||
}
|
||||
|
||||
// Prevent dropping of a node before, after, or on itself
|
||||
if (sourceNode == targetNode) continue;
|
||||
// Prevent dropping of a node onto its parent container
|
||||
if ((dropAction == "on") && (containerID) && (containerID == parentID)) continue;
|
||||
|
||||
RDFC.Init(Bookmarks, containerNode);
|
||||
|
||||
// make sure appropriate bookmark type is set
|
||||
var bmTypeNode = Bookmarks.GetTarget( sourceNode, typeRes, true );
|
||||
if (!bmTypeNode)
|
||||
{
|
||||
// set default bookmark type
|
||||
Bookmarks.Assert(sourceNode, typeRes, bmTypeRes, true);
|
||||
}
|
||||
|
||||
if ((dropAction == "before") || (dropAction == "after"))
|
||||
{
|
||||
// drop before or after
|
||||
var nodeIndex;
|
||||
|
||||
nodeIndex = RDFC.IndexOf(sourceNode);
|
||||
|
||||
if (nodeIndex >= 1)
|
||||
{
|
||||
// moving a node around inside of the container
|
||||
// so remove, then re-add the node
|
||||
RDFC.RemoveElementAt(nodeIndex, true, sourceNode);
|
||||
}
|
||||
|
||||
nodeIndex = RDFC.IndexOf(targetNode);
|
||||
|
||||
if (nodeIndex < 1) return(false);
|
||||
if (dropAction == "after") ++nodeIndex;
|
||||
|
||||
RDFC.InsertElementAt(sourceNode, nodeIndex, true);
|
||||
|
||||
// select the newly added node
|
||||
if (parentID)
|
||||
{
|
||||
selectDroppedItems(treeRoot, containerID, sourceID);
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// drop on
|
||||
RDFC.AppendElement(sourceNode);
|
||||
|
||||
// select the newly added node
|
||||
if (parentID)
|
||||
{
|
||||
selectDroppedItems(treeRoot, containerID, sourceID);
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if ((checkNameHack == true) || (name != null))
|
||||
{
|
||||
var srcArc = RDF.GetResource(sourceID, true);
|
||||
var propArc = RDF.GetResource(NC_NS + "Name", true);
|
||||
if (srcArc && propArc && Bookmarks)
|
||||
{
|
||||
var targetArc = Bookmarks.GetTarget(srcArc, propArc, true);
|
||||
if (!targetArc)
|
||||
{
|
||||
// if no name, fallback to using the URL as the name
|
||||
var defaultNameArc = RDF.GetLiteral((name != null && name != "") ? name : sourceID);
|
||||
if (defaultNameArc)
|
||||
{
|
||||
Bookmarks.Assert(srcArc, propArc, defaultNameArc, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// should we move the node? (i.e. take it out of the source container?)
|
||||
if ((parentNode != null) && (containerNode != parentNode))
|
||||
{
|
||||
try
|
||||
{
|
||||
RDFC.Init(Bookmarks, parentNode);
|
||||
nodeIndex = RDFC.IndexOf(sourceNode);
|
||||
|
||||
if (nodeIndex >= 1)
|
||||
{
|
||||
RDFC.RemoveElementAt(nodeIndex, true, sourceNode);
|
||||
}
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (dirty == true)
|
||||
{
|
||||
var remote = Bookmarks.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
if (remote)
|
||||
{
|
||||
remote.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function selectDroppedItems(treeRoot, containerID, targetID)
|
||||
{
|
||||
var select_list = treeRoot.getElementsByAttribute("id", targetID);
|
||||
for (var x=0; x<select_list.length; x++)
|
||||
{
|
||||
var node = select_list[x];
|
||||
if (!node) continue;
|
||||
|
||||
var parent = node.parentNode.parentNode;
|
||||
if (!parent) continue;
|
||||
|
||||
var id = parent.getAttribute("ref");
|
||||
if (!id || id=="")
|
||||
{
|
||||
id = parent.getAttribute("id");
|
||||
}
|
||||
if (!id || id=="") continue;
|
||||
|
||||
if (id == containerID)
|
||||
{
|
||||
treeRoot.selectItem(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,397 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author, v2.0)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var NC_NS = "http://home.netscape.com/NC-rdf#";
|
||||
var RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||
|
||||
var gSpringLoadTracker = {
|
||||
timeout: 0,
|
||||
element: null,
|
||||
|
||||
open: function (aRDFNode)
|
||||
{
|
||||
if (this.element)
|
||||
this.element.setAttribute("open", "true");
|
||||
clearTimeout(this.timeout);
|
||||
}
|
||||
};
|
||||
|
||||
var bookmarksDNDObserver = {
|
||||
_RDF: null,
|
||||
get RDF ()
|
||||
{
|
||||
if (!this._RDF) {
|
||||
const kRDFContractID = "@mozilla.org/rdf/rdf-service;1";
|
||||
const kRDFIID = Components.interfaces.nsIRDFService;
|
||||
this._RDF = Components.classes[kRDFContractID].getService(kRDFIID);
|
||||
}
|
||||
return this._RDF;
|
||||
},
|
||||
|
||||
// XXX I belong somewhere shared.
|
||||
getResource: function(aString)
|
||||
{
|
||||
return this.RDF.GetResource(aString, true);
|
||||
},
|
||||
|
||||
getTarget: function(aDS, aSourceID, aPropertyID)
|
||||
{
|
||||
var source = this.getResource(aSourceID);
|
||||
var property = this.getResource(aPropertyID);
|
||||
return aDS.GetTarget(source, property, true);
|
||||
},
|
||||
|
||||
onDragStart: function (aEvent, aXferData, aDragAction)
|
||||
{
|
||||
var bookmarksTree = document.getElementById("bookmarksTree");
|
||||
if (aEvent.target == bookmarksTree || aEvent.target.localName == "treechildren" ||
|
||||
aEvent.target.localName == "splitter" || aEvent.target.localName == "menu")
|
||||
throw Components.results.NS_OK; // not a draggable item.
|
||||
if (aEvent.target.parentNode && aEvent.target.parentNode.parentNode &&
|
||||
aEvent.target.parentNode.parentNode.localName == "treehead")
|
||||
throw Components.results.NS_OK; // don't drag treehead cells.
|
||||
if (bookmarksTree.getAttribute("sortActive") == "true")
|
||||
throw Components.results.NS_OK;
|
||||
|
||||
var selItems = null;
|
||||
if (bookmarksTree.selectedItems.length <= 0)
|
||||
selItems = [aEvent.target.parentNode.parentNode];
|
||||
else
|
||||
selItems = bookmarksTree.selectedItems;
|
||||
aXferData.data = new TransferDataSet();
|
||||
for (var i = 0; i < selItems.length; ++i) {
|
||||
var currItem = selItems[i];
|
||||
var currURI = NODE_ID(currItem);
|
||||
|
||||
var parentItem = currItem.parentNode.parentNode;
|
||||
var parentURI = NODE_ID(parentItem);
|
||||
|
||||
var type = this.getTarget(bookmarksTree.database, currURI, RDF_NS + "type");
|
||||
type = type.QueryInterface(Components.interfaces.nsIRDFResource).Value;
|
||||
if (!type || (type != (NC_NS + "BookmarkSeparator") &&
|
||||
type != (NC_NS + "Bookmark") &&
|
||||
type != (NC_NS + "Folder")))
|
||||
throw Components.results.NS_OK;
|
||||
var name = this.getTarget(bookmarksTree.database, currURI, NC_NS + "Name");
|
||||
var data = new TransferData();
|
||||
if (name) {
|
||||
name = name.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
data.addDataForFlavour("text/x-moz-url", currURI + "\n" + name);
|
||||
}
|
||||
else {
|
||||
data.addDataForFlavour("text/x-moz-url", currURI);
|
||||
}
|
||||
data.addDataForFlavour("moz/rdfitem", currURI + "\n" + parentURI);
|
||||
|
||||
data.addDataForFlavour("text/unicode", currURI);
|
||||
aXferData.data.push(data);
|
||||
}
|
||||
|
||||
if (aEvent.ctrlKey) {
|
||||
const kDSIID = Components.interfaces.nsIDragService;
|
||||
aDragAction.action = kDSIID.DRAGDROP_ACTION_COPY + kDSIID.DRAGDROP_ACTION_LINK;
|
||||
}
|
||||
},
|
||||
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
var bookmarksTree = document.getElementById("bookmarksTree");
|
||||
var rowGroup = aEvent.target.parentNode.parentNode;
|
||||
if (rowGroup)
|
||||
rowGroup.setAttribute("dd-triggerrepaint" +
|
||||
(bookmarksTree.getAttribute("sortActive") == "true" ? "sorted" : ""), 0);
|
||||
|
||||
var rdfNode = gBookmarksShell.findRDFNode(aEvent.target, true);
|
||||
var rdfParent = rdfNode.parentNode.parentNode;
|
||||
var isContainer = false;
|
||||
if (rdfParent && rdfParent.getAttribute("container") == "true") {
|
||||
var rDragOverContainer = this.RDF.GetResource(NODE_ID(rdfParent));
|
||||
|
||||
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
const kRDFCUtilsContractID = "@mozilla.org/rdf/container-utils;1";
|
||||
const kRDFCUtilsIID = Components.interfaces.nsIRDFContainerUtils;
|
||||
const kRDFCUtils = Components.classes[kRDFCUtilsContractID].getService(kRDFCUtilsIID);
|
||||
isContainer = kRDFCUtils.IsContainer(kBMDS, rDragOverContainer);
|
||||
}
|
||||
|
||||
if (!isContainer || rowGroup.id == "headRow") {
|
||||
// Not a container, or dropping onto something that isn't designed to take drops
|
||||
// (e.g. the tree header)
|
||||
aDragSession.canDrop = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Springloaded folders.
|
||||
/* XXX - not yet.
|
||||
if (rdfNode && rdfNode.getAttribute("container") == "true" &&
|
||||
rdfNode.getAttribute("open") != "true") {
|
||||
if (!gSpringLoadTracker.element || gSpringLoadTracker.element.id != rdfNode.id) {
|
||||
// XXX - this is not good enough. We need to keep track of nesting and close up
|
||||
// folders after the user has dragged out of them otherwise we end up with
|
||||
// everything open and a big mess!
|
||||
if (gSpringLoadTracker.timeout)
|
||||
clearTimeout(gSpringLoadTracker.timeout);
|
||||
gSpringLoadTracker.element = rdfNode;
|
||||
gSpringLoadTracker.timeout = setTimeout("gSpringLoadTracker.open()", 100);
|
||||
}
|
||||
}
|
||||
*/
|
||||
},
|
||||
|
||||
_flavourSet: null,
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
if (!this._flavourSet) {
|
||||
this._flavourSet = new FlavourSet();
|
||||
this._flavourSet.appendFlavour("moz/rdfitem");
|
||||
this._flavourSet.appendFlavour("text/x-moz-url");
|
||||
this._flavourSet.appendFlavour("text/unicode");
|
||||
}
|
||||
return this._flavourSet;
|
||||
},
|
||||
|
||||
canHandleMultipleItems: true,
|
||||
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var bookmarksTree = document.getElementById("bookmarksTree");
|
||||
// XXX lame
|
||||
if (bookmarksTree.getAttribute("sortActive") == "true") return;
|
||||
|
||||
const kRDFCContractID = "@mozilla.org/rdf/container;1";
|
||||
const kRDFIID = Components.interfaces.nsIRDFContainer;
|
||||
var RDFC = Components.classes[kRDFCContractID].getService(kRDFIID);
|
||||
|
||||
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
|
||||
var dropItem = aEvent.target.parentNode.parentNode;
|
||||
if (aEvent.target.localName == "treechildren")
|
||||
dropItem = aEvent.target.parentNode; // handle drop on blank space.
|
||||
|
||||
// In the default view, the root node is the NC root, and we don't want to append
|
||||
// to that. Adjust accordingly...
|
||||
if (NODE_ID(dropItem) == "NC:NavCenter")
|
||||
dropItem = document.getElementById("treechildren-bookmarks").firstChild;
|
||||
|
||||
// Don't allow drops on the header row & prevent catastrophe
|
||||
if (dropItem.id == "headRow" || !dropItem) return;
|
||||
|
||||
// XXX we could probably compute this ourselves, but let the tree do this
|
||||
// automagically for now.
|
||||
var dropBefore = dropItem.getAttribute("dd-droplocation");
|
||||
var dropOn = dropItem.getAttribute("dd-dropon");
|
||||
|
||||
var dropAction = dropBefore == "true" ? "before" : dropOn == "true" ? "on" : "after";
|
||||
if (aEvent.target.localName == "treechildren")
|
||||
dropAction = "on"; // handle drop on blank space.
|
||||
var containerItem = dropAction == "on" ? dropItem : dropItem.parentNode.parentNode;
|
||||
|
||||
// XXX magical fix for bug # 33546: handle dropping after open container
|
||||
if (dropItem.getAttribute("container") && dropItem.getAttribute("open") &&
|
||||
dropAction == "after") {
|
||||
dropAction = "before";
|
||||
containerItem = dropItem;
|
||||
|
||||
dropItem = null;
|
||||
for (var i = 0; i < containerItem.childNodes.length; ++i) {
|
||||
if (containerItem.childNodes[i].localName == "treechildren") {
|
||||
dropItem = containerItem.childNodes[i].firstChild;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dropItem) {
|
||||
dropAction = "on";
|
||||
dropItem = containerItem.parentNode.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
var rTarget = this.getResource(NODE_ID(dropItem));
|
||||
var rContainer = this.getResource(NODE_ID(containerItem));
|
||||
|
||||
const kRDFCUtilsContractID = "@mozilla.org/rdf/container-utils;1";
|
||||
const kRDFCUtilsIID = Components.interfaces.nsIRDFContainerUtils;
|
||||
const kRDFCUtils = Components.classes[kRDFCUtilsContractID].getService(kRDFCUtilsIID);
|
||||
var isContainer = kRDFCUtils.IsContainer(kBMDS, rContainer);
|
||||
|
||||
// XXX
|
||||
var rType = this.getResource(RDF_NS + "type");
|
||||
var rBookmark = this.getResource(NC_NS + "Bookmark");
|
||||
|
||||
var dirty = false;
|
||||
var additiveFlag = false;
|
||||
var numObjects = aXferData.dataList.length;
|
||||
/*
|
||||
if (numObjects > 1) {
|
||||
var bo = bookmarksTree.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject);
|
||||
bo.beginBatch();
|
||||
}
|
||||
*/
|
||||
|
||||
var sourceID = [], parentID = [], nameRequired = [], name = [];
|
||||
var flavourData;
|
||||
for (i = 0; i < numObjects; ++i) {
|
||||
flavourData = aXferData.dataList[i].first;
|
||||
nameRequired[i] = false;
|
||||
name[i] = null;
|
||||
var data = flavourData.data;
|
||||
switch (flavourData.flavour.contentType) {
|
||||
case "moz/rdfitem":
|
||||
var ix = data.indexOf("\n");
|
||||
sourceID[i] = ix >= 0 ? (parentID[i] = data.substr(ix+1), data.substr(0, ix)) : data;
|
||||
break;
|
||||
case "text/x-moz-url":
|
||||
ix = data.indexOf("\n");
|
||||
sourceID[i] = ix >= 0 ? (name[i] = data.substr(ix+1), data.substr(0, ix)) : data;
|
||||
break;
|
||||
case "text/unicode":
|
||||
sourceID[i] = data;
|
||||
nameRequired[i] = true;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
var rSource = this.getResource(sourceID[i]);
|
||||
var rParent = parentID[i] ? this.getResource(parentID[i]) : null;
|
||||
|
||||
// Prevent dropping node on itself, before or after itself, on its parent
|
||||
// container, or a weird situation when an open container is dropped into
|
||||
// itself (which results in data loss!).
|
||||
// Also prevent dropping into a folder that isn't actually a container
|
||||
// (and is thus probably a pseudo-container from an aggregated datasource,
|
||||
// see bug 68656 fir details).
|
||||
if (rSource == rTarget || (dropAction == "on" && rContainer == rParent) ||
|
||||
rContainer == rSource || !isContainer)
|
||||
return;
|
||||
|
||||
// Prevent dropping node into one of its own subfolders
|
||||
var dropItem2 = dropItem;
|
||||
do {
|
||||
var targetAncestor = NODE_ID(dropItem2);
|
||||
dropItem2 = dropItem2.parentNode;
|
||||
} while (targetAncestor != "NC:BookmarksRoot" && targetAncestor != sourceID[i]);
|
||||
if (targetAncestor == sourceID[i]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < numObjects; ++i) {
|
||||
flavourData = aXferData.dataList[i].first;
|
||||
rSource = this.getResource(sourceID[i]);
|
||||
rParent = parentID[i] ? this.getResource(parentID[i]) : null;
|
||||
|
||||
// XXX if any of the following fails, the nodes are gone for good!
|
||||
const kDSIID = Components.interfaces.nsIDragService;
|
||||
const kCopyAction = kDSIID.DRAGDROP_ACTION_COPY + kDSIID.DRAGDROP_ACTION_LINK;
|
||||
if (rParent) {
|
||||
if (!(aDragSession.dragAction & kCopyAction)) {
|
||||
try {
|
||||
RDFC.Init(kBMDS, rParent);
|
||||
ix = RDFC.IndexOf(rSource);
|
||||
if (ix >= 1)
|
||||
RDFC.RemoveElementAt(ix, true);
|
||||
}
|
||||
catch (ex) { }
|
||||
}
|
||||
}
|
||||
|
||||
RDFC.Init(kBMDS, rContainer);
|
||||
|
||||
// If this item already exists in this container, don't paste, as
|
||||
// this will result in the creation of multiple copies in the datasource
|
||||
// but will not result in an update of the UI. (In Short: we don't
|
||||
// handle multiple bookmarks well)
|
||||
ix = RDFC.IndexOf(rSource);
|
||||
if (ix != -1)
|
||||
continue;
|
||||
|
||||
var bmType = this.getTarget(bookmarksTree.database, sourceID[i], RDF_NS + "type");
|
||||
if (!bmType)
|
||||
kBMDS.Assert(rSource, rType, rBookmark, true);
|
||||
if (bmType == NC_NS + "Folder") {
|
||||
// If we're going to copy a folder type, we need to clone the folder
|
||||
// rather than just asserting the new node as a child of the drop folder.
|
||||
if (aDragSession.dragAction & kCopyAction)
|
||||
rSource = BookmarksUtils.cloneFolder(rSource, rContainer, rTarget);
|
||||
}
|
||||
|
||||
if (dropAction == "before" || dropAction == "after") {
|
||||
var dropIx = RDFC.IndexOf(rTarget);
|
||||
RDFC.InsertElementAt(rSource, dropAction == "after" ? ++dropIx : dropIx, true);
|
||||
}
|
||||
else
|
||||
RDFC.AppendElement(rSource); // drop on
|
||||
|
||||
dirty = true;
|
||||
|
||||
if (rParent) {
|
||||
gBookmarksShell.selectFolderItem(rContainer.Value, sourceID[i], additiveFlag);
|
||||
if (!additiveFlag) additiveFlag = true;
|
||||
}
|
||||
|
||||
// If a name is supplied, we want to assert this information into the
|
||||
// graph. E.g. user drags an internet shortcut to the app, we want to
|
||||
// preserve not only the URL but the name of the shortcut. The other case
|
||||
// where we need to assert a name is when the node does not already exist
|
||||
// in the graph, in this case we'll just use the URL as the name.
|
||||
if (name[i] || nameRequired[i]) {
|
||||
var currentName = this.getTarget(bookmarksTree.database, sourceID[i], NC_NS + "Name");
|
||||
if (!currentName) {
|
||||
var rDefaultName = this.RDF.GetLiteral(name[i] || sourceID[i]);
|
||||
if (rDefaultName) {
|
||||
var rName = this.RDF.GetResource(NC_NS + "Name");
|
||||
kBMDS.Assert(rSource, rName, rDefaultName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (numObjects > 1) {
|
||||
var bo = bookmarksTree.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject);
|
||||
bo.endBatch();
|
||||
}
|
||||
*/
|
||||
|
||||
if (dirty) {
|
||||
var remoteDS = kBMDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
remoteDS.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,954 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var NC_NS = "http://home.netscape.com/NC-rdf#";
|
||||
var RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||
const NC_NS_CMD = NC_NS + "command?cmd=";
|
||||
|
||||
/**
|
||||
* XXX - 04/16/01
|
||||
* ACK! massive command name collision problems are causing big issues
|
||||
* in getting this stuff to work in the Navigator window. For sanity's
|
||||
* sake, we need to rename all the commands to be of the form cmd_bm_*
|
||||
* otherwise there'll continue to be problems. For now, we're just
|
||||
* renaming those that affect the personal toolbar (edit operations,
|
||||
* which were clashing with the textfield controller)
|
||||
*
|
||||
* There are also several places that need to be updated if you need
|
||||
* to change a command name.
|
||||
* 1) the controller in ALL clients (bookmarksTree.js, personalToolbar.js)
|
||||
* 2) the command nodes in the overlay
|
||||
* 3) the command human-readable name key in bookmark.properties
|
||||
* 4) the function 'getAllCmds' in bookmarksOverlay.js
|
||||
* 5) the function 'execCommand' in bookmarksOverlay.js
|
||||
* Yes, this blows crusty dead goats through straws, and I should probably
|
||||
* create some constants somewhere to bring this number down to 3.
|
||||
* However, if you fail to do one of these, you WILL break something
|
||||
* and I WILL come after you with a knife.
|
||||
*/
|
||||
|
||||
function LITERAL (aDB, aElement, aPropertyID)
|
||||
{
|
||||
var RDF = BookmarksUIElement.prototype.RDF;
|
||||
var rSource = RDF.GetResource(aElement.id);
|
||||
var rProperty = RDF.GetResource(aPropertyID);
|
||||
var node = aDB.GetTarget(rSource, rProperty, true);
|
||||
return node ? node.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : "";
|
||||
}
|
||||
|
||||
function BookmarksUIElement () { }
|
||||
BookmarksUIElement.prototype = {
|
||||
_rdf: null,
|
||||
get RDF ()
|
||||
{
|
||||
if (!this._rdf) {
|
||||
const kRDFContractID = "@mozilla.org/rdf/rdf-service;1";
|
||||
const kRDFIID = Components.interfaces.nsIRDFService;
|
||||
this._rdf = Components.classes[kRDFContractID].getService(kRDFIID);
|
||||
}
|
||||
return this._rdf;
|
||||
},
|
||||
|
||||
propertySet: function (sourceID, propertyID, newValue)
|
||||
{
|
||||
if (!newValue) return;
|
||||
const kRDFContractID = "@mozilla.org/rdf/rdf-service;1";
|
||||
const kRDFIID = Components.interfaces.nsIRDFService;
|
||||
const kRDF = Components.classes[kRDFContractID].getService(kRDFIID);
|
||||
// need to shuffle this into an API.
|
||||
const kBMDS = kRDF.GetDataSource("rdf:bookmarks");
|
||||
const krProperty = kRDF.GetResource(propertyID);
|
||||
const krItem = kRDF.GetResource(sourceID);
|
||||
var rCurrValue = kBMDS.GetTarget(krItem, krProperty, true);
|
||||
const krNewValue = kRDF.GetLiteral(newValue);
|
||||
if (!rCurrValue)
|
||||
kBMDS.Assert(krItem, krProperty, krNewValue, true);
|
||||
else {
|
||||
rCurrValue = rCurrValue.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (rCurrValue.Value != newValue)
|
||||
kBMDS.Change(krItem, krProperty, rCurrValue, krNewValue);
|
||||
}
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Fill a context menu popup with menuitems that are appropriate for the current
|
||||
// selection.
|
||||
createContextMenu: function (aEvent)
|
||||
{
|
||||
var popup = aEvent.target;
|
||||
// clear out the old context menu contents (if any)
|
||||
while (popup.hasChildNodes())
|
||||
popup.removeChild(popup.firstChild);
|
||||
|
||||
var popupNode = document.popupNode;
|
||||
|
||||
if (!("findRDFNode" in this))
|
||||
throw "Clients must implement findRDFNode!";
|
||||
var itemNode = this.findRDFNode(popupNode, true);
|
||||
if (!itemNode || !itemNode.getAttributeNS(RDF_NS, "type") || itemNode.getAttribute("mode") == "edit") {
|
||||
aEvent.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (!("getContextSelection" in this))
|
||||
throw "Clients must implement getContextSelection!";
|
||||
var selection = this.getContextSelection (itemNode);
|
||||
var commonCommands = [];
|
||||
for (var i = 0; i < selection.length; ++i) {
|
||||
var commands = this.getAllCmds(selection[i].id);
|
||||
if (!commands) {
|
||||
aEvent.preventDefault();
|
||||
return;
|
||||
}
|
||||
commands = this.flattenEnumerator(commands);
|
||||
if (!commonCommands.length) commonCommands = commands;
|
||||
commonCommands = this.findCommonNodes(commands, commonCommands);
|
||||
}
|
||||
|
||||
if (!commonCommands.length) {
|
||||
aEvent.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// Now that we should have generated a list of commands that is valid
|
||||
// for the entire selection, build a context menu.
|
||||
for (i = 0; i < commonCommands.length; ++i) {
|
||||
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
var currCommand = commonCommands[i].QueryInterface(Components.interfaces.nsIRDFResource).Value;
|
||||
var element = null;
|
||||
if (currCommand != NC_NS_CMD + "bm_separator") {
|
||||
var commandName = this.getCommandName(currCommand);
|
||||
element = this.createMenuItem(commandName, currCommand, itemNode);
|
||||
}
|
||||
else if (i != 0 && i < commonCommands.length-1) {
|
||||
// Never append a separator as the first or last element in a context
|
||||
// menu.
|
||||
element = document.createElementNS(kXULNS, "menuseparator");
|
||||
}
|
||||
|
||||
if (element)
|
||||
popup.appendChild(element);
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Given two unique arrays, return an array that contains only the elements
|
||||
// common to both.
|
||||
findCommonNodes: function (aNewArray, aOldArray)
|
||||
{
|
||||
var common = [];
|
||||
for (var i = 0; i < aNewArray.length; ++i) {
|
||||
for (var j = 0; j < aOldArray.length; ++j) {
|
||||
if (common.length > 0 && common[common.length-1] == aNewArray[i])
|
||||
continue;
|
||||
if (aNewArray[i] == aOldArray[j])
|
||||
common.push(aNewArray[i]);
|
||||
}
|
||||
}
|
||||
return common;
|
||||
},
|
||||
|
||||
flattenEnumerator: function (aEnumerator)
|
||||
{
|
||||
if ("_index" in aEnumerator)
|
||||
return aEnumerator._inner;
|
||||
|
||||
var temp = [];
|
||||
while (aEnumerator.hasMoreElements())
|
||||
temp.push(aEnumerator.getNext());
|
||||
return temp;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// For a given URI (a unique identifier of a resource in the graph) return
|
||||
// an enumeration of applicable commands for that URI.
|
||||
getAllCmds: function (aNodeID)
|
||||
{
|
||||
var type = this.resolveType(aNodeID);
|
||||
if (!type) {
|
||||
if (aNodeID == "NC:PersonalToolbarFolder" || aNodeID == "NC:BookmarksRoot")
|
||||
type = "http://home.netscape.com/NC-rdf#Folder";
|
||||
else
|
||||
return null;
|
||||
}
|
||||
var commands = [];
|
||||
// menu order:
|
||||
//
|
||||
// bm_open
|
||||
// bm_openfolder
|
||||
// bm_openinnewwindow
|
||||
// /* bm_openinnewtab not yet supported */
|
||||
// ---------------------
|
||||
// /* bm_find removed */
|
||||
// bm_newfolder
|
||||
// ---------------------
|
||||
// bm_cut
|
||||
// bm_copy
|
||||
// bm_paste
|
||||
// bm_fileBookmark
|
||||
// ---------------------
|
||||
// bm_delete
|
||||
// bm_rename
|
||||
// ---------------------
|
||||
// bm_properties
|
||||
switch (type) {
|
||||
case "http://home.netscape.com/NC-rdf#BookmarkSeparator":
|
||||
commands = ["bm_newfolder", "bm_separator",
|
||||
"bm_cut", "bm_copy", "bm_paste", "bm_separator",
|
||||
"bm_delete"];
|
||||
break;
|
||||
case "http://home.netscape.com/NC-rdf#Bookmark":
|
||||
commands = ["bm_open", "bm_openinnewwindow", /* "bm_openinnewtab", */ "bm_separator",
|
||||
"bm_newfolder", "bm_separator",
|
||||
"bm_cut", "bm_copy", "bm_paste", "bm_fileBookmark", "bm_separator",
|
||||
"bm_delete", "bm_rename", "bm_separator",
|
||||
"bm_properties"];
|
||||
break;
|
||||
case "http://home.netscape.com/NC-rdf#Folder":
|
||||
commands = ["bm_openfolder", "bm_openinnewwindow", "bm_separator",
|
||||
"bm_newfolder", "bm_separator",
|
||||
"bm_cut", "bm_copy", "bm_paste", "bm_fileBookmark", "bm_separator",
|
||||
"bm_delete", "bm_rename", "bm_separator",
|
||||
"bm_properties"];
|
||||
break;
|
||||
case "http://home.netscape.com/NC-rdf#IEFavoriteFolder":
|
||||
commands = ["bm_openfolder", "bm_separator",
|
||||
"bm_delete"];
|
||||
break;
|
||||
case "http://home.netscape.com/NC-rdf#IEFavorite":
|
||||
commands = ["bm_open", "bm_openinnewwindow", /* "bm_openinnewtab", */ "bm_separator",
|
||||
"bm_copy"];
|
||||
break;
|
||||
case "http://home.netscape.com/NC-rdf#FileSystemObject":
|
||||
commands = ["bm_open", "bm_openinnewwindow", /* "bm_openinnewtab", */ "bm_separator",
|
||||
"bm_copy"];
|
||||
break;
|
||||
default:
|
||||
var source = this.RDF.GetResource(aNodeID);
|
||||
return this.db.GetAllCmds(source);
|
||||
}
|
||||
return new CommandArrayEnumerator(commands);
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Retrieve the human-readable name for a particular command. Used when
|
||||
// manufacturing a UI to invoke commands.
|
||||
getCommandName: function (aCommand)
|
||||
{
|
||||
var cmdName = aCommand.substring(NC_NS_CMD.length);
|
||||
try {
|
||||
// Note: this will succeed only if there's a string in the bookmarks
|
||||
// string bundle for this command name. Otherwise, <xul:stringbundle/>
|
||||
// will throw, we'll catch & stifle the error, and look up the command
|
||||
// name in the datasource.
|
||||
return this.getLocaleString ("cmd_" + cmdName);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
// XXX - WORK TO DO HERE! (rjc will cry if we don't fix this)
|
||||
// need to ask the ds for the commands for this node, however we don't
|
||||
// have the right params. This is kind of a problem.
|
||||
dump("*** BAD! EVIL! WICKED! NO! ACK! ARGH! ORGH!\n");
|
||||
const rName = this.RDF.GetResource(NC_NS + "Name");
|
||||
const rSource = this.RDF.GetResource(aNodeID);
|
||||
return this.db.GetTarget(rSource, rName, true).Value;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Perform a command based on a UI event. XXX - work to do here.
|
||||
preExecCommand: function (aEvent)
|
||||
{
|
||||
var commandID = aEvent.target.getAttribute("cmd");
|
||||
if (!commandID) return;
|
||||
goDoCommand("cmd_" + commandID.substring(NC_NS_CMD.length));
|
||||
},
|
||||
|
||||
execCommand: function (aCommandID)
|
||||
{
|
||||
var args = [];
|
||||
var selection = this.getSelection ();
|
||||
if (selection.length >= 1)
|
||||
var selectedItem = selection[0];
|
||||
switch (aCommandID) {
|
||||
case "bm_open":
|
||||
this.open(null, selectedItem, false);
|
||||
break;
|
||||
case "bm_openfolder":
|
||||
this.commands.openFolder(selectedItem);
|
||||
break;
|
||||
case "bm_openinnewwindow":
|
||||
if (this.resolveType(selectedItem.id) == NC_NS + "Folder")
|
||||
this.openFolderInNewWindow(selectedItem);
|
||||
else
|
||||
this.open(null, selectedItem, true);
|
||||
break;
|
||||
case "bm_rename":
|
||||
// XXX - this is SO going to break if we ever do column re-ordering.
|
||||
this.commands.editCell(selectedItem, 0);
|
||||
break;
|
||||
case "bm_editurl":
|
||||
this.commands.editCell(selectedItem, 1);
|
||||
break;
|
||||
case "bm_setnewbookmarkfolder":
|
||||
case "bm_setpersonaltoolbarfolder":
|
||||
case "bm_setnewsearchfolder":
|
||||
BookmarksUtils.doBookmarksCommand(selectedItem.id, NC_NS_CMD + aCommandID, args);
|
||||
// XXX - The containing node seems to be closed here and the
|
||||
// focus/selection is destroyed.
|
||||
this.selectElement(selectedItem);
|
||||
break;
|
||||
case "bm_properties":
|
||||
this.showPropertiesForNode(selectedItem);
|
||||
break;
|
||||
case "bm_find":
|
||||
this.findInBookmarks();
|
||||
break;
|
||||
case "bm_cut":
|
||||
this.copySelection(selection);
|
||||
this.deleteSelection(selection);
|
||||
break;
|
||||
case "bm_copy":
|
||||
this.copySelection(selection);
|
||||
break;
|
||||
case "bm_paste":
|
||||
this.paste(selection);
|
||||
break;
|
||||
case "bm_delete":
|
||||
this.deleteSelection(selection);
|
||||
break;
|
||||
case "bm_fileBookmark":
|
||||
var rv = { selectedFolder: null };
|
||||
openDialog("chrome://communicator/content/bookmarks/addBookmark.xul", "",
|
||||
"centerscreen,chrome,modal=yes,dialog=yes,resizable=yes", null, null, folder, null, "selectFolder", rv);
|
||||
if (rv.selectedFolder) {
|
||||
for (var k = 0; k < selection.length; ++k) {
|
||||
if (selection[k].id == rv.selectedFolder)
|
||||
return; // Selection contains the target folder. Just fail silently.
|
||||
}
|
||||
var additiveFlag = false;
|
||||
var selectedItems = [].concat(this.getSelection())
|
||||
for (var i = 0; i < selectedItems.length; ++i) {
|
||||
var currItem = selectedItems[i];
|
||||
var currURI = currItem.id;
|
||||
var parent = gBookmarksShell.findRDFNode(currItem, false);
|
||||
gBookmarksShell.moveBookmark(currURI, parent.id, rv.selectedFolder);
|
||||
gBookmarksShell.selectFolderItem(rv.selectedFolder, currURI, additiveFlag);
|
||||
if (!additiveFlag) additiveFlag = true;
|
||||
}
|
||||
gBookmarksShell.flushDataSource();
|
||||
}
|
||||
break;
|
||||
case "bm_newfolder":
|
||||
var nfseln = this.getBestItem();
|
||||
this.commands.createBookmarkItem("folder", nfseln);
|
||||
break;
|
||||
case "bm_newbookmark":
|
||||
var folder = this.getSelectedFolder();
|
||||
openDialog("chrome://communicator/content/bookmarks/addBookmark.xul", "",
|
||||
"centerscreen,chrome,modal=yes,dialog=yes,resizable=no", null, null, folder, null, "newBookmark");
|
||||
break;
|
||||
case "bm_newseparator":
|
||||
nfseln = this.getBestItem();
|
||||
var parentNode = this.findRDFNode(nfseln, false);
|
||||
args = [{ property: NC_NS + "parent",
|
||||
resource: parentNode.id }];
|
||||
BookmarksUtils.doBookmarksCommand(nfseln.id, NC_NS_CMD + "newseparator", args);
|
||||
break;
|
||||
case "bm_import":
|
||||
case "bm_export":
|
||||
const isImport = aCommandID == "bm_import";
|
||||
try {
|
||||
const kFilePickerContractID = "@mozilla.org/filepicker;1";
|
||||
const kFilePickerIID = Components.interfaces.nsIFilePicker;
|
||||
const kFilePicker = Components.classes[kFilePickerContractID].createInstance(kFilePickerIID);
|
||||
|
||||
const kTitle = this.getLocaleString(isImport ? "SelectImport": "EnterExport");
|
||||
kFilePicker.init(window, kTitle, kFilePickerIID[isImport ? "modeOpen" : "modeSave"]);
|
||||
kFilePicker.appendFilters(kFilePickerIID.filterHTML | kFilePickerIID.filterAll);
|
||||
if (!isImport) kFilePicker.defaultString = "bookmarks.html";
|
||||
if (kFilePicker.show() != kFilePickerIID.returnCancel) {
|
||||
var fileName = kFilePicker.fileURL.spec;
|
||||
if (!fileName) break;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
catch (e) {
|
||||
break;
|
||||
}
|
||||
var seln = this.getBestItem();
|
||||
args = [{ property: NC_NS + "URL", literal: fileName}];
|
||||
BookmarksUtils.doBookmarksCommand(seln.id, NC_NS_CMD + aCommandID, args);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
openFolderInNewWindow: function (aSelectedItem)
|
||||
{
|
||||
openDialog("chrome://communicator/content/bookmarks/bookmarks.xul",
|
||||
"", "chrome,all,dialog=no", aSelectedItem.id);
|
||||
},
|
||||
|
||||
copySelection: function (aSelection)
|
||||
{
|
||||
const kSuppArrayContractID = "@mozilla.org/supports-array;1";
|
||||
const kSuppArrayIID = Components.interfaces.nsISupportsArray;
|
||||
var itemArray = Components.classes[kSuppArrayContractID].createInstance(kSuppArrayIID);
|
||||
|
||||
const kSuppWStringContractID = "@mozilla.org/supports-wstring;1";
|
||||
const kSuppWStringIID = Components.interfaces.nsISupportsWString;
|
||||
var bmstring = Components.classes[kSuppWStringContractID].createInstance(kSuppWStringIID);
|
||||
var unicodestring = Components.classes[kSuppWStringContractID].createInstance(kSuppWStringIID);
|
||||
var htmlstring = Components.classes[kSuppWStringContractID].createInstance(kSuppWStringIID);
|
||||
|
||||
var sBookmarkItem = ""; var sTextUnicode = ""; var sTextHTML = "";
|
||||
for (var i = 0; i < aSelection.length; ++i) {
|
||||
var url = LITERAL(this.db, aSelection[i], NC_NS + "URL");
|
||||
var name = LITERAL(this.db, aSelection[i], NC_NS + "Name");
|
||||
sBookmarkItem += aSelection[i].id + "\n";
|
||||
sTextUnicode += url + "\n";
|
||||
sTextHTML += "<A HREF=\"" + url + "\">" + name + "</A>";
|
||||
}
|
||||
|
||||
const kXferableContractID = "@mozilla.org/widget/transferable;1";
|
||||
const kXferableIID = Components.interfaces.nsITransferable;
|
||||
var xferable = Components.classes[kXferableContractID].createInstance(kXferableIID);
|
||||
|
||||
xferable.addDataFlavor("moz/bookmarkclipboarditem");
|
||||
bmstring.data = sBookmarkItem;
|
||||
xferable.setTransferData("moz/bookmarkclipboarditem", bmstring, sBookmarkItem.length*2)
|
||||
|
||||
xferable.addDataFlavor("text/html");
|
||||
htmlstring.data = sTextHTML;
|
||||
xferable.setTransferData("text/html", htmlstring, sTextHTML.length*2)
|
||||
|
||||
xferable.addDataFlavor("text/unicode");
|
||||
unicodestring.data = sTextUnicode;
|
||||
xferable.setTransferData("text/unicode", unicodestring, sTextUnicode.length*2)
|
||||
|
||||
const kClipboardContractID = "@mozilla.org/widget/clipboard;1";
|
||||
const kClipboardIID = Components.interfaces.nsIClipboard;
|
||||
var clipboard = Components.classes[kClipboardContractID].getService(kClipboardIID);
|
||||
clipboard.setData(xferable, null, kClipboardIID.kGlobalClipboard);
|
||||
},
|
||||
|
||||
paste: function (aSelection)
|
||||
{
|
||||
const kXferableContractID = "@mozilla.org/widget/transferable;1";
|
||||
const kXferableIID = Components.interfaces.nsITransferable;
|
||||
var xferable = Components.classes[kXferableContractID].createInstance(kXferableIID);
|
||||
xferable.addDataFlavor("moz/bookmarkclipboarditem");
|
||||
xferable.addDataFlavor("text/x-moz-url");
|
||||
xferable.addDataFlavor("text/unicode");
|
||||
|
||||
const kClipboardContractID = "@mozilla.org/widget/clipboard;1";
|
||||
const kClipboardIID = Components.interfaces.nsIClipboard;
|
||||
var clipboard = Components.classes[kClipboardContractID].getService(kClipboardIID);
|
||||
clipboard.getData(xferable, kClipboardIID.kGlobalClipboard);
|
||||
|
||||
var flavour = { };
|
||||
var data = { };
|
||||
var length = { };
|
||||
xferable.getAnyTransferData(flavour, data, length);
|
||||
var nodes = []; var names = [];
|
||||
data = data.value.QueryInterface(Components.interfaces.nsISupportsWString).data;
|
||||
switch (flavour.value) {
|
||||
case "moz/bookmarkclipboarditem":
|
||||
nodes = data.split("\n");
|
||||
break;
|
||||
case "text/x-moz-url":
|
||||
var ix = data.indexOf("\n");
|
||||
nodes.push(data.substring(0, ix != -1 ? ix : data.length));
|
||||
names.push(data.substring(ix));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
const lastSelected = aSelection[aSelection.length-1];
|
||||
const kParentNode = this.resolvePasteFolder(aSelection);
|
||||
const krParent = this.RDF.GetResource(kParentNode.id);
|
||||
const krSource = this.RDF.GetResource(lastSelected.id);
|
||||
|
||||
const kRDFCContractID = "@mozilla.org/rdf/container;1";
|
||||
const kRDFCIID = Components.interfaces.nsIRDFContainer;
|
||||
const ksRDFC = Components.classes[kRDFCContractID].getService(kRDFCIID);
|
||||
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
|
||||
var additiveFlag = false;
|
||||
for (var i = 0; i < nodes.length; ++i) {
|
||||
if (!nodes[i]) continue;
|
||||
var rCurrent = this.RDF.GetResource(nodes[i]);
|
||||
const krTypeProperty = this.RDF.GetResource(RDF_NS + "type");
|
||||
var rType = this.db.GetTarget(rCurrent, krTypeProperty, true);
|
||||
try {
|
||||
rType = rType.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
rType = rType.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
}
|
||||
catch (e) {
|
||||
// OK, no type exists, so node does not exist in the graph.
|
||||
// (e.g. user pastes url as text)
|
||||
// Do some housekeeping.
|
||||
const krName = this.RDF.GetResource(names[i]);
|
||||
const krNameProperty = this.RDF.GetResource(NC_NS + "Name");
|
||||
const krBookmark = this.RDF.GetResource(NC_NS + "Bookmark");
|
||||
kBMDS.Assert(rCurrent, krNameProperty, krName, true);
|
||||
kBMDS.Assert(rCurrent, krTypeProperty, krBookmark, true);
|
||||
}
|
||||
}
|
||||
|
||||
// If the node is a folder, then we need to create a new anonymous
|
||||
// resource and copy all the arcs over.
|
||||
if (rType && rType.Value == NC_NS + "Folder")
|
||||
rCurrent = BookmarksUtils.cloneFolder(rCurrent, krParent, krSource);
|
||||
|
||||
// If this item already exists in this container, don't paste, as
|
||||
// this will result in the creation of multiple copies in the datasource
|
||||
// but will not result in an update of the UI. (In Short: we don't
|
||||
// handle multiple bookmarks well)
|
||||
ksRDFC.Init(kBMDS, krParent);
|
||||
ix = ksRDFC.IndexOf(rCurrent);
|
||||
if (ix != -1)
|
||||
continue;
|
||||
|
||||
ix = ksRDFC.IndexOf(krSource);
|
||||
if (ix != -1)
|
||||
ksRDFC.InsertElementAt(rCurrent, ix+1, true);
|
||||
else
|
||||
ksRDFC.AppendElement(rCurrent);
|
||||
this.selectFolderItem(krSource.Value, rCurrent.Value, additiveFlag);
|
||||
if (!additiveFlag) additiveFlag = true;
|
||||
|
||||
var rds = kBMDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
rds.Flush();
|
||||
}
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// For the given selection, determines the element that should form the
|
||||
// container to paste items into.
|
||||
resolvePasteFolder: function (aSelection)
|
||||
{
|
||||
const lastSelected = aSelection[aSelection.length-1];
|
||||
if (lastSelected.getAttribute("container") == "true" &&
|
||||
aSelection.length == 1)
|
||||
return lastSelected;
|
||||
return this.findRDFNode(lastSelected, false);
|
||||
},
|
||||
|
||||
canPaste: function ()
|
||||
{
|
||||
const kClipboardContractID = "@mozilla.org/widget/clipboard;1";
|
||||
const kClipboardIID = Components.interfaces.nsIClipboard;
|
||||
var clipboard = Components.classes[kClipboardContractID].getService(kClipboardIID);
|
||||
const kSuppArrayContractID = "@mozilla.org/supports-array;1";
|
||||
const kSuppArrayIID = Components.interfaces.nsISupportsArray;
|
||||
var flavourArray = Components.classes[kSuppArrayContractID].createInstance(kSuppArrayIID);
|
||||
const kSuppStringContractID = "@mozilla.org/supports-string;1";
|
||||
const kSuppStringIID = Components.interfaces.nsISupportsString;
|
||||
|
||||
var flavours = ["moz/bookmarkclipboarditem", "text/x-moz-url"];
|
||||
for (var i = 0; i < flavours.length; ++i) {
|
||||
const kSuppString = Components.classes[kSuppStringContractID].createInstance(kSuppStringIID);
|
||||
kSuppString.data = flavours[i];
|
||||
flavourArray.AppendElement(kSuppString);
|
||||
}
|
||||
var hasFlavours = clipboard.hasDataMatchingFlavors(flavourArray, kClipboardIID.kGlobalClipboard);
|
||||
return hasFlavours;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// aSelection is a mutable array, not a NodeList.
|
||||
deleteSelection: function (aSelection)
|
||||
{
|
||||
const kRDFCContractID = "@mozilla.org/rdf/container;1";
|
||||
const kRDFCIID = Components.interfaces.nsIRDFContainer;
|
||||
const ksRDFC = Components.classes[kRDFCContractID].getService(kRDFCIID);
|
||||
|
||||
var nextElement;
|
||||
var count = 0;
|
||||
|
||||
var selectionLength = aSelection.length;
|
||||
while (aSelection.length && aSelection[count]) {
|
||||
const currParent = this.findRDFNode(aSelection[count], false);
|
||||
const kSelectionURI = aSelection[count].id;
|
||||
|
||||
// Disallow the removal of certain 'special' nodes
|
||||
if (kSelectionURI == "NC:BookmarksRoot") {
|
||||
aSelection.splice(count++,1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the current bookmark is the IE Favorites folder, we have a little
|
||||
// extra work to do - set the pref |browser.bookmarks.import_system_favorites|
|
||||
// to ensure that we don't re-import next time.
|
||||
if (aSelection[count].getAttribute("type") == (NC_NS + "IEFavoriteFolder")) {
|
||||
const kPrefSvcContractID = "@mozilla.org/preferences-service;1";
|
||||
const kPrefSvcIID = Components.interfaces.nsIPrefBranch;
|
||||
const kPrefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
|
||||
kPrefSvc.setBoolPref("browser.bookmarks.import_system_favorites", false);
|
||||
}
|
||||
|
||||
const krParent = this.RDF.GetResource(currParent.id);
|
||||
const krBookmark = this.RDF.GetResource(kSelectionURI);
|
||||
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
|
||||
ksRDFC.Init(kBMDS, krParent);
|
||||
nextElement = this.getNextElement(aSelection[count]);
|
||||
ksRDFC.RemoveElement(krBookmark, true);
|
||||
|
||||
try {
|
||||
// XXX - UGH. Template builder is NOT removing the element from the
|
||||
// tree, and so selection remains non-zero in length and we go into
|
||||
// an infinite loop here. Tear the node out of the document.
|
||||
var parent = aSelection[count].parentNode;
|
||||
parent.removeChild(aSelection[count]);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
// Manipulate the selection array ourselves.
|
||||
aSelection.splice(count,1);
|
||||
}
|
||||
this.selectElement(nextElement);
|
||||
},
|
||||
|
||||
moveBookmark: function (aBookmarkURI, aFromFolderURI, aToFolderURI)
|
||||
{
|
||||
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
const kRDFCContractID = "@mozilla.org/rdf/container;1";
|
||||
const kRDFCIID = Components.interfaces.nsIRDFContainer;
|
||||
const kRDFC = Components.classes[kRDFCContractID].getService(kRDFCIID);
|
||||
const krSrc = this.RDF.GetResource(aBookmarkURI);
|
||||
const krOldParent = this.RDF.GetResource(aFromFolderURI);
|
||||
const krNewParent = this.RDF.GetResource(aToFolderURI);
|
||||
kRDFC.Init(kBMDS, krNewParent);
|
||||
kRDFC.AppendElement(krSrc);
|
||||
kRDFC.Init(kBMDS, krOldParent);
|
||||
kRDFC.RemoveElement(krSrc, true);
|
||||
},
|
||||
|
||||
open: function (aEvent, aRDFNode, aInNewWindow)
|
||||
{
|
||||
var urlValue = LITERAL(this.db, aRDFNode, NC_NS + "URL");
|
||||
|
||||
// Ignore "NC:" and empty urls.
|
||||
if (urlValue.substring(0,3) == "NC:" || !urlValue) return;
|
||||
|
||||
if (aEvent && aEvent.altKey)
|
||||
this.showPropertiesForNode (aRDFNode);
|
||||
else if (aInNewWindow)
|
||||
openDialog (getBrowserURL(), "_blank", "chrome,all,dialog=no", urlValue);
|
||||
else
|
||||
openTopWin (urlValue);
|
||||
if (aEvent)
|
||||
aEvent.preventBubble();
|
||||
},
|
||||
|
||||
showPropertiesForNode: function (aBookmarkItem)
|
||||
{
|
||||
if (aBookmarkItem.getAttribute("type") != NC_NS + "BookmarkSeparator")
|
||||
openDialog("chrome://communicator/content/bookmarks/bm-props.xul",
|
||||
"", "centerscreen,chrome,resizable=no", aBookmarkItem.id);
|
||||
},
|
||||
|
||||
findInBookmarks: function ()
|
||||
{
|
||||
openDialog("chrome://communicator/content/bookmarks/findBookmark.xul",
|
||||
"FindBookmarksWindow",
|
||||
"centerscreen,resizable=no,chrome,dependent");
|
||||
},
|
||||
|
||||
getLocaleString: function (aStringKey)
|
||||
{
|
||||
var bundle = document.getElementById("bookmarksbundle");
|
||||
return bundle.getString (aStringKey);
|
||||
},
|
||||
|
||||
flushDataSource: function ()
|
||||
{
|
||||
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
var remoteDS = kBMDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
remoteDS.Flush();
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Determine the rdf:type property for the given resource.
|
||||
resolveType: function (aID)
|
||||
{
|
||||
const krType = this.RDF.GetResource(RDF_NS + "type");
|
||||
const krElement = this.RDF.GetResource(aID);
|
||||
const type = gBookmarksShell.db.GetTarget(krElement, krType, true);
|
||||
try {
|
||||
return type.QueryInterface(Components.interfaces.nsIRDFResource).Value;
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
return type.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
}
|
||||
catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// takes a node and adds the appropriate adornments for a bookmark container.
|
||||
createBookmarkFolderDecorations: function (aNode)
|
||||
{
|
||||
aNode.setAttribute("type", "http://home.netscape.com/NC-rdf#Folder");
|
||||
aNode.setAttribute("container", "true");
|
||||
return aNode;
|
||||
}
|
||||
};
|
||||
|
||||
function CommandArrayEnumerator (aCommandArray)
|
||||
{
|
||||
this._inner = [];
|
||||
const kRDFContractID = "@mozilla.org/rdf/rdf-service;1";
|
||||
const kRDFIID = Components.interfaces.nsIRDFService;
|
||||
const RDF = Components.classes[kRDFContractID].getService(kRDFIID);
|
||||
for (var i = 0; i < aCommandArray.length; ++i)
|
||||
this._inner.push(RDF.GetResource(NC_NS_CMD + aCommandArray[i]));
|
||||
|
||||
this._index = 0;
|
||||
}
|
||||
|
||||
CommandArrayEnumerator.prototype = {
|
||||
getNext: function ()
|
||||
{
|
||||
return this._inner[this._index];
|
||||
},
|
||||
|
||||
hasMoreElements: function ()
|
||||
{
|
||||
return this._index < this._inner.length;
|
||||
}
|
||||
};
|
||||
|
||||
var BookmarksUtils = {
|
||||
_rdf: null,
|
||||
get RDF ()
|
||||
{
|
||||
if (!this._rdf) {
|
||||
const kRDFContractID = "@mozilla.org/rdf/rdf-service;1";
|
||||
const kRDFIID = Components.interfaces.nsIRDFService;
|
||||
this._rdf = Components.classes[kRDFContractID].getService(kRDFIID);
|
||||
}
|
||||
return this._rdf;
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Execute a command with the given source and arguments
|
||||
doBookmarksCommand: function (aSourceURI, aCommand, aArgumentsArray)
|
||||
{
|
||||
var rCommand = this.RDF.GetResource(aCommand);
|
||||
|
||||
var kSuppArrayContractID = "@mozilla.org/supports-array;1";
|
||||
var kSuppArrayIID = Components.interfaces.nsISupportsArray;
|
||||
var sourcesArray = Components.classes[kSuppArrayContractID].createInstance(kSuppArrayIID);
|
||||
if (aSourceURI) {
|
||||
var rSource = this.RDF.GetResource(aSourceURI);
|
||||
sourcesArray.AppendElement (rSource);
|
||||
}
|
||||
|
||||
var argsArray = Components.classes[kSuppArrayContractID].createInstance(kSuppArrayIID);
|
||||
for (var i = 0; i < aArgumentsArray.length; ++i) {
|
||||
var rArc = this.RDF.GetResource(aArgumentsArray[i].property);
|
||||
argsArray.AppendElement(rArc);
|
||||
var rValue = null;
|
||||
if ("resource" in aArgumentsArray[i]) {
|
||||
rValue = this.RDF.GetResource(aArgumentsArray[i].resource);
|
||||
}
|
||||
else
|
||||
rValue = this.RDF.GetLiteral(aArgumentsArray[i].literal);
|
||||
argsArray.AppendElement(rValue);
|
||||
}
|
||||
|
||||
// Exec the command in the Bookmarks datasource.
|
||||
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
kBMDS.DoCommand(sourcesArray, rCommand, argsArray);
|
||||
},
|
||||
|
||||
cloneFolder: function (aFolder, aParent, aRelativeItem)
|
||||
{
|
||||
var BMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
|
||||
var nameArc = this.RDF.GetResource(NC_NS + "Name");
|
||||
var rName = BMDS.GetTarget(aFolder, nameArc, true);
|
||||
rName = rName.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
|
||||
var newFolder = this.createFolderWithID(rName.Value, aRelativeItem, aParent);
|
||||
|
||||
// Now need to append kiddies.
|
||||
try {
|
||||
const kRDFCContractID = "@mozilla.org/rdf/container;1";
|
||||
const kRDFCIID = Components.interfaces.nsIRDFContainer;
|
||||
var RDFC = Components.classes[kRDFCContractID].getService(kRDFCIID);
|
||||
const kRDFCUContractID = "@mozilla.org/rdf/container-utils;1";
|
||||
const kRDFCUIID = Components.interfaces.nsIRDFContainerUtils;
|
||||
var RDFCU = Components.classes[kRDFCUContractID].getService(kRDFCUIID);
|
||||
|
||||
RDFC.Init(BMDS, aFolder);
|
||||
var elts = RDFC.GetElements();
|
||||
RDFC.Init(BMDS, newFolder);
|
||||
|
||||
while (elts.hasMoreElements()) {
|
||||
var curr = elts.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
if (RDFCU.IsContainer(BMDS, curr))
|
||||
BookmarksUtils.cloneFolder(curr, newFolder);
|
||||
else
|
||||
RDFC.AppendElement(curr);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
return newFolder;
|
||||
},
|
||||
|
||||
createFolderWithID: function (aTitle, aRelativeItem, aParentFolder)
|
||||
{
|
||||
const kRDFCContractID = "@mozilla.org/rdf/container;1";
|
||||
const kRDFCIID = Components.interfaces.nsIRDFContainer;
|
||||
var RDFC = Components.classes[kRDFCContractID].createInstance(kRDFCIID);
|
||||
var BMDS = this.RDF.GetDataSource("rdf:bookmarks");
|
||||
try {
|
||||
RDFC.Init(BMDS, aParentFolder);
|
||||
}
|
||||
catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ix = RDFC.IndexOf(aRelativeItem);
|
||||
var BMSvc = BMDS.QueryInterface(Components.interfaces.nsIBookmarksService);
|
||||
return BMSvc.createFolderWithDetails(aTitle, aParentFolder, ix);
|
||||
},
|
||||
|
||||
|
||||
addBookmarkForTabBrowser: function( aTabBrowser, aSelect )
|
||||
{
|
||||
var tabsInfo = [];
|
||||
var currentTabInfo = { name: "", url: "", charset: null };
|
||||
|
||||
const activeBrowser = aTabBrowser.selectedBrowser;
|
||||
const browsers = aTabBrowser.browsers;
|
||||
for (var i = 0; i < browsers.length; ++i) {
|
||||
var webNav = browsers[i].webNavigation;
|
||||
var url = webNav.currentURI.spec;
|
||||
var name = "";
|
||||
var charset;
|
||||
try {
|
||||
var doc = webNav.document;
|
||||
name = doc.title || url;
|
||||
charset = doc.characterSet;
|
||||
} catch (e) {
|
||||
name = url;
|
||||
}
|
||||
|
||||
tabsInfo[i] = { name: name, url: url, charset: charset };
|
||||
|
||||
if (browsers[i] == activeBrowser)
|
||||
currentTabInfo = tabsInfo[i];
|
||||
}
|
||||
|
||||
openDialog("chrome://communicator/content/bookmarks/addBookmark.xul", "",
|
||||
"centerscreen,chrome,dialog=yes,resizable,dependent",
|
||||
currentTabInfo.name, currentTabInfo.url, null,
|
||||
currentTabInfo.charset, "addGroup" + (aSelect ? ",group" : ""), tabsInfo);
|
||||
},
|
||||
|
||||
addBookmarkForBrowser: function (aDocShell, aShowDialog)
|
||||
{
|
||||
// Bug 52536: We obtain the URL and title from the nsIWebNavigation
|
||||
// associated with a <browser/> rather than from a DOMWindow.
|
||||
// This is because when a full page plugin is loaded, there is
|
||||
// no DOMWindow (?) but information about the loaded document
|
||||
// may still be obtained from the webNavigation.
|
||||
var url = aDocShell.currentURI.spec;
|
||||
var title, docCharset = null;
|
||||
try {
|
||||
title = aDocShell.document.title || url;
|
||||
docCharset = aDocShell.document.characterSet;
|
||||
}
|
||||
catch (e) {
|
||||
title = url;
|
||||
}
|
||||
|
||||
this.addBookmark(url, title, docCharset, aShowDialog);
|
||||
},
|
||||
|
||||
addBookmark: function (aURL, aTitle, aCharset, aShowDialog)
|
||||
{
|
||||
if (aCharset === undefined) {
|
||||
var fw = document.commandDispatcher.focusedWindow;
|
||||
aCharset = fw.document.characterSet;
|
||||
}
|
||||
|
||||
if (aShowDialog)
|
||||
openDialog("chrome://communicator/content/bookmarks/addBookmark.xul", "",
|
||||
"centerscreen,chrome,dialog=yes,resizable,dependent", aTitle, aURL, null, aCharset);
|
||||
else {
|
||||
// User has elected to override the file dialog and always file bookmarks
|
||||
// into the default bookmark folder.
|
||||
const kBMSvcContractID = "@mozilla.org/browser/bookmarks-service;1";
|
||||
const kBMSvcIID = Components.interfaces.nsIBookmarksService;
|
||||
const kBMSvc = Components.classes[kBMSvcContractID].getService(kBMSvcIID);
|
||||
kBMSvc.addBookmarkImmediately(aURL, aTitle, kBMSvcIID.BOOKMARK_DEFAULT_TYPE, aCharset);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var ContentUtils = {
|
||||
childByLocalName: function (aSelectedItem, aLocalName)
|
||||
{
|
||||
var temp = aSelectedItem.firstChild;
|
||||
while (temp) {
|
||||
if (temp.localName == aLocalName)
|
||||
return temp;
|
||||
temp = temp.nextSibling;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- -*- Mode: HTML; indent-tabs-mode: nil; -*- -->
|
||||
<!--
|
||||
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com> (Original Author)
|
||||
-->
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://communicator/locale/bookmarks/bookmarksOverlay.dtd">
|
||||
|
||||
<overlay id="bookmarksOverlay"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<stringbundleset id="stringbundleset">
|
||||
<stringbundle id="bookmarksbundle"
|
||||
src="chrome://communicator/locale/bookmarks/bookmark.properties"/>
|
||||
</stringbundleset>
|
||||
|
||||
<popupset id="bookmarksPopupset">
|
||||
<popup id="bmContext"
|
||||
onpopupshowing="gBookmarksShell.createContextMenu(event);"/>
|
||||
</popupset>
|
||||
|
||||
<commands id="commands">
|
||||
<commandset id="bookmarksItems">
|
||||
<command id="cmd_bm_open" oncommand="goDoCommand('cmd_bm_open');"/>
|
||||
<command id="cmd_bm_openfolder" oncommand="goDoCommand('cmd_bm_openfolder');"/>
|
||||
<command id="cmd_bm_newfolder" oncommand="goDoCommand('cmd_bm_newfolder');"/>
|
||||
<command id="cmd_bm_newbookmark" oncommand="goDoCommand('cmd_bm_newbookmark');"/>
|
||||
<command id="cmd_bm_newseparator" oncommand="goDoCommand('cmd_bm_newseparator');"/>
|
||||
<command id="cmd_bm_find" oncommand="goDoCommand('cmd_bm_find');"/>
|
||||
<command id="cmd_bm_setnewbookmarkfolder" oncommand="goDoCommand('cmd_bm_setnewbookmarkfolder');"/>
|
||||
<command id="cmd_bm_setpersonaltoolbarfolder" oncommand="goDoCommand('cmd_bm_setpersonaltoolbarfolder');"/>
|
||||
<command id="cmd_bm_setnewsearchfolder" oncommand="goDoCommand('cmd_bm_setnewsearchfolder');"/>
|
||||
<command id="cmd_bm_properties" oncommand="goDoCommand('cmd_bm_properties');"/>
|
||||
<command id="cmd_bm_rename" oncommand="goDoCommand('cmd_bm_rename');"/>
|
||||
<command id="cmd_bm_openinnewwindow" oncommand="goDoCommand('cmd_bm_openinnewwindow');"/>
|
||||
<command id="cmd_bm_import" oncommand="goDoCommand('cmd_bm_import');"/>
|
||||
<command id="cmd_bm_export" oncommand="goDoCommand('cmd_bm_export');"/>
|
||||
<command id="cmd_bm_fileBookmark" oncommand="goDoCommand('cmd_bm_fileBookmark');"/>
|
||||
|
||||
<command id="cmd_bm_cut" oncommand="goDoCommand('cmd_bm_cut');"/>
|
||||
<command id="cmd_bm_copy" oncommand="goDoCommand('cmd_bm_copy');"/>
|
||||
<command id="cmd_bm_paste" oncommand="goDoCommand('cmd_bm_paste');"/>
|
||||
<command id="cmd_bm_delete" oncommand="goDoCommand('cmd_bm_delete');"/>
|
||||
<command id="cmd_bm_selectAll" oncommand="goDoCommand('cmd_bm_selectAll');"/>
|
||||
</commandset>
|
||||
<commandset id="selectEditMenuItems"/>
|
||||
<commandset id="globalEditMenuItems"/>
|
||||
</commands>
|
||||
|
||||
</overlay>
|
||||
@@ -1,64 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Get the two bookmarks utility libraries running, attach controllers, focus
|
||||
// tree widget, etc.
|
||||
function Startup()
|
||||
{
|
||||
var bookmarksView = document.getElementById("bookmarks-view");
|
||||
bookmarksView.treeBoxObject.selection.select(0);
|
||||
}
|
||||
|
||||
function manageBookmarks() {
|
||||
openDialog("chrome://communicator/content/bookmarks/bookmarks.xul", "", "chrome,dialog=no,resizable=yes");
|
||||
}
|
||||
|
||||
function addBookmark() {
|
||||
var contentArea = top.document.getElementById('content');
|
||||
if (contentArea) {
|
||||
const browsers = contentArea.browsers;
|
||||
if (browsers.length > 1)
|
||||
BookmarksUtils.addBookmarkForTabBrowser(contentArea);
|
||||
else
|
||||
BookmarksUtils.addBookmarkForBrowser(contentArea.webNavigation, true);
|
||||
}
|
||||
else
|
||||
BookmarksUtils.addBookmark(null, null, undefined, true);
|
||||
}
|
||||
@@ -1,759 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var gBookmarksShell = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Tracks the selected item, the cell last clicked on, and the number of clicks
|
||||
// given to it. Used to activate inline edit mode.
|
||||
var gSelectionTracker = { currentItem: null, currentCell: null, clickCount: 0 };
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Class which defines methods for a bookmarks UI implementation based around
|
||||
// a treeview. Subclasses BookmarksBase in bookmarksOverlay.js. Some methods
|
||||
// are required by the base class, others are for event handling. Window specific
|
||||
// glue code should go into the BookmarksWindow class in bookmarks.js
|
||||
function BookmarksTree (aID)
|
||||
{
|
||||
this.id = aID;
|
||||
}
|
||||
|
||||
BookmarksTree.prototype = {
|
||||
__proto__: BookmarksUIElement.prototype,
|
||||
|
||||
// XXX - change this to .element and move into base.
|
||||
get tree ()
|
||||
{
|
||||
return document.getElementById(this.id);
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// This method constructs a menuitem for a context menu for the given command.
|
||||
// This is implemented by the client so that it can intercept menuitem naming
|
||||
// as appropriate.
|
||||
createMenuItem: function (aDisplayName, aCommandName, aItemNode)
|
||||
{
|
||||
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
var xulElement = document.createElementNS(kXULNS, "menuitem");
|
||||
xulElement.setAttribute("cmd", aCommandName);
|
||||
xulElement.setAttribute("command", "cmd_" + aCommandName.substring(NC_NS_CMD.length));
|
||||
|
||||
switch (aCommandName) {
|
||||
case NC_NS_CMD + "open":
|
||||
xulElement.setAttribute("label", aDisplayName);
|
||||
xulElement.setAttribute("default", "true");
|
||||
break;
|
||||
case NC_NS_CMD + "openfolder":
|
||||
aDisplayName = aItemNode.getAttribute("open") == "true" ? this.getLocaleString("cmd_openfolder2") : aDisplayName;
|
||||
xulElement.setAttribute("label", aDisplayName);
|
||||
xulElement.setAttribute("default", "true");
|
||||
break;
|
||||
case NC_NS_CMD + "renamebookmark":
|
||||
if (!document.popupNode.hasAttribute("type")) {
|
||||
xulElement.setAttribute("label", this.getLocaleString("cmd_renamebookmark2"));
|
||||
xulElement.setAttribute("cmd", (NC_NS_CMD + "editurl"));
|
||||
}
|
||||
else
|
||||
xulElement.setAttribute("label", aDisplayName);
|
||||
break;
|
||||
default:
|
||||
xulElement.setAttribute("label", aDisplayName);
|
||||
break;
|
||||
}
|
||||
return xulElement;
|
||||
},
|
||||
|
||||
// XXX - ideally this would be in the base. this.tree needs to change to
|
||||
// this.element and then we can do just that.
|
||||
setRoot: function (aRoot)
|
||||
{
|
||||
this.tree.setAttribute("ref", aRoot);
|
||||
},
|
||||
|
||||
// Command implementation
|
||||
commands: {
|
||||
openFolder: function (aSelectedItem)
|
||||
{
|
||||
if (aSelectedItem.getAttribute("open") == "true")
|
||||
aSelectedItem.removeAttribute("open");
|
||||
else
|
||||
aSelectedItem.setAttribute("open", "true");
|
||||
},
|
||||
|
||||
// Things Needed to Satisfy Mac Weenies:
|
||||
// 1) need to implement timed single click edit. This could be Hard.
|
||||
// 2) need to implement some other method of key access apart from F2.
|
||||
// mpt claims that 'Cmd+U' is the excel equivalent.
|
||||
editCell: function (aSelectedItem, aCell)
|
||||
{
|
||||
// XXX throw up properties dialog with name selected so user can rename
|
||||
// that way, until tree conversion allows us to use IL again.
|
||||
goDoCommand("cmd_properties");
|
||||
return; // Disable inline edit for now.
|
||||
|
||||
var editCell = aSelectedItem.firstChild.childNodes[aCell];
|
||||
if (editCell.getAttribute("editable") != "true")
|
||||
return;
|
||||
|
||||
// Cause the inline edit cell binding to be used.
|
||||
editCell.setAttribute("class", "treecell-indent treecell-editable");
|
||||
var editColGroup = document.getElementById("theColumns");
|
||||
var count = 0;
|
||||
var property = "";
|
||||
for (var i = 0; i < editColGroup.childNodes.length; ++i) {
|
||||
var currCol = editColGroup.childNodes[i];
|
||||
if (currCol.getAttribute("hidden") == "true")
|
||||
return;
|
||||
if (count == aCell) {
|
||||
property = currCol.getAttribute("resource");
|
||||
break;
|
||||
}
|
||||
++count;
|
||||
|
||||
// Deal with interleaved column resizer splitters
|
||||
if (currCol.nextSibling.localName == "splitter") ++i;
|
||||
}
|
||||
|
||||
if (property) {
|
||||
editCell.setMode("edit");
|
||||
editCell.addObserver(this.postModifyCallback, "accept",
|
||||
[editCell, aSelectedItem, property]);
|
||||
}
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Called after an inline-edit cell has left inline-edit mode, and data
|
||||
// needs to be modified in the datasource.
|
||||
postModifyCallback: function (aParams)
|
||||
{
|
||||
var selItemURI = NODE_ID(aParams[1]);
|
||||
gBookmarksShell.propertySet(selItemURI, aParams[2], aParams[3]);
|
||||
gBookmarksShell.selectFolderItem(NODE_ID(gBookmarksShell.findRDFNode(aParams[1], false)),
|
||||
selItemURI, false);
|
||||
gBookmarksShell.tree.focus();
|
||||
gSelectionTracker.clickCount = 0;
|
||||
|
||||
// Set the cell back to use the standard treecell binding.
|
||||
var editCell = aParams[0];
|
||||
editCell.setAttribute("class", "treecell-indent");
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// New Folder Creation
|
||||
// Strategy: create a dummy row with edit fields to harvest information
|
||||
// from the user, then destroy these rows and create an item
|
||||
// in its place.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Edit folder name & update the datasource if name is valid
|
||||
onEditFolderName: function (aParams, aTopic)
|
||||
{
|
||||
var name = aParams[3];
|
||||
var shell = gBookmarksShell.commands; // suck
|
||||
var dummyItem = aParams[2];
|
||||
var relativeNode = aParams[1];
|
||||
var parentNode = relativeNode ? gBookmarksShell.findRDFNode(relativeNode, false) : gBookmarksShell.tree;
|
||||
|
||||
dummyItem.parentNode.removeChild(dummyItem);
|
||||
|
||||
if (!shell.validateNameAndTopic(name, aTopic, relativeNode, dummyItem)) {
|
||||
gBookmarksShell.tree.selectItem(relativeNode);
|
||||
gBookmarksShell.tree.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (relativeNode) {
|
||||
// If we're attempting to create a folder as a subfolder of an open folder,
|
||||
// we need to set the parentFolder to be relativeNode, which will be the
|
||||
// parent of the new folder, rather than the parent of the relativeNode,
|
||||
// which will result in the folder being created in an incorrect position
|
||||
// (adjacent to the relativeNode).
|
||||
var selKids = ContentUtils.childByLocalName(relativeNode, "treechildren");
|
||||
if (selKids && selKids.hasChildNodes() && selKids.lastChild == dummyItem)
|
||||
parentNode = relativeNode;
|
||||
}
|
||||
|
||||
var args = [{ property: NC_NS + "parent",
|
||||
resource: NODE_ID(parentNode) },
|
||||
{ property: NC_NS + "Name",
|
||||
literal: name }];
|
||||
|
||||
const kBMDS = gBookmarksShell.RDF.GetDataSource("rdf:bookmarks");
|
||||
kBMDS.AddObserver(newFolderRDFObserver);
|
||||
var relId = relativeNode ? NODE_ID(relativeNode) : "NC:BookmarksRoot";
|
||||
BookmarksUtils.doBookmarksCommand(relId, NC_NS_CMD + "newfolder", args);
|
||||
kBMDS.RemoveObserver(newFolderRDFObserver);
|
||||
var newFolderItem = document.getElementById(newFolderRDFObserver._newFolderURI);
|
||||
gBookmarksShell.tree.focus();
|
||||
gBookmarksShell.tree.selectItem(newFolderItem);
|
||||
// Can't use newFolderItem because it may not have been created yet. Hack, huh?
|
||||
var index = gBookmarksShell.tree.getIndexOfItem(relativeNode);
|
||||
gBookmarksShell.tree.ensureIndexIsVisible(index+1);
|
||||
gSelectionTracker.clickCount = 0;
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Performs simple validation on what the user has entered:
|
||||
// 1) prevents entering an empty string
|
||||
// 2) in the case of a canceled operation, remove the dummy item and
|
||||
// restore selection.
|
||||
validateNameAndTopic: function (aName, aTopic, aOldSelectedItem, aDummyItem)
|
||||
{
|
||||
// Don't allow user to enter an empty string "";
|
||||
if (!aName) return false;
|
||||
|
||||
// If the user hit escape, go no further.
|
||||
if (aTopic == "reject") {
|
||||
if (aOldSelectedItem)
|
||||
gBookmarksShell.tree.selectItem(aOldSelectedItem);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Creates a dummy item that can be placed in edit mode to retrieve data
|
||||
// to create new bookmarks/folders.
|
||||
createBookmarkItem: function (aMode, aSelectedItem)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// HACK HACK HACK HACK HACK
|
||||
// Disable Inline-Edit for now and just use a dialog.
|
||||
|
||||
// XXX - most of this is just copy-pasted from the other two folder
|
||||
// creation functions. Yes it's ugly, but it'll do the trick for
|
||||
// now as this is in no way intended to be a long-term solution.
|
||||
|
||||
const kPromptSvcContractID = "@mozilla.org/embedcomp/prompt-service;1";
|
||||
const kPromptSvcIID = Components.interfaces.nsIPromptService;
|
||||
const kPromptSvc = Components.classes[kPromptSvcContractID].getService(kPromptSvcIID);
|
||||
|
||||
var defaultValue = gBookmarksShell.getLocaleString("ile_newfolder");
|
||||
var dialogTitle = gBookmarksShell.getLocaleString("newfolder_dialog_title");
|
||||
var dialogMsg = gBookmarksShell.getLocaleString("newfolder_dialog_msg");
|
||||
var stringValue = { value: defaultValue };
|
||||
if (kPromptSvc.prompt(window, dialogTitle, dialogMsg, stringValue, null, { value: 0 })) {
|
||||
var relativeNode = gBookmarksShell.tree;
|
||||
var parentNode;
|
||||
if (aSelectedItem && aSelectedItem.localName != "tree") {
|
||||
// By default, create adjacent to the selected item
|
||||
relativeNode = aSelectedItem;
|
||||
if (relativeNode.getAttribute("container") == "true" &&
|
||||
relativeNode.getAttribute("open") == "true") {
|
||||
// But if it's an open container, the relative node should be the last child.
|
||||
var treechildren = ContentUtils.childByLocalName(relativeNode, "treechildren");
|
||||
if (treechildren && treechildren.hasChildNodes())
|
||||
relativeNode = treechildren.lastChild; // folder non-empty, set relativeNode
|
||||
parentNode = aSelectedItem; // no matter what, folder is open, so make it parent
|
||||
} else {
|
||||
parentNode = relativeNode ? gBookmarksShell.findRDFNode(relativeNode, false) : gBookmarksShell.tree;
|
||||
}
|
||||
}
|
||||
|
||||
var args = [{ property: NC_NS + "parent",
|
||||
resource: NODE_ID(parentNode) },
|
||||
{ property: NC_NS + "Name",
|
||||
literal: stringValue.value }];
|
||||
|
||||
const kBMDS = gBookmarksShell.RDF.GetDataSource("rdf:bookmarks");
|
||||
kBMDS.AddObserver(newFolderRDFObserver);
|
||||
var relId = relativeNode ? NODE_ID(relativeNode) : "NC:BookmarksRoot";
|
||||
BookmarksUtils.doBookmarksCommand(relId, NC_NS_CMD + "newfolder", args);
|
||||
kBMDS.RemoveObserver(newFolderRDFObserver);
|
||||
var newFolderItem = document.getElementById(newFolderRDFObserver._newFolderURI);
|
||||
gBookmarksShell.tree.focus();
|
||||
gBookmarksShell.tree.selectItem(newFolderItem);
|
||||
// Can't use newFolderItem because it may not have been created yet. Hack, huh?
|
||||
var index = gBookmarksShell.tree.getIndexOfItem(relativeNode);
|
||||
gBookmarksShell.tree.ensureIndexIsVisible(index+1);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
// HACK HACK HACK HACK HACK
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Disable inline edit for now
|
||||
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
var dummyItem = document.createElementNS(kXULNS, "treeitem");
|
||||
dummyItem = gBookmarksShell.createBookmarkFolderDecorations(dummyItem);
|
||||
dummyItem.setAttribute("class", "bookmark-item");
|
||||
|
||||
var dummyRow = document.createElementNS(kXULNS, "treerow");
|
||||
var dummyCell = document.createElementNS(kXULNS, "treecell");
|
||||
var dummyCell2 = document.createElementNS(kXULNS, "treecell");
|
||||
dummyCell.setAttribute("label", gBookmarksShell.getLocaleString("ile_newfolder") + " ");
|
||||
dummyCell.setAttribute("type", NC_NS + "Folder");
|
||||
dummyCell.setAttribute("editable", "true");
|
||||
dummyCell.setAttribute("class", "treecell-indent treecell-editable");
|
||||
dummyRow.appendChild(dummyCell);
|
||||
dummyItem.appendChild(dummyRow);
|
||||
|
||||
var relativeNode = null;
|
||||
|
||||
// If there are selected items, try to create the dummy item relative to the
|
||||
// best item, and position the bookmark there when created. Otherwise just
|
||||
// append to the root.
|
||||
if (aSelectedItem && aSelectedItem.localName != "tree") {
|
||||
// By default, create adjacent to the selected item
|
||||
relativeNode = aSelectedItem;
|
||||
if (relativeNode.getAttribute("container") == "true" &&
|
||||
relativeNode.getAttribute("open") == "true") {
|
||||
// But if it's an open container, the relative node should be the last child.
|
||||
var treechildren = ContentUtils.childByLocalName(relativeNode, "treechildren");
|
||||
if (treechildren && treechildren.hasChildNodes())
|
||||
relativeNode = treechildren.lastChild;
|
||||
}
|
||||
|
||||
if (aSelectedItem.getAttribute("container") == "true") {
|
||||
if (aSelectedItem.getAttribute("open") == "true") {
|
||||
var treechildren = ContentUtils.childByLocalName(aSelectedItem, "treechildren");
|
||||
if (!treechildren) {
|
||||
treechildren = document.createElementNS(kXULNS, "treechildren");
|
||||
aSelectedItem.appendChild(treechildren);
|
||||
}
|
||||
// Insert new item after last item.
|
||||
treechildren.appendChild(dummyItem);
|
||||
}
|
||||
else {
|
||||
if (aSelectedItem.nextSibling)
|
||||
aSelectedItem.parentNode.insertBefore(dummyItem, aSelectedItem.nextSibling);
|
||||
else
|
||||
aSelectedItem.parentNode.appendChild(dummyItem);
|
||||
}
|
||||
var index = gBookmarksShell.tree.getIndexOfItem(dummyItem);
|
||||
gBookmarksShell.tree.ensureIndexIsVisible(index);
|
||||
}
|
||||
else {
|
||||
if (aSelectedItem.nextSibling)
|
||||
aSelectedItem.parentNode.insertBefore(dummyItem, aSelectedItem.nextSibling);
|
||||
else
|
||||
aSelectedItem.parentNode.appendChild(dummyItem);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No items in the tree. Append to the root.
|
||||
var rootKids = document.getElementById("treechildren-bookmarks");
|
||||
rootKids.appendChild(dummyItem);
|
||||
}
|
||||
|
||||
dummyCell.setMode("edit");
|
||||
dummyCell.addObserver(this.onEditFolderName, "accept", [dummyCell, relativeNode, dummyItem]);
|
||||
dummyCell.addObserver(this.onEditFolderName, "reject", [dummyCell, relativeNode, dummyItem]);
|
||||
*/
|
||||
}
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Evaluates an event to determine whether or not it affords opening a tree
|
||||
// item. Typically, this is when the left mouse button is used, and provided
|
||||
// the click-rate matches that specified by our owning tree class. For example,
|
||||
// some trees open an item when double clicked (bookmarks/history windows) and
|
||||
// others on a single click (sidebar panels).
|
||||
isValidOpenEvent: function (aEvent)
|
||||
{
|
||||
return !(aEvent.type == "click" &&
|
||||
(aEvent.button != 0 || aEvent.detail != this.openClickCount))
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// For the given selection, selects the best adjacent element. This method is
|
||||
// useful when an action such as a cut or a deletion is performed on a
|
||||
// selection, and focus/selection needs to be restored after the operation
|
||||
// is performed.
|
||||
getNextElement: function (aElement)
|
||||
{
|
||||
if (aElement.nextSibling)
|
||||
return aElement.nextSibling;
|
||||
else if (aElement.previousSibling)
|
||||
return aElement.previousSibling;
|
||||
else
|
||||
return aElement.parentNode.parentNode;
|
||||
},
|
||||
|
||||
selectElement: function (aElement)
|
||||
{
|
||||
this.tree.selectItem(aElement);
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Add the treeitem element specified by aURI to the tree's current selection.
|
||||
addItemToSelection: function (aURI)
|
||||
{
|
||||
var item = document.getElementById(aURI) // XXX flawed for multiple ids
|
||||
this.tree.addItemToSelection(item);
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Return a set of DOM nodes that represent the selection in the tree widget.
|
||||
// This method is takes a node parameter which is the popupNode for the
|
||||
// document. If the popupNode is not contained by the selection, the
|
||||
// popupNode is selected and the new selection returned.
|
||||
getSelection: function ()
|
||||
{
|
||||
// Note that we don't just the selectedItems NodeList here because that
|
||||
// is a reference to a LIVE DOM NODE LIST. We want to maintain control
|
||||
// over what is in the selection array ourselves.
|
||||
return [].concat(this.tree.selectedItems);
|
||||
},
|
||||
|
||||
getBestItem: function ()
|
||||
{
|
||||
var seln = this.getSelection ();
|
||||
if (seln.length < 1) {
|
||||
var kids = ContentUtils.childByLocalName(this.tree, "treechildren");
|
||||
return kids.lastChild || this.tree;
|
||||
}
|
||||
else
|
||||
return seln[0];
|
||||
return this.tree;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Return a set of DOM nodes that represent the selection in the tree widget.
|
||||
// This method is takes a node parameter which is the popupNode for the
|
||||
// document. If the popupNode is not contained by the selection, the
|
||||
// popupNode is selected and the new selection returned.
|
||||
getContextSelection: function (aItemNode)
|
||||
{
|
||||
// How a context-click works:
|
||||
// if the popup node is contained by the selection, the context menu is
|
||||
// built for that selection. However, if the popup node is invoked on a
|
||||
// non-selected node, unless modifiers are pressed**, the previous
|
||||
// selection is discarded and that node selected.
|
||||
var selectedItems = this.tree.selectedItems;
|
||||
for (var i = 0; i < selectedItems.length; ++i) {
|
||||
if (selectedItems[i] == aItemNode)
|
||||
return selectedItems;
|
||||
}
|
||||
if (aItemNode.localName == "treeitem")
|
||||
this.tree.selectItem(aItemNode);
|
||||
return this.tree.selectedItems.length ? this.tree.selectedItems : [this.tree];
|
||||
},
|
||||
|
||||
getSelectedFolder: function ()
|
||||
{
|
||||
var selectedItem = this.getBestItem();
|
||||
if (!selectedItem) return "NC:BookmarksRoot";
|
||||
while (selectedItem && selectedItem.nodeType == Node.ELEMENT_NODE) {
|
||||
if (selectedItem.getAttribute("container") == "true" &&
|
||||
selectedItem.getAttribute("open") == "true")
|
||||
return NODE_ID(selectedItem);
|
||||
selectedItem = selectedItem.parentNode.parentNode;
|
||||
}
|
||||
return "NC:BookmarksRoot";
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// For a given start DOM element, find the enclosing DOM element that contains
|
||||
// the template builder RDF resource decorations (id, ref, etc).
|
||||
findRDFNode: function (aStartNode, aIncludeStartNodeFlag)
|
||||
{
|
||||
var temp = aIncludeStartNodeFlag ? aStartNode : aStartNode.parentNode;
|
||||
while (temp && temp.localName != "treeitem")
|
||||
temp = temp.parentNode;
|
||||
return temp || this.tree;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Tree click events. This handles when to go into inline-edit mode for
|
||||
// editable cells.
|
||||
treeClicked: function (aEvent)
|
||||
{
|
||||
// We are disabling Inline Edit for now. It's too buggy in the old XUL tree widget.
|
||||
// A more solid implementation will follow the conversion to tree
|
||||
/*
|
||||
if (this.tree.selectedItems.length > 1 || aEvent.detail > 1 || aEvent.button != 0) {
|
||||
gSelectionTracker.clickCount = 0;
|
||||
return;
|
||||
}
|
||||
if (gSelectionTracker.currentItem == this.tree.currentItem &&
|
||||
gSelectionTracker.currentCell == aEvent.target)
|
||||
++gSelectionTracker.clickCount;
|
||||
else
|
||||
gSelectionTracker.clickCount = 0;
|
||||
|
||||
if (!this.tree.currentItem)
|
||||
return;
|
||||
|
||||
gSelectionTracker.currentItem = this.tree.currentItem;
|
||||
gSelectionTracker.currentCell = aEvent.target;
|
||||
|
||||
if (gSelectionTracker.currentItem.getAttribute("type") != NC_NS + "Bookmark" &&
|
||||
gSelectionTracker.currentItem.getAttribute("type") != NC_NS + "Folder")
|
||||
return;
|
||||
|
||||
var row = gSelectionTracker.currentItem.firstChild;
|
||||
if (row) {
|
||||
for (var i = 0; i < row.childNodes.length; ++i) {
|
||||
if (row.childNodes[i] == gSelectionTracker.currentCell) {
|
||||
// Don't allow inline-edit of cells other than name for folders.
|
||||
// XXX - so so skeezy. Change this to look for NC:Name or some such.
|
||||
if (gSelectionTracker.currentItem.getAttribute("type") != NC_NS + "Bookmark" && i)
|
||||
return;
|
||||
// Don't allow editing of the root folder name
|
||||
if (gSelectionTracker.currentItem.id == "NC:BookmarksRoot")
|
||||
return;
|
||||
if (gSelectionTracker.clickCount == 1 && this.openClickCount > 1)
|
||||
gBookmarksShell.commands.editCell(this.tree.currentItem, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
},
|
||||
|
||||
treeOpen: function (aEvent)
|
||||
{
|
||||
if (this.isValidOpenEvent(aEvent)) {
|
||||
var rdfNode = this.findRDFNode(aEvent.target, true);
|
||||
if (rdfNode.getAttribute("container") != "true")
|
||||
this.open(aEvent, rdfNode);
|
||||
}
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Tree key events. This handles when to go into inline-edit mode for editable
|
||||
// cells, when to load a URL, etc.
|
||||
treeKeyPress: function (aEvent)
|
||||
{
|
||||
if (this.tree.selectedItems.length > 1) return;
|
||||
|
||||
/* Disabling Inline Edit
|
||||
if (aEvent.keyCode == 113 && aEvent.shiftKey) {
|
||||
const kNodeId = NODE_ID(this.tree.currentItem);
|
||||
if (this.resolveType(kNodeId) == NC_NS + "Bookmark")
|
||||
gBookmarksShell.commands.editCell (this.tree.currentItem, 1);
|
||||
}
|
||||
else */
|
||||
if (aEvent.keyCode == 113)
|
||||
goDoCommand("cmd_rename");
|
||||
else if (aEvent.keyCode == 13) // && this.tree.currentItem.firstChild.getAttribute("inline-edit") != "true")
|
||||
goDoCommand(aEvent.altKey ? "cmd_properties" : "cmd_open");
|
||||
},
|
||||
|
||||
selectFolderItem: function (aFolderURI, aItemURI, aAdditiveFlag)
|
||||
{
|
||||
var folder = document.getElementById(aFolderURI);
|
||||
var kids = ContentUtils.childByLocalName(folder, "treechildren");
|
||||
if (!kids) return;
|
||||
|
||||
var item = kids.firstChild;
|
||||
while (item) {
|
||||
if (item.id == aItemURI) break;
|
||||
item = item.nextSibling;
|
||||
}
|
||||
if (!item) return;
|
||||
|
||||
this.tree[aAdditiveFlag ? "addItemToSelection" : "selectItem"](item);
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Command handling & Updating.
|
||||
controller: {
|
||||
supportsCommand: function (aCommand)
|
||||
{
|
||||
switch(aCommand) {
|
||||
case "cmd_undo":
|
||||
case "cmd_redo":
|
||||
return false;
|
||||
case "cmd_bm_cut":
|
||||
case "cmd_bm_copy":
|
||||
case "cmd_bm_paste":
|
||||
case "cmd_bm_delete":
|
||||
case "cmd_bm_selectAll":
|
||||
return true;
|
||||
case "cmd_open":
|
||||
case "cmd_openfolder":
|
||||
case "cmd_openfolderinnewwindow":
|
||||
case "cmd_newbookmark":
|
||||
case "cmd_newfolder":
|
||||
case "cmd_newseparator":
|
||||
case "cmd_find":
|
||||
case "cmd_properties":
|
||||
case "cmd_rename":
|
||||
case "cmd_setnewbookmarkfolder":
|
||||
case "cmd_setpersonaltoolbarfolder":
|
||||
case "cmd_setnewsearchfolder":
|
||||
case "cmd_import":
|
||||
case "cmd_export":
|
||||
case "cmd_bm_fileBookmark":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
isCommandEnabled: function (aCommand)
|
||||
{
|
||||
var numSelectedItems = gBookmarksShell.tree.selectedItems.length;
|
||||
var seln, firstSelected, folderType, bItemCountCorrect;
|
||||
switch(aCommand) {
|
||||
case "cmd_undo":
|
||||
case "cmd_redo":
|
||||
return false;
|
||||
case "cmd_bm_paste":
|
||||
return gBookmarksShell.canPaste();
|
||||
case "cmd_bm_cut":
|
||||
case "cmd_bm_copy":
|
||||
case "cmd_bm_delete":
|
||||
return numSelectedItems >= 1;
|
||||
case "cmd_bm_selectAll":
|
||||
return true;
|
||||
case "cmd_open":
|
||||
seln = gBookmarksShell.tree.selectedItems;
|
||||
return numSelectedItems == 1 && seln[0].getAttribute("type") == NC_NS + "Bookmark";
|
||||
case "cmd_openfolder":
|
||||
case "cmd_openfolderinnewwindow":
|
||||
seln = gBookmarksShell.tree.selectedItems;
|
||||
return numSelectedItems == 1 && seln[0].getAttribute("type") == NC_NS + "Folder";
|
||||
case "cmd_find":
|
||||
case "cmd_newbookmark":
|
||||
case "cmd_newfolder":
|
||||
case "cmd_newseparator":
|
||||
case "cmd_import":
|
||||
case "cmd_export":
|
||||
return true;
|
||||
case "cmd_properties":
|
||||
case "cmd_rename":
|
||||
seln = gBookmarksShell.tree.selectedItems;
|
||||
return numSelectedItems == 1 && seln[0].getAttribute("type") != NC_NS + "BookmarkSeparator";
|
||||
case "cmd_setnewbookmarkfolder":
|
||||
seln = gBookmarksShell.tree.selectedItems;
|
||||
firstSelected = seln.length ? seln[0] : gBookmarksShell.tree;
|
||||
folderType = firstSelected.getAttribute("type") == (NC_NS + "Folder");
|
||||
bItemCountCorrect = seln.length ? numSelectedItems == 1 : true;
|
||||
return bItemCountCorrect && !(NODE_ID(firstSelected) == "NC:NewBookmarkFolder") && folderType;
|
||||
case "cmd_setpersonaltoolbarfolder":
|
||||
seln = gBookmarksShell.tree.selectedItems;
|
||||
firstSelected = seln.length ? seln[0] : gBookmarksShell.tree;
|
||||
folderType = firstSelected.getAttribute("type") == (NC_NS + "Folder");
|
||||
bItemCountCorrect = seln.length ? numSelectedItems == 1 : true;
|
||||
return bItemCountCorrect && !(NODE_ID(firstSelected) == "NC:PersonalToolbarFolder") && folderType;
|
||||
case "cmd_setnewsearchfolder":
|
||||
seln = gBookmarksShell.tree.selectedItems;
|
||||
firstSelected = seln.length ? seln[0] : gBookmarksShell.tree;
|
||||
folderType = firstSelected.getAttribute("type") == (NC_NS + "Folder");
|
||||
bItemCountCorrect = seln.length ? numSelectedItems == 1 : true;
|
||||
return bItemCountCorrect == 1 && !(NODE_ID(firstSelected) == "NC:NewSearchFolder") && folderType;
|
||||
case "cmd_bm_fileBookmark":
|
||||
seln = gBookmarksShell.tree.selectedItems;
|
||||
return seln.length > 0;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
doCommand: function (aCommand)
|
||||
{
|
||||
switch(aCommand) {
|
||||
case "cmd_undo":
|
||||
case "cmd_redo":
|
||||
break;
|
||||
case "cmd_bm_paste":
|
||||
case "cmd_bm_copy":
|
||||
case "cmd_bm_cut":
|
||||
case "cmd_bm_delete":
|
||||
case "cmd_newbookmark":
|
||||
case "cmd_newfolder":
|
||||
case "cmd_newseparator":
|
||||
case "cmd_properties":
|
||||
case "cmd_rename":
|
||||
case "cmd_open":
|
||||
case "cmd_openfolder":
|
||||
case "cmd_openfolderinnewwindow":
|
||||
case "cmd_setnewbookmarkfolder":
|
||||
case "cmd_setpersonaltoolbarfolder":
|
||||
case "cmd_setnewsearchfolder":
|
||||
case "cmd_find":
|
||||
case "cmd_import":
|
||||
case "cmd_export":
|
||||
case "cmd_bm_fileBookmark":
|
||||
gBookmarksShell.execCommand(aCommand.substring("cmd_".length));
|
||||
break;
|
||||
case "cmd_bm_selectAll":
|
||||
gBookmarksShell.tree.selectAll();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
onEvent: function (aEvent)
|
||||
{
|
||||
switch (aEvent) {
|
||||
case "tree-select":
|
||||
this.onCommandUpdate();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
onCommandUpdate: function ()
|
||||
{
|
||||
var commands = ["cmd_properties", "cmd_rename", "cmd_bm_copy",
|
||||
"cmd_bm_paste", "cmd_bm_cut", "cmd_bm_delete",
|
||||
"cmd_setpersonaltoolbarfolder",
|
||||
"cmd_setnewbookmarkfolder",
|
||||
"cmd_setnewsearchfolder", "cmd_bm_fileBookmark",
|
||||
"cmd_openfolderinnewwindow", "cmd_openfolder"];
|
||||
for (var i = 0; i < commands.length; ++i)
|
||||
goUpdateCommand(commands[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var newFolderRDFObserver = {
|
||||
_newFolderURI: null,
|
||||
onAssert: function (aDS, aSource, aProperty, aValue)
|
||||
{
|
||||
try {
|
||||
var value = aValue.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
if (aDS.URI == "rdf:bookmarks" && aProperty.Value == RDF_NS + "type" &&
|
||||
value.Value == NC_NS + "Folder")
|
||||
this._newFolderURI = aSource.Value;
|
||||
}
|
||||
catch (e) {
|
||||
// Failures are OK, the value could be a literal instead of a resource.
|
||||
}
|
||||
},
|
||||
|
||||
onUnassert: function (aDS, aSource, aProperty, aTarget) { },
|
||||
onChange: function (aDS, aSource, aProperty, aOldTarget, aNewTarget) { },
|
||||
onMove: function (aDS, aOldSource, aNewSource, aProperty, aTarget) { },
|
||||
beginUpdateBatch: function (aDS) { },
|
||||
endUpdateBatch: function (aDS) { }
|
||||
};
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const BMARKS_CONTRACTID = "@mozilla.org/browser/bookmarks-service;1";
|
||||
const nsIBookmarksService = Components.interfaces.nsIBookmarksService;
|
||||
|
||||
var gOKButton;
|
||||
var gSearchField;
|
||||
function Startup()
|
||||
{
|
||||
var bundle = document.getElementById("bookmarksBundle");
|
||||
gOKButton = document.documentElement.getButton("accept");
|
||||
gOKButton.label = bundle.getString("search_button_label");
|
||||
gOKButton.disabled = true;
|
||||
gSearchField = document.getElementById("searchField");
|
||||
gSearchField.focus();
|
||||
}
|
||||
var gCreatingNewWindow = false;
|
||||
function find()
|
||||
{
|
||||
// Build up a find URI from the search fields and open a new window
|
||||
// rooted on the URI.
|
||||
var match = document.getElementById("matchList");
|
||||
var method = document.getElementById("methodList");
|
||||
var searchURI = "find:datasource=rdf:bookmarks"
|
||||
searchURI += "&match=" + match.selectedItem.value;
|
||||
searchURI += "&method=" + method.selectedItem.value;
|
||||
searchURI += "&text=" + escape(gSearchField.value);
|
||||
var bmWindow = findMostRecentWindow("bookmarks:searchresults", "chrome://communicator/content/bookmarks/bookmarks.xul", searchURI);
|
||||
|
||||
// Update the root of the tree if we're using an existing search window.
|
||||
if (!gCreatingNewWindow)
|
||||
bmWindow.document.getElementById("bookmarks-view").tree.setAttribute("ref", searchURI);
|
||||
|
||||
bmWindow.focus();
|
||||
|
||||
if (document.getElementById("saveQuery").checked == true)
|
||||
{
|
||||
var bundle = document.getElementById("bookmarksBundle");
|
||||
var findTitle = bundle.stringBundle.formatStringFromName(
|
||||
"ShortFindTitle", [gSearchField.value], 1);
|
||||
var bmks = Components.classes[BMARKS_CONTRACTID].getService(nsIBookmarksService);
|
||||
bmks.addBookmarkImmediately(searchURI, findTitle, bmks.BOOKMARK_FIND_TYPE, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function findMostRecentWindow(aType, aURI, aParam)
|
||||
{
|
||||
var WM = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
|
||||
WM = WM.QueryInterface(Components.interfaces.nsIWindowMediator);
|
||||
var topWindow = WM.getMostRecentWindow(aType);
|
||||
if (!topWindow) gCreatingNewWindow = true;
|
||||
return topWindow || openDialog("chrome://communicator/content/bookmarks/bookmarks.xul",
|
||||
"", "chrome,all,dialog=no", aParam);
|
||||
}
|
||||
|
||||
function doEnabling()
|
||||
{
|
||||
gOKButton.disabled = !gSearchField.value;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- -*- Mode: HTML; indent-tabs-mode: nil; -*- -->
|
||||
<!--
|
||||
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com> (Original Author)
|
||||
-->
|
||||
|
||||
<!--
|
||||
"Find Bookmarks" window
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/"?>
|
||||
<!DOCTYPE window SYSTEM "chrome://communicator/locale/bookmarks/findBookmark.dtd">
|
||||
|
||||
<dialog id="findBookmarkWindow" style="width: 36em;"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&findBookmark.title;"
|
||||
onload="Startup();"
|
||||
ondialogaccept="return find();">
|
||||
|
||||
<stringbundle id="bookmarksBundle" src="chrome://communicator/locale/bookmarks/bookmark.properties"/>
|
||||
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksOverlay.js"/>
|
||||
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/findBookmark.js"/>
|
||||
|
||||
<label value="&search.for.label;"/>
|
||||
<hbox align="center">
|
||||
<menulist id="matchList" class="menulist-toolbar">
|
||||
<menupopup>
|
||||
<menuitem value="http://home.netscape.com/NC-rdf#Name" label="&search.name.label;"/>
|
||||
<menuitem value="http://home.netscape.com/NC-rdf#URL" label="&search.url.label;"/>
|
||||
<menuitem value="http://home.netscape.com/NC-rdf#Description" label="&search.description.label;"/>
|
||||
<menuitem value="http://home.netscape.com/NC-rdf#ShortcutURL" label="&search.shortcut.label;"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
<menulist id="methodList" class="menulist-toolbar">
|
||||
<menupopup>
|
||||
<menuitem value="contains" label="&search.contains.label;"/>
|
||||
<menuitem value="startswith" label="&search.startswith.label;"/>
|
||||
<menuitem value="endswith" label="&search.endswith.label;"/>
|
||||
<menuitem value="is" label="&search.is.label;"/>
|
||||
<menuitem value="isnot" label="&search.isnot.label;"/>
|
||||
<menuitem value="doesntcontain" label="&search.doesntcontain.label;"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
<textbox id="searchField" flex="1" oninput="doEnabling();"/>
|
||||
</hbox>
|
||||
<checkbox id="saveQuery" label="&save.query.label;" />
|
||||
</dialog>
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
comm.jar:
|
||||
content/communicator/bookmarks/addBookmark.xul
|
||||
content/communicator/bookmarks/addBookmark.js
|
||||
content/communicator/bookmarks/bm-props.js
|
||||
content/communicator/bookmarks/bm-props.xul
|
||||
content/communicator/bookmarks/bookmarksDD.js
|
||||
content/communicator/bookmarks/bookmarks.xul
|
||||
content/communicator/bookmarks/bookmarks.js
|
||||
content/communicator/bookmarks/bookmarks.css
|
||||
content/communicator/bookmarks/bookmarks.xml
|
||||
content/communicator/bookmarks/bookmarksTree.js
|
||||
content/communicator/bookmarks/bookmarksOverlay.xul
|
||||
content/communicator/bookmarks/bookmarksOverlay.js
|
||||
content/communicator/bookmarks/bm-panel.xul
|
||||
content/communicator/bookmarks/bookmarksPanel.js
|
||||
content/communicator/bookmarks/findBookmark.js
|
||||
content/communicator/bookmarks/findBookmark.xul
|
||||
content/communicator/bookmarks/pref-bookmarks.xul
|
||||
content/communicator/bookmarks/oTest.xul
|
||||
|
||||
en-US.jar:
|
||||
locale/en-US/communicator/bookmarks/addBookmark.dtd (locale/en-US/addBookmark.dtd)
|
||||
locale/en-US/communicator/bookmarks/bm-props.dtd (locale/en-US/bm-props.dtd)
|
||||
locale/en-US/communicator/bookmarks/bookmarks.dtd (locale/en-US/bookmarks.dtd)
|
||||
locale/en-US/communicator/bookmarks/bookmark.properties (locale/en-US/bookmark.properties)
|
||||
locale/en-US/communicator/bookmarks/bookmarksOverlay.dtd (locale/en-US/bookmarksOverlay.dtd)
|
||||
locale/en-US/communicator/bookmarks/findBookmark.dtd (locale/en-US/findBookmark.dtd)
|
||||
locale/en-US/communicator/bookmarks/pref-bookmarks.dtd (locale/en-US/pref-bookmarks.dtd)
|
||||
@@ -1,4 +0,0 @@
|
||||
en-US:bm-find.dtd
|
||||
en-US:bm-props.dtd
|
||||
en-US:bookmarks.dtd
|
||||
en-US:bookmark.properties
|
||||
@@ -1,4 +0,0 @@
|
||||
bm-find.dtd
|
||||
bm-props.dtd
|
||||
bookmark.properties
|
||||
bookmarks.dtd
|
||||
@@ -1,46 +0,0 @@
|
||||
<!--
|
||||
- The contents of this file are subject to the Mozilla Public
|
||||
- License Version 1.1 (the "License"); you may not use this file
|
||||
- except in compliance with the License. You may obtain a copy of
|
||||
- the License at http://www.mozilla.org/MPL/
|
||||
-
|
||||
- Software distributed under the License is distributed on an "AS
|
||||
- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
- implied. See the License for the specific language governing
|
||||
- rights and limitations under the License.
|
||||
-
|
||||
- The Original Code is Mozilla Communicator.
|
||||
-
|
||||
- The Initial Developer of the Original Code is Netscape
|
||||
- Communications Corp. Portions created by Netscape Communications
|
||||
- Corp. are Copyright (C) 1999 Netscape Communications Corp. All
|
||||
- Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
- Ben Goodger <ben@netscape.com> (Original Author)
|
||||
-->
|
||||
|
||||
<!ENTITY newBookmark.title "Add Bookmark">
|
||||
<!ENTITY newbookmark.label "&brandShortName; will add a bookmark to this page.">
|
||||
<!ENTITY name.label "Name:">
|
||||
<!ENTITY name.accesskey "n">
|
||||
<!ENTITY url.label "Location:">
|
||||
<!ENTITY url.accesskey "l">
|
||||
<!ENTITY button.createin.label "Create In >>">
|
||||
<!ENTITY button.createin.accesskey "c">
|
||||
<!ENTITY button.createin2.label "Create In <<">
|
||||
<!ENTITY createin.label "Create in:">
|
||||
<!ENTITY createin.accesskey "i">
|
||||
<!ENTITY button.newfolder.label "New Folder...">
|
||||
<!ENTITY button.newfolder.accesskey "w">
|
||||
<!ENTITY alwayscreateinfolder.label "Don't show this dialog again">
|
||||
<!ENTITY alwayscreateinfolder.accesskey "a">
|
||||
<!ENTITY dontshowmessage.tooltip "When this option is selected, new Bookmarks will be added using the title provided by the page.">
|
||||
<!ENTITY button.defaultfolder.label "Use Default">
|
||||
<!ENTITY button.defaultfolder.accesskey "d">
|
||||
<!ENTITY selectFolder.label "Choose Folder">
|
||||
<!ENTITY addGroup.label "Bookmark this group of tabs">
|
||||
<!ENTITY addGroup.accesskey "B">
|
||||
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
<!--
|
||||
- The contents of this file are subject to the Mozilla Public
|
||||
- License Version 1.1 (the "License"); you may not use this file
|
||||
- except in compliance with the License. You may obtain a copy of
|
||||
- the License at http://www.mozilla.org/MPL/
|
||||
-
|
||||
- Software distributed under the License is distributed on an "AS
|
||||
- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
- implied. See the License for the specific language governing
|
||||
- rights and limitations under the License.
|
||||
-
|
||||
- The Original Code is Mozilla Communicator.
|
||||
-
|
||||
- The Initial Developer of the Original Code is Netscape
|
||||
- Communications Corp. Portions created by Netscape Communications
|
||||
- Corp. are Copyright (C) 1999 Netscape Communications Corp. All
|
||||
- Rights Reserved.
|
||||
-
|
||||
- Contributor(s): Stephen Lamm <slamm@netscape.com>
|
||||
- Robert John Churchill <rjc@netscape.com>
|
||||
- Ben Goodger <ben@netscape.com>
|
||||
-->
|
||||
|
||||
<!ENTITY bookmarks.windowtitle.label "Properties for "**bm_title**"">
|
||||
|
||||
<!ENTITY generalInfo.label "Info">
|
||||
<!ENTITY generalInfo.accesskey "i">
|
||||
<!ENTITY generaldesc.label "&brandShortName; can remember the locations of sites on the Internet for you. Enter the site's name and location in the fields below, then select the site from the Bookmarks menu or your Bookmarks Sidebar tab to visit the site.">
|
||||
|
||||
<!ENTITY schedule.label "Schedule">
|
||||
<!ENTITY schedule.accesskey "s">
|
||||
<!ENTITY schedule.description "&brandShortName; can check this site for updates and notify you when one occurs. Use these settings to customize the schedule for this Bookmark.">
|
||||
<!ENTITY notification.label "Notify">
|
||||
<!ENTITY notification.accesskey "n">
|
||||
<!-- ICK. fix me -->
|
||||
<!ENTITY notification.description "&brandShortName; will notify you when this site changes. Use these settings to customize notification.">
|
||||
|
||||
<!ENTITY bookmarks.information.label "Information:">
|
||||
<!ENTITY bookmarks.name.label "Name:">
|
||||
<!ENTITY bookmarks.location.label "Location:">
|
||||
<!ENTITY bookmarks.shortcut.label "Keyword:">
|
||||
<!ENTITY bookmarks.description.label "Description:">
|
||||
|
||||
<!ENTITY checkforupdates.legend.label "Check this location for updates:">
|
||||
<!ENTITY when.label "When:">
|
||||
<!ENTITY from.label "from:">
|
||||
<!ENTITY to.label "to: ">
|
||||
<!ENTITY every.label "every">
|
||||
<!ENTITY minutes.label "minute(s)">
|
||||
<!ENTITY notifications.legend.label "Notification:">
|
||||
|
||||
<!ENTITY checknever.label "Never">
|
||||
<!ENTITY checkeveryday.label "Every day">
|
||||
<!ENTITY checkweekdays.label "Weekdays">
|
||||
<!ENTITY checkweekends.label "Weekends">
|
||||
<!ENTITY checkmondays.label "Mondays">
|
||||
<!ENTITY checktuesdays.label "Tuesdays">
|
||||
<!ENTITY checkwednesdays.label "Wednesdays">
|
||||
<!ENTITY checkthursdays.label "Thursdays">
|
||||
<!ENTITY checkfridays.label "Fridays">
|
||||
<!ENTITY checksaturdays.label "Saturdays">
|
||||
<!ENTITY checksundays.label "Sundays">
|
||||
|
||||
<!ENTITY midnight.label "Midnight">
|
||||
<!ENTITY AMone.label "1 AM">
|
||||
<!ENTITY AMtwo.label "2 AM">
|
||||
<!ENTITY AMthree.label "3 AM">
|
||||
<!ENTITY AMfour.label "4 AM">
|
||||
<!ENTITY AMfive.label "5 AM">
|
||||
<!ENTITY AMsix.label "6 AM">
|
||||
<!ENTITY AMseven.label "7 AM">
|
||||
<!ENTITY AMeight.label "8 AM">
|
||||
<!ENTITY AMnine.label "9 AM">
|
||||
<!ENTITY AMten.label "10 AM">
|
||||
<!ENTITY AMeleven.label "11 AM">
|
||||
<!ENTITY noon.label "Noon">
|
||||
<!ENTITY PMone.label "1 PM">
|
||||
<!ENTITY PMtwo.label "2 PM">
|
||||
<!ENTITY PMthree.label "3 PM">
|
||||
<!ENTITY PMfour.label "4 PM">
|
||||
<!ENTITY PMfive.label "5 PM">
|
||||
<!ENTITY PMsix.label "6 PM">
|
||||
<!ENTITY PMseven.label "7 PM">
|
||||
<!ENTITY PMeight.label "8 PM">
|
||||
<!ENTITY PMnine.label "9 PM">
|
||||
<!ENTITY PMten.label "10 PM">
|
||||
<!ENTITY PMeleven.label "11 PM">
|
||||
|
||||
<!ENTITY notification.icon.label "Change the bookmark's icon">
|
||||
<!ENTITY notification.sound.label "Play a sound">
|
||||
<!ENTITY notification.alert.label "Display an alert">
|
||||
<!ENTITY notification.window.label "Open web page in a new window">
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user