Added suppor /and fix things for SunOS port

git-svn-id: https://svn.pjsip.org/repos/pjproject/main@2 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Benny Prijono 2005-11-01 16:42:51 +00:00
parent 0a749f11c7
commit dd859a62f4
311 changed files with 91128 additions and 90888 deletions

View File

@ -1,43 +1,45 @@
DIRS = pjlib pjsdp pjmedia pjsip
MAKE_FLAGS := TARGET=$(TARGET)
ifdef MINSIZE
MAKE_FLAGS := $(MAKE_FLAGS) MINSIZE=1
endif
all clean dep depend distclean doc print realclean:
for dir in $(DIRS); do \
if [ -d $$dir ]; then \
if make $(MAKE_FLAGS) -C $$dir/build $@; then \
true; \
else \
exit 1; \
fi; \
fi \
done
LIBS = pjlib/lib/libpj.a pjsdp/lib/libpjsdp.a pjmedia/lib/libpjmedia.a \
pjsip/lib/libpjsip_core.a pjsip/lib/libpjsip_ua.a
BINS = pjsip/bin/pjsua$(EXE)
include pjlib/build/make-$(TARGET).inc
size:
@echo 'TARGET=$(TARGET)'
@echo -n 'Date: '
@date
@echo
@for lib in $(LIBS); do \
echo "$$lib:"; \
ar tv $$lib | awk '{print $$3 "\t" $$8}' | sort -n; \
echo -n 'Total: '; \
ar tv $$lib | awk '{print " + " $$3}' | xargs expr 0; \
echo; \
done
@echo
@for bin in $(BINS); do \
echo "size $$bin:"; \
size $$bin; \
done
DIRS = pjlib pjsdp pjmedia pjsip
ifdef MINSIZE
MAKE_FLAGS := MINSIZE=1
endif
all clean dep depend distclean doc print realclean:
for dir in $(DIRS); do \
if [ -d $$dir ]; then \
if make $(MAKE_FLAGS) -C $$dir/build $@; then \
true; \
else \
exit 1; \
fi; \
fi \
done
LIBS = pjlib/lib/libpj.a pjsdp/lib/libpjsdp.a pjmedia/lib/libpjmedia.a \
pjsip/lib/libpjsip_core.a pjsip/lib/libpjsip_ua.a
BINS = pjsip/bin/pjsua$(EXE)
size:
@echo -n 'Date: '
@date
@echo
@for lib in $(LIBS); do \
echo "$$lib:"; \
ar tv $$lib | awk '{print $$3 "\t" $$8}' | sort -n; \
echo -n 'Total: '; \
ar tv $$lib | awk '{print " + " $$3}' | xargs expr 0; \
echo; \
done
@echo
@for bin in $(BINS); do \
echo "size $$bin:"; \
size $$bin; \
done
dos2unix:
for f in `find . | egrep '(mak|h|c|S|s|Makefile)$$'`; do \
dos2unix "$$f" > dos2unix.tmp; \
cp dos2unix.tmp "$$f"; \
done
rm -f dos2unix.tmp

118
build.mak
View File

@ -1,55 +1,63 @@
# Build configurations:
#
# MACHINE_NAME values:
# - i386 (generic x86)
# - m68k
#
# OS_NAME values:
# - win32 (generic windows)
# - linux
#
# CC_NAME values:
# - gcc
# - msvc
#
# HOST_NAME values:
# - win32 (Windows command line)
# - mingw (Windows, mingw)
#
#
# PalmOS 6 cross-compile, cygwin
#
#export MACHINE_NAME := m68k
#export OS_NAME := palmos
#export CC_NAME := gcc
#export HOST_NAME := mingw
#
# Win32, mingw
#
#export MACHINE_NAME := i386
#export OS_NAME := win32
#export CC_NAME := gcc
#export HOST_NAME := mingw
#
# Linux i386, gcc
#
export MACHINE_NAME := i386
export OS_NAME := linux
export CC_NAME := gcc
export HOST_NAME := unix
#
# Linux KERNEL i386, gcc
#
#export MACHINE_NAME := i386
#export OS_NAME := linux-kernel
#export CC_NAME := gcc
#export HOST_NAME := unix
#export PJPROJECT_DIR := /usr/src/pjproject-0.3
##export KERNEL_DIR = /usr/src/linux
#export KERNEL_DIR = /usr/src/uml/linux
#export KERNEL_ARCH = ARCH=um
# Build configurations:
#
# MACHINE_NAME values:
# - i386 (generic x86)
# - m68k
#
# OS_NAME values:
# - win32 (generic windows)
# - linux
#
# CC_NAME values:
# - gcc
# - msvc
#
# HOST_NAME values:
# - win32 (Windows command line)
# - mingw (Windows, mingw)
#
#
# PalmOS 6 cross-compile, cygwin
#
#export MACHINE_NAME := m68k
#export OS_NAME := palmos
#export CC_NAME := gcc
#export HOST_NAME := mingw
#
# Win32, mingw
#
#export MACHINE_NAME := i386
#export OS_NAME := win32
#export CC_NAME := gcc
#export HOST_NAME := mingw
#
# Linux i386, gcc
#
export MACHINE_NAME := i386
export OS_NAME := linux
export CC_NAME := gcc
export HOST_NAME := unix
#
# Linux KERNEL i386, gcc
#
#export MACHINE_NAME := i386
#export OS_NAME := linux-kernel
#export CC_NAME := gcc
#export HOST_NAME := unix
#export PJPROJECT_DIR := /usr/src/pjproject-0.3
##export KERNEL_DIR = /usr/src/linux
#export KERNEL_DIR = /usr/src/uml/linux
#export KERNEL_ARCH = ARCH=um
#
# SunOS, sparc, gcc
#
export MACHINE_NAME := sparc
export OS_NAME := sunos
export CC_NAME := gcc
export HOST_NAME := unix

View File

@ -1,22 +1,22 @@
export CC = $(CROSS_COMPILE)gcc -c
export AR = $(CROSS_COMPILE)ar r
export LD = $(CROSS_COMPILE)gcc
export LDOUT = -o
export RANLIB = $(CROSS_COMPILE)ranlib
export OBJEXT := .o
export LIBEXT := .a
export LIBEXT2 :=
export CC_OUT := -o
export CC_INC := -I
export CC_DEF := -D
export CC_OPTIMIZE := -O2
export CC_LIB := -l
export CC_SOURCES :=
export CC_CFLAGS := -Wall
#export CC_CFLAGS += -Wdeclaration-after-statement
#export CC_CXXFLAGS := -Wdeclaration-after-statement
export CC_LDFLAGS :=
export CC = $(CROSS_COMPILE)gcc -c
export AR = $(CROSS_COMPILE)ar r
export LD = $(CROSS_COMPILE)gcc
export LDOUT = -o
export RANLIB = $(CROSS_COMPILE)ranlib
export OBJEXT := .o
export LIBEXT := .a
export LIBEXT2 :=
export CC_OUT := -o
export CC_INC := -I
export CC_DEF := -D
export CC_OPTIMIZE := -O2
export CC_LIB := -l
export CC_SOURCES :=
export CC_CFLAGS := -Wall
#export CC_CFLAGS += -Wdeclaration-after-statement
#export CC_CXXFLAGS := -Wdeclaration-after-statement
export CC_LDFLAGS :=

View File

@ -1,20 +1,20 @@
export CC := cl /c /nologo
export AR := lib /NOLOGO /OUT:
export LD := cl /nologo
export LDOUT := /Fe
export RANLIB := echo ranlib
export OBJEXT := .obj
export LIBEXT := .lib
export LIBEXT2 := .LIB
export CC_OUT := /Fo
export CC_INC := /I
export CC_DEF := /D
export CC_OPTIMIZE := /Ox
export CC_LIB :=
export CC_SOURCES :=
export CC_CFLAGS := /W4 /MT
export CC_CXXFLAGS := /GX
export CC_LDFLAGS := /MT
export CC := cl /c /nologo
export AR := lib /NOLOGO /OUT:
export LD := cl /nologo
export LDOUT := /Fe
export RANLIB := echo ranlib
export OBJEXT := .obj
export LIBEXT := .lib
export LIBEXT2 := .LIB
export CC_OUT := /Fo
export CC_INC := /I
export CC_DEF := /D
export CC_OPTIMIZE := /Ox
export CC_LIB :=
export CC_SOURCES :=
export CC_CFLAGS := /W4 /MT
export CC_CXXFLAGS := /GX
export CC_LDFLAGS := /MT

View File

@ -1,13 +1,13 @@
export HOST_MV := mv
export HOST_RM := rm -f @@
export HOST_RMR := rm -rf @@
export HOST_RMDIR := rm -rf @@
export HOST_MKDIR := mkdir @@
export HOST_EXE := .exe
export HOST_PSEP := /
export HOST_SOURCES :=
export HOST_CFLAGS :=
export HOST_CXXFLAGS :=
export HOST_LDFLAGS := $(CC_LIB)stdc++$(LIBEXT2)
export HOST_MV := mv
export HOST_RM := rm -f @@
export HOST_RMR := rm -rf @@
export HOST_RMDIR := rm -rf @@
export HOST_MKDIR := mkdir @@
export HOST_EXE := .exe
export HOST_PSEP := /
export HOST_SOURCES :=
export HOST_CFLAGS :=
export HOST_CXXFLAGS :=
export HOST_LDFLAGS := $(CC_LIB)stdc++$(LIBEXT2)

View File

@ -1,13 +1,13 @@
export HOST_MV := mv
export HOST_RM := rm -f @@
export HOST_RMR := rm -rf @@
export HOST_RMDIR := rm -rf @@
export HOST_MKDIR := mkdir @@
export HOST_EXE :=
export HOST_PSEP := /
export HOST_SOURCES :=
export HOST_CFLAGS :=
export HOST_CXXFLAGS :=
export HOST_LDFLAGS :=
export HOST_MV := mv
export HOST_RM := rm -f @@
export HOST_RMR := rm -rf @@
export HOST_RMDIR := rm -rf @@
export HOST_MKDIR := mkdir @@
export HOST_EXE :=
export HOST_PSEP := /
export HOST_SOURCES :=
export HOST_CFLAGS :=
export HOST_CXXFLAGS :=
export HOST_LDFLAGS :=

View File

@ -1,12 +1,12 @@
export HOST_MV := ren
export HOST_RM := if exist @@; del /F /Q @@
export HOST_RMR := if exist @@; del /F /Q @@
export HOST_RMDIR := if exist @@; rmdir @@
export HOST_MKDIR := if not exist @@; mkdir @@
export HOST_EXE := .exe
export HOST_PSEP := \\
export HOST_SOURCES :=
export HOST_CFLAGS :=
export HOST_CXXFLAGS :=
export HOST_LDFLAGS :=
export HOST_MV := ren
export HOST_RM := if exist @@; del /F /Q @@
export HOST_RMR := if exist @@; del /F /Q @@
export HOST_RMDIR := if exist @@; rmdir @@
export HOST_MKDIR := if not exist @@; mkdir @@
export HOST_EXE := .exe
export HOST_PSEP := \\
export HOST_SOURCES :=
export HOST_CFLAGS :=
export HOST_CXXFLAGS :=
export HOST_LDFLAGS :=

View File

@ -1,4 +1,4 @@
export M_CFLAGS := $(CC_DEF)PJ_M_ALPHA=1
export M_CXXFLAGS :=
export M_LDFLAGS :=
export M_SOURCES :=
export M_CFLAGS := $(CC_DEF)PJ_M_ALPHA=1
export M_CXXFLAGS :=
export M_LDFLAGS :=
export M_SOURCES :=

View File

@ -1,4 +1,4 @@
export M_CFLAGS := $(CC_DEF)PJ_M_I386=1
export M_CXXFLAGS :=
export M_LDFLAGS :=
export M_SOURCES :=
export M_CFLAGS := $(CC_DEF)PJ_M_I386=1
export M_CXXFLAGS :=
export M_LDFLAGS :=
export M_SOURCES :=

View File

@ -1,4 +1,4 @@
export M_CFLAGS := $(CC_DEF)PJ_M_M68K=1
export M_CXXFLAGS :=
export M_LDFLAGS :=
export M_SOURCES :=
export M_CFLAGS := $(CC_DEF)PJ_M_M68K=1
export M_CXXFLAGS :=
export M_LDFLAGS :=
export M_SOURCES :=

4
build/m-sparc.mak Normal file
View File

@ -0,0 +1,4 @@
export M_CFLAGS := $(CC_DEF)PJ_M_SPARC=1
export M_CXXFLAGS :=
export M_LDFLAGS :=
export M_SOURCES :=

View File

@ -1,43 +1,43 @@
include $(KERNEL_DIR)/.config
#
# Basic kernel compilation flags.
#
export OS_CFLAGS := $(CC_DEF)PJ_LINUX_KERNEL=1 -D__KERNEL__ \
-I$(KERNEL_DIR)/include -iwithprefix include \
-nostdinc -msoft-float
#
# Additional kernel compilation flags are taken from the kernel Makefile
# itself.
#
KERNEL_CFLAGS := \
$(shell cd $(KERNEL_DIR) ; \
make script SCRIPT='@echo $$(CFLAGS) $$(CFLAGS_MODULE)' $(KERNEL_ARCH))
export OS_CFLAGS += $(KERNEL_CFLAGS)
# -DMODULE -I$(KERNEL_DIR)/include -nostdinc \
# -Wstrict-prototypes \
# -Wno-trigraphs -fno-strict-aliasing -fno-common \
# -msoft-float -m32 -fno-builtin-sprintf -fno-builtin-log2\
# -fno-builtin-puts -mpreferred-stack-boundary=2 \
# -fno-unit-at-a-time -march=i686 -mregparm=3 \
# -iwithprefix include
#export OS_CFLAGS += -U__i386__ -Ui386 -D__arch_um__ -DSUBARCH=\"i386\" \
# -D_LARGEFILE64_SOURCE -I$(KERNEL_DIR)/arch/um/include \
# -Derrno=kernel_errno \
# -I$(KERNEL_DIR)/arch/um/kernel/tt/include \
# -I$(KERNEL_DIR)/arch/um/kernel/skas/include \
export OS_CXXFLAGS :=
export OS_LDFLAGS :=
export OS_SOURCES :=
include $(KERNEL_DIR)/.config
#
# Basic kernel compilation flags.
#
export OS_CFLAGS := $(CC_DEF)PJ_LINUX_KERNEL=1 -D__KERNEL__ \
-I$(KERNEL_DIR)/include -iwithprefix include \
-nostdinc -msoft-float
#
# Additional kernel compilation flags are taken from the kernel Makefile
# itself.
#
KERNEL_CFLAGS := \
$(shell cd $(KERNEL_DIR) ; \
make script SCRIPT='@echo $$(CFLAGS) $$(CFLAGS_MODULE)' $(KERNEL_ARCH))
export OS_CFLAGS += $(KERNEL_CFLAGS)
# -DMODULE -I$(KERNEL_DIR)/include -nostdinc \
# -Wstrict-prototypes \
# -Wno-trigraphs -fno-strict-aliasing -fno-common \
# -msoft-float -m32 -fno-builtin-sprintf -fno-builtin-log2\
# -fno-builtin-puts -mpreferred-stack-boundary=2 \
# -fno-unit-at-a-time -march=i686 -mregparm=3 \
# -iwithprefix include
#export OS_CFLAGS += -U__i386__ -Ui386 -D__arch_um__ -DSUBARCH=\"i386\" \
# -D_LARGEFILE64_SOURCE -I$(KERNEL_DIR)/arch/um/include \
# -Derrno=kernel_errno \
# -I$(KERNEL_DIR)/arch/um/kernel/tt/include \
# -I$(KERNEL_DIR)/arch/um/kernel/skas/include \
export OS_CXXFLAGS :=
export OS_LDFLAGS :=
export OS_SOURCES :=

View File

@ -1,9 +1,9 @@
export OS_CFLAGS := $(CC_DEF)PJ_LINUX=1
export OS_CXXFLAGS :=
export OS_LDFLAGS := $(CC_LIB)pthread$(LIBEXT2)
export OS_SOURCES :=
export OS_CFLAGS := $(CC_DEF)PJ_LINUX=1
export OS_CXXFLAGS :=
export OS_LDFLAGS := $(CC_LIB)pthread$(LIBEXT2)
export OS_SOURCES :=

View File

@ -1,32 +1,32 @@
#
# make-mingw.inc: Mingw specific compilation switches.
#
PALM_OS_SDK_VER := 0x06000000
PALM_OS_TARGET_HOST := TARGET_HOST_PALMOS
PALM_OS_TARGET_PLATFORM := TARGET_PLATFORM_PALMSIM_WIN32
PALM_OS_BUILD_TYPE := BUILD_TYPE_DEBUG
PALM_OS_TRACE_OUTPUT := TRACE_OUTPUT_ON
PALM_OS_CPU_TYPE := CPU_ARM
export CROSS_COMPILE :=
ifeq ($(CC_NAME),gcc)
export CFLAGS += -mno-cygwin -fexceptions -frtti
endif
export OS_CFLAGS := $(CC_DEF)PJ_PALMOS=1 \
$(CC_DEF)__PALMOS_KERNEL__=1 \
$(CC_DEF)__PALMOS__=$(PALM_OS_SDK_VER) \
$(CC_DEF)BUILD_TYPE=$(PALM_OS_BUILD_TYPE) \
$(CC_DEF)TRACE_OUTPUT=$(PALM_OS_TRACE_OUTPUT) \
$(CC_DEF)_SUPPORTS_NAMESPACE=0 \
$(CC_DEF)_SUPPORTS_RTTI=0 \
$(CC_DEF)TARGET_HOST=$(PALM_OS_TRAGET_HOST) \
$(CC_DEF)TARGET_PLATFORM=$(PALM_OS_TARGET_PLATFORM)
export OS_CXXFLAGS :=
export OS_LDFLAGS :=
export OS_SOURCES :=
#
# make-mingw.inc: Mingw specific compilation switches.
#
PALM_OS_SDK_VER := 0x06000000
PALM_OS_TARGET_HOST := TARGET_HOST_PALMOS
PALM_OS_TARGET_PLATFORM := TARGET_PLATFORM_PALMSIM_WIN32
PALM_OS_BUILD_TYPE := BUILD_TYPE_DEBUG
PALM_OS_TRACE_OUTPUT := TRACE_OUTPUT_ON
PALM_OS_CPU_TYPE := CPU_ARM
export CROSS_COMPILE :=
ifeq ($(CC_NAME),gcc)
export CFLAGS += -mno-cygwin -fexceptions -frtti
endif
export OS_CFLAGS := $(CC_DEF)PJ_PALMOS=1 \
$(CC_DEF)__PALMOS_KERNEL__=1 \
$(CC_DEF)__PALMOS__=$(PALM_OS_SDK_VER) \
$(CC_DEF)BUILD_TYPE=$(PALM_OS_BUILD_TYPE) \
$(CC_DEF)TRACE_OUTPUT=$(PALM_OS_TRACE_OUTPUT) \
$(CC_DEF)_SUPPORTS_NAMESPACE=0 \
$(CC_DEF)_SUPPORTS_RTTI=0 \
$(CC_DEF)TARGET_HOST=$(PALM_OS_TRAGET_HOST) \
$(CC_DEF)TARGET_PLATFORM=$(PALM_OS_TARGET_PLATFORM)
export OS_CXXFLAGS :=
export OS_LDFLAGS :=
export OS_SOURCES :=

12
build/os-sunos.mak Normal file
View File

@ -0,0 +1,12 @@
export OS_CFLAGS := $(CC_DEF)PJ_SUNOS=1
export OS_CXXFLAGS :=
export OS_LDFLAGS := $(CC_LIB)pthread$(LIBEXT2) \
$(CC_LIB)socket$(LIBEXT2) \
$(CC_LIB)rt$(LIBEXT2) \
$(CC_LIB)nsl$(LIBEXT2)
export OS_SOURCES :=

View File

@ -1,11 +1,11 @@
export OS_CFLAGS := $(CC_DEF)PJ_WIN32=1
export OS_CXXFLAGS :=
export OS_LDFLAGS := $(CC_LIB)wsock32$(LIBEXT2) \
$(CC_LIB)ws2_32$(LIBEXT2)\
$(CC_LIB)ole32$(LIBEXT2)
export OS_SOURCES :=
export OS_CFLAGS := $(CC_DEF)PJ_WIN32=1
export OS_CXXFLAGS :=
export OS_LDFLAGS := $(CC_LIB)wsock32$(LIBEXT2) \
$(CC_LIB)ws2_32$(LIBEXT2)\
$(CC_LIB)ole32$(LIBEXT2)
export OS_SOURCES :=

View File

@ -1,164 +1,165 @@
LIBDIR = ../lib
BINDIR = ../bin
#
# The full path of output lib file (e.g. ../lib/libapp.a).
#
LIB = $($(APP)_LIB)
#
# The full path of output executable file (e.g. ../bin/app.exe).
#
EXE = $($(APP)_EXE)
#
# Source directory
#
SRCDIR = $($(APP)_SRCDIR)
#
# Output directory for object files (i.e. output/target)
#
OBJDIR = output/$(app)-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)
ifeq ($(OS_NAME),linux-kernel)
export $(APP)_CFLAGS += -DKBUILD_MODNAME=$(app) -DKBUILD_BASENAME=$(app)
endif
#
# OBJS is ./output/target/file.o
#
OBJS = $(foreach file, $($(APP)_OBJS), $(OBJDIR)/$(file))
OBJDIRS := $(sort $(dir $(OBJS)))
#
# FULL_SRCS is ../src/app/file1.c ../src/app/file1.S
#
FULL_SRCS = $(foreach file, $($(APP)_OBJS), $(SRCDIR)/$(basename $(file)).c $(SRCDIR)/$(basename $(file)).cpp $(SRCDIR)/$(basename $(file)).S)
#
# When generating dependency (gcc -MM), ideally we use only either
# CFLAGS or CXXFLAGS (not both). But I just couldn't make if/ifeq to work.
#
DEPFLAGS = $($(APP)_CXXFLAGS) $($(APP)_CFLAGS)
# Dependency file
DEP_FILE := .$(app)-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME).depend
print_common:
@echo "###"
@echo "### DUMPING MAKE VARIABLES (I WON'T DO ANYTHING ELSE):"
@echo "###"
@echo APP=$(APP)
@echo OBJDIR=$(OBJDIR)
@echo OBJDIRS=$(OBJDIRS)
@echo OBJS=$(OBJS)
@echo SRCDIR=$(SRCDIR)
@echo FULL_SRCS=$(FULL_SRCS)
@echo $(APP)_CFLAGS=$($(APP)_CFLAGS)
@echo $(APP)_CXXFLAGS=$($(APP)_CXXFLAGS)
@echo $(APP)_LDFLAGS=$($(APP)_LDFLAGS)
@echo DEPFLAGS=$(DEPFLAGS)
print_bin: print_common
@echo EXE=$(EXE)
@echo BINDIR=$(BINDIR)
print_lib: print_common
@echo LIB=$(LIB)
@echo LIBDIR=$(LIBDIR)
$(LIB): $(LIBDIR) $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
$(AR)$(LIB) $(OBJS)
$(RANLIB) $(LIB)
$(EXE): $(BINDIR) $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
$(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$(EXE)) \
$(subst /,$(HOST_PSEP),$(OBJS)) $($(APP)_LDFLAGS)
$(OBJDIR)/$(app).o: $(OBJDIRS) $(OBJS)
$(CROSS_COMPILE)ld -r -o $@ $(OBJS)
$(OBJDIR)/$(app).ko: $(OBJDIR)/$(app).o
@echo Creating kbuild Makefile...
@echo "# Our module name:" > $(OBJDIR)/Makefile
@echo 'obj-m += $(app).o' >> $(OBJDIR)/Makefile
@echo >> $(OBJDIR)/Makefile
@echo "# Object members:" >> $(OBJDIR)/Makefile
@echo -n '$(app)-objs += ' >> $(OBJDIR)/Makefile
@for file in $($(APP)_OBJS); do \
echo -n "$$file " >> $(OBJDIR)/Makefile; \
done
@echo >> $(OBJDIR)/Makefile
@echo >> $(OBJDIR)/Makefile
@echo "# Prevent .o files to be built by kbuild:" >> $(OBJDIR)/Makefile
@for file in $($(APP)_OBJS); do \
echo ".PHONY: `pwd`/$(OBJDIR)/$$file" >> $(OBJDIR)/Makefile; \
done
@echo >> $(OBJDIR)/Makefile
@echo all: >> $(OBJDIR)/Makefile
@echo -e "\tmake -C $(KERNEL_DIR) M=`pwd`/$(OBJDIR) modules $(KERNEL_ARCH)" >> $(OBJDIR)/Makefile
@echo Invoking kbuild...
make -C $(OBJDIR)
../lib/$(app).ko: $(LIB) $(OBJDIR)/$(app).ko
cp $(OBJDIR)/$(app).ko ../lib
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.c
$(CC) $($(APP)_CFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \
$(subst /,$(HOST_PSEP),$<)
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.S
$(CC) $($(APP)_CFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \
$(subst /,$(HOST_PSEP),$<)
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.cpp
$(CC) $($(APP)_CXXFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \
$(subst /,$(HOST_PSEP),$<)
$(OBJDIRS):
$(subst @@,$(subst /,$(HOST_PSEP),$@),$(HOST_MKDIR))
$(LIBDIR):
$(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)),$(HOST_MKDIR))
$(BINDIR):
$(subst @@,$(subst /,$(HOST_PSEP),$(BINDIR)),$(HOST_MKDIR))
clean:
$(subst @@,$(subst /,$(HOST_PSEP),$(OBJDIR)/*),$(HOST_RMR))
$(subst @@,$(subst /,$(HOST_PSEP),$(OBJDIR)),$(HOST_RMDIR))
ifeq ($(OS_NAME),linux-kernel)
rm -f ../lib/$(app).o
endif
realclean: clean
$(subst @@,$(subst /,$(HOST_PSEP),$(LIB)) $(subst /,$(HOST_PSEP),$(EXE)),$(HOST_RM))
$(subst @@,$(DEP_FILE),$(HOST_RM))
ifeq ($(OS_NAME),linux-kernel)
rm -f ../lib/$(app).ko
endif
depend:
$(subst @@,$(DEP_FILE),$(HOST_RM))
for F in $(FULL_SRCS); do \
if test -f $$F; then \
echo -n $(OBJDIR)/ >> $(DEP_FILE); \
if gcc -MM $(DEPFLAGS) $$F | sed '/^#/d' >> $(DEP_FILE); then \
true; \
else \
echo 'err:' >> $(DEP_FILE); \
exit 1; \
fi; \
fi; \
done
dep: depend
-include $(DEP_FILE)
LIBDIR = ../lib
BINDIR = ../bin
#
# The full path of output lib file (e.g. ../lib/libapp.a).
#
LIB = $($(APP)_LIB)
#
# The full path of output executable file (e.g. ../bin/app.exe).
#
EXE = $($(APP)_EXE)
#
# Source directory
#
SRCDIR = $($(APP)_SRCDIR)
#
# Output directory for object files (i.e. output/target)
#
OBJDIR = output/$(app)-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)
ifeq ($(OS_NAME),linux-kernel)
export $(APP)_CFLAGS += -DKBUILD_MODNAME=$(app) -DKBUILD_BASENAME=$(app)
endif
#
# OBJS is ./output/target/file.o
#
OBJS = $(foreach file, $($(APP)_OBJS), $(OBJDIR)/$(file))
OBJDIRS := $(sort $(dir $(OBJS)))
#
# FULL_SRCS is ../src/app/file1.c ../src/app/file1.S
#
FULL_SRCS = $(foreach file, $($(APP)_OBJS), $(SRCDIR)/$(basename $(file)).c $(SRCDIR)/$(basename $(file)).cpp $(SRCDIR)/$(basename $(file)).S)
#
# When generating dependency (gcc -MM), ideally we use only either
# CFLAGS or CXXFLAGS (not both). But I just couldn't make if/ifeq to work.
#
DEPFLAGS = $($(APP)_CXXFLAGS) $($(APP)_CFLAGS)
# Dependency file
DEP_FILE := .$(app)-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME).depend
print_common:
@echo "###"
@echo "### DUMPING MAKE VARIABLES (I WON'T DO ANYTHING ELSE):"
@echo "###"
@echo APP=$(APP)
@echo OBJDIR=$(OBJDIR)
@echo OBJDIRS=$(OBJDIRS)
@echo OBJS=$(OBJS)
@echo SRCDIR=$(SRCDIR)
@echo FULL_SRCS=$(FULL_SRCS)
@echo $(APP)_CFLAGS=$($(APP)_CFLAGS)
@echo $(APP)_CXXFLAGS=$($(APP)_CXXFLAGS)
@echo $(APP)_LDFLAGS=$($(APP)_LDFLAGS)
@echo DEPFLAGS=$(DEPFLAGS)
print_bin: print_common
@echo EXE=$(EXE)
@echo BINDIR=$(BINDIR)
print_lib: print_common
@echo LIB=$(LIB)
@echo LIBDIR=$(LIBDIR)
$(LIB): $(LIBDIR) $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
$(AR)$(LIB) $(OBJS)
$(RANLIB) $(LIB)
$(EXE): $(BINDIR) $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)
$(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$(EXE)) \
$(subst /,$(HOST_PSEP),$(OBJS)) $($(APP)_LDFLAGS)
$(OBJDIR)/$(app).o: $(OBJDIRS) $(OBJS)
$(CROSS_COMPILE)ld -r -o $@ $(OBJS)
$(OBJDIR)/$(app).ko: $(OBJDIR)/$(app).o
@echo Creating kbuild Makefile...
@echo "# Our module name:" > $(OBJDIR)/Makefile
@echo 'obj-m += $(app).o' >> $(OBJDIR)/Makefile
@echo >> $(OBJDIR)/Makefile
@echo "# Object members:" >> $(OBJDIR)/Makefile
@echo -n '$(app)-objs += ' >> $(OBJDIR)/Makefile
@for file in $($(APP)_OBJS); do \
echo -n "$$file " >> $(OBJDIR)/Makefile; \
done
@echo >> $(OBJDIR)/Makefile
@echo >> $(OBJDIR)/Makefile
@echo "# Prevent .o files to be built by kbuild:" >> $(OBJDIR)/Makefile
@for file in $($(APP)_OBJS); do \
echo ".PHONY: `pwd`/$(OBJDIR)/$$file" >> $(OBJDIR)/Makefile; \
done
@echo >> $(OBJDIR)/Makefile
@echo all: >> $(OBJDIR)/Makefile
@echo -e "\tmake -C $(KERNEL_DIR) M=`pwd`/$(OBJDIR) modules $(KERNEL_ARCH)" >> $(OBJDIR)/Makefile
@echo Invoking kbuild...
make -C $(OBJDIR)
../lib/$(app).ko: $(LIB) $(OBJDIR)/$(app).ko
cp $(OBJDIR)/$(app).ko ../lib
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.c
$(CC) $($(APP)_CFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \
$(subst /,$(HOST_PSEP),$<)
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.S
$(CC) $($(APP)_CFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \
$(subst /,$(HOST_PSEP),$<)
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.cpp
$(CC) $($(APP)_CXXFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \
$(subst /,$(HOST_PSEP),$<)
$(OBJDIRS):
$(subst @@,$(subst /,$(HOST_PSEP),$@),$(HOST_MKDIR))
$(LIBDIR):
$(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)),$(HOST_MKDIR))
$(BINDIR):
$(subst @@,$(subst /,$(HOST_PSEP),$(BINDIR)),$(HOST_MKDIR))
clean:
$(subst @@,$(subst /,$(HOST_PSEP),$(OBJDIR)/*),$(HOST_RMR))
$(subst @@,$(subst /,$(HOST_PSEP),$(OBJDIR)),$(HOST_RMDIR))
ifeq ($(OS_NAME),linux-kernel)
rm -f ../lib/$(app).o
endif
realclean: clean
$(subst @@,$(subst /,$(HOST_PSEP),$(LIB)) $(subst /,$(HOST_PSEP),$(EXE)),$(HOST_RM))
$(subst @@,$(DEP_FILE),$(HOST_RM))
ifeq ($(OS_NAME),linux-kernel)
rm -f ../lib/$(app).ko
endif
depend:
$(subst @@,$(DEP_FILE),$(HOST_RM))
for F in $(FULL_SRCS); do \
if test -f $$F; then \
bash -c "echo -n $(OBJDIR)/" >> $(DEP_FILE); \
if gcc -MM $(DEPFLAGS) $$F | sed '/^#/d' >> $(DEP_FILE); then \
true; \
else \
echo 'err:' >> $(DEP_FILE); \
rm -f $(DEP_FILE); \
exit 1; \
fi; \
fi; \
done;
dep: depend
-include $(DEP_FILE)

View File

@ -1,151 +1,151 @@
#
# Include host/target/compiler selection.
# This will export CC_NAME, MACHINE_NAME, OS_NAME, and HOST_NAME variables.
#
include ../../build.mak
#
# Include global compiler specific definitions
#
include ../../build/cc-$(CC_NAME).mak
#
# (Optionally) Include compiler specific configuration that is
# specific to this project. This configuration file is
# located in this directory.
#
-include cc-$(CC_NAME).mak
#
# Include global machine specific definitions
#
include ../../build/m-$(MACHINE_NAME).mak
-include m-$(MACHINE_NAME).mak
#
# Include target OS specific definitions
#
include ../../build/os-$(OS_NAME).mak
#
# (Optionally) Include target OS specific configuration that is
# specific to this project. This configuration file is
# located in this directory.
#
-include os-$(OS_NAME).mak
#
# Include host specific definitions
#
include ../../build/host-$(HOST_NAME).mak
#
# (Optionally) Include host specific configuration that is
# specific to this project. This configuration file is
# located in this directory.
#
-include host-$(HOST_NAME).mak
#
# Include global user configuration, if any
#
-include ../../user.mak
RULES_MAK := ../../build/rules.mak
export PJLIB_LIB := ../lib/libpj-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)$(LIBEXT)
###############################################################################
# Gather all flags.
#
export _CFLAGS := $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) \
$(CFLAGS) $(CC_INC)../include
export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
$(HOST_CXXFLAGS) $(CXXFLAGS)
export _LDFLAGS := $(subst /,$(HOST_PSEP),$(PJLIB_LIB)) \
$(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
$(LDFLAGS)
###############################################################################
# Defines for building PJLIB library
#
export PJLIB_SRCDIR = ../src/pj
export PJLIB_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
array.o config.o errno.o except.o fifobuf.o guid.o \
hash.o list.o lock.o log.o \
md5.o pool.o pool_caching.o rand.o \
rbtree.o scanner.o string.o stun.o stun_client.o timer.o \
types.o xml.o symbols.o
export PJLIB_CFLAGS += $(_CFLAGS)
###############################################################################
# Defines for building test application
#
export TEST_SRCDIR = ../src/pjlib-test
export TEST_OBJS += atomic.o echo_clt.o echo_srv.o errno.o exception.o \
fifobuf.o \
ioq_perf.o ioq_udp.o ioq_tcp.o \
list.o mutex.o os.o pool.o pool_perf.o rand.o rbtree.o \
select.o sleep.o sock.o sock_perf.o \
string.o test.o thread.o timer.o timestamp.o \
udp_echo_srv_sync.o \
util.o xml.o
export TEST_CFLAGS += $(_CFLAGS)
export TEST_LDFLAGS += $(_LDFLAGS)
export TEST_EXE := ../bin/pjlib-test-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)$(HOST_EXE)
export CC_OUT CC AR RANLIB HOST_MV HOST_RM HOST_RMDIR HOST_MKDIR OBJEXT LD LDOUT
###############################################################################
# Main entry
#
# $(TARGET) is defined in os-$(OS_NAME).mak file in current directory.
#
all: $(TARGETS)
doc:
cd .. && doxygen docs/doxygen.cfg
print:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib print_lib
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test print_bin
depend:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib depend
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test depend
echo '$(TEST_EXE): $(PJLIB_LIB)' >> .pjlib-test-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME).depend
.PHONY: dep depend pjlib pjlib-test clean realclean distclean
dep: depend
pjlib:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $(PJLIB_LIB)
pjlib-test:
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $(TEST_EXE)
.PHONY: ../lib/pjlib.ko
../lib/pjlib.ko:
echo Making $@
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $@
.PHONY: ../lib/pjlib-test.ko
../lib/pjlib-test.ko:
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $@
clean:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib clean
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test clean
realclean:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib realclean
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test realclean
distclean: realclean
#
# Include host/target/compiler selection.
# This will export CC_NAME, MACHINE_NAME, OS_NAME, and HOST_NAME variables.
#
include ../../build.mak
#
# Include global compiler specific definitions
#
include ../../build/cc-$(CC_NAME).mak
#
# (Optionally) Include compiler specific configuration that is
# specific to this project. This configuration file is
# located in this directory.
#
-include cc-$(CC_NAME).mak
#
# Include global machine specific definitions
#
include ../../build/m-$(MACHINE_NAME).mak
-include m-$(MACHINE_NAME).mak
#
# Include target OS specific definitions
#
include ../../build/os-$(OS_NAME).mak
#
# (Optionally) Include target OS specific configuration that is
# specific to this project. This configuration file is
# located in this directory.
#
-include os-$(OS_NAME).mak
#
# Include host specific definitions
#
include ../../build/host-$(HOST_NAME).mak
#
# (Optionally) Include host specific configuration that is
# specific to this project. This configuration file is
# located in this directory.
#
-include host-$(HOST_NAME).mak
#
# Include global user configuration, if any
#
-include ../../user.mak
RULES_MAK := ../../build/rules.mak
export PJLIB_LIB := ../lib/libpj-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)$(LIBEXT)
###############################################################################
# Gather all flags.
#
export _CFLAGS := -O2 $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) \
$(CFLAGS) $(CC_INC)../include
export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
$(HOST_CXXFLAGS) $(CXXFLAGS)
export _LDFLAGS := $(subst /,$(HOST_PSEP),$(PJLIB_LIB)) \
$(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
$(LDFLAGS)
###############################################################################
# Defines for building PJLIB library
#
export PJLIB_SRCDIR = ../src/pj
export PJLIB_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
array.o config.o errno.o except.o fifobuf.o guid.o \
hash.o list.o lock.o log.o \
md5.o pool.o pool_caching.o rand.o \
rbtree.o scanner.o string.o stun.o stun_client.o timer.o \
types.o xml.o symbols.o
export PJLIB_CFLAGS += $(_CFLAGS)
###############################################################################
# Defines for building test application
#
export TEST_SRCDIR = ../src/pjlib-test
export TEST_OBJS += atomic.o echo_clt.o echo_srv.o errno.o exception.o \
fifobuf.o \
ioq_perf.o ioq_udp.o ioq_tcp.o \
list.o mutex.o os.o pool.o pool_perf.o rand.o rbtree.o \
select.o sleep.o sock.o sock_perf.o \
string.o test.o thread.o timer.o timestamp.o \
udp_echo_srv_sync.o \
util.o xml.o
export TEST_CFLAGS += $(_CFLAGS)
export TEST_LDFLAGS += $(_LDFLAGS)
export TEST_EXE := ../bin/pjlib-test-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)$(HOST_EXE)
export CC_OUT CC AR RANLIB HOST_MV HOST_RM HOST_RMDIR HOST_MKDIR OBJEXT LD LDOUT
###############################################################################
# Main entry
#
# $(TARGET) is defined in os-$(OS_NAME).mak file in current directory.
#
all: $(TARGETS)
doc:
cd .. && doxygen docs/doxygen.cfg
print:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib print_lib
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test print_bin
depend:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib depend
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test depend
echo '$(TEST_EXE): $(PJLIB_LIB)' >> .pjlib-test-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME).depend
.PHONY: dep depend pjlib pjlib-test clean realclean distclean
dep: depend
pjlib:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $(PJLIB_LIB)
pjlib-test:
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $(TEST_EXE)
.PHONY: ../lib/pjlib.ko
../lib/pjlib.ko:
echo Making $@
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib $@
.PHONY: ../lib/pjlib-test.ko
../lib/pjlib-test.ko:
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test $@
clean:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib clean
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test clean
realclean:
$(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib realclean
$(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test realclean
distclean: realclean

View File

@ -1,47 +1,47 @@
#
# OS specific configuration for Linux Kernel module target.
#
#
# PJLIB_OBJS specified here are object files to be included in PJLIB
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += compat/sigjmp.o compat/setjmp_i386.o \
compat/longjmp_i386.o compat/string.o \
addr_resolv_linux_kernel.o \
guid_simple.o \
log_writer_printk.o pool_policy_kmalloc.o \
os_error_linux_kernel.o os_core_linux_kernel.o \
os_time_linux_kernel.o os_timestamp_common.o \
os_timestamp_linux_kernel.o \
sock_linux_kernel.o sock_select.o
# For IOQueue, we can use either epoll or select
export PJLIB_OBJS += ioqueue_epoll.o
#export PJLIB_OBJS += ioqueue_select.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += main_mod.o
#
# Additional CFLAGS
#
export TEST_CFLAGS += -msoft-float
#
# Additional LD_FLAGS for this target.
#
export TEST_LDFLAGS += -lgcc
#
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS := ../lib/pjlib.ko ../lib/pjlib-test.ko
#
# OS specific configuration for Linux Kernel module target.
#
#
# PJLIB_OBJS specified here are object files to be included in PJLIB
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += compat/sigjmp.o compat/setjmp_i386.o \
compat/longjmp_i386.o compat/string.o \
addr_resolv_linux_kernel.o \
guid_simple.o \
log_writer_printk.o pool_policy_kmalloc.o \
os_error_linux_kernel.o os_core_linux_kernel.o \
os_time_linux_kernel.o os_timestamp_common.o \
os_timestamp_linux_kernel.o \
sock_linux_kernel.o sock_select.o
# For IOQueue, we can use either epoll or select
export PJLIB_OBJS += ioqueue_epoll.o
#export PJLIB_OBJS += ioqueue_select.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += main_mod.o
#
# Additional CFLAGS
#
export TEST_CFLAGS += -msoft-float
#
# Additional LD_FLAGS for this target.
#
export TEST_LDFLAGS += -lgcc
#
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS := ../lib/pjlib.ko ../lib/pjlib-test.ko

View File

@ -1,36 +1,36 @@
#
# OS specific configuration for Linux OS target.
#
#
# PJLIB_OBJS specified here are object files to be included in PJLIB
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += addr_resolv_sock.o guid_simple.o \
log_writer_stdout.o os_core_unix.o \
os_error_unix.o os_time_ansi.o \
os_timestamp_common.o os_timestamp_linux.o \
os_time_ansi.o \
pool_policy_malloc.o sock_bsd.o sock_select.o
export PJLIB_OBJS += ioqueue_select.o
#export PJLIB_OBJS += ioqueue_epoll.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += main.o
#
# Additional LDFLAGS for pjlib-test
#
export TEST_LDFLAGS += -lm
#
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS = pjlib pjlib-test
#
# OS specific configuration for Linux OS target.
#
#
# PJLIB_OBJS specified here are object files to be included in PJLIB
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += addr_resolv_sock.o guid_simple.o \
log_writer_stdout.o os_core_unix.o \
os_error_unix.o os_time_ansi.o \
os_timestamp_common.o os_timestamp_linux.o \
os_time_ansi.o \
pool_policy_malloc.o sock_bsd.o sock_select.o
export PJLIB_OBJS += ioqueue_select.o
#export PJLIB_OBJS += ioqueue_epoll.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += main.o
#
# Additional LDFLAGS for pjlib-test
#
export TEST_LDFLAGS += -lm
#
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS = pjlib pjlib-test

36
pjlib/build/os-sunos.mak Normal file
View File

@ -0,0 +1,36 @@
#
# PJLIB OS specific configuration for SunOS target.
#
#
# PJLIB_OBJS specified here are object files to be included in PJLIB
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += addr_resolv_sock.o guid_simple.o \
log_writer_stdout.o os_core_unix.o \
os_error_unix.o os_time_ansi.o \
os_timestamp_common.o os_timestamp_linux.o \
os_time_ansi.o \
pool_policy_malloc.o sock_bsd.o sock_select.o
export PJLIB_OBJS += ioqueue_select.o
#export PJLIB_OBJS += ioqueue_epoll.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += main.o
#
# Additional LDFLAGS for pjlib-test
#
export TEST_LDFLAGS += -lm
#
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS = pjlib pjlib-test

View File

@ -1,27 +1,27 @@
#
# OS specific configuration for Win32 OS target.
#
#
# PJLIB_OBJS specified here are object files to be included in PJLIB
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += addr_resolv_sock.o guid_win32.o ioqueue_winnt.o \
log_writer_stdout.o os_core_win32.o \
os_error_win32.o os_time_ansi.o os_timestamp_common.o \
os_timestamp_win32.o \
pool_policy_malloc.o sock_bsd.o sock_select.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += main.o
#
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS = pjlib pjlib-test
#
# OS specific configuration for Win32 OS target.
#
#
# PJLIB_OBJS specified here are object files to be included in PJLIB
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += addr_resolv_sock.o guid_win32.o ioqueue_winnt.o \
log_writer_stdout.o os_core_win32.o \
os_error_win32.o os_time_ansi.o os_timestamp_common.o \
os_timestamp_win32.o \
pool_policy_malloc.o sock_bsd.o sock_select.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += main.o
#
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS = pjlib pjlib-test

View File

@ -1,35 +1,35 @@
OUTDIR=.\output\pjlib-samples-i386-win32-vc6-$(MODE)
SRCDIR=../src/pjlib-samples
SAMPLES=$(OUTDIR)/except.exe \
$(OUTDIR)/log.exe \
$(OUTDIR)/list.exe \
!IF "$(MODE)" == "debug"
MODE_CFLAGS=/MTd
!ELSE
MODE_CFLAGS=/MT
!ENDIF
CFLAGS=/nologo /W4 $(MODE_CFLAGS) /DPJ_WIN32=1 /DPJ_M_I386=1 /I../include
PJLIB=../lib/pjlib-i386-win32-vc6-$(MODE).lib
DEPEND=$(PJLIB)
LIBS=netapi32.lib mswsock.lib ws2_32.lib ole32.lib
CL=cl.exe
all: "$(OUTDIR)" $(SAMPLES)
$(SAMPLES): "$(SRCDIR)/$(@B).c" $(DEPEND)
$(CL) /Fe$@ \
/Fo$(@R).obj \
$(CFLAGS) \
$** $(LIBS)
"$(OUTDIR)" :
@IF NOT EXIST "$(OUTDIR)" MKDIR "$(OUTDIR)"
clean :
@IF EXIST "$(OUTDIR)" DEL /Q "$(OUTDIR)\*.*" && RMDIR "$(OUTDIR)"
OUTDIR=.\output\pjlib-samples-i386-win32-vc6-$(MODE)
SRCDIR=../src/pjlib-samples
SAMPLES=$(OUTDIR)/except.exe \
$(OUTDIR)/log.exe \
$(OUTDIR)/list.exe \
!IF "$(MODE)" == "debug"
MODE_CFLAGS=/MTd
!ELSE
MODE_CFLAGS=/MT
!ENDIF
CFLAGS=/nologo /W4 $(MODE_CFLAGS) /DPJ_WIN32=1 /DPJ_M_I386=1 /I../include
PJLIB=../lib/pjlib-i386-win32-vc6-$(MODE).lib
DEPEND=$(PJLIB)
LIBS=netapi32.lib mswsock.lib ws2_32.lib ole32.lib
CL=cl.exe
all: "$(OUTDIR)" $(SAMPLES)
$(SAMPLES): "$(SRCDIR)/$(@B).c" $(DEPEND)
$(CL) /Fe$@ \
/Fo$(@R).obj \
$(CFLAGS) \
$** $(LIBS)
"$(OUTDIR)" :
@IF NOT EXIST "$(OUTDIR)" MKDIR "$(OUTDIR)"
clean :
@IF EXIST "$(OUTDIR)" DEL /Q "$(OUTDIR)\*.*" && RMDIR "$(OUTDIR)"

View File

@ -1,305 +1,305 @@
BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
font-family: Geneva, Arial, Helvetica, sans-serif;
}
BODY,TD {
font-size: 80%;
}
CODE {
font-size: 120%;
font-family: monospace;
}
.fragment, pre {
font-size: 110%;
font-family: monospace;
}
H1 {
text-align: center;
font-size: 240%;
}
H2 {
font-size: 200%;
margin-top : 60px;
}
H3 {
font-size: 160%;
}
H4 {
font-size: 120%;
}
CAPTION { font-weight: bold }
DIV.qindex {
width: 100%;
background-color: #eeeeff;
border: 1px solid #b0b0b0;
text-align: center;
margin: 2px;
padding: 2px;
line-height: 140%;
}
DIV.nav {
width: 100%;
background-color: #eeeeff;
border: 1px solid #b0b0b0;
text-align: center;
margin: 2px;
padding: 2px;
line-height: 140%;
}
A.qindex {
text-decoration: none;
font-size: 120%;
color: #1A419D;
}
A.qindex:visited {
text-decoration: none;
color: #1A419D
}
A.qindex:hover {
text-decoration: none;
background-color: #ddddff;
}
A.qindexHL {
text-decoration: none;
font-weight: bold;
background-color: #6666cc;
color: #ffffff;
border: 1px double #9295C2;
}
A.qindexHL:hover {
text-decoration: none;
background-color: #6666cc;
color: #ffffff;
}
A.qindexHL:visited { text-decoration: none; background-color: #6666cc; color: #ffffff }
A.el { text-decoration: none; font-weight: bold }
A.elRef { font-weight: bold }
A.code:link { text-decoration: none; font-weight: normal; color: #0000FF; }
A.code:visited { text-decoration: none; font-weight: normal; color: #0000FF}
A.codeRef:link { font-weight: normal; color: #0000FF}
A.codeRef:visited { font-weight: normal; color: #0000FF}
A:hover { text-decoration: none; background-color: #f2f2ff }
DL.el { margin-left: -1cm }
PRE.fragment {
border: 1px solid #CCCCCC;
background-color: #f5f5f5;
margin-top: 4px;
margin-bottom: 4px;
margin-left: 2px;
margin-right: 8px;
padding-left: 6px;
padding-right: 6px;
padding-top: 4px;
padding-bottom: 4px;
}
DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px }
TD.md { background-color: #F4F4FB; font-weight: bold; }
TD.mdPrefix {
background-color: #F4F4FB;
color: #606060;
font-size: 80%;
}
TD.mdname1 { background-color: #F4F4FB; font-weight: bold; color: #602020; }
TD.mdname { background-color: #F4F4FB; font-weight: bold; color: #602020; width: 600px; }
DIV.groupHeader {
margin-left: 16px;
margin-top: 12px;
margin-bottom: 6px;
font-weight: bold;
}
DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% }
BODY {
background: white;
color: black;
margin-right: 20px;
margin-left: 20px;
}
TD.indexkey {
background-color: #eeeeff;
font-weight: bold;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px;
border: 1px solid #CCCCCC;
}
TD.indexvalue {
background-color: #eeeeff;
font-style: italic;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px;
border: 1px solid #CCCCCC;
}
TR.memlist {
background-color: #f0f0f0;
}
P.formulaDsp { text-align: center; }
IMG.formulaDsp { }
IMG.formulaInl { vertical-align: middle; }
SPAN.keyword { color: #008000 }
SPAN.keywordtype { color: #604020 }
SPAN.keywordflow { color: #e08000 }
SPAN.comment { color: #800000 }
SPAN.preprocessor { color: #806020 }
SPAN.stringliteral { color: #002080 }
SPAN.charliteral { color: #008080 }
.mdTable {
border: 1px solid #868686;
background-color: #F4F4FB;
}
.mdRow {
padding: 8px 10px;
}
.mdescLeft {
padding: 0px 8px 4px 8px;
font-size: 80%;
font-style: italic;
background-color: #FAFAFA;
border-top: 1px none #E0E0E0;
border-right: 1px none #E0E0E0;
border-bottom: 1px none #E0E0E0;
border-left: 1px none #E0E0E0;
margin: 0px;
}
.mdescRight {
padding: 0px 8px 4px 8px;
font-size: 80%;
font-style: italic;
background-color: #FAFAFA;
border-top: 1px none #E0E0E0;
border-right: 1px none #E0E0E0;
border-bottom: 1px none #E0E0E0;
border-left: 1px none #E0E0E0;
margin: 0px;
}
.memItemLeft {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memItemRight {
padding: 1px 8px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplItemLeft {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplItemRight {
padding: 1px 8px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplParams {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
color: #606060;
background-color: #FAFAFA;
font-size: 80%;
}
.search { color: #003399;
font-weight: bold;
}
FORM.search {
margin-bottom: 0px;
margin-top: 0px;
}
INPUT.search { font-size: 75%;
color: #000080;
font-weight: normal;
background-color: #eeeeff;
}
TD.tiny { font-size: 75%;
}
a {
color: #252E78;
}
a:visited {
color: #3D2185;
}
.dirtab { padding: 4px;
border-collapse: collapse;
border: 1px solid #b0b0b0;
}
TH.dirtab { background: #eeeeff;
font-weight: bold;
}
HR { height: 1px;
border: none;
border-top: 1px solid black;
}
BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
font-family: Geneva, Arial, Helvetica, sans-serif;
}
BODY,TD {
font-size: 80%;
}
CODE {
font-size: 120%;
font-family: monospace;
}
.fragment, pre {
font-size: 110%;
font-family: monospace;
}
H1 {
text-align: center;
font-size: 240%;
}
H2 {
font-size: 200%;
margin-top : 60px;
}
H3 {
font-size: 160%;
}
H4 {
font-size: 120%;
}
CAPTION { font-weight: bold }
DIV.qindex {
width: 100%;
background-color: #eeeeff;
border: 1px solid #b0b0b0;
text-align: center;
margin: 2px;
padding: 2px;
line-height: 140%;
}
DIV.nav {
width: 100%;
background-color: #eeeeff;
border: 1px solid #b0b0b0;
text-align: center;
margin: 2px;
padding: 2px;
line-height: 140%;
}
A.qindex {
text-decoration: none;
font-size: 120%;
color: #1A419D;
}
A.qindex:visited {
text-decoration: none;
color: #1A419D
}
A.qindex:hover {
text-decoration: none;
background-color: #ddddff;
}
A.qindexHL {
text-decoration: none;
font-weight: bold;
background-color: #6666cc;
color: #ffffff;
border: 1px double #9295C2;
}
A.qindexHL:hover {
text-decoration: none;
background-color: #6666cc;
color: #ffffff;
}
A.qindexHL:visited { text-decoration: none; background-color: #6666cc; color: #ffffff }
A.el { text-decoration: none; font-weight: bold }
A.elRef { font-weight: bold }
A.code:link { text-decoration: none; font-weight: normal; color: #0000FF; }
A.code:visited { text-decoration: none; font-weight: normal; color: #0000FF}
A.codeRef:link { font-weight: normal; color: #0000FF}
A.codeRef:visited { font-weight: normal; color: #0000FF}
A:hover { text-decoration: none; background-color: #f2f2ff }
DL.el { margin-left: -1cm }
PRE.fragment {
border: 1px solid #CCCCCC;
background-color: #f5f5f5;
margin-top: 4px;
margin-bottom: 4px;
margin-left: 2px;
margin-right: 8px;
padding-left: 6px;
padding-right: 6px;
padding-top: 4px;
padding-bottom: 4px;
}
DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px }
TD.md { background-color: #F4F4FB; font-weight: bold; }
TD.mdPrefix {
background-color: #F4F4FB;
color: #606060;
font-size: 80%;
}
TD.mdname1 { background-color: #F4F4FB; font-weight: bold; color: #602020; }
TD.mdname { background-color: #F4F4FB; font-weight: bold; color: #602020; width: 600px; }
DIV.groupHeader {
margin-left: 16px;
margin-top: 12px;
margin-bottom: 6px;
font-weight: bold;
}
DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% }
BODY {
background: white;
color: black;
margin-right: 20px;
margin-left: 20px;
}
TD.indexkey {
background-color: #eeeeff;
font-weight: bold;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px;
border: 1px solid #CCCCCC;
}
TD.indexvalue {
background-color: #eeeeff;
font-style: italic;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px;
border: 1px solid #CCCCCC;
}
TR.memlist {
background-color: #f0f0f0;
}
P.formulaDsp { text-align: center; }
IMG.formulaDsp { }
IMG.formulaInl { vertical-align: middle; }
SPAN.keyword { color: #008000 }
SPAN.keywordtype { color: #604020 }
SPAN.keywordflow { color: #e08000 }
SPAN.comment { color: #800000 }
SPAN.preprocessor { color: #806020 }
SPAN.stringliteral { color: #002080 }
SPAN.charliteral { color: #008080 }
.mdTable {
border: 1px solid #868686;
background-color: #F4F4FB;
}
.mdRow {
padding: 8px 10px;
}
.mdescLeft {
padding: 0px 8px 4px 8px;
font-size: 80%;
font-style: italic;
background-color: #FAFAFA;
border-top: 1px none #E0E0E0;
border-right: 1px none #E0E0E0;
border-bottom: 1px none #E0E0E0;
border-left: 1px none #E0E0E0;
margin: 0px;
}
.mdescRight {
padding: 0px 8px 4px 8px;
font-size: 80%;
font-style: italic;
background-color: #FAFAFA;
border-top: 1px none #E0E0E0;
border-right: 1px none #E0E0E0;
border-bottom: 1px none #E0E0E0;
border-left: 1px none #E0E0E0;
margin: 0px;
}
.memItemLeft {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memItemRight {
padding: 1px 8px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplItemLeft {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplItemRight {
padding: 1px 8px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplParams {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
color: #606060;
background-color: #FAFAFA;
font-size: 80%;
}
.search { color: #003399;
font-weight: bold;
}
FORM.search {
margin-bottom: 0px;
margin-top: 0px;
}
INPUT.search { font-size: 75%;
color: #000080;
font-weight: normal;
background-color: #eeeeff;
}
TD.tiny { font-size: 75%;
}
a {
color: #252E78;
}
a:visited {
color: #3D2185;
}
.dirtab { padding: 4px;
border-collapse: collapse;
border: 1px solid #b0b0b0;
}
TH.dirtab { background: #eeeeff;
font-weight: bold;
}
HR { height: 1px;
border: none;
border-top: 1px solid black;
}

View File

@ -1,76 +1,76 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/addr_resolv.h 2 10/14/05 12:25a Bennylp $ */
#ifndef __PJ_ADDR_RESOLV_H__
#define __PJ_ADDR_RESOLV_H__
/**
* @file addr_resolv.h
* @brief Address resolve (pj_gethostbyname()).
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup pj_addr_resolve Address Resolution
* @ingroup PJ_IO
* @{
*
* This module provides function to resolve Internet address of the
* specified host name. To resolve a particular host name, application
* can just call #pj_gethostbyname().
*
* Example:
* <pre>
* ...
* pj_hostent he;
* pj_status_t rc;
* pj_str_t host = pj_str("host.example.com");
*
* rc = pj_gethostbyname( &host, &he);
* if (rc != PJ_SUCCESS) {
* char errbuf[80];
* pj_strerror( rc, errbuf, sizeof(errbuf));
* PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf));
* return rc;
* }
*
* // process address...
* addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr;
* ...
* </pre>
*
* It's pretty simple really...
*/
/** This structure describes an Internet host address. */
typedef struct pj_hostent
{
char *h_name; /**< The official name of the host. */
char **h_aliases; /**< Aliases list. */
int h_addrtype; /**< Host address type. */
int h_length; /**< Length of address. */
char **h_addr_list; /**< List of addresses. */
} pj_hostent;
/** Shortcut to h_addr_list[0] */
#define h_addr h_addr_list[0]
/**
* This function fills the structure of type pj_hostent for a given host name.
*
* @param name Host name, or IPv4 or IPv6 address in standard dot notation.
* @param he The pj_hostent structure to be filled.
*
* @return PJ_SUCCESS, or the appropriate error codes.
*/
PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
/** @} */
PJ_END_DECL
#endif /* __PJ_ADDR_RESOLV_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/addr_resolv.h 2 10/14/05 12:25a Bennylp $ */
#ifndef __PJ_ADDR_RESOLV_H__
#define __PJ_ADDR_RESOLV_H__
/**
* @file addr_resolv.h
* @brief Address resolve (pj_gethostbyname()).
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup pj_addr_resolve Address Resolution
* @ingroup PJ_IO
* @{
*
* This module provides function to resolve Internet address of the
* specified host name. To resolve a particular host name, application
* can just call #pj_gethostbyname().
*
* Example:
* <pre>
* ...
* pj_hostent he;
* pj_status_t rc;
* pj_str_t host = pj_str("host.example.com");
*
* rc = pj_gethostbyname( &host, &he);
* if (rc != PJ_SUCCESS) {
* char errbuf[80];
* pj_strerror( rc, errbuf, sizeof(errbuf));
* PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf));
* return rc;
* }
*
* // process address...
* addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr;
* ...
* </pre>
*
* It's pretty simple really...
*/
/** This structure describes an Internet host address. */
typedef struct pj_hostent
{
char *h_name; /**< The official name of the host. */
char **h_aliases; /**< Aliases list. */
int h_addrtype; /**< Host address type. */
int h_length; /**< Length of address. */
char **h_addr_list; /**< List of addresses. */
} pj_hostent;
/** Shortcut to h_addr_list[0] */
#define h_addr h_addr_list[0]
/**
* This function fills the structure of type pj_hostent for a given host name.
*
* @param name Host name, or IPv4 or IPv6 address in standard dot notation.
* @param he The pj_hostent structure to be filled.
*
* @return PJ_SUCCESS, or the appropriate error codes.
*/
PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
/** @} */
PJ_END_DECL
#endif /* __PJ_ADDR_RESOLV_H__ */

View File

@ -1,78 +1,78 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/array.h 7 10/14/05 12:25a Bennylp $ */
#ifndef __PJ_ARRAY_H__
#define __PJ_ARRAY_H__
/**
* @file array.h
* @brief PJLIB Array helper.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_ARRAY Array helper.
* @ingroup PJ_DS
* @{
*
* This module provides helper to manipulate array of elements of any size.
* It provides most used array operations such as insert, erase, and search.
*/
/**
* Insert value to the array at the given position, and rearrange the
* remaining nodes after the position.
*
* @param array the array.
* @param elem_size the size of the individual element.
* @param count the current number of elements in the array.
* @param pos the position where the new element is put.
* @param value the value to copy to the new element.
*/
PJ_DECL(void) pj_array_insert( void *array,
unsigned elem_size,
unsigned count,
unsigned pos,
const void *value);
/**
* Erase a value from the array at given position, and rearrange the remaining
* elements post the erased element.
*
* @param array the array.
* @param elem_size the size of the individual element.
* @param count the current number of elements in the array.
* @param pos the index/position to delete.
*/
PJ_DECL(void) pj_array_erase( void *array,
unsigned elem_size,
unsigned count,
unsigned pos);
/**
* Search the first value in the array according to matching function.
*
* @param array the array.
* @param elem_size the individual size of the element.
* @param count the number of elements.
* @param matching the matching function, which MUST return PJ_SUCCESS if
* the specified element match.
* @param result the pointer to the value found.
*
* @return PJ_SUCCESS if value is found, otherwise the error code.
*/
PJ_DECL(pj_status_t) pj_array_find( const void *array,
unsigned elem_size,
unsigned count,
pj_status_t (*matching)(const void *value),
void **result);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_ARRAY_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/array.h 7 10/14/05 12:25a Bennylp $ */
#ifndef __PJ_ARRAY_H__
#define __PJ_ARRAY_H__
/**
* @file array.h
* @brief PJLIB Array helper.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_ARRAY Array helper.
* @ingroup PJ_DS
* @{
*
* This module provides helper to manipulate array of elements of any size.
* It provides most used array operations such as insert, erase, and search.
*/
/**
* Insert value to the array at the given position, and rearrange the
* remaining nodes after the position.
*
* @param array the array.
* @param elem_size the size of the individual element.
* @param count the current number of elements in the array.
* @param pos the position where the new element is put.
* @param value the value to copy to the new element.
*/
PJ_DECL(void) pj_array_insert( void *array,
unsigned elem_size,
unsigned count,
unsigned pos,
const void *value);
/**
* Erase a value from the array at given position, and rearrange the remaining
* elements post the erased element.
*
* @param array the array.
* @param elem_size the size of the individual element.
* @param count the current number of elements in the array.
* @param pos the index/position to delete.
*/
PJ_DECL(void) pj_array_erase( void *array,
unsigned elem_size,
unsigned count,
unsigned pos);
/**
* Search the first value in the array according to matching function.
*
* @param array the array.
* @param elem_size the individual size of the element.
* @param count the number of elements.
* @param matching the matching function, which MUST return PJ_SUCCESS if
* the specified element match.
* @param result the pointer to the value found.
*
* @return PJ_SUCCESS if value is found, otherwise the error code.
*/
PJ_DECL(pj_status_t) pj_array_find( const void *array,
unsigned elem_size,
unsigned count,
pj_status_t (*matching)(const void *value),
void **result);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_ARRAY_H__ */

View File

@ -1,56 +1,56 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/assert.h 4 10/14/05 12:25a Bennylp $ */
#ifndef __PJ_ASSERT_H__
#define __PJ_ASSERT_H__
/**
* @file assert.h
* @brief Assertion macro pj_assert().
*/
#include <pj/config.h>
#include <pj/compat/assert.h>
/**
* @defgroup pj_assert Assertion Macro
* @ingroup PJ_MISC
* @{
*
* Assertion and other helper macros for sanity checking.
*/
/**
* @hideinitializer
* Check during debug build that an expression is true. If the expression
* computes to false during run-time, then the program will stop at the
* offending statements.
* For release build, this macro will not do anything.
*
* @param expr The expression to be evaluated.
*/
#define pj_assert(expr) assert(expr)
/**
* @hideinitializer
* If #PJ_ENABLE_EXTRA_CHECK is declared and non-zero, then
* #PJ_ASSERT_RETURN macro will evaluate the expression in @a expr during
* run-time. If the expression yields false, assertion will be triggered
* and the current function will return with the specified return value.
*
* If #PJ_ENABLE_EXTRA_CHECK is not declared or is zero, then no run-time
* checking will be performed. The macro simply evaluates to pj_assert(expr).
*/
#if defined(PJ_ENABLE_EXTRA_CHECK) && PJ_ENABLE_EXTRA_CHECK != 0
# define PJ_ASSERT_RETURN(expr,retval) \
do { \
pj_assert(expr); \
if (!(expr)) return retval; \
} while (0)
#else
# define PJ_ASSERT_RETURN(expr,retval) pj_assert(expr)
#endif
/** @} */
#endif /* __PJ_ASSERT_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/assert.h 4 10/14/05 12:25a Bennylp $ */
#ifndef __PJ_ASSERT_H__
#define __PJ_ASSERT_H__
/**
* @file assert.h
* @brief Assertion macro pj_assert().
*/
#include <pj/config.h>
#include <pj/compat/assert.h>
/**
* @defgroup pj_assert Assertion Macro
* @ingroup PJ_MISC
* @{
*
* Assertion and other helper macros for sanity checking.
*/
/**
* @hideinitializer
* Check during debug build that an expression is true. If the expression
* computes to false during run-time, then the program will stop at the
* offending statements.
* For release build, this macro will not do anything.
*
* @param expr The expression to be evaluated.
*/
#define pj_assert(expr) assert(expr)
/**
* @hideinitializer
* If #PJ_ENABLE_EXTRA_CHECK is declared and non-zero, then
* #PJ_ASSERT_RETURN macro will evaluate the expression in @a expr during
* run-time. If the expression yields false, assertion will be triggered
* and the current function will return with the specified return value.
*
* If #PJ_ENABLE_EXTRA_CHECK is not declared or is zero, then no run-time
* checking will be performed. The macro simply evaluates to pj_assert(expr).
*/
#if defined(PJ_ENABLE_EXTRA_CHECK) && PJ_ENABLE_EXTRA_CHECK != 0
# define PJ_ASSERT_RETURN(expr,retval) \
do { \
pj_assert(expr); \
if (!(expr)) return retval; \
} while (0)
#else
# define PJ_ASSERT_RETURN(expr,retval) pj_assert(expr)
#endif
/** @} */
#endif /* __PJ_ASSERT_H__ */

View File

@ -1,38 +1,38 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/assert.h 3 9/22/05 10:31a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/assert.h $
*
* 3 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_ASSERT_H__
#define __PJ_COMPAT_ASSERT_H__
/**
* @file assert.h
* @brief Provides assert() macro.
*/
#if defined(PJ_HAS_ASSERT_H) && PJ_HAS_ASSERT_H != 0
# include <assert.h>
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
# define assert(expr) do { \
if (!(expr)) \
printk("!!ASSERTION FAILED: [%s:%d] \"" #expr "\"\n",\
__FILE__, __LINE__); \
} while (0)
#else
# warning "assert() is not implemented"
# define assert(expr)
#endif
#endif /* __PJ_COMPAT_ASSERT_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/assert.h 3 9/22/05 10:31a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/assert.h $
*
* 3 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_ASSERT_H__
#define __PJ_COMPAT_ASSERT_H__
/**
* @file assert.h
* @brief Provides assert() macro.
*/
#if defined(PJ_HAS_ASSERT_H) && PJ_HAS_ASSERT_H != 0
# include <assert.h>
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
# define assert(expr) do { \
if (!(expr)) \
printk("!!ASSERTION FAILED: [%s:%d] \"" #expr "\"\n",\
__FILE__, __LINE__); \
} while (0)
#else
# warning "assert() is not implemented"
# define assert(expr)
#endif
#endif /* __PJ_COMPAT_ASSERT_H__ */

View File

@ -1,32 +1,32 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/cc_gcc.h 2 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/cc_gcc.h $
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_CC_GCC_H__
#define __PJ_COMPAT_CC_GCC_H__
/**
* @file cc_gcc.h
* @brief Describes GCC compiler specifics.
*/
#ifndef __GNUC__
# error "This file is only for gcc!"
#endif
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_HAS_INT64 1
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#endif /* __PJ_COMPAT_CC_GCC_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/cc_gcc.h 2 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/cc_gcc.h $
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_CC_GCC_H__
#define __PJ_COMPAT_CC_GCC_H__
/**
* @file cc_gcc.h
* @brief Describes GCC compiler specifics.
*/
#ifndef __GNUC__
# error "This file is only for gcc!"
#endif
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_HAS_INT64 1
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#endif /* __PJ_COMPAT_CC_GCC_H__ */

View File

@ -1,40 +1,40 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/cc_msvc.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/cc_msvc.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_CC_MSVC_H__
#define __PJ_COMPAT_CC_MSVC_H__
/**
* @file cc_msvc.h
* @brief Describes Microsoft Visual C compiler specifics.
*/
#ifndef _MSC_VER
# error "This header file is only for Visual C compiler!"
#endif
# pragma warning(disable: 4127) // conditional expression is constant
# pragma warning(disable: 4611) // not wise to mix setjmp with C++
# pragma warning(disable: 4514) // unreferenced inline function has been removed
# ifdef __cplusplus
# define PJ_INLINE_SPECIFIER inline
# else
# define PJ_INLINE_SPECIFIER static __inline
# endif
# define PJ_THREAD_FUNC
# define PJ_NORETURN __declspec(noreturn)
# define PJ_ATTR_NORETURN
# define PJ_HAS_INT64 1
typedef __int64 pj_int64_t;
typedef unsigned __int64 pj_uint64_t;
#endif /* __PJ_COMPAT_CC_MSVC_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/cc_msvc.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/cc_msvc.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_CC_MSVC_H__
#define __PJ_COMPAT_CC_MSVC_H__
/**
* @file cc_msvc.h
* @brief Describes Microsoft Visual C compiler specifics.
*/
#ifndef _MSC_VER
# error "This header file is only for Visual C compiler!"
#endif
# pragma warning(disable: 4127) // conditional expression is constant
# pragma warning(disable: 4611) // not wise to mix setjmp with C++
# pragma warning(disable: 4514) // unreferenced inline function has been removed
# ifdef __cplusplus
# define PJ_INLINE_SPECIFIER inline
# else
# define PJ_INLINE_SPECIFIER static __inline
# endif
# define PJ_THREAD_FUNC
# define PJ_NORETURN __declspec(noreturn)
# define PJ_ATTR_NORETURN
# define PJ_HAS_INT64 1
typedef __int64 pj_int64_t;
typedef unsigned __int64 pj_uint64_t;
#endif /* __PJ_COMPAT_CC_MSVC_H__ */

View File

@ -1,42 +1,42 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/ctype.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/ctype.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_CTYPE_H__
#define __PJ_COMPAT_CTYPE_H__
/**
* @file ctype.h
* @brief Provides ctype function family.
*/
#if defined(PJ_HAS_CTYPE_H) && PJ_HAS_CTYPE_H != 0
# include <ctype.h>
#else
# define isalnum(c) (isalpha(c) || isdigit(c))
# define isalpha(c) (islower(c) || isupper(c))
# define isascii(c) (((unsigned char)(c))<=0x7f)
# define isdigit(c) ((c)>='0' && (c)<='9')
# define isspace(c) ((c)==' ' || (c)=='\t' ||\
(c)=='\n' || (c)=='\r' || (c)=='\v')
# define islower(c) ((c)>='a' && (c)<='z')
# define isupper(c) ((c)>='A' && (c)<='Z')
# define isxdigit(c) (isdigit(c) || (tolower(c)>='a'&&tolower(c)<='f'))
# define tolower(c) (((c) >= 'A' && (c) <= 'Z') ? (c)+('a'-'A') : (c))
# define toupper(c) (((c) >= 'a' && (c) <= 'z') ? (c)-('a'-'A') : (c))
#endif
#define isblank(c) (c==' ' || c=='\t')
#endif /* __PJ_COMPAT_CTYPE_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/ctype.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/ctype.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_CTYPE_H__
#define __PJ_COMPAT_CTYPE_H__
/**
* @file ctype.h
* @brief Provides ctype function family.
*/
#if defined(PJ_HAS_CTYPE_H) && PJ_HAS_CTYPE_H != 0
# include <ctype.h>
#else
# define isalnum(c) (isalpha(c) || isdigit(c))
# define isalpha(c) (islower(c) || isupper(c))
# define isascii(c) (((unsigned char)(c))<=0x7f)
# define isdigit(c) ((c)>='0' && (c)<='9')
# define isspace(c) ((c)==' ' || (c)=='\t' ||\
(c)=='\n' || (c)=='\r' || (c)=='\v')
# define islower(c) ((c)>='a' && (c)<='z')
# define isupper(c) ((c)>='A' && (c)<='Z')
# define isxdigit(c) (isdigit(c) || (tolower(c)>='a'&&tolower(c)<='f'))
# define tolower(c) (((c) >= 'A' && (c) <= 'Z') ? (c)+('a'-'A') : (c))
# define toupper(c) (((c) >= 'a' && (c) <= 'z') ? (c)-('a'-'A') : (c))
#endif
#define isblank(c) (c==' ' || c=='\t')
#endif /* __PJ_COMPAT_CTYPE_H__ */

View File

@ -1,26 +1,27 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/errno.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_COMPAT_ERRNO_H__
#define __PJ_COMPAT_ERRNO_H__
#if defined(PJ_WIN32) && PJ_WIN32 != 0
typedef unsigned long pj_os_err_type;
# define pj_get_native_os_error() GetLastError()
# define pj_get_native_netos_error() WSAGetLastError()
#elif (defined(PJ_LINUX) && PJ_LINUX != 0) || \
(defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0)
typedef int pj_os_err_type;
# define pj_get_native_os_error() (errno)
# define pj_get_native_netos_error() (errno)
#else
# error "Please define pj_os_err_type for this platform here!"
#endif
#endif /* __PJ_COMPAT_ERRNO_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/errno.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_COMPAT_ERRNO_H__
#define __PJ_COMPAT_ERRNO_H__
#if defined(PJ_WIN32) && PJ_WIN32 != 0
typedef unsigned long pj_os_err_type;
# define pj_get_native_os_error() GetLastError()
# define pj_get_native_netos_error() WSAGetLastError()
#elif (defined(PJ_LINUX) && PJ_LINUX != 0) || \
(defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0) || \
(defined(PJ_SUNOS) && PJ_SUNOS != 0)
typedef int pj_os_err_type;
# define pj_get_native_os_error() (errno)
# define pj_get_native_netos_error() (errno)
#else
# error "Please define pj_os_err_type for this platform here!"
#endif
#endif /* __PJ_COMPAT_ERRNO_H__ */

View File

@ -1,83 +1,85 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/high_precision.h 3 10/29/05 11:51a Bennylp $ */
#ifndef __PJ_COMPAT_HIGH_PRECISION_H__
#define __PJ_COMPAT_HIGH_PRECISION_H__
#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT != 0
/*
* The first choice for high precision math is to use double.
*/
# include <math.h>
typedef double pj_highprec_t;
# define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
# define pj_highprec_mod(a,b) (a=fmod(a,b))
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
# include <asm/div64.h>
typedef pj_int64_t pj_highprec_t;
# define pj_highprec_div(a1,a2) do_div(a1,a2)
# define pj_highprec_mod(a1,a2) (a1=do_mod(a1, a2))
PJ_INLINE(pj_int64_t) do_mod( pj_int64_t a1, pj_int64_t a2)
{
return do_div(a1,a2);
}
#elif defined(PJ_HAS_INT64) && PJ_HAS_INT64 != 0
/*
* Next choice is to use 64-bit arithmatics.
*/
typedef pj_int64_t pj_highprec_t;
#else
/*
* Last, fallback to 32-bit arithmetics.
*/
typedef pj_int32_t pj_highprec_t;
#endif
/**
* @def pj_highprec_mul
* pj_highprec_mul(a1, a2) - High Precision Multiplication
* Multiply a1 and a2, and store the result in a1.
*/
#ifndef pj_highprec_mul
# define pj_highprec_mul(a1,a2) (a1 = a1 * a2)
#endif
/**
* @def pj_highprec_div
* pj_highprec_div(a1, a2) - High Precision Division
* Divide a2 from a1, and store the result in a1.
*/
#ifndef pj_highprec_div
# define pj_highprec_div(a1,a2) (a1 = a1 / a2)
#endif
/**
* @def pj_highprec_mod
* pj_highprec_mod(a1, a2) - High Precision Modulus
* Get the modulus a2 from a1, and store the result in a1.
*/
#ifndef pj_highprec_mod
# define pj_highprec_mod(a1,a2) (a1 = a1 % a2)
#endif
/**
* @def PJ_HIGHPREC_VALUE_IS_ZERO(a)
* Test if the specified high precision value is zero.
*/
#ifndef PJ_HIGHPREC_VALUE_IS_ZERO
# define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
#endif
#endif /* __PJ_COMPAT_HIGH_PRECISION_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/high_precision.h 3 10/29/05 11:51a Bennylp $ */
#ifndef __PJ_COMPAT_HIGH_PRECISION_H__
#define __PJ_COMPAT_HIGH_PRECISION_H__
#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT != 0
/*
* The first choice for high precision math is to use double.
*/
# include <math.h>
typedef double pj_highprec_t;
# define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
# define pj_highprec_mod(a,b) (a=fmod(a,b))
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
# include <asm/div64.h>
typedef pj_int64_t pj_highprec_t;
# define pj_highprec_div(a1,a2) do_div(a1,a2)
# define pj_highprec_mod(a1,a2) (a1=do_mod(a1, a2))
PJ_INLINE(pj_int64_t) do_mod( pj_int64_t a1, pj_int64_t a2)
{
return do_div(a1,a2);
}
#elif defined(PJ_HAS_INT64) && PJ_HAS_INT64 != 0
/*
* Next choice is to use 64-bit arithmatics.
*/
typedef pj_int64_t pj_highprec_t;
#else
# warning "High precision math is not available"
/*
* Last, fallback to 32-bit arithmetics.
*/
typedef pj_int32_t pj_highprec_t;
#endif
/**
* @def pj_highprec_mul
* pj_highprec_mul(a1, a2) - High Precision Multiplication
* Multiply a1 and a2, and store the result in a1.
*/
#ifndef pj_highprec_mul
# define pj_highprec_mul(a1,a2) (a1 = a1 * a2)
#endif
/**
* @def pj_highprec_div
* pj_highprec_div(a1, a2) - High Precision Division
* Divide a2 from a1, and store the result in a1.
*/
#ifndef pj_highprec_div
# define pj_highprec_div(a1,a2) (a1 = a1 / a2)
#endif
/**
* @def pj_highprec_mod
* pj_highprec_mod(a1, a2) - High Precision Modulus
* Get the modulus a2 from a1, and store the result in a1.
*/
#ifndef pj_highprec_mod
# define pj_highprec_mod(a1,a2) (a1 = a1 % a2)
#endif
/**
* @def PJ_HIGHPREC_VALUE_IS_ZERO(a)
* Test if the specified high precision value is zero.
*/
#ifndef PJ_HIGHPREC_VALUE_IS_ZERO
# define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
#endif
#endif /* __PJ_COMPAT_HIGH_PRECISION_H__ */

View File

@ -1,23 +1,23 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/m_alpha.h 1 10/29/05 5:23p Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/include/pj/compat/m_alpha.h $
*
* 1 10/29/05 5:23p Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_M_ALPHA_H__
#define __PJ_COMPAT_M_ALPHA_H__
/**
* @file m_alpha.h
* @brief Describes Alpha processor family specifics.
*/
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_ALPHA_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/m_alpha.h 1 10/29/05 5:23p Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/include/pj/compat/m_alpha.h $
*
* 1 10/29/05 5:23p Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_M_ALPHA_H__
#define __PJ_COMPAT_M_ALPHA_H__
/**
* @file m_alpha.h
* @brief Describes Alpha processor family specifics.
*/
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_ALPHA_H__ */

View File

@ -1,26 +1,26 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/m_i386.h 3 9/21/05 1:39p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/m_i386.h $
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_M_i386_H__
#define __PJ_COMPAT_M_i386_H__
/**
* @file m_i386.h
* @brief Describes Intel i386 family processor specifics.
*/
#define PJ_M_I386 1
#define PJ_HAS_PENTIUM 1
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_i386_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/m_i386.h 3 9/21/05 1:39p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/m_i386.h $
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_M_i386_H__
#define __PJ_COMPAT_M_i386_H__
/**
* @file m_i386.h
* @brief Describes Intel i386 family processor specifics.
*/
#define PJ_M_I386 1
#define PJ_HAS_PENTIUM 1
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_i386_H__ */

View File

@ -1,21 +1,21 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/m_m68k.h 2 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/m_m68k.h $
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_M_M68K_H__
#define __PJ_COMPAT_M_M68K_H__
/**
* @file m_m68k.h
* @brief Describes Motorola m68k family processor specifics.
*/
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_M68K_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/m_m68k.h 2 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/m_m68k.h $
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_M_M68K_H__
#define __PJ_COMPAT_M_M68K_H__
/**
* @file m_m68k.h
* @brief Describes Motorola m68k family processor specifics.
*/
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_M68K_H__ */

View File

@ -0,0 +1,21 @@
/* $Header: $ */
/*
*$Log: $
*
*/
#ifndef __PJ_COMPAT_M_SPARC_H__
#define __PJ_COMPAT_M_SPARC_H__
/**
* @file m_sparc.h
* @brief Describes SPARC family processor specifics.
*/
#define PJ_SPARC 1
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 0
#define PJ_IS_BIG_ENDIAN 1
#endif /* __PJ_COMPAT_M_SPARC_H__ */

View File

@ -1,25 +1,25 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/malloc.h 2 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/malloc.h $
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
* 1 9/16/05 10:02p Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_MALLOC_H__
#define __PJ_COMPAT_MALLOC_H__
/**
* @file malloc.h
* @brief Provides malloc() and free() functions.
*/
#if defined(PJ_HAS_MALLOC_H) && PJ_HAS_MALLOC_H != 0
# include <malloc.h>
#elif defined(PJ_HAS_STDLIB_H) && PJ_HAS_STDLIB_H != 0
# include <stdlib.h>
#endif
#endif /* __PJ_COMPAT_MALLOC_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/malloc.h 2 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/malloc.h $
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
* 1 9/16/05 10:02p Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_MALLOC_H__
#define __PJ_COMPAT_MALLOC_H__
/**
* @file malloc.h
* @brief Provides malloc() and free() functions.
*/
#if defined(PJ_HAS_MALLOC_H) && PJ_HAS_MALLOC_H != 0
# include <malloc.h>
#elif defined(PJ_HAS_STDLIB_H) && PJ_HAS_STDLIB_H != 0
# include <stdlib.h>
#endif
#endif /* __PJ_COMPAT_MALLOC_H__ */

View File

@ -1,69 +1,69 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/os_linux.h 6 10/29/05 11:51a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/os_linux.h $
*
* 6 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 5 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 4 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_OS_LINUX_H__
#define __PJ_COMPAT_OS_LINUX_H__
/**
* @file os_linux.h
* @brief Describes Linux operating system specifics.
*/
#define PJ_HAS_ARPA_INET_H 1
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 1
#define PJ_HAS_LINUX_SOCKET_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 1
#define PJ_HAS_NETINET_IN_H 1
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 1
#define PJ_HAS_SYS_SELECT_H 1
#define PJ_HAS_SYS_SOCKET_H 1
#define PJ_HAS_SYS_TIMEB_H 1
#define PJ_HAS_SYS_TYPES_H 1
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 1
#define PJ_HAS_MSWSOCK_H 0
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 0
#define PJ_SOCK_HAS_INET_ATON 1
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_HAS_MALLOC 1
#define PJ_OS_HAS_CHECK_STACK 0
#define PJ_ATOMIC_VALUE_TYPE long
#endif /* __PJ_COMPAT_OS_LINUX_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/os_linux.h 6 10/29/05 11:51a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/os_linux.h $
*
* 6 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 5 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 4 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_OS_LINUX_H__
#define __PJ_COMPAT_OS_LINUX_H__
/**
* @file os_linux.h
* @brief Describes Linux operating system specifics.
*/
#define PJ_HAS_ARPA_INET_H 1
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 1
#define PJ_HAS_LINUX_SOCKET_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 1
#define PJ_HAS_NETINET_IN_H 1
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 1
#define PJ_HAS_SYS_SELECT_H 1
#define PJ_HAS_SYS_SOCKET_H 1
#define PJ_HAS_SYS_TIMEB_H 1
#define PJ_HAS_SYS_TYPES_H 1
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 1
#define PJ_HAS_MSWSOCK_H 0
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 0
#define PJ_SOCK_HAS_INET_ATON 1
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_HAS_MALLOC 1
#define PJ_OS_HAS_CHECK_STACK 0
#define PJ_ATOMIC_VALUE_TYPE long
#endif /* __PJ_COMPAT_OS_LINUX_H__ */

View File

@ -1,86 +1,86 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/os_linux_kernel.h 4 10/29/05 11:51a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/os_linux_kernel.h $
*
* 4 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 1 9/21/05 1:38p Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_OS_LINUX_KERNEL_H__
#define __PJ_COMPAT_OS_LINUX_KERNEL_H__
/**
* @file os_linux.h
* @brief Describes Linux operating system specifics.
*/
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 0
#define PJ_HAS_CTYPE_H 0
#define PJ_HAS_ERRNO_H 0
#define PJ_HAS_LINUX_SOCKET_H 1
#define PJ_HAS_MALLOC_H 0
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_SETJMP_H 0
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 0
#define PJ_HAS_STDIO_H 0
#define PJ_HAS_STDLIB_H 0
#define PJ_HAS_STRING_H 0
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIMEB_H 0
#define PJ_HAS_SYS_TYPES_H 0
#define PJ_HAS_TIME_H 0
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 0
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 0
#define PJ_SOCK_HAS_INET_ATON 0
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
/*
* Declare __FD_SETSIZE now before including <linux*>.
*/
#define __FD_SETSIZE PJ_IOQUEUE_MAX_HANDLES
#define NULL ((void*)0)
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#define __PJ_EXPORT_SYMBOL(a) EXPORT_SYMBOL(a);
/*
* Override features.
*/
#define PJ_HAS_FLOATING_POINT 0
#define PJ_HAS_MALLOC 0
#define PJ_HAS_SEMAPHORE 0
#define PJ_HAS_EVENT_OBJ 0
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_OS_HAS_CHECK_STACK 0
#define PJ_TERM_HAS_COLOR 0
#define PJ_ATOMIC_VALUE_TYPE int
#define PJ_THREAD_DESC_SIZE 128
#endif /* __PJ_COMPAT_OS_LINUX_KERNEL_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/os_linux_kernel.h 4 10/29/05 11:51a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/os_linux_kernel.h $
*
* 4 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 1 9/21/05 1:38p Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_OS_LINUX_KERNEL_H__
#define __PJ_COMPAT_OS_LINUX_KERNEL_H__
/**
* @file os_linux.h
* @brief Describes Linux operating system specifics.
*/
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 0
#define PJ_HAS_CTYPE_H 0
#define PJ_HAS_ERRNO_H 0
#define PJ_HAS_LINUX_SOCKET_H 1
#define PJ_HAS_MALLOC_H 0
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_SETJMP_H 0
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 0
#define PJ_HAS_STDIO_H 0
#define PJ_HAS_STDLIB_H 0
#define PJ_HAS_STRING_H 0
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIMEB_H 0
#define PJ_HAS_SYS_TYPES_H 0
#define PJ_HAS_TIME_H 0
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 0
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 0
#define PJ_SOCK_HAS_INET_ATON 0
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
/*
* Declare __FD_SETSIZE now before including <linux*>.
*/
#define __FD_SETSIZE PJ_IOQUEUE_MAX_HANDLES
#define NULL ((void*)0)
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#define __PJ_EXPORT_SYMBOL(a) EXPORT_SYMBOL(a);
/*
* Override features.
*/
#define PJ_HAS_FLOATING_POINT 0
#define PJ_HAS_MALLOC 0
#define PJ_HAS_SEMAPHORE 0
#define PJ_HAS_EVENT_OBJ 0
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_OS_HAS_CHECK_STACK 0
#define PJ_TERM_HAS_COLOR 0
#define PJ_ATOMIC_VALUE_TYPE int
#define PJ_THREAD_DESC_SIZE 128
#endif /* __PJ_COMPAT_OS_LINUX_KERNEL_H__ */

View File

@ -1,54 +1,54 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/os_palmos.h 3 9/21/05 1:39p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/os_palmos.h $
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_OS_PALMOS_H__
#define __PJ_COMPAT_OS_PALMOS_H__
/**
* @file os_palmos.h
* @brief Describes PalmOS operating system specifics.
*/
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIMEB_H 0
#define PJ_HAS_SYS_TYPES_H 1
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 0
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 0
#define PJ_SOCK_HAS_INET_ATON 0
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_OS_HAS_CHECK_STACK 0
#endif /* __PJ_COMPAT_OS_PALMOS_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/os_palmos.h 3 9/21/05 1:39p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/os_palmos.h $
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_OS_PALMOS_H__
#define __PJ_COMPAT_OS_PALMOS_H__
/**
* @file os_palmos.h
* @brief Describes PalmOS operating system specifics.
*/
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIMEB_H 0
#define PJ_HAS_SYS_TYPES_H 1
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 0
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 0
#define PJ_SOCK_HAS_INET_ATON 0
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_OS_HAS_CHECK_STACK 0
#endif /* __PJ_COMPAT_OS_PALMOS_H__ */

View File

@ -0,0 +1,56 @@
/* $Header: $ */
/* $Log: $
*
*/
#ifndef __PJ_COMPAT_OS_SUNOS_H__
#define __PJ_COMPAT_OS_SUNOS_H__
/**
* @file os_sunos.h
* @brief Describes SunOS/Solaris operating system specifics.
*/
#define PJ_HAS_ARPA_INET_H 1
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 1
#define PJ_HAS_LINUX_SOCKET_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 1
#define PJ_HAS_NETINET_IN_H 1
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 1
#define PJ_HAS_SYS_SELECT_H 1
#define PJ_HAS_SYS_SOCKET_H 1
#define PJ_HAS_SYS_TIMEB_H 1
#define PJ_HAS_SYS_TYPES_H 1
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 1
#define PJ_HAS_MSWSOCK_H 0
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 0
#define PJ_SOCK_HAS_INET_ATON 0
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_HAS_MALLOC 1
#define PJ_OS_HAS_CHECK_STACK 0
#define PJ_ATOMIC_VALUE_TYPE long
/* Get BSD related identifers in Sun's include files */
#define BSD_COMP
#endif /* __PJ_COMPAT_OS_SUNOS_H__ */

View File

@ -1,72 +1,72 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/os_win32.h 6 10/29/05 11:51a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/os_win32.h $
*
* 6 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 5 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 4 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_OS_WIN32_H__
#define __PJ_COMPAT_OS_WIN32_H__
/**
* @file os_win32.h
* @brief Describes Win32 operating system family specifics.
*/
#define WIN32_LEAN_AND_MEAN
#define PJ_WIN32_WINNT 0x0400
#define _WIN32_WINNT PJ_WIN32_WINNT
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 0 /* Must be zero, otherwise errno_test() fails. */
#define PJ_HAS_LINUX_SOCKET_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIMEB_H 1
#define PJ_HAS_SYS_TYPES_H 1
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 1
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 1
#define PJ_SOCK_HAS_INET_ATON 0
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_HAS_MALLOC 1
#define PJ_OS_HAS_CHECK_STACK 1
#define PJ_ATOMIC_VALUE_TYPE long
#endif /* __PJ_COMPAT_OS_WIN32_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/os_win32.h 6 10/29/05 11:51a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/os_win32.h $
*
* 6 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 5 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 4 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_OS_WIN32_H__
#define __PJ_COMPAT_OS_WIN32_H__
/**
* @file os_win32.h
* @brief Describes Win32 operating system family specifics.
*/
#define WIN32_LEAN_AND_MEAN
#define PJ_WIN32_WINNT 0x0400
#define _WIN32_WINNT PJ_WIN32_WINNT
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 0 /* Must be zero, otherwise errno_test() fails. */
#define PJ_HAS_LINUX_SOCKET_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIMEB_H 1
#define PJ_HAS_SYS_TYPES_H 1
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 1
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 1
#define PJ_SOCK_HAS_INET_ATON 0
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_HAS_MALLOC 1
#define PJ_OS_HAS_CHECK_STACK 1
#define PJ_ATOMIC_VALUE_TYPE long
#endif /* __PJ_COMPAT_OS_WIN32_H__ */

View File

@ -1,65 +1,65 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/rand.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/rand.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_RAND_H__
#define __PJ_COMPAT_RAND_H__
/**
* @file rand.h
* @brief Provides platform_rand() and platform_srand() functions.
*/
#if defined(PJ_HAS_STDLIB_H) && PJ_HAS_STDLIB_H != 0
/*
* Use stdlib based rand() and srand().
*/
# include <stdlib.h>
# define platform_srand srand
# if defined(RAND_MAX) && RAND_MAX <= 0xFFFF
/*
* When rand() is only 16 bit strong, double the strength
* by calling it twice!
*/
PJ_INLINE(int) platform_rand(void)
{
return ((rand() & 0xFFFF) << 16) | (rand() & 0xFFFF);
}
# else
# define platform_rand rand
# endif
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
/*
* Linux kernel mode random number generator.
*/
# include <linux/random.h>
# define platform_srand(seed)
PJ_INLINE(int) platform_rand(void)
{
int value;
get_random_bytes((void*)&value, sizeof(value));
return value;
}
#else
# warning "platform_rand() is not implemented"
# define platform_rand() 1
# define platform_srand(seed)
#endif
#endif /* __PJ_COMPAT_RAND_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/rand.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/rand.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_RAND_H__
#define __PJ_COMPAT_RAND_H__
/**
* @file rand.h
* @brief Provides platform_rand() and platform_srand() functions.
*/
#if defined(PJ_HAS_STDLIB_H) && PJ_HAS_STDLIB_H != 0
/*
* Use stdlib based rand() and srand().
*/
# include <stdlib.h>
# define platform_srand srand
# if defined(RAND_MAX) && RAND_MAX <= 0xFFFF
/*
* When rand() is only 16 bit strong, double the strength
* by calling it twice!
*/
PJ_INLINE(int) platform_rand(void)
{
return ((rand() & 0xFFFF) << 16) | (rand() & 0xFFFF);
}
# else
# define platform_rand rand
# endif
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
/*
* Linux kernel mode random number generator.
*/
# include <linux/random.h>
# define platform_srand(seed)
PJ_INLINE(int) platform_rand(void)
{
int value;
get_random_bytes((void*)&value, sizeof(value));
return value;
}
#else
# warning "platform_rand() is not implemented"
# define platform_rand() 1
# define platform_srand(seed)
#endif
#endif /* __PJ_COMPAT_RAND_H__ */

View File

@ -1,89 +1,89 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/setjmp.h 4 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/setjmp.h $
*
* 4 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 3 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_SETJMP_H__
#define __PJ_COMPAT_SETJMP_H__
/**
* @file setjmp.h
* @brief Provides setjmp.h functionality.
*/
#if defined(PJ_HAS_SETJMP_H) && PJ_HAS_SETJMP_H != 0
# include <setjmp.h>
typedef jmp_buf pj_jmp_buf;
# define pj_setjmp(buf) setjmp(buf)
# define pj_longjmp(buf,d) longjmp(buf,d)
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0 && \
defined(PJ_M_I386) && PJ_M_I386 != 0
/*
* These are taken from uClibc.
* Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
*/
# if defined __USE_MISC || defined _ASM
# define JB_BX 0
# define JB_SI 1
# define JB_DI 2
# define JB_BP 3
# define JB_SP 4
# define JB_PC 5
# define JB_SIZE 24
# endif
# ifndef _ASM
typedef int __jmp_buf[6];
/* A `sigset_t' has a bit for each signal. */
# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
typedef struct __sigset_t_tag
{
unsigned long int __val[_SIGSET_NWORDS];
} __sigset_t;
/* Calling environment, plus possibly a saved signal mask. */
typedef struct __jmp_buf_tag /* C++ doesn't like tagless structs. */
{
/* NOTE: The machine-dependent definitions of `__sigsetjmp'
assume that a `jmp_buf' begins with a `__jmp_buf' and that
`__mask_was_saved' follows it. Do not move these members
or add others before it. */
__jmp_buf __jmpbuf; /* Calling environment. */
int __mask_was_saved; /* Saved the signal mask? */
// we never saved the mask.
__sigset_t __saved_mask; /* Saved signal mask. */
} jmp_buf[1];
typedef jmp_buf sigjmp_buf;
typedef jmp_buf pj_jmp_buf;
PJ_DECL(int) pj_setjmp(pj_jmp_buf env);
PJ_DECL(void) pj_longjmp(pj_jmp_buf env, int val) __attribute__((noreturn));
# endif /* _ASM */
#else
# warning "setjmp()/longjmp() is not implemented"
typedef int pj_jmp_buf[1];
# define pj_setjmp(buf) 0
# define pj_longjmp(buf,d) 0
#endif
#endif /* __PJ_COMPAT_SETJMP_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/setjmp.h 4 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/setjmp.h $
*
* 4 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 3 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_SETJMP_H__
#define __PJ_COMPAT_SETJMP_H__
/**
* @file setjmp.h
* @brief Provides setjmp.h functionality.
*/
#if defined(PJ_HAS_SETJMP_H) && PJ_HAS_SETJMP_H != 0
# include <setjmp.h>
typedef jmp_buf pj_jmp_buf;
# define pj_setjmp(buf) setjmp(buf)
# define pj_longjmp(buf,d) longjmp(buf,d)
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0 && \
defined(PJ_M_I386) && PJ_M_I386 != 0
/*
* These are taken from uClibc.
* Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
*/
# if defined __USE_MISC || defined _ASM
# define JB_BX 0
# define JB_SI 1
# define JB_DI 2
# define JB_BP 3
# define JB_SP 4
# define JB_PC 5
# define JB_SIZE 24
# endif
# ifndef _ASM
typedef int __jmp_buf[6];
/* A `sigset_t' has a bit for each signal. */
# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
typedef struct __sigset_t_tag
{
unsigned long int __val[_SIGSET_NWORDS];
} __sigset_t;
/* Calling environment, plus possibly a saved signal mask. */
typedef struct __jmp_buf_tag /* C++ doesn't like tagless structs. */
{
/* NOTE: The machine-dependent definitions of `__sigsetjmp'
assume that a `jmp_buf' begins with a `__jmp_buf' and that
`__mask_was_saved' follows it. Do not move these members
or add others before it. */
__jmp_buf __jmpbuf; /* Calling environment. */
int __mask_was_saved; /* Saved the signal mask? */
// we never saved the mask.
__sigset_t __saved_mask; /* Saved signal mask. */
} jmp_buf[1];
typedef jmp_buf sigjmp_buf;
typedef jmp_buf pj_jmp_buf;
PJ_DECL(int) pj_setjmp(pj_jmp_buf env);
PJ_DECL(void) pj_longjmp(pj_jmp_buf env, int val) __attribute__((noreturn));
# endif /* _ASM */
#else
# warning "setjmp()/longjmp() is not implemented"
typedef int pj_jmp_buf[1];
# define pj_setjmp(buf) 0
# define pj_longjmp(buf,d) 0
#endif
#endif /* __PJ_COMPAT_SETJMP_H__ */

View File

@ -1,23 +1,23 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/size_t.h 2 9/21/05 1:39p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/size_t.h $
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_SIZE_T_H__
#define __PJ_COMPAT_SIZE_T_H__
/**
* @file size_t.h
* @brief Provides size_t type.
*/
#if PJ_HAS_STDDEF_H
# include <stddef.h>
#endif
#endif /* __PJ_COMPAT_SIZE_T_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/size_t.h 2 9/21/05 1:39p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/size_t.h $
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_SIZE_T_H__
#define __PJ_COMPAT_SIZE_T_H__
/**
* @file size_t.h
* @brief Provides size_t type.
*/
#if PJ_HAS_STDDEF_H
# include <stddef.h>
#endif
#endif /* __PJ_COMPAT_SIZE_T_H__ */

View File

@ -1,129 +1,129 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/socket.h 5 10/29/05 11:51a Bennylp $*/
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/socket.h $
*
* 5 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 4 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_SOCKET_H__
#define __PJ_COMPAT_SOCKET_H__
/**
* @file socket.h
* @brief Provides all socket related functions,data types, error codes, etc.
*/
#if defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0
# include <winsock.h>
#endif
#if defined(PJ_HAS_WINSOCK2_H) && PJ_HAS_WINSOCK2_H != 0
# include <winsock2.h>
#endif
#if defined(PJ_HAS_SYS_TYPES_H) && PJ_HAS_SYS_TYPES_H != 0
# include <sys/types.h>
#endif
#if defined(PJ_HAS_SYS_SOCKET_H) && PJ_HAS_SYS_SOCKET_H != 0
# include <sys/socket.h>
#endif
#if defined(PJ_HAS_LINUX_SOCKET_H) && PJ_HAS_LINUX_SOCKET_H != 0
# include <linux/socket.h>
#endif
#if defined(PJ_HAS_SYS_SELECT_H) && PJ_HAS_SYS_SELECT_H != 0
# include <sys/select.h>
#endif
#if defined(PJ_HAS_NETINET_IN_H) && PJ_HAS_NETINET_IN_H != 0
# include <netinet/in.h>
#endif
#if defined(PJ_HAS_ARPA_INET_H) && PJ_HAS_ARPA_INET_H != 0
# include <arpa/inet.h>
#endif
#if defined(PJ_HAS_SYS_IOCTL_H) && PJ_HAS_SYS_IOCTL_H != 0
# include <sys/ioctl.h> /* FBIONBIO */
#endif
#if defined(PJ_HAS_ERRNO_H) && PJ_HAS_ERRNO_H != 0
# include <errno.h>
#endif
#if defined(PJ_HAS_NETDB_H) && PJ_HAS_NETDB_H != 0
# include <netdb.h>
#endif
#if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H != 0
# include <unistd.h>
#endif
/*
* Define common errors.
*/
#ifdef PJ_WIN32
# define OSERR_EWOULDBLOCK WSAEWOULDBLOCK
# define OSERR_EINPROGRESS WSAEINPROGRESS
#else
# define OSERR_EWOULDBLOCK EWOULDBLOCK
# define OSERR_EINPROGRESS EINPROGRESS
#endif
/*
* And undefine this..
*/
#undef s_addr
/*
* Linux kernel specifics
*/
#ifdef PJ_LINUX_KERNEL
# include <linux/net.h>
# include <asm/ioctls.h> /* FIONBIO */
# include <linux/syscalls.h> /* sys_select() */
# include <asm/uaccess.h> /* set/get_fs() */
typedef int socklen_t;
# define getsockopt sys_getsockopt
/*
* Wrapper for select() in Linux kernel.
*/
PJ_INLINE(int) select(int n, fd_set *inp, fd_set *outp, fd_set *exp,
struct timeval *tvp)
{
int count;
mm_segment_t oldfs = get_fs();
set_fs(KERNEL_DS);
count = sys_select(n, inp, outp, exp, tvp);
set_fs(oldfs);
return count;
}
#endif /* PJ_LINUX_KERNEL */
/*
* Windows specific
*/
#ifdef PJ_WIN32
typedef int socklen_t;;
#endif
#endif /* __PJ_COMPAT_SOCKET_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/socket.h 5 10/29/05 11:51a Bennylp $*/
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/socket.h $
*
* 5 10/29/05 11:51a Bennylp
* Version 0.3-pre2.
*
* 4 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 3 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#ifndef __PJ_COMPAT_SOCKET_H__
#define __PJ_COMPAT_SOCKET_H__
/**
* @file socket.h
* @brief Provides all socket related functions,data types, error codes, etc.
*/
#if defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0
# include <winsock.h>
#endif
#if defined(PJ_HAS_WINSOCK2_H) && PJ_HAS_WINSOCK2_H != 0
# include <winsock2.h>
#endif
#if defined(PJ_HAS_SYS_TYPES_H) && PJ_HAS_SYS_TYPES_H != 0
# include <sys/types.h>
#endif
#if defined(PJ_HAS_SYS_SOCKET_H) && PJ_HAS_SYS_SOCKET_H != 0
# include <sys/socket.h>
#endif
#if defined(PJ_HAS_LINUX_SOCKET_H) && PJ_HAS_LINUX_SOCKET_H != 0
# include <linux/socket.h>
#endif
#if defined(PJ_HAS_SYS_SELECT_H) && PJ_HAS_SYS_SELECT_H != 0
# include <sys/select.h>
#endif
#if defined(PJ_HAS_NETINET_IN_H) && PJ_HAS_NETINET_IN_H != 0
# include <netinet/in.h>
#endif
#if defined(PJ_HAS_ARPA_INET_H) && PJ_HAS_ARPA_INET_H != 0
# include <arpa/inet.h>
#endif
#if defined(PJ_HAS_SYS_IOCTL_H) && PJ_HAS_SYS_IOCTL_H != 0
# include <sys/ioctl.h> /* FBIONBIO */
#endif
#if defined(PJ_HAS_ERRNO_H) && PJ_HAS_ERRNO_H != 0
# include <errno.h>
#endif
#if defined(PJ_HAS_NETDB_H) && PJ_HAS_NETDB_H != 0
# include <netdb.h>
#endif
#if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H != 0
# include <unistd.h>
#endif
/*
* Define common errors.
*/
#ifdef PJ_WIN32
# define OSERR_EWOULDBLOCK WSAEWOULDBLOCK
# define OSERR_EINPROGRESS WSAEINPROGRESS
#else
# define OSERR_EWOULDBLOCK EWOULDBLOCK
# define OSERR_EINPROGRESS EINPROGRESS
#endif
/*
* And undefine this..
*/
#undef s_addr
/*
* Linux kernel specifics
*/
#ifdef PJ_LINUX_KERNEL
# include <linux/net.h>
# include <asm/ioctls.h> /* FIONBIO */
# include <linux/syscalls.h> /* sys_select() */
# include <asm/uaccess.h> /* set/get_fs() */
typedef int socklen_t;
# define getsockopt sys_getsockopt
/*
* Wrapper for select() in Linux kernel.
*/
PJ_INLINE(int) select(int n, fd_set *inp, fd_set *outp, fd_set *exp,
struct timeval *tvp)
{
int count;
mm_segment_t oldfs = get_fs();
set_fs(KERNEL_DS);
count = sys_select(n, inp, outp, exp, tvp);
set_fs(oldfs);
return count;
}
#endif /* PJ_LINUX_KERNEL */
/*
* Windows specific
*/
#ifdef PJ_WIN32
typedef int socklen_t;;
#endif
#endif /* __PJ_COMPAT_SOCKET_H__ */

View File

@ -1,31 +1,31 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/sprintf.h 2 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/sprintf.h $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_SPRINTF_H__
#define __PJ_COMPAT_SPRINTF_H__
/**
* @file sprintf.h
* @brief Provides sprintf() and snprintf() functions.
*/
#if defined(PJ_HAS_STDIO_H) && PJ_HAS_STDIO_H != 0
# include <stdio.h>
#endif
#if defined(_MSC_VER)
# define snprintf _snprintf
#endif
#define pj_sprintf sprintf
#define pj_snprintf snprintf
#endif /* __PJ_COMPAT_SPRINTF_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/compat/sprintf.h 2 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/compat/sprintf.h $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_SPRINTF_H__
#define __PJ_COMPAT_SPRINTF_H__
/**
* @file sprintf.h
* @brief Provides sprintf() and snprintf() functions.
*/
#if defined(PJ_HAS_STDIO_H) && PJ_HAS_STDIO_H != 0
# include <stdio.h>
#endif
#if defined(_MSC_VER)
# define snprintf _snprintf
#endif
#define pj_sprintf sprintf
#define pj_snprintf snprintf
#endif /* __PJ_COMPAT_SPRINTF_H__ */

View File

@ -1,20 +1,20 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/stdarg.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/stdarg.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_STDARG_H__
#define __PJ_COMPAT_STDARG_H__
/**
* @file stdarg.h
* @brief Provides stdarg functionality.
*/
#if defined(PJ_HAS_STDARG_H) && PJ_HAS_STDARG_H != 0
# include <stdarg.h>
#endif
#endif /* __PJ_COMPAT_STDARG_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/stdarg.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/stdarg.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_STDARG_H__
#define __PJ_COMPAT_STDARG_H__
/**
* @file stdarg.h
* @brief Provides stdarg functionality.
*/
#if defined(PJ_HAS_STDARG_H) && PJ_HAS_STDARG_H != 0
# include <stdarg.h>
#endif
#endif /* __PJ_COMPAT_STDARG_H__ */

View File

@ -1,20 +1,20 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/stdfileio.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/stdfileio.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_STDFILEIO_H__
#define __PJ_COMPAT_STDFILEIO_H__
/**
* @file stdfileio.h
* @brief Compatibility for ANSI file I/O like fputs, fflush, etc.
*/
#if defined(PJ_HAS_STDIO_H) && PJ_HAS_STDIO_H != 0
# include <stdio.h>
#endif
#endif /* __PJ_COMPAT_STDFILEIO_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/stdfileio.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/stdfileio.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_STDFILEIO_H__
#define __PJ_COMPAT_STDFILEIO_H__
/**
* @file stdfileio.h
* @brief Compatibility for ANSI file I/O like fputs, fflush, etc.
*/
#if defined(PJ_HAS_STDIO_H) && PJ_HAS_STDIO_H != 0
# include <stdio.h>
#endif
#endif /* __PJ_COMPAT_STDFILEIO_H__ */

View File

@ -1,41 +1,41 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/string.h 3 9/22/05 10:31a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/string.h $
*
* 3 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_STRING_H__
#define __PJ_COMPAT_STRING_H__
/**
* @file string.h
* @brief Provides string manipulation functions found in ANSI string.h.
*/
#if defined(PJ_HAS_STRING_H) && PJ_HAS_STRING_H != 0
# include <string.h>
#else
PJ_DECL(int) strcasecmp(const char *s1, const char *s2);
PJ_DECL(int) strncasecmp(const char *s1, const char *s2, int len);
#endif
#if defined(_MSC_VER)
# define strcasecmp stricmp
# define strncasecmp strnicmp
# define snprintf _snprintf
#else
# define stricmp strcasecmp
# define strnicmp strncasecmp
#endif
#endif /* __PJ_COMPAT_STRING_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/string.h 3 9/22/05 10:31a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/string.h $
*
* 3 9/22/05 10:31a Bennylp
* Moving all *.h files to include/.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_STRING_H__
#define __PJ_COMPAT_STRING_H__
/**
* @file string.h
* @brief Provides string manipulation functions found in ANSI string.h.
*/
#if defined(PJ_HAS_STRING_H) && PJ_HAS_STRING_H != 0
# include <string.h>
#else
PJ_DECL(int) strcasecmp(const char *s1, const char *s2);
PJ_DECL(int) strncasecmp(const char *s1, const char *s2, int len);
#endif
#if defined(_MSC_VER)
# define strcasecmp stricmp
# define strncasecmp strnicmp
# define snprintf _snprintf
#else
# define stricmp strcasecmp
# define strnicmp strncasecmp
#endif
#endif /* __PJ_COMPAT_STRING_H__ */

View File

@ -1,25 +1,25 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/time.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/time.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_TIME_H__
#define __PJ_COMPAT_TIME_H__
/**
* @file time.h
* @brief Provides ftime() and localtime() etc functions.
*/
#if defined(PJ_HAS_TIME_H) && PJ_HAS_TIME_H != 0
# include <time.h>
#endif
#if defined(PJ_HAS_SYS_TIMEB_H) && PJ_HAS_SYS_TIMEB_H != 0
# include <sys/timeb.h>
#endif
#endif /* __PJ_COMPAT_TIME_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/time.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/time.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_TIME_H__
#define __PJ_COMPAT_TIME_H__
/**
* @file time.h
* @brief Provides ftime() and localtime() etc functions.
*/
#if defined(PJ_HAS_TIME_H) && PJ_HAS_TIME_H != 0
# include <time.h>
#endif
#if defined(PJ_HAS_SYS_TIMEB_H) && PJ_HAS_SYS_TIMEB_H != 0
# include <sys/timeb.h>
#endif
#endif /* __PJ_COMPAT_TIME_H__ */

View File

@ -1,26 +1,26 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/vsprintf.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/vsprintf.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_VSPRINTF_H__
#define __PJ_COMPAT_VSPRINTF_H__
/**
* @file vsprintf.h
* @brief Provides vsprintf and vsnprintf function.
*/
#if defined(PJ_HAS_STDIO_H) && PJ_HAS_STDIO_H != 0
# include <stdio.h>
#endif
#if defined(_MSC_VER)
# define vsnprintf _vsnprintf
#endif
#define pj_vsnprintf vsnprintf
#endif /* __PJ_COMPAT_VSPRINTF_H__ */
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/vsprintf.h 1 9/17/05 10:36a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/vsprintf.h $
*
* 1 9/17/05 10:36a Bennylp
* Created.
*
*/
#ifndef __PJ_COMPAT_VSPRINTF_H__
#define __PJ_COMPAT_VSPRINTF_H__
/**
* @file vsprintf.h
* @brief Provides vsprintf and vsnprintf function.
*/
#if defined(PJ_HAS_STDIO_H) && PJ_HAS_STDIO_H != 0
# include <stdio.h>
#endif
#if defined(_MSC_VER)
# define vsnprintf _vsnprintf
#endif
#define pj_vsnprintf vsnprintf
#endif /* __PJ_COMPAT_VSPRINTF_H__ */

View File

@ -1,438 +1,442 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/config.h 12 10/29/05 10:25p Bennylp $ */
#ifndef __PJ_CONFIG_H__
#define __PJ_CONFIG_H__
/**
* @file config.h
* @brief PJLIB Main configuration settings.
*/
/********************************************************************
* Include compiler specific configuration.
*/
#if defined(_MSC_VER)
# include <pj/compat/cc_msvc.h>
#elif defined(__GNUC__)
# include <pj/compat/cc_gcc.h>
#else
# error "Unknown compiler."
#endif
/********************************************************************
* Include target specific configuration.
*/
#if defined(PJ_WIN32)
# include <pj/compat/os_win32.h>
#elif defined(PJ_LINUX)
# include <pj/compat/os_linux.h>
#elif defined(PJ_LINUX_KERNEL)
# include <pj/compat/os_linux_kernel.h>
#elif defined(PJ_PALMOS)
# include <pj/compat/os_palmos.h>
#else
# error "Please specify target os."
#endif
/********************************************************************
* Target machine specific configuration.
*/
#if defined (PJ_M_I386) && PJ_M_I386 != 0
# include <pj/compat/m_i386.h>
#elif defined (PJ_M_M68K) && PJ_M_M68K != 0
# include <pj/compat/m_m68k.h>
#elif defined (PJ_M_ALPHA) && PJ_M_ALPHA != 0
# include <pj/compat/m_alpha.h>
#else
# error "Please specify target machine."
#endif
/* Include size_t definition. */
#include <pj/compat/size_t.h>
/* Include site/user specific configuration to control PJLIB features.
* YOU MUST CREATE THIS FILE YOURSELF!!
*/
#include <pj/config_site.h>
/********************************************************************
* PJLIB Features.
*/
/* Overrides for DOXYGEN */
#ifdef DOXYGEN
# undef PJ_FUNCTIONS_ARE_INLINED
# undef PJ_HAS_FLOATING_POINT
# undef PJ_LOG_MAX_LEVEL
# undef PJ_LOG_MAX_SIZE
# undef PJ_LOG_USE_STACK_BUFFER
# undef PJ_TERM_HAS_COLOR
# undef PJ_POOL_DEBUG
# undef PJ_HAS_TCP
# undef PJ_MAX_HOSTNAME
# undef PJ_IOQUEUE_MAX_HANDLES
# undef FD_SETSIZE
# undef PJ_HAS_SEMAPHORE
# undef PJ_HAS_EVENT_OBJ
# undef PJ_ENABLE_EXTRA_CHECK
#endif
/**
* @defgroup pj_config Build Configuration
* @ingroup PJ
* @{
*
* This section contains macros that can set during PJLIB build process
* to controll various aspects of the library.
*
* <b>Note</b>: the values in this page does NOT necessarily reflect to the
* macro values during the build process.
*/
/**
* If this macro is set to 1, it will enable some debugging checking
* in the library.
*
* Default: equal to (NOT NDEBUG).
*/
#ifndef PJ_DEBUG
# ifndef NDEBUG
# define PJ_DEBUG 1
# else
# define PJ_DEBUG 0
# endif
#endif
/**
* Expand functions in *_i.h header files as inline.
*
* Default: 0.
*/
#ifndef PJ_FUNCTIONS_ARE_INLINED
# define PJ_FUNCTIONS_ARE_INLINED 0
#endif
/**
* Use floating point computations in the library.
*
* Default: 1.
*/
#ifndef PJ_HAS_FLOATING_POINT
# define PJ_HAS_FLOATING_POINT 1
#endif
/**
* Declare maximum logging level/verbosity. Lower number indicates higher
* importance, with the highest importance has level zero. The least
* important level is five in this implementation, but this can be extended
* by supplying the appropriate implementation.
*
* The level conventions:
* - 0: fatal error
* - 1: error
* - 2: warning
* - 3: info
* - 4: debug
* - 5: trace
* - 6: more detailed trace
*
* Default: 4
*/
#ifndef PJ_LOG_MAX_LEVEL
# define PJ_LOG_MAX_LEVEL 4
#endif
/**
* Maximum message size that can be sent to output device for each call
* to PJ_LOG(). If the message size is longer than this value, it will be cut.
* This may affect the stack usage, depending whether PJ_LOG_USE_STACK_BUFFER
* flag is set.
*
* Default: 800
*/
#ifndef PJ_LOG_MAX_SIZE
# define PJ_LOG_MAX_SIZE 800
#endif
/**
* Log buffer.
* Does the log get the buffer from the stack? (default is yes).
* If the value is set to NO, then the buffer will be taken from static
* buffer, which in this case will make the log function non-reentrant.
*
* Default: 1
*/
#ifndef PJ_LOG_USE_STACK_BUFFER
# define PJ_LOG_USE_STACK_BUFFER 1
#endif
/**
* Colorfull terminal (for logging etc).
*
* Default: 1
*/
#ifndef PJ_TERM_HAS_COLOR
# define PJ_TERM_HAS_COLOR 1
#endif
/**
* Pool debugging.
*
* Default: 0
*/
#ifndef PJ_POOL_DEBUG
# define PJ_POOL_DEBUG 0
#endif
/**
* \def PJ_HAS_TCP
* Support TCP in the library.
* Disabling TCP will reduce the footprint slightly (about 6KB).
*
* Default: 1
*/
#ifndef PJ_HAS_TCP
# define PJ_HAS_TCP 1
#endif
/**
* Maximum hostname length.
* Libraries sometimes needs to make copy of an address to stack buffer;
* the value here affects the stack usage.
*
* Default: 128
*/
#ifndef PJ_MAX_HOSTNAME
# define PJ_MAX_HOSTNAME (128)
#endif
/**
* Constants for declaring the maximum handles that can be supported by
* a single IOQ framework. This constant might not be relevant to the
* underlying I/O queue impelementation, but still, developers should be
* aware of this constant, to make sure that the program will not break when
* the underlying implementation changes.
*
* For implementation based on select(), the value here will be used as the
* maximum number of socket handles passed to select() (i.e. FD_SETSIZE will
* be set to this value).
*
* Default: 64
*/
#ifndef PJ_IOQUEUE_MAX_HANDLES
# define PJ_IOQUEUE_MAX_HANDLES (64)
#endif
/**
* Overrides FD_SETSIZE so it is consistent throughout the library.
* OS specific configuration header (compat/os_*) might have declared
* FD_SETSIZE, thus we only set if it hasn't been declared.
*
* Default: #PJ_IOQUEUE_MAX_HANDLES
*/
#ifndef FD_SETSIZE
# define FD_SETSIZE PJ_IOQUEUE_MAX_HANDLES
#endif
/**
* Has semaphore functionality?
*
* Default: 1
*/
#ifndef PJ_HAS_SEMAPHORE
# define PJ_HAS_SEMAPHORE 1
#endif
/**
* Event object (for synchronization, e.g. in Win32)
*
* Default: 1
*/
#ifndef PJ_HAS_EVENT_OBJ
# define PJ_HAS_EVENT_OBJ 1
#endif
/**
* Enable library's extra check.
* If this macro is enabled, #PJ_ASSERT_RETURN macro will expand to
* run-time checking. If this macro is disabled, #PJ_ASSERT_RETURN
* will simply evaluate to #pj_assert().
*
* You can disable this macro to reduce size, at the risk of crashes
* if invalid value (e.g. NULL) is passed to the library.
*
* Default: 1
*/
#ifndef PJ_ENABLE_EXTRA_CHECK
# define PJ_ENABLE_EXTRA_CHECK 1
#endif
/**
* Enable name registration for exceptions with #pj_exception_id_alloc().
* If this feature is enabled, then the library will keep track of
* names associated with each exception ID requested by application via
* #pj_exception_id_alloc().
*
* Disabling this macro will reduce the code and .bss size by a tad bit.
* See also #PJ_MAX_EXCEPTION_ID.
*
* Default: 1
*/
#ifndef PJ_HAS_EXCEPTION_NAMES
# define PJ_HAS_EXCEPTION_NAMES 1
#endif
/**
* Maximum number of unique exception IDs that can be requested
* with #pj_exception_id_alloc(). For each entry, a small record will
* be allocated in the .bss segment.
*
* Default: 16
*/
#ifndef PJ_MAX_EXCEPTION_ID
# define PJ_MAX_EXCEPTION_ID 16
#endif
/** @} */
/********************************************************************
* General macros.
*/
/**
* @def PJ_INLINE(type)
* @param type The return type of the function.
* Expand the function as inline.
*/
#define PJ_INLINE(type) PJ_INLINE_SPECIFIER type
/**
* @def PJ_DECL(type)
* @param type The return type of the function.
* Declare a function.
*/
/**
* @def PJ_DECL_NO_RETURN(type)
* @param type The return type of the function.
* Declare a function that will not return.
*/
/**
* @def PJ_BEGIN_DECL
* Mark beginning of declaration section in a header file.
*/
/**
* @def PJ_END_DECL
* Mark end of declaration section in a header file.
*/
#ifdef __cplusplus
# define PJ_DECL(type) type
# define PJ_DECL_NO_RETURN(type) type PJ_NORETURN
# define PJ_BEGIN_DECL extern "C" {
# define PJ_END_DECL }
#else
# define PJ_DECL(type) extern type
# define PJ_DECL_NO_RETURN(type) PJ_NORETURN type
# define PJ_BEGIN_DECL
# define PJ_END_DECL
#endif
/**
* @def PJ_DEF(type)
* @param type The return type of the function.
* Define a function.
*/
#define PJ_DEF(type) type
/**
* @def PJ_EXPORT_SYMBOL(sym)
* @param sym The symbol to export.
* Export the specified symbol in compilation type that requires export
* (e.g. Linux kernel).
*/
#ifdef __PJ_EXPORT_SYMBOL
# define PJ_EXPORT_SYMBOL(sym) __PJ_EXPORT_SYMBOL(sym)
#else
# define PJ_EXPORT_SYMBOL(sym)
#endif
/**
* @def PJ_IDECL(type)
* @param type The function's return type.
* Declare a function that may be expanded as inline.
*/
/**
* @def PJ_IDEF(type)
* @param type The function's return type.
* Define a function that may be expanded as inline.
*/
#if PJ_FUNCTIONS_ARE_INLINED
# define PJ_IDECL(type) PJ_INLINE(type)
# define PJ_IDEF(type) PJ_INLINE(type)
#else
# define PJ_IDECL(type) PJ_DECL(type)
# define PJ_IDEF(type) PJ_DEF(type)
#endif
/**
* @def PJ_UNUSED_ARG(arg)
* @param arg The argument name.
* PJ_UNUSED_ARG prevents warning about unused argument in a function.
*/
#define PJ_UNUSED_ARG(arg) (void)arg
/**
* @def PJ_TODO(id)
* @param id Any identifier that will be printed as TODO message.
* PJ_TODO macro will display TODO message as warning during compilation.
* Example: PJ_TODO(CLEAN_UP_ERROR);
*/
#ifndef PJ_TODO
# define PJ_TODO(id) TODO___##id:
#endif
/********************************************************************
* Sanity Checks
*/
#ifndef PJ_HAS_HIGH_RES_TIMER
# error "PJ_HAS_HIGH_RES_TIMER is not defined!"
#endif
#if !defined(PJ_HAS_PENTIUM)
# error "PJ_HAS_PENTIUM is not defined!"
#endif
#if !defined(PJ_IS_LITTLE_ENDIAN)
# error "PJ_IS_LITTLE_ENDIAN is not defined!"
#endif
#if !defined(PJ_IS_BIG_ENDIAN)
# error "PJ_IS_BIG_ENDIAN is not defined!"
#endif
PJ_BEGIN_DECL
/**
* PJLIB version string.
*/
extern const char *PJ_VERSION;
/**
* Dump configuration to log with verbosity equal to info(3).
*/
PJ_DECL(void) pj_dump_config(void);
PJ_END_DECL
#endif /* __PJ_CONFIG_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/config.h 12 10/29/05 10:25p Bennylp $ */
#ifndef __PJ_CONFIG_H__
#define __PJ_CONFIG_H__
/**
* @file config.h
* @brief PJLIB Main configuration settings.
*/
/********************************************************************
* Include compiler specific configuration.
*/
#if defined(_MSC_VER)
# include <pj/compat/cc_msvc.h>
#elif defined(__GNUC__)
# include <pj/compat/cc_gcc.h>
#else
# error "Unknown compiler."
#endif
/********************************************************************
* Include target OS specific configuration.
*/
#if defined(PJ_WIN32) && PJ_WIN32!=0
# include <pj/compat/os_win32.h>
#elif defined(PJ_LINUX) && PJ_LINUX!=0
# include <pj/compat/os_linux.h>
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL!=0
# include <pj/compat/os_linux_kernel.h>
#elif defined(PJ_PALMOS) && PJ_PALMOS!=0
# include <pj/compat/os_palmos.h>
#elif defined(PJ_SUNOS) && PJ_SUNOS!=0
# include <pj/compat/os_sunos.h>
#else
# error "Please specify target os."
#endif
/********************************************************************
* Target machine specific configuration.
*/
#if defined (PJ_M_I386) && PJ_M_I386 != 0
# include <pj/compat/m_i386.h>
#elif defined (PJ_M_M68K) && PJ_M_M68K != 0
# include <pj/compat/m_m68k.h>
#elif defined (PJ_M_ALPHA) && PJ_M_ALPHA != 0
# include <pj/compat/m_alpha.h>
#elif defined (PJ_M_SPARC) && PJ_M_SPARC != 0
# include <pj/compat/m_sparc.h>
#else
# error "Please specify target machine."
#endif
/* Include size_t definition. */
#include <pj/compat/size_t.h>
/* Include site/user specific configuration to control PJLIB features.
* YOU MUST CREATE THIS FILE YOURSELF!!
*/
#include <pj/config_site.h>
/********************************************************************
* PJLIB Features.
*/
/* Overrides for DOXYGEN */
#ifdef DOXYGEN
# undef PJ_FUNCTIONS_ARE_INLINED
# undef PJ_HAS_FLOATING_POINT
# undef PJ_LOG_MAX_LEVEL
# undef PJ_LOG_MAX_SIZE
# undef PJ_LOG_USE_STACK_BUFFER
# undef PJ_TERM_HAS_COLOR
# undef PJ_POOL_DEBUG
# undef PJ_HAS_TCP
# undef PJ_MAX_HOSTNAME
# undef PJ_IOQUEUE_MAX_HANDLES
# undef FD_SETSIZE
# undef PJ_HAS_SEMAPHORE
# undef PJ_HAS_EVENT_OBJ
# undef PJ_ENABLE_EXTRA_CHECK
#endif
/**
* @defgroup pj_config Build Configuration
* @ingroup PJ
* @{
*
* This section contains macros that can set during PJLIB build process
* to controll various aspects of the library.
*
* <b>Note</b>: the values in this page does NOT necessarily reflect to the
* macro values during the build process.
*/
/**
* If this macro is set to 1, it will enable some debugging checking
* in the library.
*
* Default: equal to (NOT NDEBUG).
*/
#ifndef PJ_DEBUG
# ifndef NDEBUG
# define PJ_DEBUG 1
# else
# define PJ_DEBUG 0
# endif
#endif
/**
* Expand functions in *_i.h header files as inline.
*
* Default: 0.
*/
#ifndef PJ_FUNCTIONS_ARE_INLINED
# define PJ_FUNCTIONS_ARE_INLINED 0
#endif
/**
* Use floating point computations in the library.
*
* Default: 1.
*/
#ifndef PJ_HAS_FLOATING_POINT
# define PJ_HAS_FLOATING_POINT 1
#endif
/**
* Declare maximum logging level/verbosity. Lower number indicates higher
* importance, with the highest importance has level zero. The least
* important level is five in this implementation, but this can be extended
* by supplying the appropriate implementation.
*
* The level conventions:
* - 0: fatal error
* - 1: error
* - 2: warning
* - 3: info
* - 4: debug
* - 5: trace
* - 6: more detailed trace
*
* Default: 4
*/
#ifndef PJ_LOG_MAX_LEVEL
# define PJ_LOG_MAX_LEVEL 4
#endif
/**
* Maximum message size that can be sent to output device for each call
* to PJ_LOG(). If the message size is longer than this value, it will be cut.
* This may affect the stack usage, depending whether PJ_LOG_USE_STACK_BUFFER
* flag is set.
*
* Default: 800
*/
#ifndef PJ_LOG_MAX_SIZE
# define PJ_LOG_MAX_SIZE 800
#endif
/**
* Log buffer.
* Does the log get the buffer from the stack? (default is yes).
* If the value is set to NO, then the buffer will be taken from static
* buffer, which in this case will make the log function non-reentrant.
*
* Default: 1
*/
#ifndef PJ_LOG_USE_STACK_BUFFER
# define PJ_LOG_USE_STACK_BUFFER 1
#endif
/**
* Colorfull terminal (for logging etc).
*
* Default: 1
*/
#ifndef PJ_TERM_HAS_COLOR
# define PJ_TERM_HAS_COLOR 1
#endif
/**
* Pool debugging.
*
* Default: 0
*/
#ifndef PJ_POOL_DEBUG
# define PJ_POOL_DEBUG 0
#endif
/**
* \def PJ_HAS_TCP
* Support TCP in the library.
* Disabling TCP will reduce the footprint slightly (about 6KB).
*
* Default: 1
*/
#ifndef PJ_HAS_TCP
# define PJ_HAS_TCP 1
#endif
/**
* Maximum hostname length.
* Libraries sometimes needs to make copy of an address to stack buffer;
* the value here affects the stack usage.
*
* Default: 128
*/
#ifndef PJ_MAX_HOSTNAME
# define PJ_MAX_HOSTNAME (128)
#endif
/**
* Constants for declaring the maximum handles that can be supported by
* a single IOQ framework. This constant might not be relevant to the
* underlying I/O queue impelementation, but still, developers should be
* aware of this constant, to make sure that the program will not break when
* the underlying implementation changes.
*
* For implementation based on select(), the value here will be used as the
* maximum number of socket handles passed to select() (i.e. FD_SETSIZE will
* be set to this value).
*
* Default: 64
*/
#ifndef PJ_IOQUEUE_MAX_HANDLES
# define PJ_IOQUEUE_MAX_HANDLES (64)
#endif
/**
* Overrides FD_SETSIZE so it is consistent throughout the library.
* OS specific configuration header (compat/os_*) might have declared
* FD_SETSIZE, thus we only set if it hasn't been declared.
*
* Default: #PJ_IOQUEUE_MAX_HANDLES
*/
#ifndef FD_SETSIZE
# define FD_SETSIZE PJ_IOQUEUE_MAX_HANDLES
#endif
/**
* Has semaphore functionality?
*
* Default: 1
*/
#ifndef PJ_HAS_SEMAPHORE
# define PJ_HAS_SEMAPHORE 1
#endif
/**
* Event object (for synchronization, e.g. in Win32)
*
* Default: 1
*/
#ifndef PJ_HAS_EVENT_OBJ
# define PJ_HAS_EVENT_OBJ 1
#endif
/**
* Enable library's extra check.
* If this macro is enabled, #PJ_ASSERT_RETURN macro will expand to
* run-time checking. If this macro is disabled, #PJ_ASSERT_RETURN
* will simply evaluate to #pj_assert().
*
* You can disable this macro to reduce size, at the risk of crashes
* if invalid value (e.g. NULL) is passed to the library.
*
* Default: 1
*/
#ifndef PJ_ENABLE_EXTRA_CHECK
# define PJ_ENABLE_EXTRA_CHECK 1
#endif
/**
* Enable name registration for exceptions with #pj_exception_id_alloc().
* If this feature is enabled, then the library will keep track of
* names associated with each exception ID requested by application via
* #pj_exception_id_alloc().
*
* Disabling this macro will reduce the code and .bss size by a tad bit.
* See also #PJ_MAX_EXCEPTION_ID.
*
* Default: 1
*/
#ifndef PJ_HAS_EXCEPTION_NAMES
# define PJ_HAS_EXCEPTION_NAMES 1
#endif
/**
* Maximum number of unique exception IDs that can be requested
* with #pj_exception_id_alloc(). For each entry, a small record will
* be allocated in the .bss segment.
*
* Default: 16
*/
#ifndef PJ_MAX_EXCEPTION_ID
# define PJ_MAX_EXCEPTION_ID 16
#endif
/** @} */
/********************************************************************
* General macros.
*/
/**
* @def PJ_INLINE(type)
* @param type The return type of the function.
* Expand the function as inline.
*/
#define PJ_INLINE(type) PJ_INLINE_SPECIFIER type
/**
* @def PJ_DECL(type)
* @param type The return type of the function.
* Declare a function.
*/
/**
* @def PJ_DECL_NO_RETURN(type)
* @param type The return type of the function.
* Declare a function that will not return.
*/
/**
* @def PJ_BEGIN_DECL
* Mark beginning of declaration section in a header file.
*/
/**
* @def PJ_END_DECL
* Mark end of declaration section in a header file.
*/
#ifdef __cplusplus
# define PJ_DECL(type) type
# define PJ_DECL_NO_RETURN(type) type PJ_NORETURN
# define PJ_BEGIN_DECL extern "C" {
# define PJ_END_DECL }
#else
# define PJ_DECL(type) extern type
# define PJ_DECL_NO_RETURN(type) PJ_NORETURN type
# define PJ_BEGIN_DECL
# define PJ_END_DECL
#endif
/**
* @def PJ_DEF(type)
* @param type The return type of the function.
* Define a function.
*/
#define PJ_DEF(type) type
/**
* @def PJ_EXPORT_SYMBOL(sym)
* @param sym The symbol to export.
* Export the specified symbol in compilation type that requires export
* (e.g. Linux kernel).
*/
#ifdef __PJ_EXPORT_SYMBOL
# define PJ_EXPORT_SYMBOL(sym) __PJ_EXPORT_SYMBOL(sym)
#else
# define PJ_EXPORT_SYMBOL(sym)
#endif
/**
* @def PJ_IDECL(type)
* @param type The function's return type.
* Declare a function that may be expanded as inline.
*/
/**
* @def PJ_IDEF(type)
* @param type The function's return type.
* Define a function that may be expanded as inline.
*/
#if PJ_FUNCTIONS_ARE_INLINED
# define PJ_IDECL(type) PJ_INLINE(type)
# define PJ_IDEF(type) PJ_INLINE(type)
#else
# define PJ_IDECL(type) PJ_DECL(type)
# define PJ_IDEF(type) PJ_DEF(type)
#endif
/**
* @def PJ_UNUSED_ARG(arg)
* @param arg The argument name.
* PJ_UNUSED_ARG prevents warning about unused argument in a function.
*/
#define PJ_UNUSED_ARG(arg) (void)arg
/**
* @def PJ_TODO(id)
* @param id Any identifier that will be printed as TODO message.
* PJ_TODO macro will display TODO message as warning during compilation.
* Example: PJ_TODO(CLEAN_UP_ERROR);
*/
#ifndef PJ_TODO
# define PJ_TODO(id) TODO___##id:
#endif
/********************************************************************
* Sanity Checks
*/
#ifndef PJ_HAS_HIGH_RES_TIMER
# error "PJ_HAS_HIGH_RES_TIMER is not defined!"
#endif
#if !defined(PJ_HAS_PENTIUM)
# error "PJ_HAS_PENTIUM is not defined!"
#endif
#if !defined(PJ_IS_LITTLE_ENDIAN)
# error "PJ_IS_LITTLE_ENDIAN is not defined!"
#endif
#if !defined(PJ_IS_BIG_ENDIAN)
# error "PJ_IS_BIG_ENDIAN is not defined!"
#endif
PJ_BEGIN_DECL
/**
* PJLIB version string.
*/
extern const char *PJ_VERSION;
/**
* Dump configuration to log with verbosity equal to info(3).
*/
PJ_DECL(void) pj_dump_config(void);
PJ_END_DECL
#endif /* __PJ_CONFIG_H__ */

View File

@ -1,119 +1,119 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/ctype.h 4 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_CTYPE_H__
#define __PJ_CTYPE_H__
/**
* @file ctype.h
* @brief C type helper macros.
*/
#include <pj/compat/ctype.h>
/**
* @defgroup pj_ctype ctype - Character Type
* @ingroup PJ_MISC
* @{
*
* This module contains several inline functions/macros for testing or
* manipulating character types. It is provided in PJLIB because PJLIB
* must not depend to LIBC.
*/
/**
* Returns a non-zero value if either isalpha or isdigit is true for c.
* @param c The integer character to test.
* @return Non-zero value if either isalpha or isdigit is true for c.
*/
PJ_INLINE(int) pj_isalnum(int c) { return isalnum(c); }
/**
* Returns a non-zero value if c is a particular representation of an
* alphabetic character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of an
* alphabetic character.
*/
PJ_INLINE(int) pj_isalpha(int c) { return isalpha(c); }
/**
* Returns a non-zero value if c is a particular representation of an
* ASCII character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* an ASCII character.
*/
PJ_INLINE(int) pj_isascii(int c) { return isascii(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a decimal-digit character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a decimal-digit character.
*/
PJ_INLINE(int) pj_isdigit(int c) { return isdigit(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a space character (0x09 - 0x0D or 0x20).
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a space character (0x09 - 0x0D or 0x20).
*/
PJ_INLINE(int) pj_isspace(int c) { return isspace(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a lowercase character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a lowercase character.
*/
PJ_INLINE(int) pj_islower(int c) { return islower(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a uppercase character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a uppercase character.
*/
PJ_INLINE(int) pj_isupper(int c) { return isupper(c); }
/**
* Returns a non-zero value if c is a particular representation of
* an hexadecimal digit character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* an hexadecimal digit character.
*/
PJ_INLINE(int) pj_isxdigit(int c){ return isxdigit(c); }
/**
* Returns a non-zero value if c is a either a space (' ') or horizontal
* tab ('\\t') character.
* @param c The integer character to test.
* @return Non-zero value if c is a either a space (' ') or horizontal
* tab ('\\t') character.
*/
PJ_INLINE(int) pj_isblank(int c) { return isblank(c); }
/**
* Converts character to lowercase.
* @param c The integer character to convert.
* @return Lowercase character of c.
*/
PJ_INLINE(int) pj_tolower(int c) { return tolower(c); }
/**
* Converts character to uppercase.
* @param c The integer character to convert.
* @return Uppercase character of c.
*/
PJ_INLINE(int) pj_toupper(int c) { return toupper(c); }
/** @} */
#endif /* __PJ_CTYPE_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/ctype.h 4 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_CTYPE_H__
#define __PJ_CTYPE_H__
/**
* @file ctype.h
* @brief C type helper macros.
*/
#include <pj/compat/ctype.h>
/**
* @defgroup pj_ctype ctype - Character Type
* @ingroup PJ_MISC
* @{
*
* This module contains several inline functions/macros for testing or
* manipulating character types. It is provided in PJLIB because PJLIB
* must not depend to LIBC.
*/
/**
* Returns a non-zero value if either isalpha or isdigit is true for c.
* @param c The integer character to test.
* @return Non-zero value if either isalpha or isdigit is true for c.
*/
PJ_INLINE(int) pj_isalnum(int c) { return isalnum(c); }
/**
* Returns a non-zero value if c is a particular representation of an
* alphabetic character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of an
* alphabetic character.
*/
PJ_INLINE(int) pj_isalpha(int c) { return isalpha(c); }
/**
* Returns a non-zero value if c is a particular representation of an
* ASCII character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* an ASCII character.
*/
PJ_INLINE(int) pj_isascii(int c) { return isascii(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a decimal-digit character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a decimal-digit character.
*/
PJ_INLINE(int) pj_isdigit(int c) { return isdigit(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a space character (0x09 - 0x0D or 0x20).
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a space character (0x09 - 0x0D or 0x20).
*/
PJ_INLINE(int) pj_isspace(int c) { return isspace(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a lowercase character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a lowercase character.
*/
PJ_INLINE(int) pj_islower(int c) { return islower(c); }
/**
* Returns a non-zero value if c is a particular representation of
* a uppercase character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* a uppercase character.
*/
PJ_INLINE(int) pj_isupper(int c) { return isupper(c); }
/**
* Returns a non-zero value if c is a particular representation of
* an hexadecimal digit character.
* @param c The integer character to test.
* @return Non-zero value if c is a particular representation of
* an hexadecimal digit character.
*/
PJ_INLINE(int) pj_isxdigit(int c){ return isxdigit(c); }
/**
* Returns a non-zero value if c is a either a space (' ') or horizontal
* tab ('\\t') character.
* @param c The integer character to test.
* @return Non-zero value if c is a either a space (' ') or horizontal
* tab ('\\t') character.
*/
PJ_INLINE(int) pj_isblank(int c) { return isblank(c); }
/**
* Converts character to lowercase.
* @param c The integer character to convert.
* @return Lowercase character of c.
*/
PJ_INLINE(int) pj_tolower(int c) { return tolower(c); }
/**
* Converts character to uppercase.
* @param c The integer character to convert.
* @return Uppercase character of c.
*/
PJ_INLINE(int) pj_toupper(int c) { return toupper(c); }
/** @} */
#endif /* __PJ_CTYPE_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,319 +1,319 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/equeue.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_EQUEUE_H__
#define __PJ_EQUEUE_H__
/**
* @file equeue.h
* @brief Event Queue
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_EQUEUE Event Queue
* @brief Event Queue
* @ingroup PJ_OS
* @{
*/
/**
* Opaque data type for Event Queue.
*/
typedef struct pj_equeue_t pj_equeue_t;
/**
* Opaque data type for Event Queue key.
*/
typedef struct pj_equeue_key_t pj_equeue_key_t;
/**
* This structure describes the callbacks to be called when I/O operation
* completes.
*/
typedef struct pj_io_callback
{
/**
* This callback is called when #pj_equeue_read, #pj_equeue_recv or
* #pj_equeue_recvfrom completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been read.
*/
void (*on_read_complete)(pj_equeue_key_t *key, pj_ssize_t bytes_read);
/**
* This callback is called when #pj_equeue_write, #pj_equeue_send, or
* #pj_equeue_sendto completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been written.
*/
void (*on_write_complete)(pj_equeue_key_t *key, pj_ssize_t bytes_sent);
/**
* This callback is called when #pj_equeue_accept completes.
*
* @param key The key.
* @param status Zero if the operation completes successfully.
*/
void (*on_accept_complete)(pj_equeue_key_t *key, int status);
/**
* This callback is called when #pj_equeue_connect completes.
*
* @param key The key.
* @param status Zero if the operation completes successfully.
*/
void (*on_connect_complete)(pj_equeue_key_t *key, int status);
} pj_io_callback;
/**
* Event Queue options.
*/
typedef struct pj_equeue_options
{
/** Maximum number of threads that are allowed to access Event Queue
* simulteneously.
*/
unsigned nb_threads;
/** If non-zero, then no mutex protection will be used. */
pj_bool_t no_lock;
/** Interval of the busy loop inside the event queue.
* The time resolution here determines the accuracy of the
* timer in the Event Queue.
*/
pj_time_val poll_interval;
} pj_equeue_options;
/**
* Error value returned by I/O operations to indicate that the operation
* can't complete immediately and will complete later.
*/
#define PJ_EQUEUE_PENDING (-2)
/**
* Types of Event Queue operation.
*/
typedef enum pj_equeue_op
{
PJ_EQUEUE_OP_NONE = 0, /**< No operation. */
PJ_EQUEUE_OP_READ = 1, /**< read() operation. */
PJ_EQUEUE_OP_RECV_FROM = 2, /**< recvfrom() operation. */
PJ_EQUEUE_OP_WRITE = 4, /**< write() operation. */
PJ_EQUEUE_OP_SEND_TO = 8, /**< sendto() operation. */
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
PJ_EQUEUE_OP_ACCEPT = 16, /**< accept() operation. */
PJ_EQUEUE_OP_CONNECT = 32, /**< connect() operation. */
#endif /* PJ_HAS_TCP */
} pj_equeue_op;
/**
* Initialize Event Queue options with default values.
*
* @param options Event Queue options.
*/
PJ_DECL(void) pj_equeue_options_init(pj_equeue_options *options);
/**
* Create a new Event Queue framework.
*
* @param pool The pool to allocate the event queue structure.
* @param options Event queue options, or if NULL is given, then
* default options will be used.
* @param equeue Pointer to receive event queue structure.
*
* @return zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_create( pj_pool_t *pool,
const pj_equeue_options *options,
pj_equeue_t **equeue);
/**
* Get the first instance of Event Queue, or NULL if no Event Queue
* instance has been created in the application.
*
* @return The first instance of Event Queue created, or NULL.
*/
PJ_DECL(pj_equeue_t*) pj_equeue_instance(void);
/**
* Destroy the Event Queue.
*
* @param equeue The Event Queue instance to be destroyed.
*/
PJ_DECL(pj_status_t) pj_equeue_destroy( pj_equeue_t *equeue );
/**
* Customize the lock object that is used by the Event Queue.
*
* @param equeue The Event Queue instance.
* @param lock The lock object.
* @param auto_del If non-zero, the lock will be destroyed by
* Event Queue.
*
* @return Zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_set_lock( pj_equeue_t *equeue,
pj_lock_t *lock,
pj_bool_t auto_del);
/**
* Associate an Event Queue key to particular handle. The key is also
* associated with the callback and user data, which will be used by
* the Event Queue framework when signalling event back to application.
*
* @param pool To allocate the resource for the specified handle, which
* must be valid until the handle/key is unregistered
* from Event Queue.
* @param equeue The Event Queue.
* @param hnd The OS handle to be registered, which can be a socket
* descriptor (pj_sock_t), file descriptor, etc.
* @param cb Callback to be called when I/O operation completes.
* @param user_data User data to be associated with the key.
* @param key Pointer to receive the key.
*
* @return Zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_register( pj_pool_t *pool,
pj_equeue_t *equeue,
pj_oshandle_t hnd,
pj_io_callback *cb,
void *user_data,
pj_equeue_key_t **key);
/**
* Retrieve user data associated with a key.
*
* @param key The Event Queue key.
*
* @return User data associated with the key.
*/
PJ_DECL(void*) pj_equeue_get_user_data( pj_equeue_key_t *key );
/**
* Unregister Event Queue key from the Event Queue.
*
* @param equeue The Event Queue.
* @param key The key.
*
* @return Zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_unregister( pj_equeue_t *equeue,
pj_equeue_key_t *key);
/**
* Instruct the Event Queue to read from the specified handle. This function
* returns immediately (i.e. non-blocking) regardless whether some data has
* been transfered. If the operation can't complete immediately, caller will
* be notified about the completion when it calls pj_equeue_poll().
*
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param size The maximum size to be read.
*
* @return
* - zero or positive number to indicate the number of bytes has been
* read, and in this case the operation was not queued.
* - (-1) on error, which in this case operation was not queued.
* - PJ_EQUEUE_PENDING if the operation has been queued.
*/
PJ_DECL(pj_ssize_t) pj_equeue_read( pj_equeue_key_t *key,
void *buffer,
pj_size_t size);
/**
* Start recv() operation on the specified handle.
*
* @see ::pj_ioqueue_read
*/
PJ_DECL(pj_ssize_t) pj_equeue_recv( pj_equeue_key_t *key,
void *buf,
pj_size_t size,
unsigned flags);
/**
* Start recvfrom() operation on the specified handle.
*
* @see ::pj_equeue_read
*/
PJ_DECL(pj_ssize_t) pj_equeue_recvfrom( pj_equeue_key_t *key,
void *buf,
pj_size_t size,
unsigned flags,
pj_sockaddr_t *addr,
int *addrlen );
/**
* Write.
*/
PJ_DECL(pj_ssize_t) pj_equeue_write( pj_equeue_key_t *key,
const void *buf,
pj_size_t size);
/**
* Send.
*/
PJ_DECL(pj_ssize_t) pj_equeue_send( pj_equeue_key_t *key,
const void *buf,
pj_size_t size,
unsigned flags);
/**
* Sendto.
*/
PJ_DECL(pj_ssize_t) pj_equeue_sendto( pj_equeue_key_t *key,
const void *buf,
pj_size_t size,
unsigned flags,
const pj_sockaddr_t *addr,
int addrlen);
/**
* Schedule timer.
*/
PJ_DECL(pj_status_t) pj_equeue_schedule_timer( pj_equeue_t *equeue,
const pj_time_val *timeout,
pj_timer_entry *entry);
/**
* Cancel timer.
*/
PJ_DECL(pj_status_t) pj_equeue_cancel_timer( pj_equeue_t *equeue,
pj_timer_entry *entry);
/**
* Poll for events.
*/
PJ_DECL(pj_status_t) pj_equeue_poll( pj_equeue_t *equeue,
const pj_time_val *timeout );
/**
* Run.
*/
PJ_DECL(pj_status_t) pj_equeue_run( pj_equeue_t *equeue );
/**
* Stop all running threads.
*/
PJ_DECL(pj_status_t) pj_equeue_stop( pj_equeue_t *equeue );
/** @} */
PJ_END_DECL
#endif /* __PJ_EQUEUE_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/equeue.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_EQUEUE_H__
#define __PJ_EQUEUE_H__
/**
* @file equeue.h
* @brief Event Queue
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_EQUEUE Event Queue
* @brief Event Queue
* @ingroup PJ_OS
* @{
*/
/**
* Opaque data type for Event Queue.
*/
typedef struct pj_equeue_t pj_equeue_t;
/**
* Opaque data type for Event Queue key.
*/
typedef struct pj_equeue_key_t pj_equeue_key_t;
/**
* This structure describes the callbacks to be called when I/O operation
* completes.
*/
typedef struct pj_io_callback
{
/**
* This callback is called when #pj_equeue_read, #pj_equeue_recv or
* #pj_equeue_recvfrom completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been read.
*/
void (*on_read_complete)(pj_equeue_key_t *key, pj_ssize_t bytes_read);
/**
* This callback is called when #pj_equeue_write, #pj_equeue_send, or
* #pj_equeue_sendto completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been written.
*/
void (*on_write_complete)(pj_equeue_key_t *key, pj_ssize_t bytes_sent);
/**
* This callback is called when #pj_equeue_accept completes.
*
* @param key The key.
* @param status Zero if the operation completes successfully.
*/
void (*on_accept_complete)(pj_equeue_key_t *key, int status);
/**
* This callback is called when #pj_equeue_connect completes.
*
* @param key The key.
* @param status Zero if the operation completes successfully.
*/
void (*on_connect_complete)(pj_equeue_key_t *key, int status);
} pj_io_callback;
/**
* Event Queue options.
*/
typedef struct pj_equeue_options
{
/** Maximum number of threads that are allowed to access Event Queue
* simulteneously.
*/
unsigned nb_threads;
/** If non-zero, then no mutex protection will be used. */
pj_bool_t no_lock;
/** Interval of the busy loop inside the event queue.
* The time resolution here determines the accuracy of the
* timer in the Event Queue.
*/
pj_time_val poll_interval;
} pj_equeue_options;
/**
* Error value returned by I/O operations to indicate that the operation
* can't complete immediately and will complete later.
*/
#define PJ_EQUEUE_PENDING (-2)
/**
* Types of Event Queue operation.
*/
typedef enum pj_equeue_op
{
PJ_EQUEUE_OP_NONE = 0, /**< No operation. */
PJ_EQUEUE_OP_READ = 1, /**< read() operation. */
PJ_EQUEUE_OP_RECV_FROM = 2, /**< recvfrom() operation. */
PJ_EQUEUE_OP_WRITE = 4, /**< write() operation. */
PJ_EQUEUE_OP_SEND_TO = 8, /**< sendto() operation. */
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
PJ_EQUEUE_OP_ACCEPT = 16, /**< accept() operation. */
PJ_EQUEUE_OP_CONNECT = 32, /**< connect() operation. */
#endif /* PJ_HAS_TCP */
} pj_equeue_op;
/**
* Initialize Event Queue options with default values.
*
* @param options Event Queue options.
*/
PJ_DECL(void) pj_equeue_options_init(pj_equeue_options *options);
/**
* Create a new Event Queue framework.
*
* @param pool The pool to allocate the event queue structure.
* @param options Event queue options, or if NULL is given, then
* default options will be used.
* @param equeue Pointer to receive event queue structure.
*
* @return zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_create( pj_pool_t *pool,
const pj_equeue_options *options,
pj_equeue_t **equeue);
/**
* Get the first instance of Event Queue, or NULL if no Event Queue
* instance has been created in the application.
*
* @return The first instance of Event Queue created, or NULL.
*/
PJ_DECL(pj_equeue_t*) pj_equeue_instance(void);
/**
* Destroy the Event Queue.
*
* @param equeue The Event Queue instance to be destroyed.
*/
PJ_DECL(pj_status_t) pj_equeue_destroy( pj_equeue_t *equeue );
/**
* Customize the lock object that is used by the Event Queue.
*
* @param equeue The Event Queue instance.
* @param lock The lock object.
* @param auto_del If non-zero, the lock will be destroyed by
* Event Queue.
*
* @return Zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_set_lock( pj_equeue_t *equeue,
pj_lock_t *lock,
pj_bool_t auto_del);
/**
* Associate an Event Queue key to particular handle. The key is also
* associated with the callback and user data, which will be used by
* the Event Queue framework when signalling event back to application.
*
* @param pool To allocate the resource for the specified handle, which
* must be valid until the handle/key is unregistered
* from Event Queue.
* @param equeue The Event Queue.
* @param hnd The OS handle to be registered, which can be a socket
* descriptor (pj_sock_t), file descriptor, etc.
* @param cb Callback to be called when I/O operation completes.
* @param user_data User data to be associated with the key.
* @param key Pointer to receive the key.
*
* @return Zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_register( pj_pool_t *pool,
pj_equeue_t *equeue,
pj_oshandle_t hnd,
pj_io_callback *cb,
void *user_data,
pj_equeue_key_t **key);
/**
* Retrieve user data associated with a key.
*
* @param key The Event Queue key.
*
* @return User data associated with the key.
*/
PJ_DECL(void*) pj_equeue_get_user_data( pj_equeue_key_t *key );
/**
* Unregister Event Queue key from the Event Queue.
*
* @param equeue The Event Queue.
* @param key The key.
*
* @return Zero on success.
*/
PJ_DECL(pj_status_t) pj_equeue_unregister( pj_equeue_t *equeue,
pj_equeue_key_t *key);
/**
* Instruct the Event Queue to read from the specified handle. This function
* returns immediately (i.e. non-blocking) regardless whether some data has
* been transfered. If the operation can't complete immediately, caller will
* be notified about the completion when it calls pj_equeue_poll().
*
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param size The maximum size to be read.
*
* @return
* - zero or positive number to indicate the number of bytes has been
* read, and in this case the operation was not queued.
* - (-1) on error, which in this case operation was not queued.
* - PJ_EQUEUE_PENDING if the operation has been queued.
*/
PJ_DECL(pj_ssize_t) pj_equeue_read( pj_equeue_key_t *key,
void *buffer,
pj_size_t size);
/**
* Start recv() operation on the specified handle.
*
* @see ::pj_ioqueue_read
*/
PJ_DECL(pj_ssize_t) pj_equeue_recv( pj_equeue_key_t *key,
void *buf,
pj_size_t size,
unsigned flags);
/**
* Start recvfrom() operation on the specified handle.
*
* @see ::pj_equeue_read
*/
PJ_DECL(pj_ssize_t) pj_equeue_recvfrom( pj_equeue_key_t *key,
void *buf,
pj_size_t size,
unsigned flags,
pj_sockaddr_t *addr,
int *addrlen );
/**
* Write.
*/
PJ_DECL(pj_ssize_t) pj_equeue_write( pj_equeue_key_t *key,
const void *buf,
pj_size_t size);
/**
* Send.
*/
PJ_DECL(pj_ssize_t) pj_equeue_send( pj_equeue_key_t *key,
const void *buf,
pj_size_t size,
unsigned flags);
/**
* Sendto.
*/
PJ_DECL(pj_ssize_t) pj_equeue_sendto( pj_equeue_key_t *key,
const void *buf,
pj_size_t size,
unsigned flags,
const pj_sockaddr_t *addr,
int addrlen);
/**
* Schedule timer.
*/
PJ_DECL(pj_status_t) pj_equeue_schedule_timer( pj_equeue_t *equeue,
const pj_time_val *timeout,
pj_timer_entry *entry);
/**
* Cancel timer.
*/
PJ_DECL(pj_status_t) pj_equeue_cancel_timer( pj_equeue_t *equeue,
pj_timer_entry *entry);
/**
* Poll for events.
*/
PJ_DECL(pj_status_t) pj_equeue_poll( pj_equeue_t *equeue,
const pj_time_val *timeout );
/**
* Run.
*/
PJ_DECL(pj_status_t) pj_equeue_run( pj_equeue_t *equeue );
/**
* Stop all running threads.
*/
PJ_DECL(pj_status_t) pj_equeue_stop( pj_equeue_t *equeue );
/** @} */
PJ_END_DECL
#endif /* __PJ_EQUEUE_H__ */

View File

@ -1,249 +1,249 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/errno.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_ERRNO_H__
#define __PJ_ERRNO_H__
/**
* @file errno.h
* @brief PJLIB Error Codes
*/
#include <pj/types.h>
#include <pj/compat/errno.h>
PJ_BEGIN_DECL
/**
* @defgroup pj_errno Error Codes
* @ingroup PJ
* @{
*
* In PJLIB, error/status codes from operating system are translated
* into PJLIB error namespace, and stored in @a pj_status_t. All functions
* that work with @a pj_status_t expect to get PJLIB error code instead
* of native codes.
*
* @section pj_errno_retval Return Values
*
* All functions that returns @a pj_status_t returns @a PJ_SUCCESS if the
* operation was completed successfully, or non-zero value to indicate
* error. If the error came from operating system, then the native error
* code is translated/folded into PJLIB's error namespace by using
* #PJ_STATUS_FROM_OS() macro. The function will do this automatically
* before returning the error to caller.
*
* @section pj_errno_errmsg Error Message
*
* To get the error message corresponding to a particular code, use function
* #pj_strerror(). This function expects error code in PJLIB error namespace,
* not the native error code. Application can pass the value from the
* following sources to this function:
* - #pj_get_os_error()
* - #pj_get_netos_error()
* - any return value from function returning @a pj_status_t.
*
* Application MUST NOT pass native error code (such as error code from
* functions like GetLastError() or errno) to PJLIB functions expecting
* @a pj_status_t.
*
*/
/**
* Get the last platform error/status, folded into pj_status_t.
* @return OS dependent error code, folded into pj_status_t.
* @remark This function gets errno, or calls GetLastError() function and
* convert the code into pj_status_t with PJ_STATUS_FROM_OS. Do
* not call this for socket functions!
* @see pj_get_netos_error()
*/
PJ_DECL(pj_status_t) pj_get_os_error(void);
/**
* Set last error.
* @param code pj_status_t
*/
PJ_DECL(void) pj_set_os_error(pj_status_t code);
/**
* Get the last error from socket operations.
* @return Last socket error, folded into pj_status_t.
*/
PJ_DECL(pj_status_t) pj_get_netos_error(void);
/**
* Set error code.
* @param code pj_status_t.
*/
PJ_DECL(void) pj_set_netos_error(pj_status_t code);
/**
* Get the error message for the specified error code. The message
* string will be NULL terminated.
*
* @param statcode The error code.
* @param buf Buffer to hold the error message string.
* @param bufsize Size of the buffer.
*
* @return The error message as NULL terminated string,
* wrapped with pj_str_t.
*/
PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode,
char *buf, pj_size_t bufsize);
/**
* @hideinitializer
* Return platform os error code folded into pj_status_t code. This is
* the macro that is used throughout the library for all PJLIB's functions
* that returns error from operating system. Application may override
* this macro to reduce size (e.g. by defining it to always return
* #PJ_EUNKNOWN).
*
* Note:
* This macro MUST return non-zero value regardless whether zero is
* passed as the argument. The reason is to protect logic error when
* the operating system doesn't report error codes properly.
*
* @param os_code Platform OS error code. This value may be evaluated
* more than once.
* @return The platform os error code folded into pj_status_t.
*/
#ifndef PJ_RETURN_OS_ERROR
# define PJ_RETURN_OS_ERROR(os_code) (os_code ? \
PJ_STATUS_FROM_OS(os_code) : -1)
#endif
/**
* @hideinitializer
* Fold a platform specific error into an pj_status_t code.
*
* @param e The platform os error code.
* @return pj_status_t
* @warning Macro implementation; the syserr argument may be evaluated
* multiple times.
*/
#define PJ_STATUS_FROM_OS(e) (e == 0 ? PJ_SUCCESS : e + PJ_ERRNO_START_SYS)
/**
* @hideinitializer
* Fold an pj_status_t code back to the native platform defined error.
*
* @param e The pj_status_t folded platform os error code.
* @return pj_os_err_type
* @warning macro implementation; the statcode argument may be evaluated
* multiple times. If the statcode was not created by
* pj_get_os_error or PJ_STATUS_FROM_OS, the results are undefined.
*/
#define PJ_STATUS_TO_OS(e) (e == 0 ? PJ_SUCCESS : e - PJ_ERRNO_START_SYS)
/**
* @defgroup pj_errnum PJLIB's Own Error Codes
* @ingroup pj_errno
* @{
*/
/**
* @hideinitializer
* Unknown error has been reported.
*/
#define PJ_EUNKNOWN (PJ_ERRNO_START_STATUS + 1)
/**
* @hideinitializer
* The operation is pending and will be completed later.
*/
#define PJ_EPENDING (PJ_ERRNO_START_STATUS + 2)
/**
* @hideinitializer
* Too many connecting sockets.
*/
#define PJ_ETOOMANYCONN (PJ_ERRNO_START_STATUS + 3)
/**
* @hideinitializer
* Invalid argument.
*/
#define PJ_EINVAL (PJ_ERRNO_START_STATUS + 4)
/**
* @hideinitializer
* Name too long (eg. hostname too long).
*/
#define PJ_ENAMETOOLONG (PJ_ERRNO_START_STATUS + 5)
/**
* @hideinitializer
* Not found.
*/
#define PJ_ENOTFOUND (PJ_ERRNO_START_STATUS + 6)
/**
* @hideinitializer
* Not enough memory.
*/
#define PJ_ENOMEM (PJ_ERRNO_START_STATUS + 7)
/**
* @hideinitializer
* Bug detected!
*/
#define PJ_EBUG (PJ_ERRNO_START_STATUS + 8)
/**
* @hideinitializer
* Operation timed out.
*/
#define PJ_ETIMEDOUT (PJ_ERRNO_START_STATUS + 9)
/**
* @hideinitializer
* Too many objects.
*/
#define PJ_ETOOMANY (PJ_ERRNO_START_STATUS + 10)
/**
* @hideinitializer
* Object is busy.
*/
#define PJ_EBUSY (PJ_ERRNO_START_STATUS + 11)
/**
* @hideinitializer
* The specified option is not supported.
*/
#define PJ_ENOTSUP (PJ_ERRNO_START_STATUS + 12)
/**
* @hideinitializer
* Invalid operation.
*/
#define PJ_EINVALIDOP (PJ_ERRNO_START_STATUS + 13)
/** @} */ /* pj_errnum */
/** @} */ /* pj_errno */
/**
* PJ_ERRNO_START is where PJLIB specific error values start.
*/
#define PJ_ERRNO_START 20000
/**
* PJ_ERRNO_SPACE_SIZE is the maximum number of errors in one of
* the error/status range below.
*/
#define PJ_ERRNO_SPACE_SIZE 50000
/**
* PJ_ERRNO_START_STATUS is where PJLIB specific status codes start.
*/
#define PJ_ERRNO_START_STATUS (PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
/**
* PJ_ERRNO_START_SYS converts platform specific error codes into
* pj_status_t values.
*/
#define PJ_ERRNO_START_SYS (PJ_ERRNO_START_STATUS + PJ_ERRNO_SPACE_SIZE)
/**
* PJ_ERRNO_START_USER are reserved for applications that use error
* codes along with PJLIB codes.
*/
#define PJ_ERRNO_START_USER (PJ_ERRNO_START_SYS + PJ_ERRNO_SPACE_SIZE)
PJ_END_DECL
#endif /* __PJ_ERRNO_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/errno.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_ERRNO_H__
#define __PJ_ERRNO_H__
/**
* @file errno.h
* @brief PJLIB Error Codes
*/
#include <pj/types.h>
#include <pj/compat/errno.h>
PJ_BEGIN_DECL
/**
* @defgroup pj_errno Error Codes
* @ingroup PJ
* @{
*
* In PJLIB, error/status codes from operating system are translated
* into PJLIB error namespace, and stored in @a pj_status_t. All functions
* that work with @a pj_status_t expect to get PJLIB error code instead
* of native codes.
*
* @section pj_errno_retval Return Values
*
* All functions that returns @a pj_status_t returns @a PJ_SUCCESS if the
* operation was completed successfully, or non-zero value to indicate
* error. If the error came from operating system, then the native error
* code is translated/folded into PJLIB's error namespace by using
* #PJ_STATUS_FROM_OS() macro. The function will do this automatically
* before returning the error to caller.
*
* @section pj_errno_errmsg Error Message
*
* To get the error message corresponding to a particular code, use function
* #pj_strerror(). This function expects error code in PJLIB error namespace,
* not the native error code. Application can pass the value from the
* following sources to this function:
* - #pj_get_os_error()
* - #pj_get_netos_error()
* - any return value from function returning @a pj_status_t.
*
* Application MUST NOT pass native error code (such as error code from
* functions like GetLastError() or errno) to PJLIB functions expecting
* @a pj_status_t.
*
*/
/**
* Get the last platform error/status, folded into pj_status_t.
* @return OS dependent error code, folded into pj_status_t.
* @remark This function gets errno, or calls GetLastError() function and
* convert the code into pj_status_t with PJ_STATUS_FROM_OS. Do
* not call this for socket functions!
* @see pj_get_netos_error()
*/
PJ_DECL(pj_status_t) pj_get_os_error(void);
/**
* Set last error.
* @param code pj_status_t
*/
PJ_DECL(void) pj_set_os_error(pj_status_t code);
/**
* Get the last error from socket operations.
* @return Last socket error, folded into pj_status_t.
*/
PJ_DECL(pj_status_t) pj_get_netos_error(void);
/**
* Set error code.
* @param code pj_status_t.
*/
PJ_DECL(void) pj_set_netos_error(pj_status_t code);
/**
* Get the error message for the specified error code. The message
* string will be NULL terminated.
*
* @param statcode The error code.
* @param buf Buffer to hold the error message string.
* @param bufsize Size of the buffer.
*
* @return The error message as NULL terminated string,
* wrapped with pj_str_t.
*/
PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode,
char *buf, pj_size_t bufsize);
/**
* @hideinitializer
* Return platform os error code folded into pj_status_t code. This is
* the macro that is used throughout the library for all PJLIB's functions
* that returns error from operating system. Application may override
* this macro to reduce size (e.g. by defining it to always return
* #PJ_EUNKNOWN).
*
* Note:
* This macro MUST return non-zero value regardless whether zero is
* passed as the argument. The reason is to protect logic error when
* the operating system doesn't report error codes properly.
*
* @param os_code Platform OS error code. This value may be evaluated
* more than once.
* @return The platform os error code folded into pj_status_t.
*/
#ifndef PJ_RETURN_OS_ERROR
# define PJ_RETURN_OS_ERROR(os_code) (os_code ? \
PJ_STATUS_FROM_OS(os_code) : -1)
#endif
/**
* @hideinitializer
* Fold a platform specific error into an pj_status_t code.
*
* @param e The platform os error code.
* @return pj_status_t
* @warning Macro implementation; the syserr argument may be evaluated
* multiple times.
*/
#define PJ_STATUS_FROM_OS(e) (e == 0 ? PJ_SUCCESS : e + PJ_ERRNO_START_SYS)
/**
* @hideinitializer
* Fold an pj_status_t code back to the native platform defined error.
*
* @param e The pj_status_t folded platform os error code.
* @return pj_os_err_type
* @warning macro implementation; the statcode argument may be evaluated
* multiple times. If the statcode was not created by
* pj_get_os_error or PJ_STATUS_FROM_OS, the results are undefined.
*/
#define PJ_STATUS_TO_OS(e) (e == 0 ? PJ_SUCCESS : e - PJ_ERRNO_START_SYS)
/**
* @defgroup pj_errnum PJLIB's Own Error Codes
* @ingroup pj_errno
* @{
*/
/**
* @hideinitializer
* Unknown error has been reported.
*/
#define PJ_EUNKNOWN (PJ_ERRNO_START_STATUS + 1)
/**
* @hideinitializer
* The operation is pending and will be completed later.
*/
#define PJ_EPENDING (PJ_ERRNO_START_STATUS + 2)
/**
* @hideinitializer
* Too many connecting sockets.
*/
#define PJ_ETOOMANYCONN (PJ_ERRNO_START_STATUS + 3)
/**
* @hideinitializer
* Invalid argument.
*/
#define PJ_EINVAL (PJ_ERRNO_START_STATUS + 4)
/**
* @hideinitializer
* Name too long (eg. hostname too long).
*/
#define PJ_ENAMETOOLONG (PJ_ERRNO_START_STATUS + 5)
/**
* @hideinitializer
* Not found.
*/
#define PJ_ENOTFOUND (PJ_ERRNO_START_STATUS + 6)
/**
* @hideinitializer
* Not enough memory.
*/
#define PJ_ENOMEM (PJ_ERRNO_START_STATUS + 7)
/**
* @hideinitializer
* Bug detected!
*/
#define PJ_EBUG (PJ_ERRNO_START_STATUS + 8)
/**
* @hideinitializer
* Operation timed out.
*/
#define PJ_ETIMEDOUT (PJ_ERRNO_START_STATUS + 9)
/**
* @hideinitializer
* Too many objects.
*/
#define PJ_ETOOMANY (PJ_ERRNO_START_STATUS + 10)
/**
* @hideinitializer
* Object is busy.
*/
#define PJ_EBUSY (PJ_ERRNO_START_STATUS + 11)
/**
* @hideinitializer
* The specified option is not supported.
*/
#define PJ_ENOTSUP (PJ_ERRNO_START_STATUS + 12)
/**
* @hideinitializer
* Invalid operation.
*/
#define PJ_EINVALIDOP (PJ_ERRNO_START_STATUS + 13)
/** @} */ /* pj_errnum */
/** @} */ /* pj_errno */
/**
* PJ_ERRNO_START is where PJLIB specific error values start.
*/
#define PJ_ERRNO_START 20000
/**
* PJ_ERRNO_SPACE_SIZE is the maximum number of errors in one of
* the error/status range below.
*/
#define PJ_ERRNO_SPACE_SIZE 50000
/**
* PJ_ERRNO_START_STATUS is where PJLIB specific status codes start.
*/
#define PJ_ERRNO_START_STATUS (PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
/**
* PJ_ERRNO_START_SYS converts platform specific error codes into
* pj_status_t values.
*/
#define PJ_ERRNO_START_SYS (PJ_ERRNO_START_STATUS + PJ_ERRNO_SPACE_SIZE)
/**
* PJ_ERRNO_START_USER are reserved for applications that use error
* codes along with PJLIB codes.
*/
#define PJ_ERRNO_START_USER (PJ_ERRNO_START_SYS + PJ_ERRNO_SPACE_SIZE)
PJ_END_DECL
#endif /* __PJ_ERRNO_H__ */

View File

@ -1,267 +1,267 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/except.h 9 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_EXCEPTION_H__
#define __PJ_EXCEPTION_H__
/**
* @file except.h
* @brief Exception Handling in C.
*/
#include <pj/types.h>
#include <pj/compat/setjmp.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_EXCEPT Exception Handling
* @ingroup PJ_MISC
* @{
*
* \section pj_except_sample_sec Quick Example
*
* For the impatient, take a look at some examples:
* - @ref page_pjlib_samples_except_c
* - @ref page_pjlib_exception_test
*
* \section pj_except_except Exception Handling
*
* This module provides exception handling syntactically similar to C++ in
* C language. The underlying mechanism use setjmp() and longjmp(), and since
* these constructs are ANSI standard, the mechanism here should be available
* on most platforms/compilers which are ANSI compliant.
*
* If ANSI libc is not available, then setjmp()/longjmp() implementation will
* be provided. See <pj/compat/setjmp.h> for compatibility.
*
* The exception handling mechanism is completely thread safe, so the exception
* thrown by one thread will not interfere with other thread.
*
* CAVEATS:
* - unlike C++ exception, the scheme here won't call destructors of local
* objects if exception is thrown. Care must be taken when a function
* hold some resorce such as pool or mutex etc.
* - You CAN NOT make nested exception in one single function without using
* a nested PJ_USE_EXCEPTION.
* - Exceptions will always be caught by the first handle (unlike C++ where
* exception is only caught if the type matches.
*
* The exception handling constructs are similar to C++. The blocks will be
* constructed similar to the following sample:
*
* \verbatim
#define NO_MEMORY 1
#define SYNTAX_ERROR 2
int main()
{
PJ_USE_EXCEPTION; // declare local exception stack.
PJ_TRY {
...// do something..
}
PJ_CATCH(NO_MEMORY) {
... // handle exception 1
}
PJ_CATCH(SYNTAX_ERROR) {
... // handle exception 2
}
PJ_DEFAULT {
... // handle other exceptions.
}
PJ_END;
}
\endverbatim
*
* The above sample uses hard coded exception ID. It is @b strongly
* recommended that applications request a unique exception ID instead
* of hard coded value like above.
*
* \section pj_except_reg Exception ID Allocation
*
* To ensure that exception ID (number) are used consistently and to
* prevent ID collisions in an application, it is strongly suggested that
* applications allocate an exception ID for each possible exception
* type. As a bonus of this process, the application can identify
* the name of the exception when the particular exception is thrown.
*
* Exception ID management are performed with the following APIs:
* - #pj_exception_id_alloc().
* - #pj_exception_id_free().
* - #pj_exception_id_name().
*
*
* PJLIB itself automatically allocates one exception id, i.e.
* #PJ_NO_MEMORY_EXCEPTION which is declared in <pj/pool.h>. This exception
* ID is raised by default pool policy when it fails to allocate memory.
*
* \section PJ_EX_KEYWORDS Keywords
*
* \subsection PJ_THROW PJ_THROW(expression)
* Throw an exception. The expression thrown is an integer as the result of
* the \a expression. This keyword can be specified anywhere within the
* program.
*
* \subsection PJ_USE_EXCEPTION PJ_USE_EXCEPTION
* Specify this in the variable definition section of the function block
* (or any blocks) to specify that the block has \a PJ_TRY/PJ_CATCH exception
* block.
* Actually, this is just a macro to declare local variable which is used to
* push the exception state to the exception stack.
*
* \subsection PJ_TRY PJ_TRY
* The \a PJ_TRY keyword is typically followed by a block. If an exception is
* thrown in this block, then the execution will resume to the \a PJ_CATCH
* handler.
*
* \subsection PJ_CATCH PJ_CATCH(expression)
* The \a PJ_CATCH is normally followed by a block. This block will be executed
* if the exception being thrown is equal to the expression specified in the
* \a PJ_CATCH.
*
* \subsection PJ_DEFAULT PJ_DEFAULT
* The \a PJ_DEFAULT keyword is normally followed by a block. This block will
* be executed if the exception being thrown doesn't match any of the \a
* PJ_CATCH specification. The \a PJ_DEFAULT block \b MUST be placed as the
* last block of the handlers.
*
* \subsection PJ_END PJ_END
* Specify this keyword to mark the end of \a PJ_TRY / \a PJ_CATCH blocks.
*
* \subsection PJ_GET_EXCEPTION PJ_GET_EXCEPTION(void)
* Get the last exception thrown. This macro is normally called inside the
* \a PJ_CATCH or \a PJ_DEFAULT block, altough it can be used anywhere where
* the \a PJ_USE_EXCEPTION definition is in scope.
*
*
* \section pj_except_examples_sec Examples
*
* For some examples on how to use the exception construct, please see:
* - @ref page_pjlib_samples_except_c
* - @ref page_pjlib_exception_test
*/
/**
* Allocate a unique exception id.
* Applications don't have to allocate a unique exception ID before using
* the exception construct. However, by doing so it ensures that there is
* no collisions of exception ID.
*
* As a bonus, when exception number is acquired through this function,
* the library can assign name to the exception (only if
* PJ_HAS_EXCEPTION_NAMES is enabled (default is yes)) and find out the
* exception name when it catches an exception.
*
* @param name Name to be associated with the exception ID.
* @param id Pointer to receive the ID.
*
* @return PJ_SUCCESS on success or PJ_ETOOMANY if the library
* is running out out ids.
*/
PJ_DECL(pj_status_t) pj_exception_id_alloc(const char *name,
pj_exception_id_t *id);
/**
* Free an exception id.
*
* @param id The exception ID.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_exception_id_free(pj_exception_id_t id);
/**
* Retrieve name associated with the exception id.
*
* @param id The exception ID.
*
* @return The name associated with the specified ID.
*/
PJ_DECL(const char*) pj_exception_id_name(pj_exception_id_t id);
/** @} */
/**
* This structure (which should be invisible to user) manages the TRY handler
* stack.
*/
struct pj_exception_state_t
{
struct pj_exception_state_t *prev; /**< Previous state in the list. */
pj_jmp_buf state; /**< jmp_buf. */
};
/**
* Throw exception.
* @param id Exception Id.
*/
PJ_DECL_NO_RETURN(void)
pj_throw_exception_(pj_exception_id_t id) PJ_ATTR_NORETURN;
/**
* Push exception handler.
*/
PJ_DECL(void) pj_push_exception_handler_(struct pj_exception_state_t *rec);
/**
* Pop exception handler.
*/
PJ_DECL(void) pj_pop_exception_handler_(void);
/**
* Declare that the function will use exception.
* @hideinitializer
*/
#define PJ_USE_EXCEPTION struct pj_exception_state_t pj_x_except__; int pj_x_code__
/**
* Start exception specification block.
* @hideinitializer
*/
#define PJ_TRY if (1) { \
pj_push_exception_handler_(&pj_x_except__); \
pj_x_code__ = pj_setjmp(pj_x_except__.state); \
if (pj_x_code__ == 0)
/**
* Catch the specified exception Id.
* @param id The exception number to catch.
* @hideinitializer
*/
#define PJ_CATCH(id) else if (pj_x_code__ == (id))
/**
* Catch any exception number.
* @hideinitializer
*/
#define PJ_DEFAULT else
/**
* End of exception specification block.
* @hideinitializer
*/
#define PJ_END pj_pop_exception_handler_(); \
} else {}
/**
* Throw exception.
* @param exception_id The exception number.
* @hideinitializer
*/
#define PJ_THROW(exception_id) pj_throw_exception_(exception_id)
/**
* Get current exception.
* @return Current exception code.
* @hideinitializer
*/
#define PJ_GET_EXCEPTION() (pj_x_code__)
PJ_END_DECL
#endif /* __PJ_EXCEPTION_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/except.h 9 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_EXCEPTION_H__
#define __PJ_EXCEPTION_H__
/**
* @file except.h
* @brief Exception Handling in C.
*/
#include <pj/types.h>
#include <pj/compat/setjmp.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_EXCEPT Exception Handling
* @ingroup PJ_MISC
* @{
*
* \section pj_except_sample_sec Quick Example
*
* For the impatient, take a look at some examples:
* - @ref page_pjlib_samples_except_c
* - @ref page_pjlib_exception_test
*
* \section pj_except_except Exception Handling
*
* This module provides exception handling syntactically similar to C++ in
* C language. The underlying mechanism use setjmp() and longjmp(), and since
* these constructs are ANSI standard, the mechanism here should be available
* on most platforms/compilers which are ANSI compliant.
*
* If ANSI libc is not available, then setjmp()/longjmp() implementation will
* be provided. See <pj/compat/setjmp.h> for compatibility.
*
* The exception handling mechanism is completely thread safe, so the exception
* thrown by one thread will not interfere with other thread.
*
* CAVEATS:
* - unlike C++ exception, the scheme here won't call destructors of local
* objects if exception is thrown. Care must be taken when a function
* hold some resorce such as pool or mutex etc.
* - You CAN NOT make nested exception in one single function without using
* a nested PJ_USE_EXCEPTION.
* - Exceptions will always be caught by the first handle (unlike C++ where
* exception is only caught if the type matches.
*
* The exception handling constructs are similar to C++. The blocks will be
* constructed similar to the following sample:
*
* \verbatim
#define NO_MEMORY 1
#define SYNTAX_ERROR 2
int main()
{
PJ_USE_EXCEPTION; // declare local exception stack.
PJ_TRY {
...// do something..
}
PJ_CATCH(NO_MEMORY) {
... // handle exception 1
}
PJ_CATCH(SYNTAX_ERROR) {
... // handle exception 2
}
PJ_DEFAULT {
... // handle other exceptions.
}
PJ_END;
}
\endverbatim
*
* The above sample uses hard coded exception ID. It is @b strongly
* recommended that applications request a unique exception ID instead
* of hard coded value like above.
*
* \section pj_except_reg Exception ID Allocation
*
* To ensure that exception ID (number) are used consistently and to
* prevent ID collisions in an application, it is strongly suggested that
* applications allocate an exception ID for each possible exception
* type. As a bonus of this process, the application can identify
* the name of the exception when the particular exception is thrown.
*
* Exception ID management are performed with the following APIs:
* - #pj_exception_id_alloc().
* - #pj_exception_id_free().
* - #pj_exception_id_name().
*
*
* PJLIB itself automatically allocates one exception id, i.e.
* #PJ_NO_MEMORY_EXCEPTION which is declared in <pj/pool.h>. This exception
* ID is raised by default pool policy when it fails to allocate memory.
*
* \section PJ_EX_KEYWORDS Keywords
*
* \subsection PJ_THROW PJ_THROW(expression)
* Throw an exception. The expression thrown is an integer as the result of
* the \a expression. This keyword can be specified anywhere within the
* program.
*
* \subsection PJ_USE_EXCEPTION PJ_USE_EXCEPTION
* Specify this in the variable definition section of the function block
* (or any blocks) to specify that the block has \a PJ_TRY/PJ_CATCH exception
* block.
* Actually, this is just a macro to declare local variable which is used to
* push the exception state to the exception stack.
*
* \subsection PJ_TRY PJ_TRY
* The \a PJ_TRY keyword is typically followed by a block. If an exception is
* thrown in this block, then the execution will resume to the \a PJ_CATCH
* handler.
*
* \subsection PJ_CATCH PJ_CATCH(expression)
* The \a PJ_CATCH is normally followed by a block. This block will be executed
* if the exception being thrown is equal to the expression specified in the
* \a PJ_CATCH.
*
* \subsection PJ_DEFAULT PJ_DEFAULT
* The \a PJ_DEFAULT keyword is normally followed by a block. This block will
* be executed if the exception being thrown doesn't match any of the \a
* PJ_CATCH specification. The \a PJ_DEFAULT block \b MUST be placed as the
* last block of the handlers.
*
* \subsection PJ_END PJ_END
* Specify this keyword to mark the end of \a PJ_TRY / \a PJ_CATCH blocks.
*
* \subsection PJ_GET_EXCEPTION PJ_GET_EXCEPTION(void)
* Get the last exception thrown. This macro is normally called inside the
* \a PJ_CATCH or \a PJ_DEFAULT block, altough it can be used anywhere where
* the \a PJ_USE_EXCEPTION definition is in scope.
*
*
* \section pj_except_examples_sec Examples
*
* For some examples on how to use the exception construct, please see:
* - @ref page_pjlib_samples_except_c
* - @ref page_pjlib_exception_test
*/
/**
* Allocate a unique exception id.
* Applications don't have to allocate a unique exception ID before using
* the exception construct. However, by doing so it ensures that there is
* no collisions of exception ID.
*
* As a bonus, when exception number is acquired through this function,
* the library can assign name to the exception (only if
* PJ_HAS_EXCEPTION_NAMES is enabled (default is yes)) and find out the
* exception name when it catches an exception.
*
* @param name Name to be associated with the exception ID.
* @param id Pointer to receive the ID.
*
* @return PJ_SUCCESS on success or PJ_ETOOMANY if the library
* is running out out ids.
*/
PJ_DECL(pj_status_t) pj_exception_id_alloc(const char *name,
pj_exception_id_t *id);
/**
* Free an exception id.
*
* @param id The exception ID.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_exception_id_free(pj_exception_id_t id);
/**
* Retrieve name associated with the exception id.
*
* @param id The exception ID.
*
* @return The name associated with the specified ID.
*/
PJ_DECL(const char*) pj_exception_id_name(pj_exception_id_t id);
/** @} */
/**
* This structure (which should be invisible to user) manages the TRY handler
* stack.
*/
struct pj_exception_state_t
{
struct pj_exception_state_t *prev; /**< Previous state in the list. */
pj_jmp_buf state; /**< jmp_buf. */
};
/**
* Throw exception.
* @param id Exception Id.
*/
PJ_DECL_NO_RETURN(void)
pj_throw_exception_(pj_exception_id_t id) PJ_ATTR_NORETURN;
/**
* Push exception handler.
*/
PJ_DECL(void) pj_push_exception_handler_(struct pj_exception_state_t *rec);
/**
* Pop exception handler.
*/
PJ_DECL(void) pj_pop_exception_handler_(void);
/**
* Declare that the function will use exception.
* @hideinitializer
*/
#define PJ_USE_EXCEPTION struct pj_exception_state_t pj_x_except__; int pj_x_code__
/**
* Start exception specification block.
* @hideinitializer
*/
#define PJ_TRY if (1) { \
pj_push_exception_handler_(&pj_x_except__); \
pj_x_code__ = pj_setjmp(pj_x_except__.state); \
if (pj_x_code__ == 0)
/**
* Catch the specified exception Id.
* @param id The exception number to catch.
* @hideinitializer
*/
#define PJ_CATCH(id) else if (pj_x_code__ == (id))
/**
* Catch any exception number.
* @hideinitializer
*/
#define PJ_DEFAULT else
/**
* End of exception specification block.
* @hideinitializer
*/
#define PJ_END pj_pop_exception_handler_(); \
} else {}
/**
* Throw exception.
* @param exception_id The exception number.
* @hideinitializer
*/
#define PJ_THROW(exception_id) pj_throw_exception_(exception_id)
/**
* Get current exception.
* @return Current exception code.
* @hideinitializer
*/
#define PJ_GET_EXCEPTION() (pj_x_code__)
PJ_END_DECL
#endif /* __PJ_EXCEPTION_H__ */

View File

@ -1,27 +1,27 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/fifobuf.h 4 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_FIFOBUF_H__
#define __PJ_FIFOBUF_H__
#include <pj/types.h>
PJ_BEGIN_DECL
typedef struct pj_fifobuf_t pj_fifobuf_t;
struct pj_fifobuf_t
{
char *first, *last;
char *ubegin, *uend;
int full;
};
PJ_DECL(void) pj_fifobuf_init (pj_fifobuf_t *fb, void *buffer, unsigned size);
PJ_DECL(unsigned) pj_fifobuf_max_size (pj_fifobuf_t *fb);
PJ_DECL(void*) pj_fifobuf_alloc (pj_fifobuf_t *fb, unsigned size);
PJ_DECL(pj_status_t) pj_fifobuf_unalloc (pj_fifobuf_t *fb, void *buf);
PJ_DECL(pj_status_t) pj_fifobuf_free (pj_fifobuf_t *fb, void *buf);
PJ_END_DECL
#endif /* __PJ_FIFOBUF_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/fifobuf.h 4 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_FIFOBUF_H__
#define __PJ_FIFOBUF_H__
#include <pj/types.h>
PJ_BEGIN_DECL
typedef struct pj_fifobuf_t pj_fifobuf_t;
struct pj_fifobuf_t
{
char *first, *last;
char *ubegin, *uend;
int full;
};
PJ_DECL(void) pj_fifobuf_init (pj_fifobuf_t *fb, void *buffer, unsigned size);
PJ_DECL(unsigned) pj_fifobuf_max_size (pj_fifobuf_t *fb);
PJ_DECL(void*) pj_fifobuf_alloc (pj_fifobuf_t *fb, unsigned size);
PJ_DECL(pj_status_t) pj_fifobuf_unalloc (pj_fifobuf_t *fb, void *buf);
PJ_DECL(pj_status_t) pj_fifobuf_free (pj_fifobuf_t *fb, void *buf);
PJ_END_DECL
#endif /* __PJ_FIFOBUF_H__ */

View File

@ -1,75 +1,75 @@
/* $header: $ */
#ifndef __PJ_GUID_H__
#define __PJ_GUID_H__
/**
* @file guid.h
* @brief GUID Globally Unique Identifier.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_DS Data Structure.
* @ingroup PJ
*/
/**
* @defgroup PJ_GUID Globally Unique Identifier
* @ingroup PJ_DS
* @{
*
* This module provides API to create string that is globally unique.
* If application doesn't require that strong requirement, it can just
* use #pj_create_random_string() instead.
*/
/**
* PJ_GUID_STRING_LENGTH specifies length of GUID string. The value is
* dependent on the algorithm used internally to generate the GUID string.
* If real GUID generator is used, then the length will be 128bit or
* 32 bytes. If shadow GUID generator is used, then the length
* will be 20 bytes. Application should not assume which algorithm will
* be used by GUID generator.
*/
extern const unsigned PJ_GUID_STRING_LENGTH;
/**
* PJ_GUID_MAX_LENGTH specifies the maximum length of GUID string,
* regardless of which algorithm to use.
*/
#define PJ_GUID_MAX_LENGTH 32
/**
* Create a globally unique string, which length is PJ_GUID_STRING_LENGTH
* characters. Caller is responsible for preallocating the storage used
* in the string.
*
* @param str The string to store the result.
*
* @return The string.
*/
PJ_DECL(pj_str_t*) pj_generate_unique_string(pj_str_t *str);
/**
* Generate a unique string.
*
* @param pool Pool to allocate memory from.
* @param str The string.
*/
PJ_DECL(void) pj_create_unique_string(pj_pool_t *pool, pj_str_t *str);
/**
* @}
*/
PJ_END_DECL
#endif/* __PJ_GUID_H__ */
/* $header: $ */
#ifndef __PJ_GUID_H__
#define __PJ_GUID_H__
/**
* @file guid.h
* @brief GUID Globally Unique Identifier.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_DS Data Structure.
* @ingroup PJ
*/
/**
* @defgroup PJ_GUID Globally Unique Identifier
* @ingroup PJ_DS
* @{
*
* This module provides API to create string that is globally unique.
* If application doesn't require that strong requirement, it can just
* use #pj_create_random_string() instead.
*/
/**
* PJ_GUID_STRING_LENGTH specifies length of GUID string. The value is
* dependent on the algorithm used internally to generate the GUID string.
* If real GUID generator is used, then the length will be 128bit or
* 32 bytes. If shadow GUID generator is used, then the length
* will be 20 bytes. Application should not assume which algorithm will
* be used by GUID generator.
*/
extern const unsigned PJ_GUID_STRING_LENGTH;
/**
* PJ_GUID_MAX_LENGTH specifies the maximum length of GUID string,
* regardless of which algorithm to use.
*/
#define PJ_GUID_MAX_LENGTH 32
/**
* Create a globally unique string, which length is PJ_GUID_STRING_LENGTH
* characters. Caller is responsible for preallocating the storage used
* in the string.
*
* @param str The string to store the result.
*
* @return The string.
*/
PJ_DECL(pj_str_t*) pj_generate_unique_string(pj_str_t *str);
/**
* Generate a unique string.
*
* @param pool Pool to allocate memory from.
* @param str The string.
*/
PJ_DECL(void) pj_create_unique_string(pj_pool_t *pool, pj_str_t *str);
/**
* @}
*/
PJ_END_DECL
#endif/* __PJ_GUID_H__ */

View File

@ -1,140 +1,140 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/hash.h 6 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_HASH_H__
#define __PJ_HASH_H__
/**
* @file hash.h
* @brief Hash Table.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_HASH Hash Table
* @ingroup PJ_DS
* @{
* A hash table is a dictionary in which keys are mapped to array positions by
* hash functions. Having the keys of more than one item map to the same
* position is called a collision. In this library, we will chain the nodes
* that have the same key in a list.
*/
/**
* If this constant is used as keylen, then the key is interpreted as
* NULL terminated string.
*/
#define PJ_HASH_KEY_STRING ((unsigned)-1)
/**
* This is the function that is used by the hash table to calculate hash value
* of the specified key.
*
* @param hval the initial hash value, or zero.
* @param key the key to calculate.
* @param keylen the length of the key, or PJ_HASH_KEY_STRING to treat
* the key as null terminated string.
*
* @return the hash value.
*/
PJ_DECL(pj_uint32_t) pj_hash_calc(pj_uint32_t hval,
const void *key, unsigned keylen);
/**
* Create a hash table with the specified 'bucket' size.
*
* @param pool the pool from which the hash table will be allocated from.
* @param size the bucket size, which will be round-up to the nearest 2^n+1
*
* @return the hash table.
*/
PJ_DECL(pj_hash_table_t*) pj_hash_create(pj_pool_t *pool, unsigned size);
/**
* Get the value associated with the specified key.
*
* @param ht the hash table.
* @param key the key to look for.
* @param keylen the length of the key, or PJ_HASH_KEY_STRING to use the
* string length of the key.
*
* @return the value associated with the key, or NULL if the key is not found.
*/
PJ_DECL(void *) pj_hash_get( pj_hash_table_t *ht,
const void *key, unsigned keylen );
/**
* Associate/disassociate a value with the specified key.
*
* @param pool the pool to allocate the new entry if a new entry has to be
* created.
* @param ht the hash table.
* @param key the key.
* @param keylen the length of the key, or PJ_HASH_KEY_STRING to use the
* string length of the key.
* @param value value to be associated, or NULL to delete the entry with
* the specified key.
*/
PJ_DECL(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht,
const void *key, unsigned keylen,
void *value );
/**
* Get the total number of entries in the hash table.
*
* @param ht the hash table.
*
* @return the number of entries in the hash table.
*/
PJ_DECL(unsigned) pj_hash_count( pj_hash_table_t *ht );
/**
* Get the iterator to the first element in the hash table.
*
* @param ht the hash table.
* @param it the iterator for iterating hash elements.
*
* @return the iterator to the hash element, or NULL if no element presents.
*/
PJ_DECL(pj_hash_iterator_t*) pj_hash_first( pj_hash_table_t *ht,
pj_hash_iterator_t *it );
/**
* Get the next element from the iterator.
*
* @param ht the hash table.
* @param it the hash iterator.
*
* @return the next iterator, or NULL if there's no more element.
*/
PJ_DECL(pj_hash_iterator_t*) pj_hash_next( pj_hash_table_t *ht,
pj_hash_iterator_t *it );
/**
* Get the value associated with a hash iterator.
*
* @param ht the hash table.
* @param it the hash iterator.
*
* @return the value associated with the current element in iterator.
*/
PJ_DECL(void*) pj_hash_this( pj_hash_table_t *ht,
pj_hash_iterator_t *it );
/**
* @}
*/
PJ_END_DECL
#endif
/* $Header: /pjproject-0.3/pjlib/include/pj/hash.h 6 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_HASH_H__
#define __PJ_HASH_H__
/**
* @file hash.h
* @brief Hash Table.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_HASH Hash Table
* @ingroup PJ_DS
* @{
* A hash table is a dictionary in which keys are mapped to array positions by
* hash functions. Having the keys of more than one item map to the same
* position is called a collision. In this library, we will chain the nodes
* that have the same key in a list.
*/
/**
* If this constant is used as keylen, then the key is interpreted as
* NULL terminated string.
*/
#define PJ_HASH_KEY_STRING ((unsigned)-1)
/**
* This is the function that is used by the hash table to calculate hash value
* of the specified key.
*
* @param hval the initial hash value, or zero.
* @param key the key to calculate.
* @param keylen the length of the key, or PJ_HASH_KEY_STRING to treat
* the key as null terminated string.
*
* @return the hash value.
*/
PJ_DECL(pj_uint32_t) pj_hash_calc(pj_uint32_t hval,
const void *key, unsigned keylen);
/**
* Create a hash table with the specified 'bucket' size.
*
* @param pool the pool from which the hash table will be allocated from.
* @param size the bucket size, which will be round-up to the nearest 2^n+1
*
* @return the hash table.
*/
PJ_DECL(pj_hash_table_t*) pj_hash_create(pj_pool_t *pool, unsigned size);
/**
* Get the value associated with the specified key.
*
* @param ht the hash table.
* @param key the key to look for.
* @param keylen the length of the key, or PJ_HASH_KEY_STRING to use the
* string length of the key.
*
* @return the value associated with the key, or NULL if the key is not found.
*/
PJ_DECL(void *) pj_hash_get( pj_hash_table_t *ht,
const void *key, unsigned keylen );
/**
* Associate/disassociate a value with the specified key.
*
* @param pool the pool to allocate the new entry if a new entry has to be
* created.
* @param ht the hash table.
* @param key the key.
* @param keylen the length of the key, or PJ_HASH_KEY_STRING to use the
* string length of the key.
* @param value value to be associated, or NULL to delete the entry with
* the specified key.
*/
PJ_DECL(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht,
const void *key, unsigned keylen,
void *value );
/**
* Get the total number of entries in the hash table.
*
* @param ht the hash table.
*
* @return the number of entries in the hash table.
*/
PJ_DECL(unsigned) pj_hash_count( pj_hash_table_t *ht );
/**
* Get the iterator to the first element in the hash table.
*
* @param ht the hash table.
* @param it the iterator for iterating hash elements.
*
* @return the iterator to the hash element, or NULL if no element presents.
*/
PJ_DECL(pj_hash_iterator_t*) pj_hash_first( pj_hash_table_t *ht,
pj_hash_iterator_t *it );
/**
* Get the next element from the iterator.
*
* @param ht the hash table.
* @param it the hash iterator.
*
* @return the next iterator, or NULL if there's no more element.
*/
PJ_DECL(pj_hash_iterator_t*) pj_hash_next( pj_hash_table_t *ht,
pj_hash_iterator_t *it );
/**
* Get the value associated with a hash iterator.
*
* @param ht the hash table.
* @param it the hash iterator.
*
* @return the value associated with the current element in iterator.
*/
PJ_DECL(void*) pj_hash_this( pj_hash_table_t *ht,
pj_hash_iterator_t *it );
/**
* @}
*/
PJ_END_DECL
#endif

View File

@ -1,473 +1,473 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/ioqueue.h 10 10/29/05 11:29a Bennylp $ */
#ifndef __PJ_IOQUEUE_H__
#define __PJ_IOQUEUE_H__
/**
* @file ioqueue.h
* @brief I/O Dispatching Mechanism
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_IO Network I/O
* @brief Network I/O
* @ingroup PJ_OS
*
* This section contains API building blocks to perform network I/O and
* communications. If provides:
* - @ref PJ_SOCK
*\n
* A highly portable socket abstraction, runs on all kind of
* network APIs such as standard BSD socket, Windows socket, Linux
* \b kernel socket, PalmOS networking API, etc.
*
* - @ref pj_addr_resolve
*\n
* Portable address resolution, which implements #pj_gethostbyname().
*
* - @ref PJ_SOCK_SELECT
*\n
* A portable \a select() like API (#pj_sock_select()) which can be
* implemented with various back-ends.
*
* - @ref PJ_IOQUEUE
*\n
* Framework for dispatching network events.
*
* For more information see the modules below.
*/
/**
* @defgroup PJ_IOQUEUE I/O Event Dispatching Queue
* @ingroup PJ_IO
* @{
*
* This file provides abstraction for various event dispatching mechanisms.
* The interfaces for event dispatching vary alot, even in a single
* operating system. The abstraction here hopefully is suitable for most of
* the event dispatching available.
*
* Currently, the I/O Queue supports:
* - select(), as the common denominator, but the least efficient.
* - I/O Completion ports in Windows NT/2000/XP, which is the most efficient
* way to dispatch events in Windows NT based OSes, and most importantly,
* it doesn't have the limit on how many handles to monitor. And it works
* with files (not only sockets) as well.
*
* \section pj_ioqeuue_examples_sec Examples
*
* For some examples on how to use the I/O Queue, please see:
*
* - \ref page_pjlib_ioqueue_tcp_test
* - \ref page_pjlib_ioqueue_udp_test
* - \ref page_pjlib_ioqueue_perf_test
*/
/**
* This structure describes the callbacks to be called when I/O operation
* completes.
*/
typedef struct pj_ioqueue_callback
{
/**
* This callback is called when #pj_ioqueue_read or #pj_ioqueue_recvfrom
* completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been read.
*/
void (*on_read_complete)(pj_ioqueue_key_t *key, pj_ssize_t bytes_read);
/**
* This callback is called when #pj_ioqueue_write or #pj_ioqueue_sendto
* completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been read.
*/
void (*on_write_complete)(pj_ioqueue_key_t *key, pj_ssize_t bytes_sent);
/**
* This callback is called when #pj_ioqueue_accept completes.
*
* @param key The key.
* @param sock Newly connected socket.
* @param status Zero if the operation completes successfully.
*/
void (*on_accept_complete)(pj_ioqueue_key_t *key, pj_sock_t sock,
int status);
/**
* This callback is called when #pj_ioqueue_connect completes.
*
* @param key The key.
* @param status Zero if the operation completes successfully.
*/
void (*on_connect_complete)(pj_ioqueue_key_t *key, int status);
} pj_ioqueue_callback;
/**
* Types of I/O Queue operation.
*/
typedef enum pj_ioqueue_operation_e
{
PJ_IOQUEUE_OP_NONE = 0, /**< No operation. */
PJ_IOQUEUE_OP_READ = 1, /**< read() operation. */
PJ_IOQUEUE_OP_RECV = 2, /**< recv() operation. */
PJ_IOQUEUE_OP_RECV_FROM = 4, /**< recvfrom() operation. */
PJ_IOQUEUE_OP_WRITE = 8, /**< write() operation. */
PJ_IOQUEUE_OP_SEND = 16, /**< send() operation. */
PJ_IOQUEUE_OP_SEND_TO = 32, /**< sendto() operation. */
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
PJ_IOQUEUE_OP_ACCEPT = 64, /**< accept() operation. */
PJ_IOQUEUE_OP_CONNECT = 128, /**< connect() operation. */
#endif /* PJ_HAS_TCP */
} pj_ioqueue_operation_e;
/**
* Indicates that the I/O Queue should be created to handle reasonable
* number of threads.
*/
#define PJ_IOQUEUE_DEFAULT_THREADS 0
/**
* Create a new I/O Queue framework.
*
* @param pool The pool to allocate the I/O queue structure.
* @param max_fd The maximum number of handles to be supported, which
* should not exceed PJ_IOQUEUE_MAX_HANDLES.
* @param max_threads The maximum number of threads that are allowed to
* operate on a single descriptor simultaneously. If
* the value is zero, the framework will set it
* to a reasonable value.
* @param ioqueue Pointer to hold the newly created I/O Queue.
*
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pj_ioqueue_create( pj_pool_t *pool,
pj_size_t max_fd,
int max_threads,
pj_ioqueue_t **ioqueue);
/**
* Destroy the I/O queue.
*
* @param ioque The I/O Queue to be destroyed.
*
* @return PJ_SUCCESS if success.
*/
PJ_DECL(pj_status_t) pj_ioqueue_destroy( pj_ioqueue_t *ioque );
/**
* Set the lock object to be used by the I/O Queue. This function can only
* be called right after the I/O queue is created, before any handle is
* registered to the I/O queue.
*
* Initially the I/O queue is created with non-recursive mutex protection.
* Applications can supply alternative lock to be used by calling this
* function.
*
* @param ioque The ioqueue instance.
* @param lock The lock to be used by the ioqueue.
* @param auto_delete In non-zero, the lock will be deleted by the ioqueue.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_set_lock( pj_ioqueue_t *ioque,
pj_lock_t *lock,
pj_bool_t auto_delete );
/**
* Register a socket to the I/O queue framework.
* When a socket is registered to the IOQueue, it may be modified to use
* non-blocking IO. If it is modified, there is no guarantee that this
* modification will be restored after the socket is unregistered.
*
* @param pool To allocate the resource for the specified handle,
* which must be valid until the handle/key is unregistered
* from I/O Queue.
* @param ioque The I/O Queue.
* @param sock The socket.
* @param user_data User data to be associated with the key, which can be
* retrieved later.
* @param cb Callback to be called when I/O operation completes.
* @param key Pointer to receive the returned key.
*
* @return PJ_SUCCESS on success, or the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
pj_ioqueue_t *ioque,
pj_sock_t sock,
void *user_data,
const pj_ioqueue_callback *cb,
pj_ioqueue_key_t **key);
/**
* Unregister a handle from the I/O Queue framework.
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle, which is
* returned from the function #pj_ioqueue_register_sock()
* or other registration functions.
*
* @return PJ_SUCCESS on success or the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key );
/**
* Get user data associated with the I/O Queue key.
*
* @param key The key previously associated with the socket/handle with
* #pj_ioqueue_register_sock() (or other registration
* functions).
*
* @return The user data associated with the key, or NULL on error
* of if no data is associated with the key during
* registration.
*/
PJ_DECL(void*) pj_ioqueue_get_user_data( pj_ioqueue_key_t *key );
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
/**
* Instruct I/O Queue to wait for incoming connections on the specified
* listening socket. This function will return
* immediately (i.e. non-blocking) regardless whether some data has been
* transfered. If the function can't complete immediately, and the caller will
* be notified about the completion when it calls pj_ioqueue_poll().
*
* @param ioqueue The I/O Queue
* @param key The key which registered to the server socket.
* @param sock Argument which contain pointer to receive
* the socket for the incoming connection.
* @param local Optional argument which contain pointer to variable to
* receive local address.
* @param remote Optional argument which contain pointer to variable to
* receive the remote address.
* @param addrlen On input, contains the length of the buffer for the
* address, and on output, contains the actual length of the
* address. This argument is optional.
* @return
* - PJ_SUCCESS If there's a connection available immediately, which
* in this case the callback should have been called before
* the function returns.
* - PJ_EPENDING If accept is queued, or
* - non-zero which indicates the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_accept( pj_ioqueue_t *ioqueue,
pj_ioqueue_key_t *key,
pj_sock_t *sock,
pj_sockaddr_t *local,
pj_sockaddr_t *remote,
int *addrlen );
/**
* Initiate non-blocking socket connect. If the socket can NOT be connected
* immediately, the result will be reported during poll.
*
* @param ioqueue The ioqueue
* @param key The key associated with TCP socket
* @param addr The remote address.
* @param addrlen The remote address length.
*
* @return
* - PJ_SUCCESS If socket is connected immediately, which in this case
* the callback should have been called.
* - PJ_EPENDING If operation is queued, or
* - non-zero Indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_connect( pj_ioqueue_t *ioqueue,
pj_ioqueue_key_t *key,
const pj_sockaddr_t *addr,
int addrlen );
#endif /* PJ_HAS_TCP */
/**
* Poll the I/O Queue for completed events.
*
* @param ioque the I/O Queue.
* @param timeout polling timeout, or NULL if the thread wishes to wait
* indefinetely for the event.
*
* @return
* - zero if timed out (no event).
* - (<0) if error occured during polling. Callback will NOT be called.
* - (>1) to indicate numbers of events. Callbacks have been called.
*/
PJ_DECL(int) pj_ioqueue_poll( pj_ioqueue_t *ioque,
const pj_time_val *timeout);
/**
* Instruct the I/O Queue to read from the specified handle. This function
* returns immediately (i.e. non-blocking) regardless whether some data has
* been transfered. If the operation can't complete immediately, caller will
* be notified about the completion when it calls pj_ioqueue_poll().
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param buflen The maximum size to be read.
*
* @return
* - PJ_SUCCESS If immediate data has been received. In this case, the
* callback must have been called before this function
* returns, and no pending operation is scheduled.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_read( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
void *buffer,
pj_size_t buflen);
/**
* This function behaves similarly as #pj_ioqueue_read(), except that it is
* normally called for socket.
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param buflen The maximum size to be read.
* @param flags Recv flag.
*
* @return
* - PJ_SUCCESS If immediate data has been received. In this case, the
* callback must have been called before this function
* returns, and no pending operation is scheduled.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_recv( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
void *buffer,
pj_size_t buflen,
unsigned flags );
/**
* This function behaves similarly as #pj_ioqueue_read(), except that it is
* normally called for socket, and the remote address will also be returned
* along with the data. Caller MUST make sure that both buffer and addr
* remain valid until the framework completes reading the data.
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param buflen The maximum size to be read.
* @param flags Recv flag.
* @param addr Pointer to buffer to receive the address, or NULL.
* @param addrlen On input, specifies the length of the address buffer.
* On output, it will be filled with the actual length of
* the address.
*
* @return
* - PJ_SUCCESS If immediate data has been received. In this case, the
* callback must have been called before this function
* returns, and no pending operation is scheduled.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
void *buffer,
pj_size_t buflen,
unsigned flags,
pj_sockaddr_t *addr,
int *addrlen);
/**
* Instruct the I/O Queue to write to the handle. This function will return
* immediately (i.e. non-blocking) regardless whether some data has been
* transfered. If the function can't complete immediately, and the caller will
* be notified about the completion when it calls pj_ioqueue_poll().
*
* @param ioque the I/O Queue.
* @param key the key that identifies the handle.
* @param data the data to send. Caller MUST make sure that this buffer
* remains valid until the write operation completes.
* @param datalen the length of the data.
*
* @return
* - PJ_SUCCESS If data was immediately written.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_write( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
const void *data,
pj_size_t datalen);
/**
* This function behaves similarly as #pj_ioqueue_write(), except that
* pj_sock_send() (or equivalent) will be called to send the data.
*
* @param ioque the I/O Queue.
* @param key the key that identifies the handle.
* @param data the data to send. Caller MUST make sure that this buffer
* remains valid until the write operation completes.
* @param datalen the length of the data.
* @param flags send flags.
*
* @return
* - PJ_SUCCESS If data was immediately written.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_send( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
const void *data,
pj_size_t datalen,
unsigned flags );
/**
* This function behaves similarly as #pj_ioqueue_write(), except that
* pj_sock_sendto() (or equivalent) will be called to send the data.
*
* @param ioque the I/O Queue.
* @param key the key that identifies the handle.
* @param data the data to send. Caller MUST make sure that this buffer
* remains valid until the write operation completes.
* @param datalen the length of the data.
* @param flags send flags.
* @param addr remote address.
* @param addrlen remote address length.
*
* @return
* - PJ_SUCCESS If data was immediately written.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
const void *data,
pj_size_t datalen,
unsigned flags,
const pj_sockaddr_t *addr,
int addrlen);
/**
* !}
*/
PJ_END_DECL
#endif /* __PJ_IOQUEUE_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/ioqueue.h 10 10/29/05 11:29a Bennylp $ */
#ifndef __PJ_IOQUEUE_H__
#define __PJ_IOQUEUE_H__
/**
* @file ioqueue.h
* @brief I/O Dispatching Mechanism
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_IO Network I/O
* @brief Network I/O
* @ingroup PJ_OS
*
* This section contains API building blocks to perform network I/O and
* communications. If provides:
* - @ref PJ_SOCK
*\n
* A highly portable socket abstraction, runs on all kind of
* network APIs such as standard BSD socket, Windows socket, Linux
* \b kernel socket, PalmOS networking API, etc.
*
* - @ref pj_addr_resolve
*\n
* Portable address resolution, which implements #pj_gethostbyname().
*
* - @ref PJ_SOCK_SELECT
*\n
* A portable \a select() like API (#pj_sock_select()) which can be
* implemented with various back-ends.
*
* - @ref PJ_IOQUEUE
*\n
* Framework for dispatching network events.
*
* For more information see the modules below.
*/
/**
* @defgroup PJ_IOQUEUE I/O Event Dispatching Queue
* @ingroup PJ_IO
* @{
*
* This file provides abstraction for various event dispatching mechanisms.
* The interfaces for event dispatching vary alot, even in a single
* operating system. The abstraction here hopefully is suitable for most of
* the event dispatching available.
*
* Currently, the I/O Queue supports:
* - select(), as the common denominator, but the least efficient.
* - I/O Completion ports in Windows NT/2000/XP, which is the most efficient
* way to dispatch events in Windows NT based OSes, and most importantly,
* it doesn't have the limit on how many handles to monitor. And it works
* with files (not only sockets) as well.
*
* \section pj_ioqeuue_examples_sec Examples
*
* For some examples on how to use the I/O Queue, please see:
*
* - \ref page_pjlib_ioqueue_tcp_test
* - \ref page_pjlib_ioqueue_udp_test
* - \ref page_pjlib_ioqueue_perf_test
*/
/**
* This structure describes the callbacks to be called when I/O operation
* completes.
*/
typedef struct pj_ioqueue_callback
{
/**
* This callback is called when #pj_ioqueue_read or #pj_ioqueue_recvfrom
* completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been read.
*/
void (*on_read_complete)(pj_ioqueue_key_t *key, pj_ssize_t bytes_read);
/**
* This callback is called when #pj_ioqueue_write or #pj_ioqueue_sendto
* completes.
*
* @param key The key.
* @param bytes_read The size of data that has just been read.
*/
void (*on_write_complete)(pj_ioqueue_key_t *key, pj_ssize_t bytes_sent);
/**
* This callback is called when #pj_ioqueue_accept completes.
*
* @param key The key.
* @param sock Newly connected socket.
* @param status Zero if the operation completes successfully.
*/
void (*on_accept_complete)(pj_ioqueue_key_t *key, pj_sock_t sock,
int status);
/**
* This callback is called when #pj_ioqueue_connect completes.
*
* @param key The key.
* @param status Zero if the operation completes successfully.
*/
void (*on_connect_complete)(pj_ioqueue_key_t *key, int status);
} pj_ioqueue_callback;
/**
* Types of I/O Queue operation.
*/
typedef enum pj_ioqueue_operation_e
{
PJ_IOQUEUE_OP_NONE = 0, /**< No operation. */
PJ_IOQUEUE_OP_READ = 1, /**< read() operation. */
PJ_IOQUEUE_OP_RECV = 2, /**< recv() operation. */
PJ_IOQUEUE_OP_RECV_FROM = 4, /**< recvfrom() operation. */
PJ_IOQUEUE_OP_WRITE = 8, /**< write() operation. */
PJ_IOQUEUE_OP_SEND = 16, /**< send() operation. */
PJ_IOQUEUE_OP_SEND_TO = 32, /**< sendto() operation. */
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
PJ_IOQUEUE_OP_ACCEPT = 64, /**< accept() operation. */
PJ_IOQUEUE_OP_CONNECT = 128, /**< connect() operation. */
#endif /* PJ_HAS_TCP */
} pj_ioqueue_operation_e;
/**
* Indicates that the I/O Queue should be created to handle reasonable
* number of threads.
*/
#define PJ_IOQUEUE_DEFAULT_THREADS 0
/**
* Create a new I/O Queue framework.
*
* @param pool The pool to allocate the I/O queue structure.
* @param max_fd The maximum number of handles to be supported, which
* should not exceed PJ_IOQUEUE_MAX_HANDLES.
* @param max_threads The maximum number of threads that are allowed to
* operate on a single descriptor simultaneously. If
* the value is zero, the framework will set it
* to a reasonable value.
* @param ioqueue Pointer to hold the newly created I/O Queue.
*
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pj_ioqueue_create( pj_pool_t *pool,
pj_size_t max_fd,
int max_threads,
pj_ioqueue_t **ioqueue);
/**
* Destroy the I/O queue.
*
* @param ioque The I/O Queue to be destroyed.
*
* @return PJ_SUCCESS if success.
*/
PJ_DECL(pj_status_t) pj_ioqueue_destroy( pj_ioqueue_t *ioque );
/**
* Set the lock object to be used by the I/O Queue. This function can only
* be called right after the I/O queue is created, before any handle is
* registered to the I/O queue.
*
* Initially the I/O queue is created with non-recursive mutex protection.
* Applications can supply alternative lock to be used by calling this
* function.
*
* @param ioque The ioqueue instance.
* @param lock The lock to be used by the ioqueue.
* @param auto_delete In non-zero, the lock will be deleted by the ioqueue.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_set_lock( pj_ioqueue_t *ioque,
pj_lock_t *lock,
pj_bool_t auto_delete );
/**
* Register a socket to the I/O queue framework.
* When a socket is registered to the IOQueue, it may be modified to use
* non-blocking IO. If it is modified, there is no guarantee that this
* modification will be restored after the socket is unregistered.
*
* @param pool To allocate the resource for the specified handle,
* which must be valid until the handle/key is unregistered
* from I/O Queue.
* @param ioque The I/O Queue.
* @param sock The socket.
* @param user_data User data to be associated with the key, which can be
* retrieved later.
* @param cb Callback to be called when I/O operation completes.
* @param key Pointer to receive the returned key.
*
* @return PJ_SUCCESS on success, or the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
pj_ioqueue_t *ioque,
pj_sock_t sock,
void *user_data,
const pj_ioqueue_callback *cb,
pj_ioqueue_key_t **key);
/**
* Unregister a handle from the I/O Queue framework.
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle, which is
* returned from the function #pj_ioqueue_register_sock()
* or other registration functions.
*
* @return PJ_SUCCESS on success or the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key );
/**
* Get user data associated with the I/O Queue key.
*
* @param key The key previously associated with the socket/handle with
* #pj_ioqueue_register_sock() (or other registration
* functions).
*
* @return The user data associated with the key, or NULL on error
* of if no data is associated with the key during
* registration.
*/
PJ_DECL(void*) pj_ioqueue_get_user_data( pj_ioqueue_key_t *key );
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
/**
* Instruct I/O Queue to wait for incoming connections on the specified
* listening socket. This function will return
* immediately (i.e. non-blocking) regardless whether some data has been
* transfered. If the function can't complete immediately, and the caller will
* be notified about the completion when it calls pj_ioqueue_poll().
*
* @param ioqueue The I/O Queue
* @param key The key which registered to the server socket.
* @param sock Argument which contain pointer to receive
* the socket for the incoming connection.
* @param local Optional argument which contain pointer to variable to
* receive local address.
* @param remote Optional argument which contain pointer to variable to
* receive the remote address.
* @param addrlen On input, contains the length of the buffer for the
* address, and on output, contains the actual length of the
* address. This argument is optional.
* @return
* - PJ_SUCCESS If there's a connection available immediately, which
* in this case the callback should have been called before
* the function returns.
* - PJ_EPENDING If accept is queued, or
* - non-zero which indicates the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_accept( pj_ioqueue_t *ioqueue,
pj_ioqueue_key_t *key,
pj_sock_t *sock,
pj_sockaddr_t *local,
pj_sockaddr_t *remote,
int *addrlen );
/**
* Initiate non-blocking socket connect. If the socket can NOT be connected
* immediately, the result will be reported during poll.
*
* @param ioqueue The ioqueue
* @param key The key associated with TCP socket
* @param addr The remote address.
* @param addrlen The remote address length.
*
* @return
* - PJ_SUCCESS If socket is connected immediately, which in this case
* the callback should have been called.
* - PJ_EPENDING If operation is queued, or
* - non-zero Indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_connect( pj_ioqueue_t *ioqueue,
pj_ioqueue_key_t *key,
const pj_sockaddr_t *addr,
int addrlen );
#endif /* PJ_HAS_TCP */
/**
* Poll the I/O Queue for completed events.
*
* @param ioque the I/O Queue.
* @param timeout polling timeout, or NULL if the thread wishes to wait
* indefinetely for the event.
*
* @return
* - zero if timed out (no event).
* - (<0) if error occured during polling. Callback will NOT be called.
* - (>1) to indicate numbers of events. Callbacks have been called.
*/
PJ_DECL(int) pj_ioqueue_poll( pj_ioqueue_t *ioque,
const pj_time_val *timeout);
/**
* Instruct the I/O Queue to read from the specified handle. This function
* returns immediately (i.e. non-blocking) regardless whether some data has
* been transfered. If the operation can't complete immediately, caller will
* be notified about the completion when it calls pj_ioqueue_poll().
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param buflen The maximum size to be read.
*
* @return
* - PJ_SUCCESS If immediate data has been received. In this case, the
* callback must have been called before this function
* returns, and no pending operation is scheduled.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_read( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
void *buffer,
pj_size_t buflen);
/**
* This function behaves similarly as #pj_ioqueue_read(), except that it is
* normally called for socket.
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param buflen The maximum size to be read.
* @param flags Recv flag.
*
* @return
* - PJ_SUCCESS If immediate data has been received. In this case, the
* callback must have been called before this function
* returns, and no pending operation is scheduled.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_recv( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
void *buffer,
pj_size_t buflen,
unsigned flags );
/**
* This function behaves similarly as #pj_ioqueue_read(), except that it is
* normally called for socket, and the remote address will also be returned
* along with the data. Caller MUST make sure that both buffer and addr
* remain valid until the framework completes reading the data.
*
* @param ioque The I/O Queue.
* @param key The key that uniquely identifies the handle.
* @param buffer The buffer to hold the read data. The caller MUST make sure
* that this buffer remain valid until the framework completes
* reading the handle.
* @param buflen The maximum size to be read.
* @param flags Recv flag.
* @param addr Pointer to buffer to receive the address, or NULL.
* @param addrlen On input, specifies the length of the address buffer.
* On output, it will be filled with the actual length of
* the address.
*
* @return
* - PJ_SUCCESS If immediate data has been received. In this case, the
* callback must have been called before this function
* returns, and no pending operation is scheduled.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
void *buffer,
pj_size_t buflen,
unsigned flags,
pj_sockaddr_t *addr,
int *addrlen);
/**
* Instruct the I/O Queue to write to the handle. This function will return
* immediately (i.e. non-blocking) regardless whether some data has been
* transfered. If the function can't complete immediately, and the caller will
* be notified about the completion when it calls pj_ioqueue_poll().
*
* @param ioque the I/O Queue.
* @param key the key that identifies the handle.
* @param data the data to send. Caller MUST make sure that this buffer
* remains valid until the write operation completes.
* @param datalen the length of the data.
*
* @return
* - PJ_SUCCESS If data was immediately written.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_write( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
const void *data,
pj_size_t datalen);
/**
* This function behaves similarly as #pj_ioqueue_write(), except that
* pj_sock_send() (or equivalent) will be called to send the data.
*
* @param ioque the I/O Queue.
* @param key the key that identifies the handle.
* @param data the data to send. Caller MUST make sure that this buffer
* remains valid until the write operation completes.
* @param datalen the length of the data.
* @param flags send flags.
*
* @return
* - PJ_SUCCESS If data was immediately written.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_send( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
const void *data,
pj_size_t datalen,
unsigned flags );
/**
* This function behaves similarly as #pj_ioqueue_write(), except that
* pj_sock_sendto() (or equivalent) will be called to send the data.
*
* @param ioque the I/O Queue.
* @param key the key that identifies the handle.
* @param data the data to send. Caller MUST make sure that this buffer
* remains valid until the write operation completes.
* @param datalen the length of the data.
* @param flags send flags.
* @param addr remote address.
* @param addrlen remote address length.
*
* @return
* - PJ_SUCCESS If data was immediately written.
* - PJ_EPENDING If the operation has been queued.
* - non-zero The return value indicates the error code.
*/
PJ_DECL(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_t *ioque,
pj_ioqueue_key_t *key,
const void *data,
pj_size_t datalen,
unsigned flags,
const pj_sockaddr_t *addr,
int addrlen);
/**
* !}
*/
PJ_END_DECL
#endif /* __PJ_IOQUEUE_H__ */

View File

@ -1,217 +1,217 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/list.h 8 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_LIST_H__
#define __PJ_LIST_H__
/**
* @file list.h
* @brief Linked List data structure.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/*
* @defgroup PJ_DS Data Structure.
* @ingroup PJ
*/
/**
* @defgroup PJ_LIST Linked List
* @ingroup PJ_DS
* @{
*
* List in PJLIB is implemented as doubly-linked list, and it won't require
* dynamic memory allocation (just as all PJLIB data structures). The list here
* should be viewed more like a low level C list instead of high level C++ list
* (which normally are easier to use but require dynamic memory allocations),
* therefore all caveats with C list apply here too (such as you can NOT put
* a node in more than one lists).
*
* \section pj_list_example_sec Examples
*
* See below for examples on how to manipulate linked list:
* - @ref page_pjlib_samples_list_c
* - @ref page_pjlib_list_test
*/
/**
* Use this macro in the start of the structure declaration to declare that
* the structure can be used in the linked list operation. This macro simply
* declares additional member @a prev and @a next to the structure.
* @hideinitializer
*/
#define PJ_DECL_LIST_MEMBER(type) type *prev; /** List @a prev. */ \
type *next; /** List @a next. */
/**
* This structure describes generic list node and list. The owner of this list
* must initialize the 'value' member to an appropriate value (typically the
* owner itself).
*/
struct pj_list
{
PJ_DECL_LIST_MEMBER(void)
};
/**
* Initialize the list.
* Initially, the list will have no member, and function pj_list_empty() will
* always return nonzero (which indicates TRUE) for the newly initialized
* list.
*
* @param node The list head.
*/
PJ_INLINE(void) pj_list_init(pj_list_type * node)
{
((pj_list*)node)->next = ((pj_list*)node)->prev = node;
}
/**
* Check that the list is empty.
*
* @param node The list head.
*
* @return Non-zero if the list is not-empty, or zero if it is empty.
*
*/
PJ_INLINE(int) pj_list_empty(const pj_list_type * node)
{
return ((pj_list*)node)->next == node;
}
/**
* Insert the node to the list before the specified element position.
*
* @param pos The element to which the node will be inserted before.
* @param node The element to be inserted.
*
* @return void.
*/
PJ_IDECL(void) pj_list_insert_before(pj_list_type *pos, pj_list_type *node);
/**
* Inserts all nodes in \a nodes to the target list.
*
* @param lst The target list.
* @param nodes Nodes list.
*/
PJ_IDECL(void) pj_list_insert_nodes_before(pj_list_type *lst,
pj_list_type *nodes);
/**
* Insert a node to the list after the specified element position.
*
* @param pos The element in the list which will precede the inserted
* element.
* @param node The element to be inserted after the position element.
*
* @return void.
*/
PJ_IDECL(void) pj_list_insert_after(pj_list_type *pos, pj_list_type *node);
/**
* Insert all nodes in \a nodes to the target list.
*
* @param lst The target list.
* @param nodes Nodes list.
*/
PJ_IDECL(void) pj_list_insert_nodes_after(pj_list_type *lst,
pj_list_type *nodes);
/**
* Remove elements from the source list, and insert them to the destination
* list. The elements of the source list will occupy the
* front elements of the target list. Note that the node pointed by \a list2
* itself is not considered as a node, but rather as the list descriptor, so
* it will not be inserted to the \a list1. The elements to be inserted starts
* at \a list2->next. If \a list2 is to be included in the operation, use
* \a pj_list_insert_nodes_before.
*
* @param list1 The destination list.
* @param list2 The source list.
*
* @return void.
*/
PJ_IDECL(void) pj_list_merge_first(pj_list_type *list1, pj_list_type *list2);
/**
* Remove elements from the second list argument, and insert them to the list
* in the first argument. The elements from the second list will be appended
* to the first list. Note that the node pointed by \a list2
* itself is not considered as a node, but rather as the list descriptor, so
* it will not be inserted to the \a list1. The elements to be inserted starts
* at \a list2->next. If \a list2 is to be included in the operation, use
* \a pj_list_insert_nodes_before.
*
* @param list1 The element in the list which will precede the inserted
* element.
* @param list2 The element in the list to be inserted.
*
* @return void.
*/
PJ_IDECL(void) pj_list_merge_last( pj_list_type *list1, pj_list_type *list2);
/**
* Erase the node from the list it currently belongs.
*
* @param node The element to be erased.
*/
PJ_IDECL(void) pj_list_erase(pj_list_type *node);
/**
* Find node in the list.
*
* @param list The list head.
* @param node The node element to be searched.
*
* @return The node itself if it is found in the list, or NULL if it is not
* found in the list.
*/
PJ_IDECL(pj_list_type*) pj_list_find_node(pj_list_type *list,
pj_list_type *node);
/**
* Search the list for the specified value, using the specified comparison
* function. This function iterates on nodes in the list, started with the
* first node, and call the user supplied comparison function until the
* comparison function returns ZERO.
*
* @param list The list head.
* @param value The user defined value to be passed in the comparison
* function
* @param comp The comparison function, which should return ZERO to
* indicate that the searched value is found.
*
* @return The first node that matched, or NULL if it is not found.
*/
PJ_IDECL(pj_list_type*) pj_list_search(pj_list_type *list, void *value,
int (*comp)(void *value,
const pj_list_type *node)
);
/**
* @}
*/
#if PJ_FUNCTIONS_ARE_INLINED
# include "list_i.h"
#endif
PJ_END_DECL
#endif /* __PJ_LIST_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/list.h 8 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_LIST_H__
#define __PJ_LIST_H__
/**
* @file list.h
* @brief Linked List data structure.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/*
* @defgroup PJ_DS Data Structure.
* @ingroup PJ
*/
/**
* @defgroup PJ_LIST Linked List
* @ingroup PJ_DS
* @{
*
* List in PJLIB is implemented as doubly-linked list, and it won't require
* dynamic memory allocation (just as all PJLIB data structures). The list here
* should be viewed more like a low level C list instead of high level C++ list
* (which normally are easier to use but require dynamic memory allocations),
* therefore all caveats with C list apply here too (such as you can NOT put
* a node in more than one lists).
*
* \section pj_list_example_sec Examples
*
* See below for examples on how to manipulate linked list:
* - @ref page_pjlib_samples_list_c
* - @ref page_pjlib_list_test
*/
/**
* Use this macro in the start of the structure declaration to declare that
* the structure can be used in the linked list operation. This macro simply
* declares additional member @a prev and @a next to the structure.
* @hideinitializer
*/
#define PJ_DECL_LIST_MEMBER(type) type *prev; /** List @a prev. */ \
type *next; /** List @a next. */
/**
* This structure describes generic list node and list. The owner of this list
* must initialize the 'value' member to an appropriate value (typically the
* owner itself).
*/
struct pj_list
{
PJ_DECL_LIST_MEMBER(void)
};
/**
* Initialize the list.
* Initially, the list will have no member, and function pj_list_empty() will
* always return nonzero (which indicates TRUE) for the newly initialized
* list.
*
* @param node The list head.
*/
PJ_INLINE(void) pj_list_init(pj_list_type * node)
{
((pj_list*)node)->next = ((pj_list*)node)->prev = node;
}
/**
* Check that the list is empty.
*
* @param node The list head.
*
* @return Non-zero if the list is not-empty, or zero if it is empty.
*
*/
PJ_INLINE(int) pj_list_empty(const pj_list_type * node)
{
return ((pj_list*)node)->next == node;
}
/**
* Insert the node to the list before the specified element position.
*
* @param pos The element to which the node will be inserted before.
* @param node The element to be inserted.
*
* @return void.
*/
PJ_IDECL(void) pj_list_insert_before(pj_list_type *pos, pj_list_type *node);
/**
* Inserts all nodes in \a nodes to the target list.
*
* @param lst The target list.
* @param nodes Nodes list.
*/
PJ_IDECL(void) pj_list_insert_nodes_before(pj_list_type *lst,
pj_list_type *nodes);
/**
* Insert a node to the list after the specified element position.
*
* @param pos The element in the list which will precede the inserted
* element.
* @param node The element to be inserted after the position element.
*
* @return void.
*/
PJ_IDECL(void) pj_list_insert_after(pj_list_type *pos, pj_list_type *node);
/**
* Insert all nodes in \a nodes to the target list.
*
* @param lst The target list.
* @param nodes Nodes list.
*/
PJ_IDECL(void) pj_list_insert_nodes_after(pj_list_type *lst,
pj_list_type *nodes);
/**
* Remove elements from the source list, and insert them to the destination
* list. The elements of the source list will occupy the
* front elements of the target list. Note that the node pointed by \a list2
* itself is not considered as a node, but rather as the list descriptor, so
* it will not be inserted to the \a list1. The elements to be inserted starts
* at \a list2->next. If \a list2 is to be included in the operation, use
* \a pj_list_insert_nodes_before.
*
* @param list1 The destination list.
* @param list2 The source list.
*
* @return void.
*/
PJ_IDECL(void) pj_list_merge_first(pj_list_type *list1, pj_list_type *list2);
/**
* Remove elements from the second list argument, and insert them to the list
* in the first argument. The elements from the second list will be appended
* to the first list. Note that the node pointed by \a list2
* itself is not considered as a node, but rather as the list descriptor, so
* it will not be inserted to the \a list1. The elements to be inserted starts
* at \a list2->next. If \a list2 is to be included in the operation, use
* \a pj_list_insert_nodes_before.
*
* @param list1 The element in the list which will precede the inserted
* element.
* @param list2 The element in the list to be inserted.
*
* @return void.
*/
PJ_IDECL(void) pj_list_merge_last( pj_list_type *list1, pj_list_type *list2);
/**
* Erase the node from the list it currently belongs.
*
* @param node The element to be erased.
*/
PJ_IDECL(void) pj_list_erase(pj_list_type *node);
/**
* Find node in the list.
*
* @param list The list head.
* @param node The node element to be searched.
*
* @return The node itself if it is found in the list, or NULL if it is not
* found in the list.
*/
PJ_IDECL(pj_list_type*) pj_list_find_node(pj_list_type *list,
pj_list_type *node);
/**
* Search the list for the specified value, using the specified comparison
* function. This function iterates on nodes in the list, started with the
* first node, and call the user supplied comparison function until the
* comparison function returns ZERO.
*
* @param list The list head.
* @param value The user defined value to be passed in the comparison
* function
* @param comp The comparison function, which should return ZERO to
* indicate that the searched value is found.
*
* @return The first node that matched, or NULL if it is not found.
*/
PJ_IDECL(pj_list_type*) pj_list_search(pj_list_type *list, void *value,
int (*comp)(void *value,
const pj_list_type *node)
);
/**
* @}
*/
#if PJ_FUNCTIONS_ARE_INLINED
# include "list_i.h"
#endif
PJ_END_DECL
#endif /* __PJ_LIST_H__ */

View File

@ -1,101 +1,101 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/list_i.h 4 10/14/05 12:26a Bennylp $ */
/* Internal */
PJ_IDEF(void) pj_link_node(pj_list_type *prev, pj_list_type *next)
{
((pj_list*)prev)->next = next;
((pj_list*)next)->prev = prev;
}
/*
PJ_IDEF(void)
pj_list_init(pj_list_type * node)
{
((pj_list*)node)->next = ((pj_list*)node)->prev = node;
}
PJ_IDEF(int) pj_list_empty(const pj_list_type * node)
{
return ((pj_list*)node)->next == node;
}
*/
PJ_IDEF(void)
pj_list_insert_after(pj_list_type *pos, pj_list_type *node)
{
((pj_list*)node)->prev = pos;
((pj_list*)node)->next = ((pj_list*)pos)->next;
((pj_list*) ((pj_list*)pos)->next) ->prev = node;
((pj_list*)pos)->next = node;
}
PJ_IDEF(void)
pj_list_insert_before(pj_list_type *pos, pj_list_type *node)
{
pj_list_insert_after(((pj_list*)pos)->prev, node);
}
PJ_IDEF(void)
pj_list_insert_nodes_after(pj_list_type *pos, pj_list_type *lst)
{
pj_list *lst_last = (pj_list *) ((pj_list*)lst)->prev;
pj_list *pos_next = (pj_list *) ((pj_list*)pos)->next;
pj_link_node(pos, lst);
pj_link_node(lst_last, pos_next);
}
PJ_IDEF(void)
pj_list_insert_nodes_before(pj_list_type *pos, pj_list_type *lst)
{
pj_list_insert_nodes_after(((pj_list*)pos)->prev, lst);
}
PJ_IDEF(void)
pj_list_merge_last(pj_list_type *lst1, pj_list_type *lst2)
{
pj_link_node(((pj_list*)lst1)->prev, ((pj_list*)lst2)->next);
pj_link_node(((pj_list*)lst2)->prev, lst1);
pj_list_init(lst2);
}
PJ_IDEF(void)
pj_list_merge_first(pj_list_type *lst1, pj_list_type *lst2)
{
pj_link_node(((pj_list*)lst2)->prev, ((pj_list*)lst1)->next);
pj_link_node(((pj_list*)lst1), ((pj_list*)lst2)->next);
pj_list_init(lst2);
}
PJ_IDEF(void)
pj_list_erase(pj_list_type *node)
{
pj_link_node( ((pj_list*)node)->prev, ((pj_list*)node)->next);
}
PJ_IDEF(pj_list_type*)
pj_list_find_node(pj_list_type *list, pj_list_type *node)
{
pj_list *p = (pj_list *) ((pj_list*)list)->next;
while (p != list && p != node)
p = (pj_list *) p->next;
return p==node ? p : NULL;
}
PJ_IDEF(pj_list_type*)
pj_list_search(pj_list_type *list, void *value,
int (*comp)(void *value, const pj_list_type *node))
{
pj_list *p = (pj_list *) ((pj_list*)list)->next;
while (p != list && (*comp)(value, p) != 0)
p = (pj_list *) p->next;
return p==list ? NULL : p;
}
/* $Header: /pjproject-0.3/pjlib/include/pj/list_i.h 4 10/14/05 12:26a Bennylp $ */
/* Internal */
PJ_IDEF(void) pj_link_node(pj_list_type *prev, pj_list_type *next)
{
((pj_list*)prev)->next = next;
((pj_list*)next)->prev = prev;
}
/*
PJ_IDEF(void)
pj_list_init(pj_list_type * node)
{
((pj_list*)node)->next = ((pj_list*)node)->prev = node;
}
PJ_IDEF(int) pj_list_empty(const pj_list_type * node)
{
return ((pj_list*)node)->next == node;
}
*/
PJ_IDEF(void)
pj_list_insert_after(pj_list_type *pos, pj_list_type *node)
{
((pj_list*)node)->prev = pos;
((pj_list*)node)->next = ((pj_list*)pos)->next;
((pj_list*) ((pj_list*)pos)->next) ->prev = node;
((pj_list*)pos)->next = node;
}
PJ_IDEF(void)
pj_list_insert_before(pj_list_type *pos, pj_list_type *node)
{
pj_list_insert_after(((pj_list*)pos)->prev, node);
}
PJ_IDEF(void)
pj_list_insert_nodes_after(pj_list_type *pos, pj_list_type *lst)
{
pj_list *lst_last = (pj_list *) ((pj_list*)lst)->prev;
pj_list *pos_next = (pj_list *) ((pj_list*)pos)->next;
pj_link_node(pos, lst);
pj_link_node(lst_last, pos_next);
}
PJ_IDEF(void)
pj_list_insert_nodes_before(pj_list_type *pos, pj_list_type *lst)
{
pj_list_insert_nodes_after(((pj_list*)pos)->prev, lst);
}
PJ_IDEF(void)
pj_list_merge_last(pj_list_type *lst1, pj_list_type *lst2)
{
pj_link_node(((pj_list*)lst1)->prev, ((pj_list*)lst2)->next);
pj_link_node(((pj_list*)lst2)->prev, lst1);
pj_list_init(lst2);
}
PJ_IDEF(void)
pj_list_merge_first(pj_list_type *lst1, pj_list_type *lst2)
{
pj_link_node(((pj_list*)lst2)->prev, ((pj_list*)lst1)->next);
pj_link_node(((pj_list*)lst1), ((pj_list*)lst2)->next);
pj_list_init(lst2);
}
PJ_IDEF(void)
pj_list_erase(pj_list_type *node)
{
pj_link_node( ((pj_list*)node)->prev, ((pj_list*)node)->next);
}
PJ_IDEF(pj_list_type*)
pj_list_find_node(pj_list_type *list, pj_list_type *node)
{
pj_list *p = (pj_list *) ((pj_list*)list)->next;
while (p != list && p != node)
p = (pj_list *) p->next;
return p==node ? p : NULL;
}
PJ_IDEF(pj_list_type*)
pj_list_search(pj_list_type *list, void *value,
int (*comp)(void *value, const pj_list_type *node))
{
pj_list *p = (pj_list *) ((pj_list*)list)->next;
while (p != list && (*comp)(value, p) != 0)
p = (pj_list *) p->next;
return p==list ? NULL : p;
}

View File

@ -1,136 +1,136 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/lock.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_LOCK_H__
#define __PJ_LOCK_H__
/**
* @file lock.h
* @brief Higher abstraction for locking objects.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_LOCK Lock Objects
* @ingroup PJ_OS
* @{
*
* <b>Lock Objects</b> are higher abstraction for different lock mechanisms.
* It offers the same API for manipulating different lock types (e.g.
* @ref PJ_MUTEX "mutex", @ref PJ_SEM "semaphores", or null locks).
* Because Lock Objects have the same API for different types of lock
* implementation, it can be passed around in function arguments. As the
* result, it can be used to control locking policy for a particular
* feature.
*/
/**
* Create simple, non recursive mutex lock object.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_simple_mutex( pj_pool_t *pool,
const char *name,
pj_lock_t **lock );
/**
* Create recursive mutex lock object.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_recursive_mutex( pj_pool_t *pool,
const char *name,
pj_lock_t **lock );
/**
* Create NULL mutex. A NULL mutex doesn't actually have any synchronization
* object attached to it.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_null_mutex( pj_pool_t *pool,
const char *name,
pj_lock_t **lock );
#if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
/**
* Create semaphore lock object.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param initial Initial value of the semaphore.
* @param max Maximum value of the semaphore.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_semaphore( pj_pool_t *pool,
const char *name,
unsigned initial,
unsigned max,
pj_lock_t **lock );
#endif /* PJ_HAS_SEMAPHORE */
/**
* Acquire lock on the specified lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_acquire( pj_lock_t *lock );
/**
* Try to acquire lock on the specified lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_tryacquire( pj_lock_t *lock );
/**
* Release lock on the specified lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_release( pj_lock_t *lock );
/**
* Destroy the lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_destroy( pj_lock_t *lock );
/** @} */
PJ_END_DECL
#endif /* __PJ_LOCK_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/lock.h 2 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_LOCK_H__
#define __PJ_LOCK_H__
/**
* @file lock.h
* @brief Higher abstraction for locking objects.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_LOCK Lock Objects
* @ingroup PJ_OS
* @{
*
* <b>Lock Objects</b> are higher abstraction for different lock mechanisms.
* It offers the same API for manipulating different lock types (e.g.
* @ref PJ_MUTEX "mutex", @ref PJ_SEM "semaphores", or null locks).
* Because Lock Objects have the same API for different types of lock
* implementation, it can be passed around in function arguments. As the
* result, it can be used to control locking policy for a particular
* feature.
*/
/**
* Create simple, non recursive mutex lock object.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_simple_mutex( pj_pool_t *pool,
const char *name,
pj_lock_t **lock );
/**
* Create recursive mutex lock object.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_recursive_mutex( pj_pool_t *pool,
const char *name,
pj_lock_t **lock );
/**
* Create NULL mutex. A NULL mutex doesn't actually have any synchronization
* object attached to it.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_null_mutex( pj_pool_t *pool,
const char *name,
pj_lock_t **lock );
#if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
/**
* Create semaphore lock object.
*
* @param pool Memory pool.
* @param name Lock object's name.
* @param initial Initial value of the semaphore.
* @param max Maximum value of the semaphore.
* @param lock Pointer to store the returned handle.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_create_semaphore( pj_pool_t *pool,
const char *name,
unsigned initial,
unsigned max,
pj_lock_t **lock );
#endif /* PJ_HAS_SEMAPHORE */
/**
* Acquire lock on the specified lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_acquire( pj_lock_t *lock );
/**
* Try to acquire lock on the specified lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_tryacquire( pj_lock_t *lock );
/**
* Release lock on the specified lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_release( pj_lock_t *lock );
/**
* Destroy the lock object.
*
* @param lock The lock object.
*
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_lock_destroy( pj_lock_t *lock );
/** @} */
PJ_END_DECL
#endif /* __PJ_LOCK_H__ */

View File

@ -1,304 +1,304 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/log.h 7 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_LOG_H__
#define __PJ_LOG_H__
/**
* @file log.h
* @brief Logging Utility.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_MISC Miscelaneous
* @ingroup PJ
*/
/**
* @defgroup PJ_LOG Logging Facility
* @ingroup PJ_MISC
* @{
*
* The PJLIB logging facility is a configurable, flexible, and convenient
* way to write logging or trace information.
*
* To write to the log, one uses construct like below:
*
* <pre>
* ...
* PJ_LOG(3, ("main.c", "Starting hello..."));
* ...
* PJ_LOG(3, ("main.c", "Hello world from process %d", pj_getpid()));
* ...
* </pre>
*
* In the above example, the number @b 3 controls the verbosity level of
* the information (which means "information", by convention). The string
* "main.c" specifies the source or sender of the message.
*
*
* \section pj_log_quick_sample_sec Examples
*
* For examples, see:
* - @ref page_pjlib_samples_log_c.
*
*/
/**
* Log decoration flag, to be specified with #pj_log_set_decor().
*/
enum pj_log_decoration
{
PJ_LOG_HAS_DAY_NAME = 1, /**< Include day name [default: no]. */
PJ_LOG_HAS_YEAR = 2, /**< Include year digit [default: no] */
PJ_LOG_HAS_MONTH = 4, /**< Include month [default: no] */
PJ_LOG_HAS_DAY_OF_MON = 8, /**< Include day of month [default: no] */
PJ_LOG_HAS_TIME = 16, /**< Include time [default: yes]. */
PJ_LOG_HAS_MICRO_SEC = 32, /**< Include microseconds [yes] */
PJ_LOG_HAS_SENDER = 64, /**< Include sender in the log [yes]. */
PJ_LOG_HAS_NEWLINE = 128, /**< Terminate each call with newline [yes].*/
};
/**
* Write log message.
* This is the main macro used to write text to the logging backend.
*
* @param level The logging verbosity level. Lower number indicates higher
* importance, with level zero indicates fatal error. Only
* numeral argument is permitted (e.g. not variable).
* @param arg Enclosed 'printf' like arguments, with the first
* argument is the sender, the second argument is format
* string and the following arguments are variable number of
* arguments suitable for the format string.
*
* Sample:
* \verbatim
PJ_LOG(2, (__FILE__, "current value is %d", value));
\endverbatim
* @hideinitializer
*/
#define PJ_LOG(level,arg) pj_log_wrapper_##level(arg)
/**
* Signature for function to be registered to the logging subsystem to
* write the actual log message to some output device.
*
* @param level Log level.
* @param data Log message.
* @param len Message length.
*/
typedef void pj_log_func(int level, const char *data, int len);
/**
* Default logging writer function used by front end logger function.
* Application normally should NOT need to call this function, but
* rather use the PJ_LOG macro.
*
* @param level Log level.
* @param buffer Log message.
* @param len Message length.
*/
PJ_DECL(void) pj_log_write(int level, const char *buffer, int len);
#if PJ_LOG_MAX_LEVEL >= 1
/**
* Change log output function. The front-end logging functions will call
* this function to write the actual message to the desired device.
* By default, the front-end functions use pj_log_write() to write
* the messages, unless it's changed by calling this function.
*
* @param func The function that will be called to write the log
* messages to the desired device.
*/
PJ_DECL(void) pj_log_set_log_func( pj_log_func *func );
/**
* Get the current log output function that is used to write log messages.
*
* @return Current log output function.
*/
PJ_DECL(pj_log_func*) pj_log_get_log_func(void);
/**
* Set maximum log level. Application can call this function to set
* the desired level of verbosity of the logging messages. The bigger the
* value, the more verbose the logging messages will be printed. However,
* the maximum level of verbosity can not exceed compile time value of
* PJ_LOG_MAX_LEVEL.
*
* @param level The maximum level of verbosity of the logging
* messages (6=very detailed..1=error only, 0=disabled)
*/
PJ_DECL(void) pj_log_set_level(int level);
/**
* Get current maximum log verbositylevel.
*
* @return Current log maximum level.
*/
PJ_DECL(int) pj_log_get_level(void);
/**
* Set log decoration. The log decoration flag controls what are printed
* to output device alongside the actual message. For example, application
* can specify that date/time information should be displayed with each
* log message.
*
* @param decor Bitmask combination of #pj_log_decoration to control
* the layout of the log message.
*/
PJ_DECL(void) pj_log_set_decor(unsigned decor);
/**
* Get current log decoration flag.
*
* @return Log decoration flag.
*/
PJ_DECL(unsigned) pj_log_get_decor(void);
#else /* #if PJ_LOG_MAX_LEVEL >= 1 */
/**
* Change log output function. The front-end logging functions will call
* this function to write the actual message to the desired device.
* By default, the front-end functions use pj_log_write() to write
* the messages, unless it's changed by calling this function.
*
* @param func The function that will be called to write the log
* messages to the desired device.
*/
# define pj_log_set_log_func(func)
/**
* Set maximum log level. Application can call this function to set
* the desired level of verbosity of the logging messages. The bigger the
* value, the more verbose the logging messages will be printed. However,
* the maximum level of verbosity can not exceed compile time value of
* PJ_LOG_MAX_LEVEL.
*
* @param level The maximum level of verbosity of the logging
* messages (6=very detailed..1=error only, 0=disabled)
*/
# define pj_log_set_level(level)
/**
* Set log decoration. The log decoration flag controls what are printed
* to output device alongside the actual message. For example, application
* can specify that date/time information should be displayed with each
* log message.
*
* @param decor Bitmask combination of #pj_log_decoration to control
* the layout of the log message.
*/
# define pj_log_set_decor(decor)
#endif /* #if PJ_LOG_MAX_LEVEL >= 1 */
/**
* @}
*/
///////////////////////////////////////////////////////////////////////////////
/*
* Log functions implementation prototypes.
* These functions are called by PJ_LOG macros according to verbosity
* level specified when calling the macro. Applications should not normally
* need to call these functions directly.
*/
/**
* @def pj_log_wrapper_1(arg)
* Internal function to write log with verbosity 1. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 1.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 1
#define pj_log_wrapper_1(arg) pj_log_1 arg
/** Internal function. */
PJ_DECL(void) pj_log_1(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_1(arg)
#endif
/**
* @def pj_log_wrapper_2(arg)
* Internal function to write log with verbosity 2. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 2.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 2
#define pj_log_wrapper_2(arg) pj_log_2 arg
/** Internal function. */
PJ_DECL(void) pj_log_2(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_2(arg)
#endif
/**
* @def pj_log_wrapper_3(arg)
* Internal function to write log with verbosity 3. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 3.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 3
#define pj_log_wrapper_3(arg) pj_log_3 arg
/** Internal function. */
PJ_DECL(void) pj_log_3(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_3(arg)
#endif
/**
* @def pj_log_wrapper_4(arg)
* Internal function to write log with verbosity 4. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 4.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 4
#define pj_log_wrapper_4(arg) pj_log_4 arg
/** Internal function. */
PJ_DECL(void) pj_log_4(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_4(arg)
#endif
/**
* @def pj_log_wrapper_5(arg)
* Internal function to write log with verbosity 5. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 5.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 5
#define pj_log_wrapper_5(arg) pj_log_5 arg
/** Internal function. */
PJ_DECL(void) pj_log_5(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_5(arg)
#endif
/**
* @def pj_log_wrapper_6(arg)
* Internal function to write log with verbosity 6. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 6.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 6
#define pj_log_wrapper_6(arg) pj_log_6 arg
/** Internal function. */
PJ_DECL(void) pj_log_6(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_6(arg)
#endif
PJ_END_DECL
#endif /* __PJ_LOG_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/log.h 7 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_LOG_H__
#define __PJ_LOG_H__
/**
* @file log.h
* @brief Logging Utility.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_MISC Miscelaneous
* @ingroup PJ
*/
/**
* @defgroup PJ_LOG Logging Facility
* @ingroup PJ_MISC
* @{
*
* The PJLIB logging facility is a configurable, flexible, and convenient
* way to write logging or trace information.
*
* To write to the log, one uses construct like below:
*
* <pre>
* ...
* PJ_LOG(3, ("main.c", "Starting hello..."));
* ...
* PJ_LOG(3, ("main.c", "Hello world from process %d", pj_getpid()));
* ...
* </pre>
*
* In the above example, the number @b 3 controls the verbosity level of
* the information (which means "information", by convention). The string
* "main.c" specifies the source or sender of the message.
*
*
* \section pj_log_quick_sample_sec Examples
*
* For examples, see:
* - @ref page_pjlib_samples_log_c.
*
*/
/**
* Log decoration flag, to be specified with #pj_log_set_decor().
*/
enum pj_log_decoration
{
PJ_LOG_HAS_DAY_NAME = 1, /**< Include day name [default: no]. */
PJ_LOG_HAS_YEAR = 2, /**< Include year digit [default: no] */
PJ_LOG_HAS_MONTH = 4, /**< Include month [default: no] */
PJ_LOG_HAS_DAY_OF_MON = 8, /**< Include day of month [default: no] */
PJ_LOG_HAS_TIME = 16, /**< Include time [default: yes]. */
PJ_LOG_HAS_MICRO_SEC = 32, /**< Include microseconds [yes] */
PJ_LOG_HAS_SENDER = 64, /**< Include sender in the log [yes]. */
PJ_LOG_HAS_NEWLINE = 128, /**< Terminate each call with newline [yes].*/
};
/**
* Write log message.
* This is the main macro used to write text to the logging backend.
*
* @param level The logging verbosity level. Lower number indicates higher
* importance, with level zero indicates fatal error. Only
* numeral argument is permitted (e.g. not variable).
* @param arg Enclosed 'printf' like arguments, with the first
* argument is the sender, the second argument is format
* string and the following arguments are variable number of
* arguments suitable for the format string.
*
* Sample:
* \verbatim
PJ_LOG(2, (__FILE__, "current value is %d", value));
\endverbatim
* @hideinitializer
*/
#define PJ_LOG(level,arg) pj_log_wrapper_##level(arg)
/**
* Signature for function to be registered to the logging subsystem to
* write the actual log message to some output device.
*
* @param level Log level.
* @param data Log message.
* @param len Message length.
*/
typedef void pj_log_func(int level, const char *data, int len);
/**
* Default logging writer function used by front end logger function.
* Application normally should NOT need to call this function, but
* rather use the PJ_LOG macro.
*
* @param level Log level.
* @param buffer Log message.
* @param len Message length.
*/
PJ_DECL(void) pj_log_write(int level, const char *buffer, int len);
#if PJ_LOG_MAX_LEVEL >= 1
/**
* Change log output function. The front-end logging functions will call
* this function to write the actual message to the desired device.
* By default, the front-end functions use pj_log_write() to write
* the messages, unless it's changed by calling this function.
*
* @param func The function that will be called to write the log
* messages to the desired device.
*/
PJ_DECL(void) pj_log_set_log_func( pj_log_func *func );
/**
* Get the current log output function that is used to write log messages.
*
* @return Current log output function.
*/
PJ_DECL(pj_log_func*) pj_log_get_log_func(void);
/**
* Set maximum log level. Application can call this function to set
* the desired level of verbosity of the logging messages. The bigger the
* value, the more verbose the logging messages will be printed. However,
* the maximum level of verbosity can not exceed compile time value of
* PJ_LOG_MAX_LEVEL.
*
* @param level The maximum level of verbosity of the logging
* messages (6=very detailed..1=error only, 0=disabled)
*/
PJ_DECL(void) pj_log_set_level(int level);
/**
* Get current maximum log verbositylevel.
*
* @return Current log maximum level.
*/
PJ_DECL(int) pj_log_get_level(void);
/**
* Set log decoration. The log decoration flag controls what are printed
* to output device alongside the actual message. For example, application
* can specify that date/time information should be displayed with each
* log message.
*
* @param decor Bitmask combination of #pj_log_decoration to control
* the layout of the log message.
*/
PJ_DECL(void) pj_log_set_decor(unsigned decor);
/**
* Get current log decoration flag.
*
* @return Log decoration flag.
*/
PJ_DECL(unsigned) pj_log_get_decor(void);
#else /* #if PJ_LOG_MAX_LEVEL >= 1 */
/**
* Change log output function. The front-end logging functions will call
* this function to write the actual message to the desired device.
* By default, the front-end functions use pj_log_write() to write
* the messages, unless it's changed by calling this function.
*
* @param func The function that will be called to write the log
* messages to the desired device.
*/
# define pj_log_set_log_func(func)
/**
* Set maximum log level. Application can call this function to set
* the desired level of verbosity of the logging messages. The bigger the
* value, the more verbose the logging messages will be printed. However,
* the maximum level of verbosity can not exceed compile time value of
* PJ_LOG_MAX_LEVEL.
*
* @param level The maximum level of verbosity of the logging
* messages (6=very detailed..1=error only, 0=disabled)
*/
# define pj_log_set_level(level)
/**
* Set log decoration. The log decoration flag controls what are printed
* to output device alongside the actual message. For example, application
* can specify that date/time information should be displayed with each
* log message.
*
* @param decor Bitmask combination of #pj_log_decoration to control
* the layout of the log message.
*/
# define pj_log_set_decor(decor)
#endif /* #if PJ_LOG_MAX_LEVEL >= 1 */
/**
* @}
*/
///////////////////////////////////////////////////////////////////////////////
/*
* Log functions implementation prototypes.
* These functions are called by PJ_LOG macros according to verbosity
* level specified when calling the macro. Applications should not normally
* need to call these functions directly.
*/
/**
* @def pj_log_wrapper_1(arg)
* Internal function to write log with verbosity 1. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 1.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 1
#define pj_log_wrapper_1(arg) pj_log_1 arg
/** Internal function. */
PJ_DECL(void) pj_log_1(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_1(arg)
#endif
/**
* @def pj_log_wrapper_2(arg)
* Internal function to write log with verbosity 2. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 2.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 2
#define pj_log_wrapper_2(arg) pj_log_2 arg
/** Internal function. */
PJ_DECL(void) pj_log_2(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_2(arg)
#endif
/**
* @def pj_log_wrapper_3(arg)
* Internal function to write log with verbosity 3. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 3.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 3
#define pj_log_wrapper_3(arg) pj_log_3 arg
/** Internal function. */
PJ_DECL(void) pj_log_3(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_3(arg)
#endif
/**
* @def pj_log_wrapper_4(arg)
* Internal function to write log with verbosity 4. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 4.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 4
#define pj_log_wrapper_4(arg) pj_log_4 arg
/** Internal function. */
PJ_DECL(void) pj_log_4(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_4(arg)
#endif
/**
* @def pj_log_wrapper_5(arg)
* Internal function to write log with verbosity 5. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 5.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 5
#define pj_log_wrapper_5(arg) pj_log_5 arg
/** Internal function. */
PJ_DECL(void) pj_log_5(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_5(arg)
#endif
/**
* @def pj_log_wrapper_6(arg)
* Internal function to write log with verbosity 6. Will evaluate to
* empty expression if PJ_LOG_MAX_LEVEL is below 6.
* @param arg Log expression.
*/
#if PJ_LOG_MAX_LEVEL >= 6
#define pj_log_wrapper_6(arg) pj_log_6 arg
/** Internal function. */
PJ_DECL(void) pj_log_6(const char *src, const char *format, ...);
#else
#define pj_log_wrapper_6(arg)
#endif
PJ_END_DECL
#endif /* __PJ_LOG_H__ */

View File

@ -1,92 +1,92 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/md5.h 5 9/17/05 10:37a Bennylp $ */
/*
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
L. Peter Deutsch
ghost@aladdin.com
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.h is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/
#ifndef md5_INCLUDED
# define md5_INCLUDED
/*
* This package supports both compile-time and run-time determination of CPU
* byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
* compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
* defined as non-zero, the code will be compiled to run only on big-endian
* CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
* run on either big- or little-endian CPUs, but will run slightly less
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
*/
typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned long md5_word_t; /* 32-bit word */
/** Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /**< message length in bits, lsw first */
md5_word_t abcd[4]; /**< digest buffer */
md5_byte_t buf[64]; /**< accumulate block */
} md5_state_t;
#ifdef __cplusplus
extern "C"
{
#endif
/** Initialize the algorithm. */
void md5_init(md5_state_t *pms);
/** Append a string to the message. */
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
/** Finish the message and return the digest. */
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif /* md5_INCLUDED */
/* $Header: /pjproject-0.3/pjlib/src/pj/md5.h 5 9/17/05 10:37a Bennylp $ */
/*
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
L. Peter Deutsch
ghost@aladdin.com
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.h is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/
#ifndef md5_INCLUDED
# define md5_INCLUDED
/*
* This package supports both compile-time and run-time determination of CPU
* byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
* compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
* defined as non-zero, the code will be compiled to run only on big-endian
* CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
* run on either big- or little-endian CPUs, but will run slightly less
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
*/
typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned long md5_word_t; /* 32-bit word */
/** Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /**< message length in bits, lsw first */
md5_word_t abcd[4]; /**< digest buffer */
md5_byte_t buf[64]; /**< accumulate block */
} md5_state_t;
#ifdef __cplusplus
extern "C"
{
#endif
/** Initialize the algorithm. */
void md5_init(md5_state_t *pms);
/** Append a string to the message. */
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
/** Finish the message and return the digest. */
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif /* md5_INCLUDED */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,74 +1,74 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/pool_i.h 6 10/14/05 12:26a Bennylp $ */
#include <pj/string.h>
PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size);
PJ_IDEF(pj_size_t) pj_pool_get_capacity( pj_pool_t *pool )
{
return pool->capacity;
}
PJ_IDEF(pj_size_t) pj_pool_get_used_size( pj_pool_t *pool )
{
return pool->used_size;
}
PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_t *pool,
pj_pool_block *block, pj_size_t size )
{
/* The operation below is valid for size==0.
* When size==0, the function will return the pointer to the pool
* memory address, but no memory will be allocated.
*/
if (size & (PJ_POOL_ALIGNMENT-1)) {
size &= ~(PJ_POOL_ALIGNMENT-1);
size += PJ_POOL_ALIGNMENT;
}
if ((unsigned)(block->end - block->cur) >= size) {
void *ptr = block->cur;
block->cur += size;
pool->used_size += size;
return ptr;
}
return NULL;
}
PJ_IDEF(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size)
{
pj_pool_block *block = pool->block_list.next;
void *ptr = pj_pool_alloc_from_block(pool, block, size);
if (!ptr)
ptr = pj_pool_allocate_find(pool, size);
return ptr;
}
PJ_IDEF(void*) pj_pool_calloc( pj_pool_t *pool, pj_size_t count, pj_size_t size)
{
void *buf = pj_pool_alloc( pool, size*count);
if (buf)
pj_memset(buf, 0, size * count);
return buf;
}
PJ_IDEF(const char *) pj_pool_getobjname( const pj_pool_t *pool )
{
return pool->obj_name;
}
PJ_IDEF(pj_pool_t*) pj_pool_create( pj_pool_factory *f,
const char *name,
pj_size_t initial_size,
pj_size_t increment_size,
pj_pool_callback *callback)
{
return (*f->create_pool)(f, name, initial_size, increment_size, callback);
}
PJ_IDEF(void) pj_pool_release( pj_pool_t *pool )
{
(*pool->factory->release_pool)(pool->factory, pool);
}
/* $Header: /pjproject-0.3/pjlib/include/pj/pool_i.h 6 10/14/05 12:26a Bennylp $ */
#include <pj/string.h>
PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size);
PJ_IDEF(pj_size_t) pj_pool_get_capacity( pj_pool_t *pool )
{
return pool->capacity;
}
PJ_IDEF(pj_size_t) pj_pool_get_used_size( pj_pool_t *pool )
{
return pool->used_size;
}
PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_t *pool,
pj_pool_block *block, pj_size_t size )
{
/* The operation below is valid for size==0.
* When size==0, the function will return the pointer to the pool
* memory address, but no memory will be allocated.
*/
if (size & (PJ_POOL_ALIGNMENT-1)) {
size &= ~(PJ_POOL_ALIGNMENT-1);
size += PJ_POOL_ALIGNMENT;
}
if ((unsigned)(block->end - block->cur) >= size) {
void *ptr = block->cur;
block->cur += size;
pool->used_size += size;
return ptr;
}
return NULL;
}
PJ_IDEF(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size)
{
pj_pool_block *block = pool->block_list.next;
void *ptr = pj_pool_alloc_from_block(pool, block, size);
if (!ptr)
ptr = pj_pool_allocate_find(pool, size);
return ptr;
}
PJ_IDEF(void*) pj_pool_calloc( pj_pool_t *pool, pj_size_t count, pj_size_t size)
{
void *buf = pj_pool_alloc( pool, size*count);
if (buf)
pj_memset(buf, 0, size * count);
return buf;
}
PJ_IDEF(const char *) pj_pool_getobjname( const pj_pool_t *pool )
{
return pool->obj_name;
}
PJ_IDEF(pj_pool_t*) pj_pool_create( pj_pool_factory *f,
const char *name,
pj_size_t initial_size,
pj_size_t increment_size,
pj_pool_callback *callback)
{
return (*f->create_pool)(f, name, initial_size, increment_size, callback);
}
PJ_IDEF(void) pj_pool_release( pj_pool_t *pool )
{
(*pool->factory->release_pool)(pool->factory, pool);
}

View File

@ -1,60 +1,60 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/rand.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/rand.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
* 1 9/15/05 8:40p Bennylp
* Created.
*/
#ifndef __PJ_RAND_H__
#define __PJ_RAND_H__
/**
* @file rand.h
* @brief Random Number Generator.
*/
#include <pj/config.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_RAND Random Number Generator
* @ingroup PJ_MISC
* @{
* This module contains functions for generating random numbers.
* This abstraction is needed not only because not all platforms have
* \a rand() and \a srand(), but also on some platforms \a rand()
* only has 16-bit randomness, which is not good enough.
*/
/**
* Put in seed to random number generator.
*
* @param seed Seed value.
*/
PJ_DECL(void) pj_srand(unsigned int seed);
/**
* Generate random integer with 32bit randomness.
*
* @return a random integer.
*/
PJ_DECL(int) pj_rand(void);
/** @} */
PJ_END_DECL
#endif /* __PJ_RAND_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/rand.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/rand.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
* 1 9/15/05 8:40p Bennylp
* Created.
*/
#ifndef __PJ_RAND_H__
#define __PJ_RAND_H__
/**
* @file rand.h
* @brief Random Number Generator.
*/
#include <pj/config.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_RAND Random Number Generator
* @ingroup PJ_MISC
* @{
* This module contains functions for generating random numbers.
* This abstraction is needed not only because not all platforms have
* \a rand() and \a srand(), but also on some platforms \a rand()
* only has 16-bit randomness, which is not good enough.
*/
/**
* Put in seed to random number generator.
*
* @param seed Seed value.
*/
PJ_DECL(void) pj_srand(unsigned int seed);
/**
* Generate random integer with 32bit randomness.
*
* @return a random integer.
*/
PJ_DECL(int) pj_rand(void);
/** @} */
PJ_END_DECL
#endif /* __PJ_RAND_H__ */

View File

@ -1,193 +1,193 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/rbtree.h 5 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_RBTREE_H__
#define __PJ_RBTREE_H__
/**
* @file rbtree.h
* @brief Red/Black Tree
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_RBTREE Red/Black Balanced Tree
* @ingroup PJ_DS
* @brief
* Red/Black tree is the variant of balanced tree, where the search, insert,
* and delete operation is \b guaranteed to take at most \a O( lg(n) ).
* @{
*/
/**
* Color type for Red-Black tree.
*/
typedef enum pj_rbcolor_t
{
PJ_RBCOLOR_BLACK,
PJ_RBCOLOR_RED
} pj_rbcolor_t;
/**
* The type of the node of the R/B Tree.
*/
typedef struct pj_rbtree_node
{
/** Pointers to the node's parent, and left and right siblings. */
struct pj_rbtree_node *parent, *left, *right;
/** Key associated with the node. */
const void *key;
/** User data associated with the node. */
void *user_data;
/** The R/B Tree node color. */
pj_rbcolor_t color;
} pj_rbtree_node;
/**
* The type of function use to compare key value of tree node.
* @return
* 0 if the keys are equal
* <0 if key1 is lower than key2
* >0 if key1 is greater than key2.
*/
typedef int pj_rbtree_comp(const void *key1, const void *key2);
/**
* Declaration of a red-black tree. All elements in the tree must have UNIQUE
* key.
* A red black tree always maintains the balance of the tree, so that the
* tree height will not be greater than lg(N). Insert, search, and delete
* operation will take lg(N) on the worst case. But for insert and delete,
* there is additional time needed to maintain the balance of the tree.
*/
typedef struct pj_rbtree
{
pj_rbtree_node null_node; /**< Constant to indicate NULL node. */
pj_rbtree_node *null; /**< Constant to indicate NULL node. */
pj_rbtree_node *root; /**< Root tree node. */
unsigned size; /**< Number of elements in the tree. */
pj_rbtree_comp *comp; /**< Key comparison function. */
} pj_rbtree;
/**
* Guidance on how much memory required for each of the node.
*/
#define PJ_RBTREE_NODE_SIZE (sizeof(pj_rbtree_node))
/**
* Guidance on memory required for the tree.
*/
#define PJ_RBTREE_SIZE (sizeof(pj_rbtree))
/**
* Initialize the tree.
* @param tree the tree to be initialized.
* @param comp key comparison function to be used for this tree.
*/
PJ_DECL(void) pj_rbtree_init( pj_rbtree *tree, pj_rbtree_comp *comp);
/**
* Get the first element in the tree.
* The first element always has the least value for the key, according to
* the comparison function.
* @param tree the tree.
* @return the tree node, or NULL if the tree has no element.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_first( pj_rbtree *tree );
/**
* Get the last element in the tree.
* The last element always has the greatest key value, according to the
* comparison function defined for the tree.
* @param tree the tree.
* @return the tree node, or NULL if the tree has no element.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_last( pj_rbtree *tree );
/**
* Get the successive element for the specified node.
* The successive element is an element with greater key value.
* @param tree the tree.
* @param node the node.
* @return the successive node, or NULL if the node has no successor.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_next( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* The the previous node for the specified node.
* The previous node is an element with less key value.
* @param tree the tree.
* @param node the node.
* @return the previous node, or NULL if the node has no previous node.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_prev( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Insert a new node.
* The node will be inserted at sorted location. The key of the node must
* be UNIQUE, i.e. it hasn't existed in the tree.
* @param tree the tree.
* @param node the node to be inserted.
* @return zero on success, or -1 if the key already exist.
*/
PJ_DECL(int) pj_rbtree_insert( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Find a node which has the specified key.
* @param tree the tree.
* @param key the key to search.
* @return the tree node with the specified key, or NULL if the key can not
* be found.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_find( pj_rbtree *tree,
const void *key );
/**
* Erase a node from the tree.
* @param tree the tree.
* @param node the node to be erased.
* @return the tree node itself.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_erase( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Get the maximum tree height from the specified node.
* @param tree the tree.
* @param node the node, or NULL to get the root of the tree.
* @return the maximum height, which should be at most lg(N)
*/
PJ_DECL(unsigned) pj_rbtree_max_height( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Get the minumum tree height from the specified node.
* @param tree the tree.
* @param node the node, or NULL to get the root of the tree.
* @return the height
*/
PJ_DECL(unsigned) pj_rbtree_min_height( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_RBTREE_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/rbtree.h 5 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_RBTREE_H__
#define __PJ_RBTREE_H__
/**
* @file rbtree.h
* @brief Red/Black Tree
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_RBTREE Red/Black Balanced Tree
* @ingroup PJ_DS
* @brief
* Red/Black tree is the variant of balanced tree, where the search, insert,
* and delete operation is \b guaranteed to take at most \a O( lg(n) ).
* @{
*/
/**
* Color type for Red-Black tree.
*/
typedef enum pj_rbcolor_t
{
PJ_RBCOLOR_BLACK,
PJ_RBCOLOR_RED
} pj_rbcolor_t;
/**
* The type of the node of the R/B Tree.
*/
typedef struct pj_rbtree_node
{
/** Pointers to the node's parent, and left and right siblings. */
struct pj_rbtree_node *parent, *left, *right;
/** Key associated with the node. */
const void *key;
/** User data associated with the node. */
void *user_data;
/** The R/B Tree node color. */
pj_rbcolor_t color;
} pj_rbtree_node;
/**
* The type of function use to compare key value of tree node.
* @return
* 0 if the keys are equal
* <0 if key1 is lower than key2
* >0 if key1 is greater than key2.
*/
typedef int pj_rbtree_comp(const void *key1, const void *key2);
/**
* Declaration of a red-black tree. All elements in the tree must have UNIQUE
* key.
* A red black tree always maintains the balance of the tree, so that the
* tree height will not be greater than lg(N). Insert, search, and delete
* operation will take lg(N) on the worst case. But for insert and delete,
* there is additional time needed to maintain the balance of the tree.
*/
typedef struct pj_rbtree
{
pj_rbtree_node null_node; /**< Constant to indicate NULL node. */
pj_rbtree_node *null; /**< Constant to indicate NULL node. */
pj_rbtree_node *root; /**< Root tree node. */
unsigned size; /**< Number of elements in the tree. */
pj_rbtree_comp *comp; /**< Key comparison function. */
} pj_rbtree;
/**
* Guidance on how much memory required for each of the node.
*/
#define PJ_RBTREE_NODE_SIZE (sizeof(pj_rbtree_node))
/**
* Guidance on memory required for the tree.
*/
#define PJ_RBTREE_SIZE (sizeof(pj_rbtree))
/**
* Initialize the tree.
* @param tree the tree to be initialized.
* @param comp key comparison function to be used for this tree.
*/
PJ_DECL(void) pj_rbtree_init( pj_rbtree *tree, pj_rbtree_comp *comp);
/**
* Get the first element in the tree.
* The first element always has the least value for the key, according to
* the comparison function.
* @param tree the tree.
* @return the tree node, or NULL if the tree has no element.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_first( pj_rbtree *tree );
/**
* Get the last element in the tree.
* The last element always has the greatest key value, according to the
* comparison function defined for the tree.
* @param tree the tree.
* @return the tree node, or NULL if the tree has no element.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_last( pj_rbtree *tree );
/**
* Get the successive element for the specified node.
* The successive element is an element with greater key value.
* @param tree the tree.
* @param node the node.
* @return the successive node, or NULL if the node has no successor.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_next( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* The the previous node for the specified node.
* The previous node is an element with less key value.
* @param tree the tree.
* @param node the node.
* @return the previous node, or NULL if the node has no previous node.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_prev( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Insert a new node.
* The node will be inserted at sorted location. The key of the node must
* be UNIQUE, i.e. it hasn't existed in the tree.
* @param tree the tree.
* @param node the node to be inserted.
* @return zero on success, or -1 if the key already exist.
*/
PJ_DECL(int) pj_rbtree_insert( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Find a node which has the specified key.
* @param tree the tree.
* @param key the key to search.
* @return the tree node with the specified key, or NULL if the key can not
* be found.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_find( pj_rbtree *tree,
const void *key );
/**
* Erase a node from the tree.
* @param tree the tree.
* @param node the node to be erased.
* @return the tree node itself.
*/
PJ_DECL(pj_rbtree_node*) pj_rbtree_erase( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Get the maximum tree height from the specified node.
* @param tree the tree.
* @param node the node, or NULL to get the root of the tree.
* @return the maximum height, which should be at most lg(N)
*/
PJ_DECL(unsigned) pj_rbtree_max_height( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* Get the minumum tree height from the specified node.
* @param tree the tree.
* @param node the node, or NULL to get the root of the tree.
* @return the height
*/
PJ_DECL(unsigned) pj_rbtree_min_height( pj_rbtree *tree,
pj_rbtree_node *node );
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_RBTREE_H__ */

View File

@ -1,454 +1,454 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/scanner.h 10 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_PARSER_H__
#define __PJ_PARSER_H__
/**
* @file scanner.h
* @brief Text Scanning.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_SCAN Text Scanning
* @ingroup PJ_MISC
* @brief
* Text scanning utility.
*/
/**
* @defgroup PJ_CHARSPEC Character Filter Specification
* @ingroup PJ_SCAN
* @brief
* The type pj_char_spec is a specification of character set used in
* scanner. Application can define multiple character specs, such as to
* scan alpha numerics, numbers, tokens, etc.
* @{
*/
/**
* This describes the type of individual character specification in
* #pj_char_spec.
*/
typedef pj_uint8_t pj_char_spec_element_t;
/**
* The character specification is implemented as array of boolean flags. Each
* flag indicates the membership of the character in the spec. If the flag
* at one position is non-zero, then the character at that position belongs
* to the specification, and vice versa.
*/
typedef pj_char_spec_element_t pj_char_spec[256];
// Note: it's got to be 256 (not 128) to cater for extended character in input.
/**
* Initialize character spec.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_init( pj_char_spec cs);
/**
* Set the membership of the specified character to TRUE.
* @param cs the scanner character specification.
* @param c the character.
*/
PJ_DECL(void) pj_cs_set( pj_char_spec cs, int c);
/**
* Add the characters in the specified range '[cstart, cend)' to the
* specification (the last character itself ('cend') is not added).
* @param cs the scanner character specification.
* @param cstart the first character in the range.
* @param cend the next character after the last character in the range.
*/
PJ_DECL(void) pj_cs_add_range( pj_char_spec cs, int cstart, int cend);
/**
* Add alphabetic characters to the specification.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_add_alpha( pj_char_spec cs);
/**
* Add numeric characters to the specification.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_add_num( pj_char_spec cs);
/**
* Add the characters in the string to the specification.
* @param cs the scanner character specification.
* @param str the string.
*/
PJ_DECL(void) pj_cs_add_str( pj_char_spec cs, const char *str);
/**
* Delete characters in the specified range from the specification.
* @param cs the scanner character specification.
* @param cstart the first character in the range.
* @param cend the next character after the last character in the range.
*/
PJ_DECL(void) pj_cs_del_range( pj_char_spec cs, int cstart, int cend);
/**
* Delete characters in the specified string from the specification.
* @param cs the scanner character specification.
* @param str the string.
*/
PJ_DECL(void) pj_cs_del_str( pj_char_spec cs, const char *str);
/**
* Invert specification.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_invert( pj_char_spec cs );
/**
* Check whether the specified character belongs to the specification.
* @param cs the scanner character specification.
* @param c the character to check for matching.
*/
PJ_INLINE(int) pj_cs_match( const pj_char_spec cs, int c )
{
return cs[c];
}
/**
* @}
*/
/**
* @defgroup PJ_SCANNER Text Scanner
* @ingroup PJ_SCAN
* @{
*/
/**
* Flags for scanner.
*/
enum
{
/** This flags specifies that the scanner should automatically skip
whitespaces
*/
PJ_SCAN_AUTOSKIP_WS = 1,
/** This flags specifies that the scanner should automatically skip
SIP header continuation. This flag implies PJ_SCAN_AUTOSKIP_WS.
*/
PJ_SCAN_AUTOSKIP_WS_HEADER = 3,
/** Auto-skip new lines.
*/
PJ_SCAN_AUTOSKIP_NEWLINE = 4,
};
/* Forward decl. */
struct pj_scanner;
/**
* The callback function type to be called by the scanner when it encounters
* syntax error.
* @param scanner The scanner instance that calls the callback .
*/
typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner);
/**
* The text scanner structure.
*/
typedef struct pj_scanner
{
char *begin; /**< Start of input buffer. */
char *end; /**< End of input buffer. */
char *curptr; /**< Current pointer. */
int line; /**< Current line. */
int col; /**< Current column. */
int skip_ws; /**< Skip whitespace flag. */
pj_syn_err_func_ptr callback; /**< Syntax error callback. */
} pj_scanner;
/**
* This structure can be used by application to store the state of the parser,
* so that the scanner state can be rollback to this state when necessary.
*/
typedef struct pj_scan_state
{
char *curptr; /**< Current scanner's pointer. */
int line; /**< Current line. */
int col; /**< Current column. */
} pj_scan_state;
/**
* Initialize the scanner. Note that the input string buffer must have
* length at least buflen+1 because the scanner will NULL terminate the
* string during initialization.
*
* @param scanner The scanner to be initialized.
* @param bufstart The input buffer to scan. Note that buffer[buflen] will be
* filled with NULL char until scanner is destroyed, so
* the actual buffer length must be at least buflen+1.
* @param buflen The length of the input buffer, which normally is
* strlen(bufstart).
* @param options Zero, or combination of PJ_SCAN_AUTOSKIP_WS or
* PJ_SCAN_AUTOSKIP_WS_HEADER
* @param callback Callback to be called when the scanner encounters syntax
* error condition.
*/
PJ_DECL(void) pj_scan_init( pj_scanner *scanner, char *bufstart, int buflen,
unsigned options,
pj_syn_err_func_ptr callback );
/**
* Call this function when application has finished using the scanner.
*
* @param scanner The scanner.
*/
PJ_DECL(void) pj_scan_fini( pj_scanner *scanner );
/**
* Determine whether the EOF condition for the scanner has been met.
*
* @param scanner The scanner.
*
* @return Non-zero if scanner is EOF.
*/
PJ_INLINE(int) pj_scan_is_eof( const pj_scanner *scanner)
{
return scanner->curptr >= scanner->end;
}
/**
* Peek strings in current position according to parameter spec, and return
* the strings in parameter out. The current scanner position will not be
* moved. If the scanner is already in EOF state, syntax error callback will
* be called thrown.
*
* @param scanner The scanner.
* @param spec The spec to match input string.
* @param out String to store the result.
*
* @return the character right after the peek-ed position or zero if there's
* no more characters.
*/
PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
const pj_char_spec spec, pj_str_t *out);
/**
* Peek len characters in current position, and return them in out parameter.
* Note that whitespaces or newlines will be returned as it is, regardless
* of PJ_SCAN_AUTOSKIP_WS settings. If the character left is less than len,
* syntax error callback will be called.
*
* @param scanner The scanner.
* @param len Length to peek.
* @param out String to store the result.
*
* @return the character right after the peek-ed position or zero if there's
* no more characters.
*/
PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
pj_size_t len, pj_str_t *out);
/**
* Peek strings in current position until spec is matched, and return
* the strings in parameter out. The current scanner position will not be
* moved. If the scanner is already in EOF state, syntax error callback will
* be called.
*
* @param scanner The scanner.
* @param spec The peeking will stop when the input match this spec.
* @param out String to store the result.
*
* @return the character right after the peek-ed position.
*/
PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner,
const pj_char_spec spec,
pj_str_t *out);
/**
* Get characters from the buffer according to the spec, and return them
* in out parameter. The scanner will attempt to get as many characters as
* possible as long as the spec matches. If the first character doesn't
* match the spec, or scanner is already in EOF when this function is called,
* an exception will be thrown.
*
* @param scanner The scanner.
* @param spec The spec to match input string.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
const pj_char_spec spec, pj_str_t *out);
/**
* Get characters between quotes. If current input doesn't match begin_quote,
* syntax error will be thrown.
*
* @param scanner The scanner.
* @param begin_quote The character to begin the quote.
* @param end_quote The character to end the quote.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_quote( pj_scanner *scanner,
int begin_quote, int end_quote,
pj_str_t *out);
/**
* Get N characters from the scanner.
*
* @param scanner The scanner.
* @param N Number of characters to get.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner,
unsigned N, pj_str_t *out);
/**
* Get one character from the scanner.
*
* @param scanner The scanner.
*
* @return (unknown)
*/
PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner );
/**
* Get a newline from the scanner. A newline is defined as '\\n', or '\\r', or
* "\\r\\n". If current input is not newline, syntax error will be thrown.
*
* @param scanner The scanner.
*/
PJ_DECL(void) pj_scan_get_newline( pj_scanner *scanner );
/**
* Get characters from the scanner and move the scanner position until the
* current character matches the spec.
*
* @param scanner The scanner.
* @param spec Get until the input match this spec.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner,
const pj_char_spec spec, pj_str_t *out);
/**
* Get characters from the scanner and move the scanner position until the
* current character matches until_char.
*
* @param scanner The scanner.
* @param until_char Get until the input match this character.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner,
int until_char, pj_str_t *out);
/**
* Get characters from the scanner and move the scanner position until the
* current character matches until_char.
*
* @param scanner The scanner.
* @param until_spec Get until the input match any of these characters.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner,
const char *until_spec, pj_str_t *out);
/**
* Advance the scanner N characters, and skip whitespace
* if necessary.
*
* @param scanner The scanner.
* @param N Number of characters to skip.
* @param skip Flag to specify whether whitespace should be skipped
* after skipping the characters.
*/
PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner,
unsigned N, pj_bool_t skip);
/**
* Compare string in current position with the specified string.
*
* @param scanner The scanner.
* @param s The string to compare with.
* @param len Length of the string to compare.
*
* @return zero, <0, or >0 (just like strcmp()).
*/
PJ_DECL(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len);
/**
* Case-less string comparison of current position with the specified
* string.
*
* @param scanner The scanner.
* @param s The string to compare with.
* @param len Length of the string to compare with.
*
* @return zero, <0, or >0 (just like strcmp()).
*/
PJ_DECL(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len);
/**
* Manually skip whitespaces according to flag that was specified when
* the scanner was initialized.
*
* @param scanner The scanner.
*/
PJ_DECL(void) pj_scan_skip_whitespace( pj_scanner *scanner );
/**
* Save the full scanner state.
*
* @param scanner The scanner.
* @param state Variable to store scanner's state.
*/
PJ_DECL(void) pj_scan_save_state( pj_scanner *scanner, pj_scan_state *state);
/**
* Restore the full scanner state.
* Note that this would not restore the string if application has modified
* it. This will only restore the scanner scanning position.
*
* @param scanner The scanner.
* @param state State of the scanner.
*/
PJ_DECL(void) pj_scan_restore_state( pj_scanner *scanner,
pj_scan_state *state);
/**
* @}
*/
#if PJ_FUNCTIONS_ARE_INLINED
# include "scanner_i.h"
#endif
PJ_END_DECL
#endif
/* $Header: /pjproject-0.3/pjlib/include/pj/scanner.h 10 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_PARSER_H__
#define __PJ_PARSER_H__
/**
* @file scanner.h
* @brief Text Scanning.
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_SCAN Text Scanning
* @ingroup PJ_MISC
* @brief
* Text scanning utility.
*/
/**
* @defgroup PJ_CHARSPEC Character Filter Specification
* @ingroup PJ_SCAN
* @brief
* The type pj_char_spec is a specification of character set used in
* scanner. Application can define multiple character specs, such as to
* scan alpha numerics, numbers, tokens, etc.
* @{
*/
/**
* This describes the type of individual character specification in
* #pj_char_spec.
*/
typedef pj_uint8_t pj_char_spec_element_t;
/**
* The character specification is implemented as array of boolean flags. Each
* flag indicates the membership of the character in the spec. If the flag
* at one position is non-zero, then the character at that position belongs
* to the specification, and vice versa.
*/
typedef pj_char_spec_element_t pj_char_spec[256];
// Note: it's got to be 256 (not 128) to cater for extended character in input.
/**
* Initialize character spec.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_init( pj_char_spec cs);
/**
* Set the membership of the specified character to TRUE.
* @param cs the scanner character specification.
* @param c the character.
*/
PJ_DECL(void) pj_cs_set( pj_char_spec cs, int c);
/**
* Add the characters in the specified range '[cstart, cend)' to the
* specification (the last character itself ('cend') is not added).
* @param cs the scanner character specification.
* @param cstart the first character in the range.
* @param cend the next character after the last character in the range.
*/
PJ_DECL(void) pj_cs_add_range( pj_char_spec cs, int cstart, int cend);
/**
* Add alphabetic characters to the specification.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_add_alpha( pj_char_spec cs);
/**
* Add numeric characters to the specification.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_add_num( pj_char_spec cs);
/**
* Add the characters in the string to the specification.
* @param cs the scanner character specification.
* @param str the string.
*/
PJ_DECL(void) pj_cs_add_str( pj_char_spec cs, const char *str);
/**
* Delete characters in the specified range from the specification.
* @param cs the scanner character specification.
* @param cstart the first character in the range.
* @param cend the next character after the last character in the range.
*/
PJ_DECL(void) pj_cs_del_range( pj_char_spec cs, int cstart, int cend);
/**
* Delete characters in the specified string from the specification.
* @param cs the scanner character specification.
* @param str the string.
*/
PJ_DECL(void) pj_cs_del_str( pj_char_spec cs, const char *str);
/**
* Invert specification.
* @param cs the scanner character specification.
*/
PJ_DECL(void) pj_cs_invert( pj_char_spec cs );
/**
* Check whether the specified character belongs to the specification.
* @param cs the scanner character specification.
* @param c the character to check for matching.
*/
PJ_INLINE(int) pj_cs_match( const pj_char_spec cs, int c )
{
return cs[c];
}
/**
* @}
*/
/**
* @defgroup PJ_SCANNER Text Scanner
* @ingroup PJ_SCAN
* @{
*/
/**
* Flags for scanner.
*/
enum
{
/** This flags specifies that the scanner should automatically skip
whitespaces
*/
PJ_SCAN_AUTOSKIP_WS = 1,
/** This flags specifies that the scanner should automatically skip
SIP header continuation. This flag implies PJ_SCAN_AUTOSKIP_WS.
*/
PJ_SCAN_AUTOSKIP_WS_HEADER = 3,
/** Auto-skip new lines.
*/
PJ_SCAN_AUTOSKIP_NEWLINE = 4,
};
/* Forward decl. */
struct pj_scanner;
/**
* The callback function type to be called by the scanner when it encounters
* syntax error.
* @param scanner The scanner instance that calls the callback .
*/
typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner);
/**
* The text scanner structure.
*/
typedef struct pj_scanner
{
char *begin; /**< Start of input buffer. */
char *end; /**< End of input buffer. */
char *curptr; /**< Current pointer. */
int line; /**< Current line. */
int col; /**< Current column. */
int skip_ws; /**< Skip whitespace flag. */
pj_syn_err_func_ptr callback; /**< Syntax error callback. */
} pj_scanner;
/**
* This structure can be used by application to store the state of the parser,
* so that the scanner state can be rollback to this state when necessary.
*/
typedef struct pj_scan_state
{
char *curptr; /**< Current scanner's pointer. */
int line; /**< Current line. */
int col; /**< Current column. */
} pj_scan_state;
/**
* Initialize the scanner. Note that the input string buffer must have
* length at least buflen+1 because the scanner will NULL terminate the
* string during initialization.
*
* @param scanner The scanner to be initialized.
* @param bufstart The input buffer to scan. Note that buffer[buflen] will be
* filled with NULL char until scanner is destroyed, so
* the actual buffer length must be at least buflen+1.
* @param buflen The length of the input buffer, which normally is
* strlen(bufstart).
* @param options Zero, or combination of PJ_SCAN_AUTOSKIP_WS or
* PJ_SCAN_AUTOSKIP_WS_HEADER
* @param callback Callback to be called when the scanner encounters syntax
* error condition.
*/
PJ_DECL(void) pj_scan_init( pj_scanner *scanner, char *bufstart, int buflen,
unsigned options,
pj_syn_err_func_ptr callback );
/**
* Call this function when application has finished using the scanner.
*
* @param scanner The scanner.
*/
PJ_DECL(void) pj_scan_fini( pj_scanner *scanner );
/**
* Determine whether the EOF condition for the scanner has been met.
*
* @param scanner The scanner.
*
* @return Non-zero if scanner is EOF.
*/
PJ_INLINE(int) pj_scan_is_eof( const pj_scanner *scanner)
{
return scanner->curptr >= scanner->end;
}
/**
* Peek strings in current position according to parameter spec, and return
* the strings in parameter out. The current scanner position will not be
* moved. If the scanner is already in EOF state, syntax error callback will
* be called thrown.
*
* @param scanner The scanner.
* @param spec The spec to match input string.
* @param out String to store the result.
*
* @return the character right after the peek-ed position or zero if there's
* no more characters.
*/
PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
const pj_char_spec spec, pj_str_t *out);
/**
* Peek len characters in current position, and return them in out parameter.
* Note that whitespaces or newlines will be returned as it is, regardless
* of PJ_SCAN_AUTOSKIP_WS settings. If the character left is less than len,
* syntax error callback will be called.
*
* @param scanner The scanner.
* @param len Length to peek.
* @param out String to store the result.
*
* @return the character right after the peek-ed position or zero if there's
* no more characters.
*/
PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
pj_size_t len, pj_str_t *out);
/**
* Peek strings in current position until spec is matched, and return
* the strings in parameter out. The current scanner position will not be
* moved. If the scanner is already in EOF state, syntax error callback will
* be called.
*
* @param scanner The scanner.
* @param spec The peeking will stop when the input match this spec.
* @param out String to store the result.
*
* @return the character right after the peek-ed position.
*/
PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner,
const pj_char_spec spec,
pj_str_t *out);
/**
* Get characters from the buffer according to the spec, and return them
* in out parameter. The scanner will attempt to get as many characters as
* possible as long as the spec matches. If the first character doesn't
* match the spec, or scanner is already in EOF when this function is called,
* an exception will be thrown.
*
* @param scanner The scanner.
* @param spec The spec to match input string.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
const pj_char_spec spec, pj_str_t *out);
/**
* Get characters between quotes. If current input doesn't match begin_quote,
* syntax error will be thrown.
*
* @param scanner The scanner.
* @param begin_quote The character to begin the quote.
* @param end_quote The character to end the quote.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_quote( pj_scanner *scanner,
int begin_quote, int end_quote,
pj_str_t *out);
/**
* Get N characters from the scanner.
*
* @param scanner The scanner.
* @param N Number of characters to get.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner,
unsigned N, pj_str_t *out);
/**
* Get one character from the scanner.
*
* @param scanner The scanner.
*
* @return (unknown)
*/
PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner );
/**
* Get a newline from the scanner. A newline is defined as '\\n', or '\\r', or
* "\\r\\n". If current input is not newline, syntax error will be thrown.
*
* @param scanner The scanner.
*/
PJ_DECL(void) pj_scan_get_newline( pj_scanner *scanner );
/**
* Get characters from the scanner and move the scanner position until the
* current character matches the spec.
*
* @param scanner The scanner.
* @param spec Get until the input match this spec.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner,
const pj_char_spec spec, pj_str_t *out);
/**
* Get characters from the scanner and move the scanner position until the
* current character matches until_char.
*
* @param scanner The scanner.
* @param until_char Get until the input match this character.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner,
int until_char, pj_str_t *out);
/**
* Get characters from the scanner and move the scanner position until the
* current character matches until_char.
*
* @param scanner The scanner.
* @param until_spec Get until the input match any of these characters.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner,
const char *until_spec, pj_str_t *out);
/**
* Advance the scanner N characters, and skip whitespace
* if necessary.
*
* @param scanner The scanner.
* @param N Number of characters to skip.
* @param skip Flag to specify whether whitespace should be skipped
* after skipping the characters.
*/
PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner,
unsigned N, pj_bool_t skip);
/**
* Compare string in current position with the specified string.
*
* @param scanner The scanner.
* @param s The string to compare with.
* @param len Length of the string to compare.
*
* @return zero, <0, or >0 (just like strcmp()).
*/
PJ_DECL(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len);
/**
* Case-less string comparison of current position with the specified
* string.
*
* @param scanner The scanner.
* @param s The string to compare with.
* @param len Length of the string to compare with.
*
* @return zero, <0, or >0 (just like strcmp()).
*/
PJ_DECL(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len);
/**
* Manually skip whitespaces according to flag that was specified when
* the scanner was initialized.
*
* @param scanner The scanner.
*/
PJ_DECL(void) pj_scan_skip_whitespace( pj_scanner *scanner );
/**
* Save the full scanner state.
*
* @param scanner The scanner.
* @param state Variable to store scanner's state.
*/
PJ_DECL(void) pj_scan_save_state( pj_scanner *scanner, pj_scan_state *state);
/**
* Restore the full scanner state.
* Note that this would not restore the string if application has modified
* it. This will only restore the scanner scanning position.
*
* @param scanner The scanner.
* @param state State of the scanner.
*/
PJ_DECL(void) pj_scan_restore_state( pj_scanner *scanner,
pj_scan_state *state);
/**
* @}
*/
#if PJ_FUNCTIONS_ARE_INLINED
# include "scanner_i.h"
#endif
PJ_END_DECL
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,141 +1,141 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/sock_select.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/sock_select.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/15/05 8:40p Bennylp
* Created.
*/
#ifndef __PJ_SELECT_H__
#define __PJ_SELECT_H__
/**
* @file sock_select.h
* @brief Socket select().
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_SOCK_SELECT Socket select() API.
* @ingroup PJ_IO
* @{
* This module provides portable abstraction for \a select() like API.
* The abstraction is needed so that it can utilize various event
* dispatching mechanisms that are available across platforms.
*
* The API is very similar to normal \a select() usage.
*
* \section pj_sock_select_examples_sec Examples
*
* For some examples on how to use the select API, please see:
*
* - \ref page_pjlib_select_test
*/
/**
* Portable structure declarations for pj_fd_set.
* The implementation of pj_sock_select() does not use this structure
* per-se, but instead it will use the native fd_set structure. However,
* we must make sure that the size of pj_fd_set_t can accomodate the
* native fd_set structure.
*/
typedef struct pj_fd_set_t
{
pj_sock_t data[FD_SETSIZE + 4]; /**< Opaque buffer for fd_set */
} pj_fd_set_t;
/**
* Initialize the descriptor set pointed to by fdsetp to the null set.
*
* @param fdsetp The descriptor set.
*/
PJ_DECL(void) PJ_FD_ZERO(pj_fd_set_t *fdsetp);
/**
* Add the file descriptor fd to the set pointed to by fdsetp.
* If the file descriptor fd is already in this set, there shall be no effect
* on the set, nor will an error be returned.
*
* @param fd The socket descriptor.
* @param fdsetp The descriptor set.
*/
PJ_DECL(void) PJ_FD_SET(pj_sock_t fd, pj_fd_set_t *fdsetp);
/**
* Remove the file descriptor fd from the set pointed to by fdsetp.
* If fd is not a member of this set, there shall be no effect on the set,
* nor will an error be returned.
*
* @param fd The socket descriptor.
* @param fdsetp The descriptor set.
*/
PJ_DECL(void) PJ_FD_CLR(pj_sock_t fd, pj_fd_set_t *fdsetp);
/**
* Evaluate to non-zero if the file descriptor fd is a member of the set
* pointed to by fdsetp, and shall evaluate to zero otherwise.
*
* @param fd The socket descriptor.
* @param fdsetp The descriptor set.
*
* @return Nonzero if fd is member of the descriptor set.
*/
PJ_DECL(pj_bool_t) PJ_FD_ISSET(pj_sock_t fd, const pj_fd_set_t *fdsetp);
/**
* Get the number of descriptors in the set.
*
* @param fdsetp The descriptor set.
*
* @return Number of descriptors in the set.
*/
PJ_DECL(pj_size_t) PJ_FD_COUNT(const pj_fd_set_t *fdsetp);
/**
* This function wait for a number of file descriptors to change status.
* The behaviour is the same as select() function call which appear in
* standard BSD socket libraries.
*
* @param n On Unices, this specifies the highest-numbered
* descriptor in any of the three set, plus 1. On Windows,
* the value is ignored.
* @param readfds Optional pointer to a set of sockets to be checked for
* readability.
* @param writefds Optional pointer to a set of sockets to be checked for
* writability.
* @param exceptfds Optional pointer to a set of sockets to be checked for
* errors.
* @param timeout Maximum time for select to wait, or null for blocking
* operations.
*
* @return The total number of socket handles that are ready, or
* zero if the time limit expired, or -1 if an error occurred.
*/
PJ_DECL(int) pj_sock_select( int n,
pj_fd_set_t *readfds,
pj_fd_set_t *writefds,
pj_fd_set_t *exceptfds,
const pj_time_val *timeout);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_SELECT_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/sock_select.h 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/include/pj/sock_select.h $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 1 9/15/05 8:40p Bennylp
* Created.
*/
#ifndef __PJ_SELECT_H__
#define __PJ_SELECT_H__
/**
* @file sock_select.h
* @brief Socket select().
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_SOCK_SELECT Socket select() API.
* @ingroup PJ_IO
* @{
* This module provides portable abstraction for \a select() like API.
* The abstraction is needed so that it can utilize various event
* dispatching mechanisms that are available across platforms.
*
* The API is very similar to normal \a select() usage.
*
* \section pj_sock_select_examples_sec Examples
*
* For some examples on how to use the select API, please see:
*
* - \ref page_pjlib_select_test
*/
/**
* Portable structure declarations for pj_fd_set.
* The implementation of pj_sock_select() does not use this structure
* per-se, but instead it will use the native fd_set structure. However,
* we must make sure that the size of pj_fd_set_t can accomodate the
* native fd_set structure.
*/
typedef struct pj_fd_set_t
{
pj_sock_t data[FD_SETSIZE + 4]; /**< Opaque buffer for fd_set */
} pj_fd_set_t;
/**
* Initialize the descriptor set pointed to by fdsetp to the null set.
*
* @param fdsetp The descriptor set.
*/
PJ_DECL(void) PJ_FD_ZERO(pj_fd_set_t *fdsetp);
/**
* Add the file descriptor fd to the set pointed to by fdsetp.
* If the file descriptor fd is already in this set, there shall be no effect
* on the set, nor will an error be returned.
*
* @param fd The socket descriptor.
* @param fdsetp The descriptor set.
*/
PJ_DECL(void) PJ_FD_SET(pj_sock_t fd, pj_fd_set_t *fdsetp);
/**
* Remove the file descriptor fd from the set pointed to by fdsetp.
* If fd is not a member of this set, there shall be no effect on the set,
* nor will an error be returned.
*
* @param fd The socket descriptor.
* @param fdsetp The descriptor set.
*/
PJ_DECL(void) PJ_FD_CLR(pj_sock_t fd, pj_fd_set_t *fdsetp);
/**
* Evaluate to non-zero if the file descriptor fd is a member of the set
* pointed to by fdsetp, and shall evaluate to zero otherwise.
*
* @param fd The socket descriptor.
* @param fdsetp The descriptor set.
*
* @return Nonzero if fd is member of the descriptor set.
*/
PJ_DECL(pj_bool_t) PJ_FD_ISSET(pj_sock_t fd, const pj_fd_set_t *fdsetp);
/**
* Get the number of descriptors in the set.
*
* @param fdsetp The descriptor set.
*
* @return Number of descriptors in the set.
*/
PJ_DECL(pj_size_t) PJ_FD_COUNT(const pj_fd_set_t *fdsetp);
/**
* This function wait for a number of file descriptors to change status.
* The behaviour is the same as select() function call which appear in
* standard BSD socket libraries.
*
* @param n On Unices, this specifies the highest-numbered
* descriptor in any of the three set, plus 1. On Windows,
* the value is ignored.
* @param readfds Optional pointer to a set of sockets to be checked for
* readability.
* @param writefds Optional pointer to a set of sockets to be checked for
* writability.
* @param exceptfds Optional pointer to a set of sockets to be checked for
* errors.
* @param timeout Maximum time for select to wait, or null for blocking
* operations.
*
* @return The total number of socket handles that are ready, or
* zero if the time limit expired, or -1 if an error occurred.
*/
PJ_DECL(int) pj_sock_select( int n,
pj_fd_set_t *readfds,
pj_fd_set_t *writefds,
pj_fd_set_t *exceptfds,
const pj_time_val *timeout);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_SELECT_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,162 +1,162 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/string_i.h 8 10/14/05 12:26a Bennylp $ */
PJ_IDEF(pj_str_t) pj_str(char *str)
{
pj_str_t dst;
dst.ptr = str;
dst.slen = str ? strlen(str) : 0;
return dst;
}
PJ_IDEF(pj_str_t*) pj_strdup(pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t *src)
{
if (src->slen) {
dst->ptr = (char*)pj_pool_alloc(pool, src->slen);
pj_memcpy(dst->ptr, src->ptr, src->slen);
}
dst->slen = src->slen;
return dst;
}
PJ_IDEF(pj_str_t*) pj_strdup_with_null( pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t *src)
{
if (src->slen) {
dst->ptr = (char*)pj_pool_alloc(pool, src->slen+1);
pj_memcpy(dst->ptr, src->ptr, src->slen);
} else {
dst->ptr = (char*)pj_pool_alloc(pool, 1);
}
dst->slen = src->slen;
dst->ptr[dst->slen] = '\0';
return dst;
}
PJ_IDEF(pj_str_t*) pj_strdup2(pj_pool_t *pool,
pj_str_t *dst,
const char *src)
{
dst->slen = src ? strlen(src) : 0;
if (dst->slen) {
dst->ptr = (char*)pj_pool_alloc(pool, dst->slen);
pj_memcpy(dst->ptr, src, dst->slen);
} else {
dst->ptr = NULL;
}
return dst;
}
PJ_IDEF(pj_str_t) pj_strdup3(pj_pool_t *pool, const char *src)
{
pj_str_t temp;
pj_strdup2(pool, &temp, src);
return temp;
}
PJ_IDEF(pj_str_t*) pj_strassign( pj_str_t *dst, pj_str_t *src )
{
dst->ptr = src->ptr;
dst->slen = src->slen;
return dst;
}
PJ_IDEF(pj_str_t*) pj_strcpy(pj_str_t *dst, const pj_str_t *src)
{
dst->slen = src->slen;
if (src->slen > 0)
pj_memcpy(dst->ptr, src->ptr, src->slen);
return dst;
}
PJ_IDEF(pj_str_t*) pj_strcpy2(pj_str_t *dst, const char *src)
{
dst->slen = src ? strlen(src) : 0;
if (dst->slen > 0)
pj_memcpy(dst->ptr, src, dst->slen);
return dst;
}
PJ_IDEF(int) pj_strcmp( const pj_str_t *str1, const pj_str_t *str2)
{
pj_ssize_t diff;
diff = str1->slen - str2->slen;
if (diff) {
return (int)diff;
} else if (str1->ptr) {
return strncmp(str1->ptr, str2->ptr, str1->slen);
} else {
return 0;
}
}
PJ_IDEF(int) pj_strncmp( const pj_str_t *str1, const pj_str_t *str2,
pj_size_t len)
{
return (str1->ptr && str2->ptr) ? strncmp(str1->ptr, str2->ptr, len) :
(str1->ptr == str2->ptr ? 0 : 1);
}
PJ_IDEF(int) pj_strncmp2( const pj_str_t *str1, const char *str2,
pj_size_t len)
{
return (str1->ptr && str2) ? strncmp(str1->ptr, str2, len) :
(str1->ptr==str2 ? 0 : 1);
}
PJ_IDEF(int) pj_strcmp2( const pj_str_t *str1, const char *str2 )
{
return pj_strncmp2( str1, str2, str1->slen);
}
PJ_IDEF(int) pj_stricmp( const pj_str_t *str1, const pj_str_t *str2)
{
pj_ssize_t diff;
diff = str1->slen - str2->slen;
if (diff) {
return (int)diff;
} else {
return strnicmp(str1->ptr, str2->ptr, str1->slen);
}
}
PJ_IDEF(int) pj_stricmp2( const pj_str_t *str1, const char *str2)
{
return (str1->ptr && str2) ? strnicmp(str1->ptr, str2, str1->slen) :
(str1->ptr==str2 ? 0 : 1);
}
PJ_IDEF(int) pj_strnicmp( const pj_str_t *str1, const pj_str_t *str2,
pj_size_t len)
{
return (str1->ptr && str2->ptr) ? strnicmp(str1->ptr, str2->ptr, len) :
(str1->ptr == str2->ptr ? 0 : 1);
}
PJ_IDEF(int) pj_strnicmp2( const pj_str_t *str1, const char *str2,
pj_size_t len)
{
return (str1->ptr && str2) ? strnicmp(str1->ptr, str2, len) :
(str1->ptr == str2 ? 0 : 1);
}
PJ_IDEF(void) pj_strcat(pj_str_t *dst, const pj_str_t *src)
{
if (src->slen) {
pj_memcpy(dst->ptr + dst->slen, src->ptr, src->slen);
dst->slen += src->slen;
}
}
PJ_IDEF(pj_str_t*) pj_strtrim( pj_str_t *str )
{
pj_strltrim(str);
pj_strrtrim(str);
return str;
}
/* $Header: /pjproject-0.3/pjlib/include/pj/string_i.h 8 10/14/05 12:26a Bennylp $ */
PJ_IDEF(pj_str_t) pj_str(char *str)
{
pj_str_t dst;
dst.ptr = str;
dst.slen = str ? strlen(str) : 0;
return dst;
}
PJ_IDEF(pj_str_t*) pj_strdup(pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t *src)
{
if (src->slen) {
dst->ptr = (char*)pj_pool_alloc(pool, src->slen);
pj_memcpy(dst->ptr, src->ptr, src->slen);
}
dst->slen = src->slen;
return dst;
}
PJ_IDEF(pj_str_t*) pj_strdup_with_null( pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t *src)
{
if (src->slen) {
dst->ptr = (char*)pj_pool_alloc(pool, src->slen+1);
pj_memcpy(dst->ptr, src->ptr, src->slen);
} else {
dst->ptr = (char*)pj_pool_alloc(pool, 1);
}
dst->slen = src->slen;
dst->ptr[dst->slen] = '\0';
return dst;
}
PJ_IDEF(pj_str_t*) pj_strdup2(pj_pool_t *pool,
pj_str_t *dst,
const char *src)
{
dst->slen = src ? strlen(src) : 0;
if (dst->slen) {
dst->ptr = (char*)pj_pool_alloc(pool, dst->slen);
pj_memcpy(dst->ptr, src, dst->slen);
} else {
dst->ptr = NULL;
}
return dst;
}
PJ_IDEF(pj_str_t) pj_strdup3(pj_pool_t *pool, const char *src)
{
pj_str_t temp;
pj_strdup2(pool, &temp, src);
return temp;
}
PJ_IDEF(pj_str_t*) pj_strassign( pj_str_t *dst, pj_str_t *src )
{
dst->ptr = src->ptr;
dst->slen = src->slen;
return dst;
}
PJ_IDEF(pj_str_t*) pj_strcpy(pj_str_t *dst, const pj_str_t *src)
{
dst->slen = src->slen;
if (src->slen > 0)
pj_memcpy(dst->ptr, src->ptr, src->slen);
return dst;
}
PJ_IDEF(pj_str_t*) pj_strcpy2(pj_str_t *dst, const char *src)
{
dst->slen = src ? strlen(src) : 0;
if (dst->slen > 0)
pj_memcpy(dst->ptr, src, dst->slen);
return dst;
}
PJ_IDEF(int) pj_strcmp( const pj_str_t *str1, const pj_str_t *str2)
{
pj_ssize_t diff;
diff = str1->slen - str2->slen;
if (diff) {
return (int)diff;
} else if (str1->ptr) {
return strncmp(str1->ptr, str2->ptr, str1->slen);
} else {
return 0;
}
}
PJ_IDEF(int) pj_strncmp( const pj_str_t *str1, const pj_str_t *str2,
pj_size_t len)
{
return (str1->ptr && str2->ptr) ? strncmp(str1->ptr, str2->ptr, len) :
(str1->ptr == str2->ptr ? 0 : 1);
}
PJ_IDEF(int) pj_strncmp2( const pj_str_t *str1, const char *str2,
pj_size_t len)
{
return (str1->ptr && str2) ? strncmp(str1->ptr, str2, len) :
(str1->ptr==str2 ? 0 : 1);
}
PJ_IDEF(int) pj_strcmp2( const pj_str_t *str1, const char *str2 )
{
return pj_strncmp2( str1, str2, str1->slen);
}
PJ_IDEF(int) pj_stricmp( const pj_str_t *str1, const pj_str_t *str2)
{
pj_ssize_t diff;
diff = str1->slen - str2->slen;
if (diff) {
return (int)diff;
} else {
return strnicmp(str1->ptr, str2->ptr, str1->slen);
}
}
PJ_IDEF(int) pj_stricmp2( const pj_str_t *str1, const char *str2)
{
return (str1->ptr && str2) ? strnicmp(str1->ptr, str2, str1->slen) :
(str1->ptr==str2 ? 0 : 1);
}
PJ_IDEF(int) pj_strnicmp( const pj_str_t *str1, const pj_str_t *str2,
pj_size_t len)
{
return (str1->ptr && str2->ptr) ? strnicmp(str1->ptr, str2->ptr, len) :
(str1->ptr == str2->ptr ? 0 : 1);
}
PJ_IDEF(int) pj_strnicmp2( const pj_str_t *str1, const char *str2,
pj_size_t len)
{
return (str1->ptr && str2) ? strnicmp(str1->ptr, str2, len) :
(str1->ptr == str2 ? 0 : 1);
}
PJ_IDEF(void) pj_strcat(pj_str_t *dst, const pj_str_t *src)
{
if (src->slen) {
pj_memcpy(dst->ptr + dst->slen, src->ptr, src->slen);
dst->slen += src->slen;
}
}
PJ_IDEF(pj_str_t*) pj_strtrim( pj_str_t *str )
{
pj_strltrim(str);
pj_strrtrim(str);
return str;
}

View File

@ -1,123 +1,123 @@
#ifndef __PJ_STUN_H__
#define __PJ_STUN_H__
#include <pj/types.h>
#include <pj/sock.h>
PJ_BEGIN_DECL
#define PJ_STUN_MAX_ATTR 16
typedef enum pj_stun_msg_type
{
PJ_STUN_BINDING_REQUEST = 0x0001,
PJ_STUN_BINDING_RESPONSE = 0x0101,
PJ_STUN_BINDING_ERROR_RESPONSE = 0x0111,
PJ_STUN_SHARED_SECRET_REQUEST = 0x0002,
PJ_STUN_SHARED_SECRET_RESPONSE = 0x0102,
PJ_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112
} pj_stun_msg_type;
typedef enum pj_stun_attr_type
{
PJ_STUN_ATTR_MAPPED_ADDR = 1,
PJ_STUN_ATTR_RESPONSE_ADDR,
PJ_STUN_ATTR_CHANGE_REQUEST,
PJ_STUN_ATTR_SOURCE_ADDR,
PJ_STUN_ATTR_CHANGED_ADDR,
PJ_STUN_ATTR_USERNAME,
PJ_STUN_ATTR_PASSWORD,
PJ_STUN_ATTR_MESSAGE_INTEGRITY,
PJ_STUN_ATTR_ERROR_CODE,
PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES,
PJ_STUN_ATTR_REFLECTED_FORM
} pj_stun_attr_type;
typedef struct pj_stun_msg_hdr
{
pj_uint16_t type;
pj_uint16_t length;
pj_uint32_t tsx[4];
} pj_stun_msg_hdr;
typedef struct pj_stun_attr_hdr
{
pj_uint16_t type;
pj_uint16_t length;
} pj_stun_attr_hdr;
typedef struct pj_stun_mapped_addr_attr
{
pj_stun_attr_hdr hdr;
pj_uint8_t ignored;
pj_uint8_t family;
pj_uint16_t port;
pj_uint32_t addr;
} pj_stun_mapped_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_response_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_changed_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_src_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_reflected_form_attr;
typedef struct pj_stun_change_request_attr
{
pj_stun_attr_hdr hdr;
pj_uint32_t value;
} pj_stun_change_request_attr;
typedef struct pj_stun_username_attr
{
pj_stun_attr_hdr hdr;
pj_uint32_t value[1];
} pj_stun_username_attr;
typedef pj_stun_username_attr pj_stun_password_attr;
typedef struct pj_stun_error_code_attr
{
pj_stun_attr_hdr hdr;
pj_uint16_t ignored;
pj_uint8_t err_class;
pj_uint8_t number;
char reason[4];
} pj_stun_error_code_attr;
typedef struct pj_stun_msg
{
pj_stun_msg_hdr *hdr;
int attr_count;
pj_stun_attr_hdr *attr[PJ_STUN_MAX_ATTR];
} pj_stun_msg;
/* STUN message API (stun.c). */
PJ_DECL(pj_status_t) pj_stun_create_bind_req( pj_pool_t *pool,
void **msg, pj_size_t *len,
pj_uint32_t id_hi,
pj_uint32_t id_lo);
PJ_DECL(pj_status_t) pj_stun_parse_msg( void *buf, pj_size_t len,
pj_stun_msg *msg);
PJ_DECL(void*) pj_stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t);
/* STUN simple client API (stun_client.c) */
enum pj_stun_err_code {
PJ_STUN_ERR_MEMORY = (-2),
PJ_STUN_ERR_RESOLVE = (-3),
PJ_STUN_ERR_TRANSPORT = (-4),
PJ_STUN_ERR_INVALID_MSG = (-5),
PJ_STUN_ERR_NO_RESPONSE = (-6),
PJ_STUN_ERR_SYMETRIC = (-7),
};
PJ_DECL(pj_status_t) pj_stun_get_mapped_addr( pj_pool_factory *pf,
int sock_cnt, pj_sock_t sock[],
const pj_str_t *srv1, int port1,
const pj_str_t *srv2, int port2,
pj_sockaddr_in mapped_addr[]);
PJ_DECL(const char*) pj_stun_get_err_msg(pj_status_t status);
PJ_END_DECL
#endif /* __PJ_STUN_H__ */
#ifndef __PJ_STUN_H__
#define __PJ_STUN_H__
#include <pj/types.h>
#include <pj/sock.h>
PJ_BEGIN_DECL
#define PJ_STUN_MAX_ATTR 16
typedef enum pj_stun_msg_type
{
PJ_STUN_BINDING_REQUEST = 0x0001,
PJ_STUN_BINDING_RESPONSE = 0x0101,
PJ_STUN_BINDING_ERROR_RESPONSE = 0x0111,
PJ_STUN_SHARED_SECRET_REQUEST = 0x0002,
PJ_STUN_SHARED_SECRET_RESPONSE = 0x0102,
PJ_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112
} pj_stun_msg_type;
typedef enum pj_stun_attr_type
{
PJ_STUN_ATTR_MAPPED_ADDR = 1,
PJ_STUN_ATTR_RESPONSE_ADDR,
PJ_STUN_ATTR_CHANGE_REQUEST,
PJ_STUN_ATTR_SOURCE_ADDR,
PJ_STUN_ATTR_CHANGED_ADDR,
PJ_STUN_ATTR_USERNAME,
PJ_STUN_ATTR_PASSWORD,
PJ_STUN_ATTR_MESSAGE_INTEGRITY,
PJ_STUN_ATTR_ERROR_CODE,
PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES,
PJ_STUN_ATTR_REFLECTED_FORM
} pj_stun_attr_type;
typedef struct pj_stun_msg_hdr
{
pj_uint16_t type;
pj_uint16_t length;
pj_uint32_t tsx[4];
} pj_stun_msg_hdr;
typedef struct pj_stun_attr_hdr
{
pj_uint16_t type;
pj_uint16_t length;
} pj_stun_attr_hdr;
typedef struct pj_stun_mapped_addr_attr
{
pj_stun_attr_hdr hdr;
pj_uint8_t ignored;
pj_uint8_t family;
pj_uint16_t port;
pj_uint32_t addr;
} pj_stun_mapped_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_response_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_changed_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_src_addr_attr;
typedef pj_stun_mapped_addr_attr pj_stun_reflected_form_attr;
typedef struct pj_stun_change_request_attr
{
pj_stun_attr_hdr hdr;
pj_uint32_t value;
} pj_stun_change_request_attr;
typedef struct pj_stun_username_attr
{
pj_stun_attr_hdr hdr;
pj_uint32_t value[1];
} pj_stun_username_attr;
typedef pj_stun_username_attr pj_stun_password_attr;
typedef struct pj_stun_error_code_attr
{
pj_stun_attr_hdr hdr;
pj_uint16_t ignored;
pj_uint8_t err_class;
pj_uint8_t number;
char reason[4];
} pj_stun_error_code_attr;
typedef struct pj_stun_msg
{
pj_stun_msg_hdr *hdr;
int attr_count;
pj_stun_attr_hdr *attr[PJ_STUN_MAX_ATTR];
} pj_stun_msg;
/* STUN message API (stun.c). */
PJ_DECL(pj_status_t) pj_stun_create_bind_req( pj_pool_t *pool,
void **msg, pj_size_t *len,
pj_uint32_t id_hi,
pj_uint32_t id_lo);
PJ_DECL(pj_status_t) pj_stun_parse_msg( void *buf, pj_size_t len,
pj_stun_msg *msg);
PJ_DECL(void*) pj_stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t);
/* STUN simple client API (stun_client.c) */
enum pj_stun_err_code {
PJ_STUN_ERR_MEMORY = (-2),
PJ_STUN_ERR_RESOLVE = (-3),
PJ_STUN_ERR_TRANSPORT = (-4),
PJ_STUN_ERR_INVALID_MSG = (-5),
PJ_STUN_ERR_NO_RESPONSE = (-6),
PJ_STUN_ERR_SYMETRIC = (-7),
};
PJ_DECL(pj_status_t) pj_stun_get_mapped_addr( pj_pool_factory *pf,
int sock_cnt, pj_sock_t sock[],
const pj_str_t *srv1, int port1,
const pj_str_t *srv2, int port2,
pj_sockaddr_in mapped_addr[]);
PJ_DECL(const char*) pj_stun_get_err_msg(pj_status_t status);
PJ_END_DECL
#endif /* __PJ_STUN_H__ */

View File

@ -1,237 +1,237 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/timer.h 7 10/14/05 12:26a Bennylp $ */
/* (C)1993-2003 Douglas C. Schmidt
*
* This file is originaly from ACE library by Doug Schmidt
* ACE(TM), TAO(TM) and CIAO(TM) are copyrighted by Douglas C. Schmidt and his research
* group at Washington University, University of California, Irvine, and Vanderbilt
* University Copyright (c) 1993-2003, all rights reserved.
*
*/
#ifndef __PJ_TIMER_H__
#define __PJ_TIMER_H__
/**
* @file timer.h
* @brief Timer Heap
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_TIMER Timer Heap Management.
* @ingroup PJ_MISC
* @brief
* The timer scheduling implementation here is based on ACE library's
* ACE_Timer_Heap, with only little modification to suit our library's style
* (I even left most of the comments in the original source).
*
* To quote the original quote in ACE_Timer_Heap_T class:
*
* This implementation uses a heap-based callout queue of
* absolute times. Therefore, in the average and worst case,
* scheduling, canceling, and expiring timers is O(log N) (where
* N is the total number of timers). In addition, we can also
* preallocate as many \a ACE_Timer_Nodes as there are slots in
* the heap. This allows us to completely remove the need for
* dynamic memory allocation, which is important for real-time
* systems.
* @{
*
* \section pj_timer_examples_sec Examples
*
* For some examples on how to use the timer heap, please see the link below.
*
* - \ref page_pjlib_timer_test
*/
/**
* The type for internal timer ID.
*/
typedef int pj_timer_id_t;
/**
* Forward declaration for pj_timer_entry.
*/
struct pj_timer_entry;
/**
* The type of callback function to be called by timer scheduler when a timer
* has expired.
*
* @param timer_heap The timer heap.
* @param entry Timer entry which timer's has expired.
*/
typedef void pj_timer_heap_callback(pj_timer_heap_t *timer_heap,
struct pj_timer_entry *entry);
/**
* This structure represents an entry to the timer.
*/
struct pj_timer_entry
{
/**
* User data to be associated with this entry.
* Applications normally will put the instance of object that
* owns the timer entry in this field.
*/
void *user_data;
/**
* Arbitrary ID assigned by the user/owner of this entry.
* Applications can use this ID to distinguish multiple
* timer entries that share the same callback and user_data.
*/
int id;
/**
* Callback to be called when the timer expires.
*/
pj_timer_heap_callback *cb;
/**
* Internal unique timer ID, which is assigned by the timer heap.
* Application should not touch this ID.
*/
pj_timer_id_t _timer_id;
/**
* The future time when the timer expires, which the value is updated
* by timer heap when the timer is scheduled.
*/
pj_time_val _timer_value;
};
/**
* Default flag for timer heap, indicates that synchronization will be
* used.
*/
#define PJ_TIMER_HEAP_SYNCHRONIZE (0)
/**
* Flag to indicate that thread synchronization is NOT needed for the
* timer heap.
*/
#define PJ_TIMER_HEAP_NO_SYNCHRONIZE (1)
/**
* Calculate memory size required to create a timer heap.
*
* @param count Number of timer entries to be supported.
* @return Memory size requirement in bytes.
*/
PJ_DECL(pj_size_t) pj_timer_heap_mem_size(pj_size_t count);
/**
* Create a timer heap.
*
* @param pool The pool where allocations in the timer heap will be
* allocated. The timer heap will dynamicly allocate
* more storate from the pool if the number of timer
* entries registered is more than the size originally
* requested when calling this function.
* @param count The maximum number of timer entries to be supported
* initially. If the application registers more entries
* during runtime, then the timer heap will resize.
* @param flag Creation flag, currently only PJ_TIMER_HEAP_NO_SYNCHRONIZE
* is recognized..
* @param ht Pointer to receive the created timer heap.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_timer_heap_create( pj_pool_t *pool,
pj_size_t count,
unsigned flag,
pj_timer_heap_t **ht);
/**
* Initialize a timer entry. Application should call this function at least
* once before scheduling the entry to the timer heap, to properly initialize
* the timer entry.
*
* @param entry The timer entry to be initialized.
* @param id Arbitrary ID assigned by the user/owner of this entry.
* Applications can use this ID to distinguish multiple
* timer entries that share the same callback and user_data.
* @param user_data User data to be associated with this entry.
* Applications normally will put the instance of object that
* owns the timer entry in this field.
* @param cb Callback function to be called when the timer elapses.
*
* @return The timer entry itself.
*/
PJ_DECL(pj_timer_entry*) pj_timer_entry_init( pj_timer_entry *entry,
int id,
void *user_data,
pj_timer_heap_callback *cb );
/**
* Schedule a timer entry which will expire AFTER the specified delay.
*
* @param ht The timer heap.
* @param entry The entry to be registered.
* @param delay The interval to expire.
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_timer_heap_schedule( pj_timer_heap_t *ht,
pj_timer_entry *entry,
const pj_time_val *delay);
/**
* Cancel a previously registered timer.
*
* @param ht The timer heap.
* @param entry The entry to be cancelled.
* @return The number of timer cancelled, which should be one if the
* entry has really been registered, or zero if no timer was
* cancelled.
*/
PJ_DECL(int) pj_timer_heap_cancel( pj_timer_heap_t *ht,
pj_timer_entry *entry);
/**
* Get the number of timer entries.
*
* @param ht The timer heap.
* @return The number of timer entries.
*/
PJ_DECL(pj_size_t) pj_timer_heap_count( pj_timer_heap_t *ht );
/**
* Get the earliest time registered in the timer heap. The timer heap
* MUST have at least one timer being scheduled (application should use
* #pj_timer_heap_count() before calling this function).
*
* @param ht The timer heap.
* @param timeval The time deadline of the earliest timer entry.
*
* @return PJ_SUCCESS, or PJ_ENOTFOUND if no entry is scheduled.
*/
PJ_DECL(pj_status_t) pj_timer_heap_earliest_time( pj_timer_heap_t *ht,
pj_time_val *timeval);
/**
* Poll the timer heap, check for expired timers and call the callback for
* each of the expired timers.
*
* @param ht The timer heap.
* @param next_delay If this parameter is not NULL, it will be filled up with
* the time delay until the next timer elapsed, or -1 in
* the sec part if no entry exist.
* @return The number of timers expired.
*/
PJ_DECL(int) pj_timer_heap_poll( pj_timer_heap_t *ht, pj_time_val *next_delay);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_TIMER_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/timer.h 7 10/14/05 12:26a Bennylp $ */
/* (C)1993-2003 Douglas C. Schmidt
*
* This file is originaly from ACE library by Doug Schmidt
* ACE(TM), TAO(TM) and CIAO(TM) are copyrighted by Douglas C. Schmidt and his research
* group at Washington University, University of California, Irvine, and Vanderbilt
* University Copyright (c) 1993-2003, all rights reserved.
*
*/
#ifndef __PJ_TIMER_H__
#define __PJ_TIMER_H__
/**
* @file timer.h
* @brief Timer Heap
*/
#include <pj/types.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_TIMER Timer Heap Management.
* @ingroup PJ_MISC
* @brief
* The timer scheduling implementation here is based on ACE library's
* ACE_Timer_Heap, with only little modification to suit our library's style
* (I even left most of the comments in the original source).
*
* To quote the original quote in ACE_Timer_Heap_T class:
*
* This implementation uses a heap-based callout queue of
* absolute times. Therefore, in the average and worst case,
* scheduling, canceling, and expiring timers is O(log N) (where
* N is the total number of timers). In addition, we can also
* preallocate as many \a ACE_Timer_Nodes as there are slots in
* the heap. This allows us to completely remove the need for
* dynamic memory allocation, which is important for real-time
* systems.
* @{
*
* \section pj_timer_examples_sec Examples
*
* For some examples on how to use the timer heap, please see the link below.
*
* - \ref page_pjlib_timer_test
*/
/**
* The type for internal timer ID.
*/
typedef int pj_timer_id_t;
/**
* Forward declaration for pj_timer_entry.
*/
struct pj_timer_entry;
/**
* The type of callback function to be called by timer scheduler when a timer
* has expired.
*
* @param timer_heap The timer heap.
* @param entry Timer entry which timer's has expired.
*/
typedef void pj_timer_heap_callback(pj_timer_heap_t *timer_heap,
struct pj_timer_entry *entry);
/**
* This structure represents an entry to the timer.
*/
struct pj_timer_entry
{
/**
* User data to be associated with this entry.
* Applications normally will put the instance of object that
* owns the timer entry in this field.
*/
void *user_data;
/**
* Arbitrary ID assigned by the user/owner of this entry.
* Applications can use this ID to distinguish multiple
* timer entries that share the same callback and user_data.
*/
int id;
/**
* Callback to be called when the timer expires.
*/
pj_timer_heap_callback *cb;
/**
* Internal unique timer ID, which is assigned by the timer heap.
* Application should not touch this ID.
*/
pj_timer_id_t _timer_id;
/**
* The future time when the timer expires, which the value is updated
* by timer heap when the timer is scheduled.
*/
pj_time_val _timer_value;
};
/**
* Default flag for timer heap, indicates that synchronization will be
* used.
*/
#define PJ_TIMER_HEAP_SYNCHRONIZE (0)
/**
* Flag to indicate that thread synchronization is NOT needed for the
* timer heap.
*/
#define PJ_TIMER_HEAP_NO_SYNCHRONIZE (1)
/**
* Calculate memory size required to create a timer heap.
*
* @param count Number of timer entries to be supported.
* @return Memory size requirement in bytes.
*/
PJ_DECL(pj_size_t) pj_timer_heap_mem_size(pj_size_t count);
/**
* Create a timer heap.
*
* @param pool The pool where allocations in the timer heap will be
* allocated. The timer heap will dynamicly allocate
* more storate from the pool if the number of timer
* entries registered is more than the size originally
* requested when calling this function.
* @param count The maximum number of timer entries to be supported
* initially. If the application registers more entries
* during runtime, then the timer heap will resize.
* @param flag Creation flag, currently only PJ_TIMER_HEAP_NO_SYNCHRONIZE
* is recognized..
* @param ht Pointer to receive the created timer heap.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_timer_heap_create( pj_pool_t *pool,
pj_size_t count,
unsigned flag,
pj_timer_heap_t **ht);
/**
* Initialize a timer entry. Application should call this function at least
* once before scheduling the entry to the timer heap, to properly initialize
* the timer entry.
*
* @param entry The timer entry to be initialized.
* @param id Arbitrary ID assigned by the user/owner of this entry.
* Applications can use this ID to distinguish multiple
* timer entries that share the same callback and user_data.
* @param user_data User data to be associated with this entry.
* Applications normally will put the instance of object that
* owns the timer entry in this field.
* @param cb Callback function to be called when the timer elapses.
*
* @return The timer entry itself.
*/
PJ_DECL(pj_timer_entry*) pj_timer_entry_init( pj_timer_entry *entry,
int id,
void *user_data,
pj_timer_heap_callback *cb );
/**
* Schedule a timer entry which will expire AFTER the specified delay.
*
* @param ht The timer heap.
* @param entry The entry to be registered.
* @param delay The interval to expire.
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_timer_heap_schedule( pj_timer_heap_t *ht,
pj_timer_entry *entry,
const pj_time_val *delay);
/**
* Cancel a previously registered timer.
*
* @param ht The timer heap.
* @param entry The entry to be cancelled.
* @return The number of timer cancelled, which should be one if the
* entry has really been registered, or zero if no timer was
* cancelled.
*/
PJ_DECL(int) pj_timer_heap_cancel( pj_timer_heap_t *ht,
pj_timer_entry *entry);
/**
* Get the number of timer entries.
*
* @param ht The timer heap.
* @return The number of timer entries.
*/
PJ_DECL(pj_size_t) pj_timer_heap_count( pj_timer_heap_t *ht );
/**
* Get the earliest time registered in the timer heap. The timer heap
* MUST have at least one timer being scheduled (application should use
* #pj_timer_heap_count() before calling this function).
*
* @param ht The timer heap.
* @param timeval The time deadline of the earliest timer entry.
*
* @return PJ_SUCCESS, or PJ_ENOTFOUND if no entry is scheduled.
*/
PJ_DECL(pj_status_t) pj_timer_heap_earliest_time( pj_timer_heap_t *ht,
pj_time_val *timeval);
/**
* Poll the timer heap, check for expired timers and call the callback for
* each of the expired timers.
*
* @param ht The timer heap.
* @param next_delay If this parameter is not NULL, it will be filled up with
* the time delay until the next timer elapsed, or -1 in
* the sec part if no entry exist.
* @return The number of timers expired.
*/
PJ_DECL(int) pj_timer_heap_poll( pj_timer_heap_t *ht, pj_time_val *next_delay);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_TIMER_H__ */

View File

@ -1,418 +1,418 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/types.h 11 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_TYPES_H__
#define __PJ_TYPES_H__
/**
* @defgroup PJ PJ Library
*/
/**
* @file types.h
* @brief Declaration of basic types and utility.
*/
/**
* @defgroup PJ_BASIC Basic Data Types and Library Functionality.
* @ingroup PJ_DS
* @{
*/
#include <pj/config.h>
PJ_BEGIN_DECL
///////////////////////////////////////////////////////////////////////////////
/** Unsigned 32bit integer. */
typedef int pj_int32_t;
/** Signed 32bit integer. */
typedef unsigned int pj_uint32_t;
/** Unsigned 16bit integer. */
typedef short pj_int16_t;
/** Signed 16bit integer. */
typedef unsigned short pj_uint16_t;
/** Unsigned 8bit integer. */
typedef signed char pj_int8_t;
/** Signed 16bit integer. */
typedef unsigned char pj_uint8_t;
/** Large unsigned integer. */
typedef size_t pj_size_t;
/** Large signed integer. */
typedef long pj_ssize_t;
/** Status code. */
typedef int pj_status_t;
/** Boolean. */
typedef int pj_bool_t;
/** Status is OK. */
#define PJ_SUCCESS 0
/** True value. */
#define PJ_TRUE 1
/** False value. */
#define PJ_FALSE 0
///////////////////////////////////////////////////////////////////////////////
/*
* Data structure types.
*/
/**
* This type is used as replacement to legacy C string, and used throughout
* the library. By convention, the string is NOT null terminated.
*/
struct pj_str_t
{
/** Buffer pointer, which is by convention NOT null terminated. */
char *ptr;
/** The length of the string. */
pj_ssize_t slen;
};
/**
* The opaque data type for linked list, which is used as arguments throughout
* the linked list operations.
*/
typedef void pj_list_type;
/**
* List.
*/
typedef struct pj_list pj_list;
/**
* Opaque data type for hash tables.
*/
typedef struct pj_hash_table_t pj_hash_table_t;
/**
* Opaque data type for hash entry (only used internally by hash table).
*/
typedef struct pj_hash_entry pj_hash_entry;
/**
* Data type for hash search iterator.
* This structure should be opaque, however applications need to declare
* concrete variable of this type, that's why the declaration is visible here.
*/
typedef struct pj_hash_iterator_t
{
pj_uint32_t index; /**< Internal index. */
pj_hash_entry *entry; /**< Internal entry. */
} pj_hash_iterator_t;
/**
* Forward declaration for memory pool factory.
*/
typedef struct pj_pool_factory pj_pool_factory;
/**
* Opaque data type for memory pool.
*/
typedef struct pj_pool_t pj_pool_t;
/**
* Forward declaration for caching pool, a pool factory implementation.
*/
typedef struct pj_caching_pool pj_caching_pool;
/**
* This type is used as replacement to legacy C string, and used throughout
* the library.
*/
typedef struct pj_str_t pj_str_t;
/**
* Opaque data type for I/O Queue structure.
*/
typedef struct pj_ioqueue_t pj_ioqueue_t;
/**
* Opaque data type for key that identifies a handle registered to the
* I/O queue framework.
*/
typedef struct pj_ioqueue_key_t pj_ioqueue_key_t;
/**
* Opaque data to identify timer heap.
*/
typedef struct pj_timer_heap_t pj_timer_heap_t;
/**
* Forward declaration for timer entry.
*/
typedef struct pj_timer_entry pj_timer_entry;
/**
* Opaque data type for atomic operations.
*/
typedef struct pj_atomic_t pj_atomic_t;
/**
* Value type of an atomic variable.
*/
typedef PJ_ATOMIC_VALUE_TYPE pj_atomic_value_t;
///////////////////////////////////////////////////////////////////////////////
/** Thread handle. */
typedef struct pj_thread_t pj_thread_t;
/** Lock object. */
typedef struct pj_lock_t pj_lock_t;
/** Mutex handle. */
typedef struct pj_mutex_t pj_mutex_t;
/** Semaphore handle. */
typedef struct pj_sem_t pj_sem_t;
/** Event object. */
typedef struct pj_event_t pj_event_t;
/** Unidirectional stream pipe object. */
typedef struct pj_pipe_t pj_pipe_t;
/** Operating system handle. */
typedef void *pj_oshandle_t;
/** Socket handle. */
typedef long pj_sock_t;
/** Generic socket address. */
typedef void pj_sockaddr_t;
/** Color type. */
typedef unsigned int pj_color_t;
/** Exception id. */
typedef int pj_exception_id_t;
///////////////////////////////////////////////////////////////////////////////
/** Utility macro to compute the number of elements in static array. */
#define PJ_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
/** Maximum value for signed 32-bit integer. */
#define PJ_MAXINT32 0x7FFFFFFFL
/**
* Length of object names.
*/
#define PJ_MAX_OBJ_NAME 16
///////////////////////////////////////////////////////////////////////////////
/*
* General.
*/
/**
* Initialize the PJ Library.
* This function must be called before using the library. The purpose of this
* function is to initialize static library data, such as character table used
* in random string generation, and to initialize operating system dependent
* functionality (such as WSAStartup() in Windows).
*/
PJ_DECL(pj_status_t) pj_init(void);
/**
* @}
*/
/**
* @addtogroup PJ_TIME Time Data Type and Manipulation.
* @ingroup PJ_MISC
* @{
*/
/**
* Representation of time value in this library.
* This type can be used to represent either an interval or a specific time
* or date.
*/
typedef struct pj_time_val
{
/** The seconds part of the time. */
long sec;
/** The miliseconds fraction of the time. */
long msec;
} pj_time_val;
/**
* Normalize the value in time value.
* @param t Time value to be normalized.
*/
PJ_DECL(void) pj_time_val_normalize(pj_time_val *t);
/**
* Get the total time value in miliseconds. This is the same as
* multiplying the second part with 1000 and then add the miliseconds
* part to the result.
*
* @param t The time value.
* @return Total time in miliseconds.
* @hideinitializer
*/
#define PJ_TIME_VAL_MSEC(t) ((t).sec * 1000 + (t).msec)
/**
* This macro will check if \a t1 is equal to \a t2.
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if both time values are equal.
* @hideinitializer
*/
#define PJ_TIME_VAL_EQ(t1, t2) ((t1).sec==(t2).sec && (t1).msec==(t2).msec)
/**
* This macro will check if \a t1 is greater than \a t2
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is greater than t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_GT(t1, t2) ((t1).sec>(t2).sec || \
((t1).sec==(t2).sec && (t1).msec>(t2).msec))
/**
* This macro will check if \a t1 is greater than or equal to \a t2
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is greater than or equal to t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_GTE(t1, t2) (PJ_TIME_VAL_GT(t1,t2) || \
PJ_TIME_VAL_EQ(t1,t2))
/**
* This macro will check if \a t1 is less than \a t2
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is less than t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_LT(t1, t2) (!(PJ_TIME_VAL_GTE(t1,t2)))
/**
* This macro will check if \a t1 is less than or equal to \a t2.
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is less than or equal to t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_LTE(t1, t2) (!PJ_TIME_VAL_GT(t1, t2))
/**
* Add \a t2 to \a t1 and store the result in \a t1. Effectively
*
* this macro will expand as: (\a t1 += \a t2).
* @param t1 The time value to add.
* @param t2 The time value to be added to \a t1.
* @hideinitializer
*/
#define PJ_TIME_VAL_ADD(t1, t2) do { \
(t1).sec += (t2).sec; \
(t1).msec += (t2).msec; \
pj_time_val_normalize(&(t1)); \
} while (0)
/**
* Substract \a t2 from \a t1 and store the result in \a t1. Effectively
* this macro will expand as (\a t1 -= \a t2).
*
* @param t1 The time value to subsctract.
* @param t2 The time value to be substracted from \a t1.
* @hideinitializer
*/
#define PJ_TIME_VAL_SUB(t1, t2) do { \
(t1).sec -= (t2).sec; \
(t1).msec -= (t2).msec; \
pj_time_val_normalize(&(t1)); \
} while (0)
/**
* This structure represent the parsed representation of time.
* It is acquired by calling #pj_time_decode().
*/
typedef struct pj_parsed_time
{
/** This represents day of week where value zero means Sunday */
int wday;
/** This represents day of the year, 0-365, where zero means
* 1st of January.
*/
int yday;
/** This represents day of month: 1-31 */
int day;
/** This represents month, with the value is 0 - 11 (zero is January) */
int mon;
/** This represent the actual year (unlike in ANSI libc where
* the value must be added by 1900).
*/
int year;
/** This represents the second part, with the value is 0-59 */
int sec;
/** This represents the minute part, with the value is: 0-59 */
int min;
/** This represents the hour part, with the value is 0-23 */
int hour;
/** This represents the milisecond part, with the value is 0-999 */
int msec;
} pj_parsed_time;
/**
* @} // Time Management
*/
///////////////////////////////////////////////////////////////////////////////
/*
* Terminal.
*/
/**
* Color code combination.
*/
enum {
PJ_TERM_COLOR_R = 2, /**< Red */
PJ_TERM_COLOR_G = 4, /**< Green */
PJ_TERM_COLOR_B = 1, /**< Blue. */
PJ_TERM_COLOR_BRIGHT = 8 /**< Bright mask. */
};
PJ_END_DECL
#endif /* __PJ_TYPES_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/types.h 11 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_TYPES_H__
#define __PJ_TYPES_H__
/**
* @defgroup PJ PJ Library
*/
/**
* @file types.h
* @brief Declaration of basic types and utility.
*/
/**
* @defgroup PJ_BASIC Basic Data Types and Library Functionality.
* @ingroup PJ_DS
* @{
*/
#include <pj/config.h>
PJ_BEGIN_DECL
///////////////////////////////////////////////////////////////////////////////
/** Unsigned 32bit integer. */
typedef int pj_int32_t;
/** Signed 32bit integer. */
typedef unsigned int pj_uint32_t;
/** Unsigned 16bit integer. */
typedef short pj_int16_t;
/** Signed 16bit integer. */
typedef unsigned short pj_uint16_t;
/** Unsigned 8bit integer. */
typedef signed char pj_int8_t;
/** Signed 16bit integer. */
typedef unsigned char pj_uint8_t;
/** Large unsigned integer. */
typedef size_t pj_size_t;
/** Large signed integer. */
typedef long pj_ssize_t;
/** Status code. */
typedef int pj_status_t;
/** Boolean. */
typedef int pj_bool_t;
/** Status is OK. */
#define PJ_SUCCESS 0
/** True value. */
#define PJ_TRUE 1
/** False value. */
#define PJ_FALSE 0
///////////////////////////////////////////////////////////////////////////////
/*
* Data structure types.
*/
/**
* This type is used as replacement to legacy C string, and used throughout
* the library. By convention, the string is NOT null terminated.
*/
struct pj_str_t
{
/** Buffer pointer, which is by convention NOT null terminated. */
char *ptr;
/** The length of the string. */
pj_ssize_t slen;
};
/**
* The opaque data type for linked list, which is used as arguments throughout
* the linked list operations.
*/
typedef void pj_list_type;
/**
* List.
*/
typedef struct pj_list pj_list;
/**
* Opaque data type for hash tables.
*/
typedef struct pj_hash_table_t pj_hash_table_t;
/**
* Opaque data type for hash entry (only used internally by hash table).
*/
typedef struct pj_hash_entry pj_hash_entry;
/**
* Data type for hash search iterator.
* This structure should be opaque, however applications need to declare
* concrete variable of this type, that's why the declaration is visible here.
*/
typedef struct pj_hash_iterator_t
{
pj_uint32_t index; /**< Internal index. */
pj_hash_entry *entry; /**< Internal entry. */
} pj_hash_iterator_t;
/**
* Forward declaration for memory pool factory.
*/
typedef struct pj_pool_factory pj_pool_factory;
/**
* Opaque data type for memory pool.
*/
typedef struct pj_pool_t pj_pool_t;
/**
* Forward declaration for caching pool, a pool factory implementation.
*/
typedef struct pj_caching_pool pj_caching_pool;
/**
* This type is used as replacement to legacy C string, and used throughout
* the library.
*/
typedef struct pj_str_t pj_str_t;
/**
* Opaque data type for I/O Queue structure.
*/
typedef struct pj_ioqueue_t pj_ioqueue_t;
/**
* Opaque data type for key that identifies a handle registered to the
* I/O queue framework.
*/
typedef struct pj_ioqueue_key_t pj_ioqueue_key_t;
/**
* Opaque data to identify timer heap.
*/
typedef struct pj_timer_heap_t pj_timer_heap_t;
/**
* Forward declaration for timer entry.
*/
typedef struct pj_timer_entry pj_timer_entry;
/**
* Opaque data type for atomic operations.
*/
typedef struct pj_atomic_t pj_atomic_t;
/**
* Value type of an atomic variable.
*/
typedef PJ_ATOMIC_VALUE_TYPE pj_atomic_value_t;
///////////////////////////////////////////////////////////////////////////////
/** Thread handle. */
typedef struct pj_thread_t pj_thread_t;
/** Lock object. */
typedef struct pj_lock_t pj_lock_t;
/** Mutex handle. */
typedef struct pj_mutex_t pj_mutex_t;
/** Semaphore handle. */
typedef struct pj_sem_t pj_sem_t;
/** Event object. */
typedef struct pj_event_t pj_event_t;
/** Unidirectional stream pipe object. */
typedef struct pj_pipe_t pj_pipe_t;
/** Operating system handle. */
typedef void *pj_oshandle_t;
/** Socket handle. */
typedef long pj_sock_t;
/** Generic socket address. */
typedef void pj_sockaddr_t;
/** Color type. */
typedef unsigned int pj_color_t;
/** Exception id. */
typedef int pj_exception_id_t;
///////////////////////////////////////////////////////////////////////////////
/** Utility macro to compute the number of elements in static array. */
#define PJ_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
/** Maximum value for signed 32-bit integer. */
#define PJ_MAXINT32 0x7FFFFFFFL
/**
* Length of object names.
*/
#define PJ_MAX_OBJ_NAME 16
///////////////////////////////////////////////////////////////////////////////
/*
* General.
*/
/**
* Initialize the PJ Library.
* This function must be called before using the library. The purpose of this
* function is to initialize static library data, such as character table used
* in random string generation, and to initialize operating system dependent
* functionality (such as WSAStartup() in Windows).
*/
PJ_DECL(pj_status_t) pj_init(void);
/**
* @}
*/
/**
* @addtogroup PJ_TIME Time Data Type and Manipulation.
* @ingroup PJ_MISC
* @{
*/
/**
* Representation of time value in this library.
* This type can be used to represent either an interval or a specific time
* or date.
*/
typedef struct pj_time_val
{
/** The seconds part of the time. */
long sec;
/** The miliseconds fraction of the time. */
long msec;
} pj_time_val;
/**
* Normalize the value in time value.
* @param t Time value to be normalized.
*/
PJ_DECL(void) pj_time_val_normalize(pj_time_val *t);
/**
* Get the total time value in miliseconds. This is the same as
* multiplying the second part with 1000 and then add the miliseconds
* part to the result.
*
* @param t The time value.
* @return Total time in miliseconds.
* @hideinitializer
*/
#define PJ_TIME_VAL_MSEC(t) ((t).sec * 1000 + (t).msec)
/**
* This macro will check if \a t1 is equal to \a t2.
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if both time values are equal.
* @hideinitializer
*/
#define PJ_TIME_VAL_EQ(t1, t2) ((t1).sec==(t2).sec && (t1).msec==(t2).msec)
/**
* This macro will check if \a t1 is greater than \a t2
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is greater than t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_GT(t1, t2) ((t1).sec>(t2).sec || \
((t1).sec==(t2).sec && (t1).msec>(t2).msec))
/**
* This macro will check if \a t1 is greater than or equal to \a t2
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is greater than or equal to t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_GTE(t1, t2) (PJ_TIME_VAL_GT(t1,t2) || \
PJ_TIME_VAL_EQ(t1,t2))
/**
* This macro will check if \a t1 is less than \a t2
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is less than t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_LT(t1, t2) (!(PJ_TIME_VAL_GTE(t1,t2)))
/**
* This macro will check if \a t1 is less than or equal to \a t2.
*
* @param t1 The first time value to compare.
* @param t2 The second time value to compare.
* @return Non-zero if t1 is less than or equal to t2.
* @hideinitializer
*/
#define PJ_TIME_VAL_LTE(t1, t2) (!PJ_TIME_VAL_GT(t1, t2))
/**
* Add \a t2 to \a t1 and store the result in \a t1. Effectively
*
* this macro will expand as: (\a t1 += \a t2).
* @param t1 The time value to add.
* @param t2 The time value to be added to \a t1.
* @hideinitializer
*/
#define PJ_TIME_VAL_ADD(t1, t2) do { \
(t1).sec += (t2).sec; \
(t1).msec += (t2).msec; \
pj_time_val_normalize(&(t1)); \
} while (0)
/**
* Substract \a t2 from \a t1 and store the result in \a t1. Effectively
* this macro will expand as (\a t1 -= \a t2).
*
* @param t1 The time value to subsctract.
* @param t2 The time value to be substracted from \a t1.
* @hideinitializer
*/
#define PJ_TIME_VAL_SUB(t1, t2) do { \
(t1).sec -= (t2).sec; \
(t1).msec -= (t2).msec; \
pj_time_val_normalize(&(t1)); \
} while (0)
/**
* This structure represent the parsed representation of time.
* It is acquired by calling #pj_time_decode().
*/
typedef struct pj_parsed_time
{
/** This represents day of week where value zero means Sunday */
int wday;
/** This represents day of the year, 0-365, where zero means
* 1st of January.
*/
int yday;
/** This represents day of month: 1-31 */
int day;
/** This represents month, with the value is 0 - 11 (zero is January) */
int mon;
/** This represent the actual year (unlike in ANSI libc where
* the value must be added by 1900).
*/
int year;
/** This represents the second part, with the value is 0-59 */
int sec;
/** This represents the minute part, with the value is: 0-59 */
int min;
/** This represents the hour part, with the value is 0-23 */
int hour;
/** This represents the milisecond part, with the value is 0-999 */
int msec;
} pj_parsed_time;
/**
* @} // Time Management
*/
///////////////////////////////////////////////////////////////////////////////
/*
* Terminal.
*/
/**
* Color code combination.
*/
enum {
PJ_TERM_COLOR_R = 2, /**< Red */
PJ_TERM_COLOR_G = 4, /**< Green */
PJ_TERM_COLOR_B = 1, /**< Blue. */
PJ_TERM_COLOR_BRIGHT = 8 /**< Bright mask. */
};
PJ_END_DECL
#endif /* __PJ_TYPES_H__ */

View File

@ -1,155 +1,155 @@
/* $Header: /pjproject-0.3/pjlib/include/pj/xml.h 4 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_XML_H__
#define __PJ_XML_H__
/**
* @file xml.h
* @brief PJLIB XML Parser/Helper.
*/
#include <pj/types.h>
#include <pj/list.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_XML XML Parser/Helper.
* @ingroup PJ
* @{
*/
/** Typedef for XML attribute. */
typedef struct pj_xml_attr pj_xml_attr;
/** Typedef for XML nodes. */
typedef struct pj_xml_node pj_xml_node;
/** This structure declares XML attribute. */
struct pj_xml_attr
{
PJ_DECL_LIST_MEMBER(pj_xml_attr)
pj_str_t name; /**< Attribute name. */
pj_str_t value; /**< Attribute value. */
};
/** This structure describes XML node head inside XML node structure.
*/
typedef struct pj_xml_node_head
{
PJ_DECL_LIST_MEMBER(pj_xml_node)
} pj_xml_node_head;
/** This structure describes XML node. */
struct pj_xml_node
{
PJ_DECL_LIST_MEMBER(pj_xml_node) /** List @a prev and @a next member */
pj_str_t name; /** Node name. */
pj_xml_attr attr_head; /** Attribute list. */
pj_xml_node_head node_head; /** Node list. */
pj_str_t content; /** Node content. */
};
/**
* Parse XML message into XML document with a single root node. The parser
* is capable of parsing XML processing instruction construct ("<?") and
* XML comments ("<!--"), however such constructs will be ignored and will not
* be included in the resulted XML node tree.
*
* @param pool Pool to allocate memory from.
* @param msg The XML message to parse.
* @param len The length of the message.
*
* @return XML root node, or NULL if the XML document can not be parsed.
*/
PJ_DECL(pj_xml_node*) pj_xml_parse( pj_pool_t *pool, char *msg, pj_size_t len);
/**
* Print XML into XML message. Note that the function WILL NOT NULL terminate
* the output.
*
* @param node The XML node to print.
* @param buf Buffer to hold the output message.
* @param len The length of the buffer.
* @param prolog If set to nonzero, will print XML prolog ("<?xml..")
*
* @return The size of the printed message, or -1 if there is not
* sufficient space in the buffer to print the message.
*/
PJ_DECL(int) pj_xml_print( const pj_xml_node *node, char *buf, pj_size_t len,
pj_bool_t include_prolog);
/**
* Add node to another node.
*
* @param parent Parent node.
* @param node Node to be added to parent.
*/
PJ_DECL(void) pj_xml_add_node( pj_xml_node *parent, pj_xml_node *node );
/**
* Add attribute to a node.
*
* @param node Node.
* @param attr Attribute to add to node.
*/
PJ_DECL(void) pj_xml_add_attr( pj_xml_node *node, pj_xml_attr *attr );
/**
* Find first node with the specified name.
*
* @param parent Parent node.
* @param name Node name to find.
*
* @return XML node found or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_node(pj_xml_node *parent, const pj_str_t *name);
/**
* Find first node with the specified name.
*
* @param parent Parent node.
* @param name Node name to find.
*
* @return XML node found or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_next_node(pj_xml_node *parent, pj_xml_node *node,
const pj_str_t *name);
/**
* Find first attribute within a node with the specified name and optional value.
*
* @param node XML Node.
* @param name Attribute name to find.
* @param value Optional value to match.
*
* @return XML attribute found, or NULL.
*/
PJ_DECL(pj_xml_attr*) pj_xml_find_attr(pj_xml_node *node, const pj_str_t *name,
const pj_str_t *value);
/**
* Find a direct child node with the specified name and match the function.
*
* @param node Parent node.
* @param name Optional name.
* @param data Data to be passed to matching function.
* @param match Optional matching function.
*
* @return The first matched node, or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find( pj_xml_node *parent, const pj_str_t *name,
const void *data,
pj_bool_t (*match)(pj_xml_node *, const void*));
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_XML_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pj/xml.h 4 10/14/05 12:26a Bennylp $ */
#ifndef __PJ_XML_H__
#define __PJ_XML_H__
/**
* @file xml.h
* @brief PJLIB XML Parser/Helper.
*/
#include <pj/types.h>
#include <pj/list.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_XML XML Parser/Helper.
* @ingroup PJ
* @{
*/
/** Typedef for XML attribute. */
typedef struct pj_xml_attr pj_xml_attr;
/** Typedef for XML nodes. */
typedef struct pj_xml_node pj_xml_node;
/** This structure declares XML attribute. */
struct pj_xml_attr
{
PJ_DECL_LIST_MEMBER(pj_xml_attr)
pj_str_t name; /**< Attribute name. */
pj_str_t value; /**< Attribute value. */
};
/** This structure describes XML node head inside XML node structure.
*/
typedef struct pj_xml_node_head
{
PJ_DECL_LIST_MEMBER(pj_xml_node)
} pj_xml_node_head;
/** This structure describes XML node. */
struct pj_xml_node
{
PJ_DECL_LIST_MEMBER(pj_xml_node) /** List @a prev and @a next member */
pj_str_t name; /** Node name. */
pj_xml_attr attr_head; /** Attribute list. */
pj_xml_node_head node_head; /** Node list. */
pj_str_t content; /** Node content. */
};
/**
* Parse XML message into XML document with a single root node. The parser
* is capable of parsing XML processing instruction construct ("<?") and
* XML comments ("<!--"), however such constructs will be ignored and will not
* be included in the resulted XML node tree.
*
* @param pool Pool to allocate memory from.
* @param msg The XML message to parse.
* @param len The length of the message.
*
* @return XML root node, or NULL if the XML document can not be parsed.
*/
PJ_DECL(pj_xml_node*) pj_xml_parse( pj_pool_t *pool, char *msg, pj_size_t len);
/**
* Print XML into XML message. Note that the function WILL NOT NULL terminate
* the output.
*
* @param node The XML node to print.
* @param buf Buffer to hold the output message.
* @param len The length of the buffer.
* @param prolog If set to nonzero, will print XML prolog ("<?xml..")
*
* @return The size of the printed message, or -1 if there is not
* sufficient space in the buffer to print the message.
*/
PJ_DECL(int) pj_xml_print( const pj_xml_node *node, char *buf, pj_size_t len,
pj_bool_t include_prolog);
/**
* Add node to another node.
*
* @param parent Parent node.
* @param node Node to be added to parent.
*/
PJ_DECL(void) pj_xml_add_node( pj_xml_node *parent, pj_xml_node *node );
/**
* Add attribute to a node.
*
* @param node Node.
* @param attr Attribute to add to node.
*/
PJ_DECL(void) pj_xml_add_attr( pj_xml_node *node, pj_xml_attr *attr );
/**
* Find first node with the specified name.
*
* @param parent Parent node.
* @param name Node name to find.
*
* @return XML node found or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_node(pj_xml_node *parent, const pj_str_t *name);
/**
* Find first node with the specified name.
*
* @param parent Parent node.
* @param name Node name to find.
*
* @return XML node found or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_next_node(pj_xml_node *parent, pj_xml_node *node,
const pj_str_t *name);
/**
* Find first attribute within a node with the specified name and optional value.
*
* @param node XML Node.
* @param name Attribute name to find.
* @param value Optional value to match.
*
* @return XML attribute found, or NULL.
*/
PJ_DECL(pj_xml_attr*) pj_xml_find_attr(pj_xml_node *node, const pj_str_t *name,
const pj_str_t *value);
/**
* Find a direct child node with the specified name and match the function.
*
* @param node Parent node.
* @param name Optional name.
* @param data Data to be passed to matching function.
* @param match Optional matching function.
*
* @return The first matched node, or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find( pj_xml_node *parent, const pj_str_t *name,
const void *data,
pj_bool_t (*match)(pj_xml_node *, const void*));
/**
* @}
*/
PJ_END_DECL
#endif /* __PJ_XML_H__ */

View File

@ -1,39 +1,39 @@
/* $Header: /pjproject-0.3/pjlib/include/pjlib.h 6 10/29/05 11:30a Bennylp $ */
#ifndef __PJLIB_H__
#define __PJLIB_H__
/**
* @file pjlib.h
* @brief Include all PJLIB header files.
*/
#include <pj/addr_resolv.h>
#include <pj/array.h>
#include <pj/assert.h>
#include <pj/ctype.h>
#include <pj/errno.h>
#include <pj/except.h>
#include <pj/fifobuf.h>
#include <pj/guid.h>
#include <pj/hash.h>
#include <pj/ioqueue.h>
#include <pj/list.h>
#include <pj/lock.h>
#include <pj/log.h>
#include <pj/md5.h>
#include <pj/os.h>
#include <pj/pool.h>
#include <pj/rand.h>
#include <pj/rbtree.h>
#include <pj/scanner.h>
#include <pj/sock.h>
#include <pj/sock_select.h>
#include <pj/string.h>
#include <pj/stun.h>
#include <pj/timer.h>
#include <pj/xml.h>
#include <pj/compat/high_precision.h>
#endif /* __PJLIB_H__ */
/* $Header: /pjproject-0.3/pjlib/include/pjlib.h 6 10/29/05 11:30a Bennylp $ */
#ifndef __PJLIB_H__
#define __PJLIB_H__
/**
* @file pjlib.h
* @brief Include all PJLIB header files.
*/
#include <pj/addr_resolv.h>
#include <pj/array.h>
#include <pj/assert.h>
#include <pj/ctype.h>
#include <pj/errno.h>
#include <pj/except.h>
#include <pj/fifobuf.h>
#include <pj/guid.h>
#include <pj/hash.h>
#include <pj/ioqueue.h>
#include <pj/list.h>
#include <pj/lock.h>
#include <pj/log.h>
#include <pj/md5.h>
#include <pj/os.h>
#include <pj/pool.h>
#include <pj/rand.h>
#include <pj/rbtree.h>
#include <pj/scanner.h>
#include <pj/sock.h>
#include <pj/sock_select.h>
#include <pj/string.h>
#include <pj/stun.h>
#include <pj/timer.h>
#include <pj/xml.h>
#include <pj/compat/high_precision.h>
#endif /* __PJLIB_H__ */

View File

@ -1,14 +1,14 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/addr_resolv_linux_kernel.c 1 10/05/05 4:41p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/addr_resolv_linux_kernel.c $
*
* 1 10/05/05 4:41p Bennylp
* Created.
*
*/
#include <pj/addr_resolv.h>
PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe)
{
return -1;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/addr_resolv_linux_kernel.c 1 10/05/05 4:41p Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/addr_resolv_linux_kernel.c $
*
* 1 10/05/05 4:41p Bennylp
* Created.
*
*/
#include <pj/addr_resolv.h>
PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe)
{
return -1;
}

View File

@ -1,44 +1,44 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/addr_resolv_sock.c 2 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/addr_resolv_sock.c $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 9/22/05 10:38a Bennylp
* Created.
*
*/
#include <pj/addr_resolv.h>
#include <pj/assert.h>
#include <pj/string.h>
#include <pj/compat/socket.h>
#include <pj/errno.h>
PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe)
{
struct hostent *he;
char copy[PJ_MAX_HOSTNAME];
pj_assert(hostname && hostname ->slen < PJ_MAX_HOSTNAME);
if (hostname->slen >= PJ_MAX_HOSTNAME)
return PJ_ENAMETOOLONG;
pj_memcpy(copy, hostname->ptr, hostname->slen);
copy[ hostname->slen ] = '\0';
he = gethostbyname(copy);
if (!he)
return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
phe->h_name = he->h_name;
phe->h_aliases = he->h_aliases;
phe->h_addrtype = he->h_addrtype;
phe->h_length = he->h_length;
phe->h_addr_list = he->h_addr_list;
return PJ_SUCCESS;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/addr_resolv_sock.c 2 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/addr_resolv_sock.c $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 9/22/05 10:38a Bennylp
* Created.
*
*/
#include <pj/addr_resolv.h>
#include <pj/assert.h>
#include <pj/string.h>
#include <pj/compat/socket.h>
#include <pj/errno.h>
PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe)
{
struct hostent *he;
char copy[PJ_MAX_HOSTNAME];
pj_assert(hostname && hostname ->slen < PJ_MAX_HOSTNAME);
if (hostname->slen >= PJ_MAX_HOSTNAME)
return PJ_ENAMETOOLONG;
pj_memcpy(copy, hostname->ptr, hostname->slen);
copy[ hostname->slen ] = '\0';
he = gethostbyname(copy);
if (!he)
return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
phe->h_name = he->h_name;
phe->h_aliases = he->h_aliases;
phe->h_addrtype = he->h_addrtype;
phe->h_length = he->h_length;
phe->h_addr_list = he->h_addr_list;
return PJ_SUCCESS;
}

View File

@ -1,63 +1,63 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/array.c 5 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/array.c $
*
* 5 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 4 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/array.h>
#include <pj/string.h>
#include <pj/assert.h>
#include <pj/errno.h>
PJ_DEF(void) pj_array_insert( void *array,
unsigned elem_size,
unsigned count,
unsigned pos,
const void *value)
{
if (count && pos < count-1) {
pj_memmove( (char*)array + (pos+1)*elem_size,
(char*)array + pos*elem_size,
(count-pos)*elem_size);
}
pj_memmove((char*)array + pos*elem_size, value, elem_size);
}
PJ_DEF(void) pj_array_erase( void *array,
unsigned elem_size,
unsigned count,
unsigned pos)
{
pj_assert(count != 0);
if (pos < count-1) {
pj_memmove( (char*)array + pos*elem_size,
(char*)array + (pos+1)*elem_size,
(count-pos-1)*elem_size);
}
}
PJ_DEF(pj_status_t) pj_array_find( const void *array,
unsigned elem_size,
unsigned count,
pj_status_t (*matching)(const void *value),
void **result)
{
unsigned i;
const char *char_array = array;
for (i=0; i<count; ++i) {
if ( (*matching)(char_array) == PJ_SUCCESS) {
if (result) {
*result = (void*)char_array;
}
return PJ_SUCCESS;
}
char_array += elem_size;
}
return PJ_ENOTFOUND;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/array.c 5 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/array.c $
*
* 5 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 4 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/array.h>
#include <pj/string.h>
#include <pj/assert.h>
#include <pj/errno.h>
PJ_DEF(void) pj_array_insert( void *array,
unsigned elem_size,
unsigned count,
unsigned pos,
const void *value)
{
if (count && pos < count-1) {
pj_memmove( (char*)array + (pos+1)*elem_size,
(char*)array + pos*elem_size,
(count-pos)*elem_size);
}
pj_memmove((char*)array + pos*elem_size, value, elem_size);
}
PJ_DEF(void) pj_array_erase( void *array,
unsigned elem_size,
unsigned count,
unsigned pos)
{
pj_assert(count != 0);
if (pos < count-1) {
pj_memmove( (char*)array + pos*elem_size,
(char*)array + (pos+1)*elem_size,
(count-pos-1)*elem_size);
}
}
PJ_DEF(pj_status_t) pj_array_find( const void *array,
unsigned elem_size,
unsigned count,
pj_status_t (*matching)(const void *value),
void **result)
{
unsigned i;
const char *char_array = array;
for (i=0; i<count; ++i) {
if ( (*matching)(char_array) == PJ_SUCCESS) {
if (result) {
*result = (void*)char_array;
}
return PJ_SUCCESS;
}
char_array += elem_size;
}
return PJ_ENOTFOUND;
}

View File

@ -1,42 +1,42 @@
/* longjmp for i386.
Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#define _ASM
#define _SETJMP_H
#define PJ_LINUX_KERNEL 1
#include <pj/compat/setjmp.h>
.global __longjmp
.type __longjmp,%function
.align 4
__longjmp:
movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */
movl 8(%esp), %eax /* Second argument is return value. */
/* Save the return address now. */
movl (JB_PC*4)(%ecx), %edx
/* Restore registers. */
movl (JB_BX*4)(%ecx), %ebx
movl (JB_SI*4)(%ecx), %esi
movl (JB_DI*4)(%ecx), %edi
movl (JB_BP*4)(%ecx), %ebp
movl (JB_SP*4)(%ecx), %esp
/* Jump to saved PC. */
jmp *%edx
.size __longjmp,.-__longjmp
/* longjmp for i386.
Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#define _ASM
#define _SETJMP_H
#define PJ_LINUX_KERNEL 1
#include <pj/compat/setjmp.h>
.global __longjmp
.type __longjmp,%function
.align 4
__longjmp:
movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */
movl 8(%esp), %eax /* Second argument is return value. */
/* Save the return address now. */
movl (JB_PC*4)(%ecx), %edx
/* Restore registers. */
movl (JB_BX*4)(%ecx), %ebx
movl (JB_SI*4)(%ecx), %esi
movl (JB_DI*4)(%ecx), %edi
movl (JB_BP*4)(%ecx), %ebp
movl (JB_SP*4)(%ecx), %esp
/* Jump to saved PC. */
jmp *%edx
.size __longjmp,.-__longjmp

View File

@ -1,61 +1,61 @@
/* setjmp for i386, ELF version.
Copyright (C) 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#define _ASM
#define _SETJMP_H
#define PJ_LINUX_KERNEL 1
#include <pj/compat/setjmp.h>
.global __sigsetjmp
.type __sigsetjmp,%function
.align 4
__sigsetjmp:
movl 4 (%esp), %eax
/* Save registers. */
movl %ebx, (0 *4)(%eax)
movl %esi, (1 *4)(%eax)
movl %edi, (2 *4)(%eax)
/* Save SP as it will be after we return. */
leal 4(%esp), %ecx
movl %ecx, (4 *4)(%eax)
/* Save PC we are returning to now. */
movl 0(%esp), %ecx
movl %ecx, (5 *4)(%eax)
/* Save caller's frame pointer. */
movl %ebp, (3 *4)(%eax)
/* Make a tail call to __sigjmp_save; it takes the same args. */
#ifdef __PIC__
/* We cannot use the PLT, because it requires that %ebx be set, but
we can't save and restore our caller's value. Instead, we do an
indirect jump through the GOT, using for the temporary register
%ecx, which is call-clobbered. */
call .Lhere
.Lhere:
popl %ecx
addl $_GLOBAL_OFFSET_TABLE_+[.- .Lhere ], %ecx
movl __sigjmp_save @GOT (%ecx), %ecx
jmp *%ecx
#else
jmp __sigjmp_save
#endif
.size __sigsetjmp,.-__sigsetjmp
/* setjmp for i386, ELF version.
Copyright (C) 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#define _ASM
#define _SETJMP_H
#define PJ_LINUX_KERNEL 1
#include <pj/compat/setjmp.h>
.global __sigsetjmp
.type __sigsetjmp,%function
.align 4
__sigsetjmp:
movl 4 (%esp), %eax
/* Save registers. */
movl %ebx, (0 *4)(%eax)
movl %esi, (1 *4)(%eax)
movl %edi, (2 *4)(%eax)
/* Save SP as it will be after we return. */
leal 4(%esp), %ecx
movl %ecx, (4 *4)(%eax)
/* Save PC we are returning to now. */
movl 0(%esp), %ecx
movl %ecx, (5 *4)(%eax)
/* Save caller's frame pointer. */
movl %ebp, (3 *4)(%eax)
/* Make a tail call to __sigjmp_save; it takes the same args. */
#ifdef __PIC__
/* We cannot use the PLT, because it requires that %ebx be set, but
we can't save and restore our caller's value. Instead, we do an
indirect jump through the GOT, using for the temporary register
%ecx, which is call-clobbered. */
call .Lhere
.Lhere:
popl %ecx
addl $_GLOBAL_OFFSET_TABLE_+[.- .Lhere ], %ecx
movl __sigjmp_save @GOT (%ecx), %ecx
jmp *%ecx
#else
jmp __sigjmp_save
#endif
.size __sigsetjmp,.-__sigsetjmp

View File

@ -1,21 +1,21 @@
#include <pj/config.h>
#include <pj/compat/setjmp.h>
int __sigjmp_save(sigjmp_buf env, int savemask)
{
return 0;
}
extern int __sigsetjmp(pj_jmp_buf env, int savemask);
extern void __longjmp(pj_jmp_buf env, int val) __attribute__((noreturn));
PJ_DEF(int) pj_setjmp(pj_jmp_buf env)
{
return __sigsetjmp(env, 0);
}
PJ_DEF(void) pj_longjmp(pj_jmp_buf env, int val)
{
__longjmp(env, val);
}
#include <pj/config.h>
#include <pj/compat/setjmp.h>
int __sigjmp_save(sigjmp_buf env, int savemask)
{
return 0;
}
extern int __sigsetjmp(pj_jmp_buf env, int savemask);
extern void __longjmp(pj_jmp_buf env, int val) __attribute__((noreturn));
PJ_DEF(int) pj_setjmp(pj_jmp_buf env)
{
return __sigsetjmp(env, 0);
}
PJ_DEF(void) pj_longjmp(pj_jmp_buf env, int val)
{
__longjmp(env, val);
}

View File

@ -1,33 +1,33 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/string.c 1 9/22/05 10:43a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/string.c $
*
* 1 9/22/05 10:43a Bennylp
* Created.
*
*/
#include <pj/types.h>
#include <pj/compat/string.h>
#include <pj/ctype.h>
PJ_DEF(int) strcasecmp(const char *s1, const char *s2)
{
while ((*s1==*s2) || (pj_tolower(*s1)==pj_tolower(*s2))) {
if (!*s1++)
return 0;
++s2;
}
return (pj_tolower(*s1) < pj_tolower(*s2)) ? -1 : 1;
}
PJ_DEF(int) strncasecmp(const char *s1, const char *s2, int len)
{
if (!len) return 0;
while ((*s1==*s2) || (pj_tolower(*s1)==pj_tolower(*s2))) {
if (!*s1++ || --len <= 0)
return 0;
++s2;
}
return (pj_tolower(*s1) < pj_tolower(*s2)) ? -1 : 1;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/compat/string.c 1 9/22/05 10:43a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/compat/string.c $
*
* 1 9/22/05 10:43a Bennylp
* Created.
*
*/
#include <pj/types.h>
#include <pj/compat/string.h>
#include <pj/ctype.h>
PJ_DEF(int) strcasecmp(const char *s1, const char *s2)
{
while ((*s1==*s2) || (pj_tolower(*s1)==pj_tolower(*s2))) {
if (!*s1++)
return 0;
++s2;
}
return (pj_tolower(*s1) < pj_tolower(*s2)) ? -1 : 1;
}
PJ_DEF(int) strncasecmp(const char *s1, const char *s2, int len)
{
if (!len) return 0;
while ((*s1==*s2) || (pj_tolower(*s1)==pj_tolower(*s2))) {
if (!*s1++ || --len <= 0)
return 0;
++s2;
}
return (pj_tolower(*s1) < pj_tolower(*s2)) ? -1 : 1;
}

View File

@ -1,40 +1,40 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/config.c 7 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/config.c $
*
* 7 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 6 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 5 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/config.h>
#include <pj/log.h>
static const char *id = "config.c";
const char *PJ_VERSION = "0.3.0-pre1";
PJ_DEF(void) pj_dump_config(void)
{
PJ_LOG(3, (id, "PJLIB (c)2005 Benny Prijono"));
PJ_LOG(3, (id, "Dumping configurations:"));
PJ_LOG(3, (id, " PJ_VERSION : %s", PJ_VERSION));
PJ_LOG(3, (id, " PJ_DEBUG : %d", PJ_DEBUG));
PJ_LOG(3, (id, " PJ_FUNCTIONS_ARE_INLINED : %d", PJ_FUNCTIONS_ARE_INLINED));
PJ_LOG(3, (id, " PJ_POOL_DEBUG : %d", PJ_POOL_DEBUG));
PJ_LOG(3, (id, " PJ_HAS_THREADS : %d", PJ_HAS_THREADS));
PJ_LOG(3, (id, " PJ_LOG_MAX_LEVEL : %d", PJ_LOG_MAX_LEVEL));
PJ_LOG(3, (id, " PJ_LOG_MAX_SIZE : %d", PJ_LOG_MAX_SIZE));
PJ_LOG(3, (id, " PJ_LOG_USE_STACK_BUFFER : %d", PJ_LOG_USE_STACK_BUFFER));
PJ_LOG(3, (id, " PJ_HAS_TCP : %d", PJ_HAS_TCP));
PJ_LOG(3, (id, " PJ_MAX_HOSTNAME : %d", PJ_MAX_HOSTNAME));
PJ_LOG(3, (id, " PJ_HAS_SEMAPHORE : %d", PJ_HAS_SEMAPHORE));
PJ_LOG(3, (id, " PJ_HAS_EVENT_OBJ : %d", PJ_HAS_EVENT_OBJ));
PJ_LOG(3, (id, " PJ_HAS_HIGH_RES_TIMER : %d", PJ_HAS_HIGH_RES_TIMER));
PJ_LOG(3, (id, " PJ_(endianness) : %s", (PJ_IS_BIG_ENDIAN?"big-endian":"little-endian")));
PJ_LOG(3, (id, " PJ_IOQUEUE_MAX_HANDLES : %d", PJ_IOQUEUE_MAX_HANDLES));
}
/* $Header: /pjproject-0.3/pjlib/src/pj/config.c 7 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/config.c $
*
* 7 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 6 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 5 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/config.h>
#include <pj/log.h>
static const char *id = "config.c";
const char *PJ_VERSION = "0.3.0-pre1";
PJ_DEF(void) pj_dump_config(void)
{
PJ_LOG(3, (id, "PJLIB (c)2005 Benny Prijono"));
PJ_LOG(3, (id, "Dumping configurations:"));
PJ_LOG(3, (id, " PJ_VERSION : %s", PJ_VERSION));
PJ_LOG(3, (id, " PJ_DEBUG : %d", PJ_DEBUG));
PJ_LOG(3, (id, " PJ_FUNCTIONS_ARE_INLINED : %d", PJ_FUNCTIONS_ARE_INLINED));
PJ_LOG(3, (id, " PJ_POOL_DEBUG : %d", PJ_POOL_DEBUG));
PJ_LOG(3, (id, " PJ_HAS_THREADS : %d", PJ_HAS_THREADS));
PJ_LOG(3, (id, " PJ_LOG_MAX_LEVEL : %d", PJ_LOG_MAX_LEVEL));
PJ_LOG(3, (id, " PJ_LOG_MAX_SIZE : %d", PJ_LOG_MAX_SIZE));
PJ_LOG(3, (id, " PJ_LOG_USE_STACK_BUFFER : %d", PJ_LOG_USE_STACK_BUFFER));
PJ_LOG(3, (id, " PJ_HAS_TCP : %d", PJ_HAS_TCP));
PJ_LOG(3, (id, " PJ_MAX_HOSTNAME : %d", PJ_MAX_HOSTNAME));
PJ_LOG(3, (id, " PJ_HAS_SEMAPHORE : %d", PJ_HAS_SEMAPHORE));
PJ_LOG(3, (id, " PJ_HAS_EVENT_OBJ : %d", PJ_HAS_EVENT_OBJ));
PJ_LOG(3, (id, " PJ_HAS_HIGH_RES_TIMER : %d", PJ_HAS_HIGH_RES_TIMER));
PJ_LOG(3, (id, " PJ_(endianness) : %s", (PJ_IS_BIG_ENDIAN?"big-endian":"little-endian")));
PJ_LOG(3, (id, " PJ_IOQUEUE_MAX_HANDLES : %d", PJ_IOQUEUE_MAX_HANDLES));
}

View File

@ -1,13 +1,13 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/equeue_winnt.c 2 10/14/05 12:26a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/equeue_winnt.c $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 10/05/05 6:19p Bennylp
* Created.
*
*/
#include <pj/equeue.h>
/* $Header: /pjproject-0.3/pjlib/src/pj/equeue_winnt.c 2 10/14/05 12:26a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/equeue_winnt.c $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 10/05/05 6:19p Bennylp
* Created.
*
*/
#include <pj/equeue.h>

View File

@ -1,107 +1,107 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/errno.c 2 10/14/05 12:26a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/errno.c $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 10/08/05 9:53a Bennylp
* Created.
*
*/
#include <pj/errno.h>
#include <pj/string.h>
#include <pj/compat/sprintf.h>
/* Prototype for platform specific error message, which will be defined
* in separate file.
*/
extern int platform_strerror( pj_os_err_type code,
char *buf, pj_size_t bufsize );
/* PJLIB's own error codes/messages */
static const struct
{
int code;
const char *msg;
} err_str[] =
{
{ PJ_EUNKNOWN, "Unknown Error" },
{ PJ_EPENDING, "Pending operation" },
{ PJ_ETOOMANYCONN, "Too many connecting sockets" },
{ PJ_EINVAL, "Invalid value or argument" },
{ PJ_ENAMETOOLONG, "Name too long" },
{ PJ_ENOTFOUND, "Not found" },
{ PJ_ENOMEM, "Not enough memory" },
{ PJ_EBUG, "BUG DETECTED!" },
{ PJ_ETIMEDOUT, "Operation timed out" },
{ PJ_ETOOMANY, "Too many objects of the specified type"},
{ PJ_EBUSY, "Object is busy"},
{ PJ_ENOTSUP, "Option/operation is not supported"},
{ PJ_EINVALIDOP, "Invalid operation"}
};
/*
* pjlib_error()
*
* Retrieve message string for PJLIB's own error code.
*/
static int pjlib_error(pj_status_t code, char *buf, pj_size_t size)
{
unsigned i;
for (i=0; i<sizeof(err_str)/sizeof(err_str[0]); ++i) {
if (err_str[i].code == code) {
pj_size_t len = strlen(err_str[i].msg);
if (len >= size) len = size-1;
pj_memcpy(buf, err_str[i].msg, len);
buf[len] = '\0';
return len;
}
}
*buf++ = '?';
*buf++ = '?';
*buf++ = '?';
*buf++ = '\0';
return 3;
}
/*
* pj_strerror()
*/
PJ_DEF(pj_str_t) pj_strerror( pj_status_t statcode,
char *buf, pj_size_t bufsize )
{
int len = -1;
pj_str_t errstr;
if (statcode < PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE) {
len = pj_snprintf( buf, bufsize, "Unknown error %d", statcode);
} else if (statcode < PJ_ERRNO_START_STATUS + PJ_ERRNO_SPACE_SIZE) {
len = pjlib_error(statcode, buf, bufsize);
} else if (statcode < PJ_ERRNO_START_SYS + PJ_ERRNO_SPACE_SIZE) {
len = platform_strerror(PJ_STATUS_TO_OS(statcode), buf, bufsize);
} else if (statcode < PJ_ERRNO_START_USER + PJ_ERRNO_SPACE_SIZE) {
len = pj_snprintf( buf, bufsize, "User error %d", statcode);
} else {
len = pj_snprintf( buf, bufsize, "Invalid error %d", statcode);
}
if (len < 1) {
*buf = '\0';
len = 0;
}
errstr.ptr = buf;
errstr.slen = len;
return errstr;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/errno.c 2 10/14/05 12:26a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/errno.c $
*
* 2 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 1 10/08/05 9:53a Bennylp
* Created.
*
*/
#include <pj/errno.h>
#include <pj/string.h>
#include <pj/compat/sprintf.h>
/* Prototype for platform specific error message, which will be defined
* in separate file.
*/
extern int platform_strerror( pj_os_err_type code,
char *buf, pj_size_t bufsize );
/* PJLIB's own error codes/messages */
static const struct
{
int code;
const char *msg;
} err_str[] =
{
{ PJ_EUNKNOWN, "Unknown Error" },
{ PJ_EPENDING, "Pending operation" },
{ PJ_ETOOMANYCONN, "Too many connecting sockets" },
{ PJ_EINVAL, "Invalid value or argument" },
{ PJ_ENAMETOOLONG, "Name too long" },
{ PJ_ENOTFOUND, "Not found" },
{ PJ_ENOMEM, "Not enough memory" },
{ PJ_EBUG, "BUG DETECTED!" },
{ PJ_ETIMEDOUT, "Operation timed out" },
{ PJ_ETOOMANY, "Too many objects of the specified type"},
{ PJ_EBUSY, "Object is busy"},
{ PJ_ENOTSUP, "Option/operation is not supported"},
{ PJ_EINVALIDOP, "Invalid operation"}
};
/*
* pjlib_error()
*
* Retrieve message string for PJLIB's own error code.
*/
static int pjlib_error(pj_status_t code, char *buf, pj_size_t size)
{
unsigned i;
for (i=0; i<sizeof(err_str)/sizeof(err_str[0]); ++i) {
if (err_str[i].code == code) {
pj_size_t len = strlen(err_str[i].msg);
if (len >= size) len = size-1;
pj_memcpy(buf, err_str[i].msg, len);
buf[len] = '\0';
return len;
}
}
*buf++ = '?';
*buf++ = '?';
*buf++ = '?';
*buf++ = '\0';
return 3;
}
/*
* pj_strerror()
*/
PJ_DEF(pj_str_t) pj_strerror( pj_status_t statcode,
char *buf, pj_size_t bufsize )
{
int len = -1;
pj_str_t errstr;
if (statcode < PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE) {
len = pj_snprintf( buf, bufsize, "Unknown error %d", statcode);
} else if (statcode < PJ_ERRNO_START_STATUS + PJ_ERRNO_SPACE_SIZE) {
len = pjlib_error(statcode, buf, bufsize);
} else if (statcode < PJ_ERRNO_START_SYS + PJ_ERRNO_SPACE_SIZE) {
len = platform_strerror(PJ_STATUS_TO_OS(statcode), buf, bufsize);
} else if (statcode < PJ_ERRNO_START_USER + PJ_ERRNO_SPACE_SIZE) {
len = pj_snprintf( buf, bufsize, "User error %d", statcode);
} else {
len = pj_snprintf( buf, bufsize, "Invalid error %d", statcode);
}
if (len < 1) {
*buf = '\0';
len = 0;
}
errstr.ptr = buf;
errstr.slen = len;
return errstr;
}

View File

@ -1,148 +1,148 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/except.c 6 10/14/05 12:26a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/except.c $
*
* 6 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 5 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 4 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/except.h>
#include <pj/os.h>
#include <pj/assert.h>
#include <pj/log.h>
#include <pj/errno.h>
static long thread_local_id = -1;
#if defined(PJ_HAS_EXCEPTION_NAMES) && PJ_HAS_EXCEPTION_NAMES != 0
static const char *exception_id_names[PJ_MAX_EXCEPTION_ID];
#else
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
static int last_exception_id = 1;
#endif /* PJ_HAS_EXCEPTION_NAMES */
PJ_DEF(void) pj_throw_exception_(int exception_id)
{
struct pj_exception_state_t *handler;
handler = pj_thread_local_get(thread_local_id);
if (handler == NULL) {
PJ_LOG(1,("except.c", "!!!FATAL: unhandled exception %d!\n", exception_id));
pj_assert(handler != NULL);
/* This will crash the system! */
}
pj_longjmp(handler->state, exception_id);
}
PJ_DEF(void) pj_push_exception_handler_(struct pj_exception_state_t *rec)
{
struct pj_exception_state_t *parent_handler = NULL;
if (thread_local_id == -1) {
pj_thread_local_alloc(&thread_local_id);
pj_assert(thread_local_id != -1);
}
parent_handler = pj_thread_local_get(thread_local_id);
rec->prev = parent_handler;
pj_thread_local_set(thread_local_id, rec);
}
PJ_DEF(void) pj_pop_exception_handler_(void)
{
struct pj_exception_state_t *handler;
handler = pj_thread_local_get(thread_local_id);
pj_assert(handler != NULL);
pj_thread_local_set(thread_local_id, handler->prev);
}
#if defined(PJ_HAS_EXCEPTION_NAMES) && PJ_HAS_EXCEPTION_NAMES != 0
PJ_DEF(pj_status_t) pj_exception_id_alloc( const char *name,
pj_exception_id_t *id)
{
unsigned i;
pj_enter_critical_section();
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
for (i=1; i<PJ_MAX_EXCEPTION_ID; ++i) {
if (exception_id_names[i] == NULL) {
exception_id_names[i] = name;
*id = i;
pj_leave_critical_section();
return PJ_SUCCESS;
}
}
pj_leave_critical_section();
return PJ_ETOOMANY;
}
PJ_DEF(pj_status_t) pj_exception_id_free( pj_exception_id_t id )
{
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
PJ_ASSERT_RETURN(id>0 && id<PJ_MAX_EXCEPTION_ID, PJ_EINVAL);
pj_enter_critical_section();
exception_id_names[id] = NULL;
pj_leave_critical_section();
return PJ_SUCCESS;
}
PJ_DEF(const char*) pj_exception_id_name(pj_exception_id_t id)
{
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
PJ_ASSERT_RETURN(id>0 && id<PJ_MAX_EXCEPTION_ID, "<Invalid ID>");
if (exception_id_names[id] == NULL)
return "<Unallocated ID>";
return exception_id_names[id];
}
#else /* PJ_HAS_EXCEPTION_NAMES */
PJ_DEF(pj_status_t) pj_exception_id_alloc( const char *name,
pj_exception_id_t *id)
{
PJ_ASSERT_RETURN(last_exception_id < PJ_MAX_EXCEPTION_ID-1, PJ_ETOOMANY);
*id = last_exception_id++
return PJ_SUCCESS;
}
PJ_DEF(pj_status_t) pj_exception_id_free( pj_exception_id_t id )
{
return PJ_SUCCESS;
}
PJ_DEF(const char*) pj_exception_id_name(pj_exception_id_t id)
{
return "";
}
#endif /* PJ_HAS_EXCEPTION_NAMES */
/* $Header: /pjproject-0.3/pjlib/src/pj/except.c 6 10/14/05 12:26a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/except.c $
*
* 6 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 5 9/21/05 1:39p Bennylp
* Periodic checkin for backup.
*
* 4 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/except.h>
#include <pj/os.h>
#include <pj/assert.h>
#include <pj/log.h>
#include <pj/errno.h>
static long thread_local_id = -1;
#if defined(PJ_HAS_EXCEPTION_NAMES) && PJ_HAS_EXCEPTION_NAMES != 0
static const char *exception_id_names[PJ_MAX_EXCEPTION_ID];
#else
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
static int last_exception_id = 1;
#endif /* PJ_HAS_EXCEPTION_NAMES */
PJ_DEF(void) pj_throw_exception_(int exception_id)
{
struct pj_exception_state_t *handler;
handler = pj_thread_local_get(thread_local_id);
if (handler == NULL) {
PJ_LOG(1,("except.c", "!!!FATAL: unhandled exception %d!\n", exception_id));
pj_assert(handler != NULL);
/* This will crash the system! */
}
pj_longjmp(handler->state, exception_id);
}
PJ_DEF(void) pj_push_exception_handler_(struct pj_exception_state_t *rec)
{
struct pj_exception_state_t *parent_handler = NULL;
if (thread_local_id == -1) {
pj_thread_local_alloc(&thread_local_id);
pj_assert(thread_local_id != -1);
}
parent_handler = pj_thread_local_get(thread_local_id);
rec->prev = parent_handler;
pj_thread_local_set(thread_local_id, rec);
}
PJ_DEF(void) pj_pop_exception_handler_(void)
{
struct pj_exception_state_t *handler;
handler = pj_thread_local_get(thread_local_id);
pj_assert(handler != NULL);
pj_thread_local_set(thread_local_id, handler->prev);
}
#if defined(PJ_HAS_EXCEPTION_NAMES) && PJ_HAS_EXCEPTION_NAMES != 0
PJ_DEF(pj_status_t) pj_exception_id_alloc( const char *name,
pj_exception_id_t *id)
{
unsigned i;
pj_enter_critical_section();
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
for (i=1; i<PJ_MAX_EXCEPTION_ID; ++i) {
if (exception_id_names[i] == NULL) {
exception_id_names[i] = name;
*id = i;
pj_leave_critical_section();
return PJ_SUCCESS;
}
}
pj_leave_critical_section();
return PJ_ETOOMANY;
}
PJ_DEF(pj_status_t) pj_exception_id_free( pj_exception_id_t id )
{
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
PJ_ASSERT_RETURN(id>0 && id<PJ_MAX_EXCEPTION_ID, PJ_EINVAL);
pj_enter_critical_section();
exception_id_names[id] = NULL;
pj_leave_critical_section();
return PJ_SUCCESS;
}
PJ_DEF(const char*) pj_exception_id_name(pj_exception_id_t id)
{
/*
* Start from 1 (not 0)!!!
* Exception 0 is reserved for normal path of setjmp()!!!
*/
PJ_ASSERT_RETURN(id>0 && id<PJ_MAX_EXCEPTION_ID, "<Invalid ID>");
if (exception_id_names[id] == NULL)
return "<Unallocated ID>";
return exception_id_names[id];
}
#else /* PJ_HAS_EXCEPTION_NAMES */
PJ_DEF(pj_status_t) pj_exception_id_alloc( const char *name,
pj_exception_id_t *id)
{
PJ_ASSERT_RETURN(last_exception_id < PJ_MAX_EXCEPTION_ID-1, PJ_ETOOMANY);
*id = last_exception_id++
return PJ_SUCCESS;
}
PJ_DEF(pj_status_t) pj_exception_id_free( pj_exception_id_t id )
{
return PJ_SUCCESS;
}
PJ_DEF(const char*) pj_exception_id_name(pj_exception_id_t id)
{
return "";
}
#endif /* PJ_HAS_EXCEPTION_NAMES */

View File

@ -1,38 +1,38 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/extra-exports.c 1 10/29/05 11:56a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/extra-exports.c $
*
* 1 10/29/05 11:56a Bennylp
* Version 0.3-pre2
*
*/
/*
* This file contains code to export extra symbols from Linux kernel.
* It should be copied to Linux kernel source tree and added to
* Linux kernel combilation.
*
* This file is part of PJLIB project.
*/
#include <linux/module.h>
#include <linux/syscalls.h>
EXPORT_SYMBOL(sys_select);
EXPORT_SYMBOL(sys_epoll_create);
EXPORT_SYMBOL(sys_epoll_ctl);
EXPORT_SYMBOL(sys_epoll_wait);
EXPORT_SYMBOL(sys_socket);
EXPORT_SYMBOL(sys_bind);
EXPORT_SYMBOL(sys_getpeername);
EXPORT_SYMBOL(sys_getsockname);
EXPORT_SYMBOL(sys_sendto);
EXPORT_SYMBOL(sys_recvfrom);
EXPORT_SYMBOL(sys_getsockopt);
EXPORT_SYMBOL(sys_setsockopt);
EXPORT_SYMBOL(sys_listen);
EXPORT_SYMBOL(sys_shutdown);
EXPORT_SYMBOL(sys_connect);
EXPORT_SYMBOL(sys_accept);
/* $Header: /pjproject-0.3/pjlib/src/pj/extra-exports.c 1 10/29/05 11:56a Bennylp $ */
/*
* $Log: /pjproject-0.3/pjlib/src/pj/extra-exports.c $
*
* 1 10/29/05 11:56a Bennylp
* Version 0.3-pre2
*
*/
/*
* This file contains code to export extra symbols from Linux kernel.
* It should be copied to Linux kernel source tree and added to
* Linux kernel combilation.
*
* This file is part of PJLIB project.
*/
#include <linux/module.h>
#include <linux/syscalls.h>
EXPORT_SYMBOL(sys_select);
EXPORT_SYMBOL(sys_epoll_create);
EXPORT_SYMBOL(sys_epoll_ctl);
EXPORT_SYMBOL(sys_epoll_wait);
EXPORT_SYMBOL(sys_socket);
EXPORT_SYMBOL(sys_bind);
EXPORT_SYMBOL(sys_getpeername);
EXPORT_SYMBOL(sys_getsockname);
EXPORT_SYMBOL(sys_sendto);
EXPORT_SYMBOL(sys_recvfrom);
EXPORT_SYMBOL(sys_getsockopt);
EXPORT_SYMBOL(sys_setsockopt);
EXPORT_SYMBOL(sys_listen);
EXPORT_SYMBOL(sys_shutdown);
EXPORT_SYMBOL(sys_connect);
EXPORT_SYMBOL(sys_accept);

View File

@ -1,182 +1,182 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/fifobuf.c 4 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/fifobuf.c $
*
* 4 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/fifobuf.h>
#include <pj/log.h>
#include <pj/assert.h>
#include <pj/os.h>
#define THIS_FILE "fifobuf"
#define SZ sizeof(unsigned)
PJ_DEF(void)
pj_fifobuf_init (pj_fifobuf_t *fifobuf, void *buffer, unsigned size)
{
PJ_CHECK_STACK();
PJ_LOG(6, (THIS_FILE,
"fifobuf_init fifobuf=%p buffer=%p, size=%d",
fifobuf, buffer, size));
fifobuf->first = buffer;
fifobuf->last = fifobuf->first + size;
fifobuf->ubegin = fifobuf->uend = fifobuf->first;
fifobuf->full = 0;
}
PJ_DEF(unsigned)
pj_fifobuf_max_size (pj_fifobuf_t *fifobuf)
{
unsigned s1, s2;
PJ_CHECK_STACK();
if (fifobuf->uend >= fifobuf->ubegin) {
s1 = fifobuf->last - fifobuf->uend;
s2 = fifobuf->ubegin - fifobuf->first;
} else {
s1 = s2 = fifobuf->ubegin - fifobuf->uend;
}
return s1<s2 ? s2 : s1;
}
PJ_DEF(void*)
pj_fifobuf_alloc (pj_fifobuf_t *fifobuf, unsigned size)
{
unsigned available;
char *start;
PJ_CHECK_STACK();
if (fifobuf->full) {
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: full!",
fifobuf, size));
return NULL;
}
/* try to allocate from the end part of the fifo */
if (fifobuf->uend >= fifobuf->ubegin) {
available = fifobuf->last - fifobuf->uend;
if (available >= size+SZ) {
char *ptr = fifobuf->uend;
fifobuf->uend += (size+SZ);
if (fifobuf->uend == fifobuf->last)
fifobuf->uend = fifobuf->first;
if (fifobuf->uend == fifobuf->ubegin)
fifobuf->full = 1;
*(unsigned*)ptr = size+SZ;
ptr += SZ;
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: returning %p, p1=%p, p2=%p",
fifobuf, size, ptr, fifobuf->ubegin, fifobuf->uend));
return ptr;
}
}
/* try to allocate from the start part of the fifo */
start = (fifobuf->uend <= fifobuf->ubegin) ? fifobuf->uend : fifobuf->first;
available = fifobuf->ubegin - start;
if (available >= size+SZ) {
char *ptr = start;
fifobuf->uend = start + size + SZ;
if (fifobuf->uend == fifobuf->ubegin)
fifobuf->full = 1;
*(unsigned*)ptr = size+SZ;
ptr += SZ;
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: returning %p, p1=%p, p2=%p",
fifobuf, size, ptr, fifobuf->ubegin, fifobuf->uend));
return ptr;
}
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: no space left! p1=%p, p2=%p",
fifobuf, size, fifobuf->ubegin, fifobuf->uend));
return NULL;
}
PJ_DEF(pj_status_t)
pj_fifobuf_unalloc (pj_fifobuf_t *fifobuf, void *buf)
{
char *ptr = buf;
char *endptr;
unsigned sz;
PJ_CHECK_STACK();
ptr -= SZ;
sz = *(unsigned*)ptr;
endptr = fifobuf->uend;
if (endptr == fifobuf->first)
endptr = fifobuf->last;
if (ptr+sz != endptr) {
pj_assert(!"Invalid pointer to undo alloc");
return -1;
}
fifobuf->uend = ptr;
fifobuf->full = 0;
PJ_LOG(6, (THIS_FILE,
"fifobuf_unalloc fifobuf=%p, ptr=%p, size=%d, p1=%p, p2=%p",
fifobuf, buf, sz, fifobuf->ubegin, fifobuf->uend));
return 0;
}
PJ_DEF(pj_status_t)
pj_fifobuf_free (pj_fifobuf_t *fifobuf, void *buf)
{
char *ptr = buf;
char *end;
unsigned sz;
PJ_CHECK_STACK();
ptr -= SZ;
if (ptr < fifobuf->first || ptr >= fifobuf->last) {
pj_assert(!"Invalid pointer to free");
return -1;
}
if (ptr != fifobuf->ubegin && ptr != fifobuf->first) {
pj_assert(!"Invalid free() sequence!");
return -1;
}
end = (fifobuf->uend > fifobuf->ubegin) ? fifobuf->uend : fifobuf->last;
sz = *(unsigned*)ptr;
if (ptr+sz > end) {
pj_assert(!"Invalid size!");
return -1;
}
fifobuf->ubegin = ptr + sz;
/* Rollover */
if (fifobuf->ubegin == fifobuf->last)
fifobuf->ubegin = fifobuf->first;
/* Reset if fifobuf is empty */
if (fifobuf->ubegin == fifobuf->uend)
fifobuf->ubegin = fifobuf->uend = fifobuf->first;
fifobuf->full = 0;
PJ_LOG(6, (THIS_FILE,
"fifobuf_free fifobuf=%p, ptr=%p, size=%d, p1=%p, p2=%p",
fifobuf, buf, sz, fifobuf->ubegin, fifobuf->uend));
return 0;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/fifobuf.c 4 9/17/05 10:37a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/fifobuf.c $
*
* 4 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/fifobuf.h>
#include <pj/log.h>
#include <pj/assert.h>
#include <pj/os.h>
#define THIS_FILE "fifobuf"
#define SZ sizeof(unsigned)
PJ_DEF(void)
pj_fifobuf_init (pj_fifobuf_t *fifobuf, void *buffer, unsigned size)
{
PJ_CHECK_STACK();
PJ_LOG(6, (THIS_FILE,
"fifobuf_init fifobuf=%p buffer=%p, size=%d",
fifobuf, buffer, size));
fifobuf->first = buffer;
fifobuf->last = fifobuf->first + size;
fifobuf->ubegin = fifobuf->uend = fifobuf->first;
fifobuf->full = 0;
}
PJ_DEF(unsigned)
pj_fifobuf_max_size (pj_fifobuf_t *fifobuf)
{
unsigned s1, s2;
PJ_CHECK_STACK();
if (fifobuf->uend >= fifobuf->ubegin) {
s1 = fifobuf->last - fifobuf->uend;
s2 = fifobuf->ubegin - fifobuf->first;
} else {
s1 = s2 = fifobuf->ubegin - fifobuf->uend;
}
return s1<s2 ? s2 : s1;
}
PJ_DEF(void*)
pj_fifobuf_alloc (pj_fifobuf_t *fifobuf, unsigned size)
{
unsigned available;
char *start;
PJ_CHECK_STACK();
if (fifobuf->full) {
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: full!",
fifobuf, size));
return NULL;
}
/* try to allocate from the end part of the fifo */
if (fifobuf->uend >= fifobuf->ubegin) {
available = fifobuf->last - fifobuf->uend;
if (available >= size+SZ) {
char *ptr = fifobuf->uend;
fifobuf->uend += (size+SZ);
if (fifobuf->uend == fifobuf->last)
fifobuf->uend = fifobuf->first;
if (fifobuf->uend == fifobuf->ubegin)
fifobuf->full = 1;
*(unsigned*)ptr = size+SZ;
ptr += SZ;
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: returning %p, p1=%p, p2=%p",
fifobuf, size, ptr, fifobuf->ubegin, fifobuf->uend));
return ptr;
}
}
/* try to allocate from the start part of the fifo */
start = (fifobuf->uend <= fifobuf->ubegin) ? fifobuf->uend : fifobuf->first;
available = fifobuf->ubegin - start;
if (available >= size+SZ) {
char *ptr = start;
fifobuf->uend = start + size + SZ;
if (fifobuf->uend == fifobuf->ubegin)
fifobuf->full = 1;
*(unsigned*)ptr = size+SZ;
ptr += SZ;
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: returning %p, p1=%p, p2=%p",
fifobuf, size, ptr, fifobuf->ubegin, fifobuf->uend));
return ptr;
}
PJ_LOG(6, (THIS_FILE,
"fifobuf_alloc fifobuf=%p, size=%d: no space left! p1=%p, p2=%p",
fifobuf, size, fifobuf->ubegin, fifobuf->uend));
return NULL;
}
PJ_DEF(pj_status_t)
pj_fifobuf_unalloc (pj_fifobuf_t *fifobuf, void *buf)
{
char *ptr = buf;
char *endptr;
unsigned sz;
PJ_CHECK_STACK();
ptr -= SZ;
sz = *(unsigned*)ptr;
endptr = fifobuf->uend;
if (endptr == fifobuf->first)
endptr = fifobuf->last;
if (ptr+sz != endptr) {
pj_assert(!"Invalid pointer to undo alloc");
return -1;
}
fifobuf->uend = ptr;
fifobuf->full = 0;
PJ_LOG(6, (THIS_FILE,
"fifobuf_unalloc fifobuf=%p, ptr=%p, size=%d, p1=%p, p2=%p",
fifobuf, buf, sz, fifobuf->ubegin, fifobuf->uend));
return 0;
}
PJ_DEF(pj_status_t)
pj_fifobuf_free (pj_fifobuf_t *fifobuf, void *buf)
{
char *ptr = buf;
char *end;
unsigned sz;
PJ_CHECK_STACK();
ptr -= SZ;
if (ptr < fifobuf->first || ptr >= fifobuf->last) {
pj_assert(!"Invalid pointer to free");
return -1;
}
if (ptr != fifobuf->ubegin && ptr != fifobuf->first) {
pj_assert(!"Invalid free() sequence!");
return -1;
}
end = (fifobuf->uend > fifobuf->ubegin) ? fifobuf->uend : fifobuf->last;
sz = *(unsigned*)ptr;
if (ptr+sz > end) {
pj_assert(!"Invalid size!");
return -1;
}
fifobuf->ubegin = ptr + sz;
/* Rollover */
if (fifobuf->ubegin == fifobuf->last)
fifobuf->ubegin = fifobuf->first;
/* Reset if fifobuf is empty */
if (fifobuf->ubegin == fifobuf->uend)
fifobuf->ubegin = fifobuf->uend = fifobuf->first;
fifobuf->full = 0;
PJ_LOG(6, (THIS_FILE,
"fifobuf_free fifobuf=%p, ptr=%p, size=%d, p1=%p, p2=%p",
fifobuf, buf, sz, fifobuf->ubegin, fifobuf->uend));
return 0;
}

View File

@ -1,19 +1,19 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/guid.c 12 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/guid.c $
*
* 12 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 11 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/guid.h>
#include <pj/pool.h>
PJ_DEF(void) pj_create_unique_string(pj_pool_t *pool, pj_str_t *str)
{
str->ptr = pj_pool_alloc(pool, PJ_GUID_STRING_LENGTH);
pj_generate_unique_string(str);
}
/* $Header: /pjproject-0.3/pjlib/src/pj/guid.c 12 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/guid.c $
*
* 12 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 11 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/guid.h>
#include <pj/pool.h>
PJ_DEF(void) pj_create_unique_string(pj_pool_t *pool, pj_str_t *str)
{
str->ptr = pj_pool_alloc(pool, PJ_GUID_STRING_LENGTH);
pj_generate_unique_string(str);
}

View File

@ -1,60 +1,60 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/guid_simple.c 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/guid_simple.c $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/guid.h>
#include <pj/os.h>
#include <pj/rand.h>
#include <pj/string.h>
#include <pj/compat/sprintf.h>
const unsigned PJ_GUID_STRING_LENGTH=20;
static void init_mac_address(unsigned char mac_addr[16])
{
unsigned long *ulval1 = (unsigned long*) &mac_addr[0];
unsigned short *usval1 = (unsigned short*) &mac_addr[4];
*ulval1 = pj_rand();
*usval1 = (unsigned short) pj_rand();
}
PJ_DEF(pj_str_t*) pj_generate_unique_string(pj_str_t *str)
{
static int guid_initialized;
static unsigned pid;
static char str_pid[5];
static unsigned char mac_addr[6];
static char str_mac_addr[16];
static unsigned clock_seq;
PJ_CHECK_STACK();
if (guid_initialized == 0) {
pid = pj_getpid();
init_mac_address(mac_addr);
clock_seq = 0;
sprintf(str_pid, "%04x", pid);
sprintf(str_mac_addr, "%02x%02x%02x%02x%02x%02x",
mac_addr[0], mac_addr[1], mac_addr[2],
mac_addr[3], mac_addr[4], mac_addr[5]);
guid_initialized = 1;
}
strcpy(str->ptr, str_pid);
sprintf(str->ptr+4, "%04x", clock_seq++);
pj_memcpy(str->ptr+8, str_mac_addr, 12);
str->slen = 20;
return str;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/guid_simple.c 3 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/guid_simple.c $
*
* 3 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 2 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/guid.h>
#include <pj/os.h>
#include <pj/rand.h>
#include <pj/string.h>
#include <pj/compat/sprintf.h>
const unsigned PJ_GUID_STRING_LENGTH=20;
static void init_mac_address(unsigned char mac_addr[16])
{
unsigned long *ulval1 = (unsigned long*) &mac_addr[0];
unsigned short *usval1 = (unsigned short*) &mac_addr[4];
*ulval1 = pj_rand();
*usval1 = (unsigned short) pj_rand();
}
PJ_DEF(pj_str_t*) pj_generate_unique_string(pj_str_t *str)
{
static int guid_initialized;
static unsigned pid;
static char str_pid[5];
static unsigned char mac_addr[6];
static char str_mac_addr[16];
static unsigned clock_seq;
PJ_CHECK_STACK();
if (guid_initialized == 0) {
pid = pj_getpid();
init_mac_address(mac_addr);
clock_seq = 0;
sprintf(str_pid, "%04x", pid);
sprintf(str_mac_addr, "%02x%02x%02x%02x%02x%02x",
mac_addr[0], mac_addr[1], mac_addr[2],
mac_addr[3], mac_addr[4], mac_addr[5]);
guid_initialized = 1;
}
strcpy(str->ptr, str_pid);
sprintf(str->ptr+4, "%04x", clock_seq++);
pj_memcpy(str->ptr+8, str_mac_addr, 12);
str->slen = 20;
return str;
}

View File

@ -1,61 +1,61 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/guid_win32.c 4 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/guid_win32.c $
*
* 4 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 3 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/guid.h>
#include <pj/string.h>
#include <pj/sock.h>
#include <windows.h>
#include <objbase.h>
#include <pj/os.h>
const unsigned PJ_GUID_STRING_LENGTH=32;
PJ_INLINE(void) hex2digit(unsigned value, char *p)
{
static char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
*p++ = hex[ (value & 0xF0) >> 4 ];
*p++ = hex[ (value & 0x0F) ];
}
static void guid_to_str( const GUID *guid, pj_str_t *str )
{
unsigned i;
GUID guid_copy;
const unsigned char *src = (const unsigned char*)&guid_copy;
char *dst = str->ptr;
pj_memcpy(&guid_copy, guid, sizeof(*guid));
guid_copy.Data1 = pj_ntohl(guid_copy.Data1);
guid_copy.Data2 = pj_ntohs(guid_copy.Data2);
guid_copy.Data3 = pj_ntohs(guid_copy.Data3);
for (i=0; i<16; ++i) {
hex2digit( *src, dst );
dst += 2;
++src;
}
str->slen = 32;
}
PJ_DEF(pj_str_t*) pj_generate_unique_string(pj_str_t *str)
{
GUID guid;
PJ_CHECK_STACK();
CoCreateGuid(&guid);
guid_to_str( &guid, str );
return str;
}
/* $Header: /pjproject-0.3/pjlib/src/pj/guid_win32.c 4 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/guid_win32.c $
*
* 4 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 3 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/guid.h>
#include <pj/string.h>
#include <pj/sock.h>
#include <windows.h>
#include <objbase.h>
#include <pj/os.h>
const unsigned PJ_GUID_STRING_LENGTH=32;
PJ_INLINE(void) hex2digit(unsigned value, char *p)
{
static char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
*p++ = hex[ (value & 0xF0) >> 4 ];
*p++ = hex[ (value & 0x0F) ];
}
static void guid_to_str( const GUID *guid, pj_str_t *str )
{
unsigned i;
GUID guid_copy;
const unsigned char *src = (const unsigned char*)&guid_copy;
char *dst = str->ptr;
pj_memcpy(&guid_copy, guid, sizeof(*guid));
guid_copy.Data1 = pj_ntohl(guid_copy.Data1);
guid_copy.Data2 = pj_ntohs(guid_copy.Data2);
guid_copy.Data3 = pj_ntohs(guid_copy.Data3);
for (i=0; i<16; ++i) {
hex2digit( *src, dst );
dst += 2;
++src;
}
str->slen = 32;
}
PJ_DEF(pj_str_t*) pj_generate_unique_string(pj_str_t *str)
{
GUID guid;
PJ_CHECK_STACK();
CoCreateGuid(&guid);
guid_to_str( &guid, str );
return str;
}

View File

@ -1,252 +1,252 @@
/* $Header: /pjproject-0.3/pjlib/src/pj/hash.c 8 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/hash.c $
*
* 8 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 7 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/hash.h>
#include <pj/log.h>
#include <pj/string.h>
#include <pj/pool.h>
#include <pj/os.h>
/**
* The hash multiplier used to calculate hash value.
*/
#define PJ_HASH_MULTIPLIER 33
struct pj_hash_entry
{
struct pj_hash_entry *next;
const void *key;
pj_uint32_t hash;
pj_uint32_t keylen;
void *value;
};
struct pj_hash_table_t
{
pj_hash_entry **table;
unsigned count, rows;
pj_hash_iterator_t iterator;
};
PJ_DEF(pj_uint32_t) pj_hash_calc(pj_uint32_t hash, const void *key, unsigned keylen)
{
PJ_CHECK_STACK();
if (keylen==PJ_HASH_KEY_STRING) {
const unsigned char *p = key;
for ( ; *p; ++p ) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
keylen = p - (const unsigned char*)key;
} else {
const unsigned char *p = key,
*end = p + keylen;
for ( ; p!=end; ++p) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
}
return hash;
}
PJ_DEF(pj_hash_table_t*) pj_hash_create(pj_pool_t *pool, unsigned size)
{
pj_hash_table_t *h;
unsigned table_size;
h = pj_pool_alloc(pool, sizeof(pj_hash_table_t));
h->count = 0;
PJ_LOG( 5, ("hashtbl", "hash table %p created from pool %s", h, pj_pool_getobjname(pool)));
/* size must be 2^n - 1.
round-up the size to this rule, except when size is 2^n, then size
will be round-down to 2^n-1.
*/
table_size = 8;
do {
table_size <<= 1;
} while (table_size <= size);
table_size -= 1;
h->rows = table_size;
h->table = pj_pool_calloc(pool, table_size+1, sizeof(pj_hash_entry*));
return h;
}
static pj_hash_entry **find_entry( pj_pool_t *pool, pj_hash_table_t *ht,
const void *key, unsigned keylen,
void *val)
{
pj_uint32_t hash;
pj_hash_entry **p_entry, *entry;
hash=0;
if (keylen==PJ_HASH_KEY_STRING) {
const unsigned char *p = key;
for ( ; *p; ++p ) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
keylen = p - (const unsigned char*)key;
} else {
const unsigned char *p = key,
*end = p + keylen;
for ( ; p!=end; ++p) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
}
/* scan the linked list */
for (p_entry = &ht->table[hash & ht->rows], entry=*p_entry;
entry;
p_entry = &entry->next, entry = *p_entry)
{
if (entry->hash==hash && entry->keylen==keylen &&
memcmp(entry->key, key, keylen)==0)
{
break;
}
}
if (entry || val==NULL)
return p_entry;
/* create a new entry */
entry = pj_pool_alloc(pool, sizeof(pj_hash_entry));
PJ_LOG(5, ("hashtbl", "%p: New p_entry %p created, pool used=%u, cap=%u", ht, entry,
pj_pool_get_used_size(pool), pj_pool_get_capacity(pool)));
entry->next = NULL;
entry->hash = hash;
entry->key = key;
entry->keylen = keylen;
entry->value = val;
*p_entry = entry;
++ht->count;
return p_entry;
}
PJ_DEF(void *) pj_hash_get( pj_hash_table_t *ht,
const void *key, unsigned keylen )
{
pj_hash_entry *entry;
entry = *find_entry( NULL, ht, key, keylen, NULL);
return entry ? entry->value : NULL;
}
PJ_DEF(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht,
const void *key, unsigned keylen,
void *value )
{
pj_hash_entry **p_entry;
p_entry = find_entry( pool, ht, key, keylen, value );
if (*p_entry) {
if (value == NULL) {
/* delete entry */
PJ_LOG(5, ("hashtbl", "%p: p_entry %p deleted", ht, *p_entry));
*p_entry = (*p_entry)->next;
--ht->count;
} else {
/* overwrite */
(*p_entry)->value = value;
PJ_LOG(5, ("hashtbl", "%p: p_entry %p value set to %p", ht, *p_entry, value));
}
}
}
PJ_DEF(unsigned) pj_hash_count( pj_hash_table_t *ht )
{
return ht->count;
}
PJ_DEF(pj_hash_iterator_t*) pj_hash_first( pj_hash_table_t *ht,
pj_hash_iterator_t *it )
{
it->index = 0;
it->entry = NULL;
for (; it->index < ht->rows; ++it->index) {
it->entry = ht->table[it->index];
if (it->entry) {
break;
}
}
return it->entry ? it : NULL;
}
PJ_DEF(pj_hash_iterator_t*) pj_hash_next( pj_hash_table_t *ht,
pj_hash_iterator_t *it )
{
it->entry = it->entry->next;
if (it->entry) {
return it;
}
for (++it->index; it->index < ht->rows; ++it->index) {
it->entry = ht->table[it->index];
if (it->entry) {
break;
}
}
return it->entry ? it : NULL;
}
PJ_DEF(void*) pj_hash_this( pj_hash_table_t *ht, pj_hash_iterator_t *it )
{
PJ_CHECK_STACK();
PJ_UNUSED_ARG(ht);
return it->entry->value;
}
#if 0
void pj_hash_dump_collision( pj_hash_table_t *ht )
{
unsigned min=0xFFFFFFFF, max=0;
unsigned i;
char line[120];
int len, totlen = 0;
for (i=0; i<ht->rows; ++i) {
unsigned count = 0;
pj_hash_entry *entry = ht->table[i];
while (entry) {
++count;
entry = entry->next;
}
if (count < min)
min = count;
if (count > max)
max = count;
len = pj_snprintf( line+totlen, sizeof(line)-totlen, "%3d:%3d ", i, count);
if (len < 1)
break;
totlen += len;
if ((i+1) % 10 == 0) {
line[totlen] = '\0';
PJ_LOG(4,(__FILE__, line));
}
}
PJ_LOG(4,(__FILE__,"Count: %d, min: %d, max: %d\n", ht->count, min, max));
}
#endif
/* $Header: /pjproject-0.3/pjlib/src/pj/hash.c 8 10/14/05 12:26a Bennylp $ */
/* $Log: /pjproject-0.3/pjlib/src/pj/hash.c $
*
* 8 10/14/05 12:26a Bennylp
* Finished error code framework, some fixes in ioqueue, etc. Pretty
* major.
*
* 7 9/17/05 10:37a Bennylp
* Major reorganization towards version 0.3.
*
*/
#include <pj/hash.h>
#include <pj/log.h>
#include <pj/string.h>
#include <pj/pool.h>
#include <pj/os.h>
/**
* The hash multiplier used to calculate hash value.
*/
#define PJ_HASH_MULTIPLIER 33
struct pj_hash_entry
{
struct pj_hash_entry *next;
const void *key;
pj_uint32_t hash;
pj_uint32_t keylen;
void *value;
};
struct pj_hash_table_t
{
pj_hash_entry **table;
unsigned count, rows;
pj_hash_iterator_t iterator;
};
PJ_DEF(pj_uint32_t) pj_hash_calc(pj_uint32_t hash, const void *key, unsigned keylen)
{
PJ_CHECK_STACK();
if (keylen==PJ_HASH_KEY_STRING) {
const unsigned char *p = key;
for ( ; *p; ++p ) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
keylen = p - (const unsigned char*)key;
} else {
const unsigned char *p = key,
*end = p + keylen;
for ( ; p!=end; ++p) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
}
return hash;
}
PJ_DEF(pj_hash_table_t*) pj_hash_create(pj_pool_t *pool, unsigned size)
{
pj_hash_table_t *h;
unsigned table_size;
h = pj_pool_alloc(pool, sizeof(pj_hash_table_t));
h->count = 0;
PJ_LOG( 5, ("hashtbl", "hash table %p created from pool %s", h, pj_pool_getobjname(pool)));
/* size must be 2^n - 1.
round-up the size to this rule, except when size is 2^n, then size
will be round-down to 2^n-1.
*/
table_size = 8;
do {
table_size <<= 1;
} while (table_size <= size);
table_size -= 1;
h->rows = table_size;
h->table = pj_pool_calloc(pool, table_size+1, sizeof(pj_hash_entry*));
return h;
}
static pj_hash_entry **find_entry( pj_pool_t *pool, pj_hash_table_t *ht,
const void *key, unsigned keylen,
void *val)
{
pj_uint32_t hash;
pj_hash_entry **p_entry, *entry;
hash=0;
if (keylen==PJ_HASH_KEY_STRING) {
const unsigned char *p = key;
for ( ; *p; ++p ) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
keylen = p - (const unsigned char*)key;
} else {
const unsigned char *p = key,
*end = p + keylen;
for ( ; p!=end; ++p) {
hash = hash * PJ_HASH_MULTIPLIER + *p;
}
}
/* scan the linked list */
for (p_entry = &ht->table[hash & ht->rows], entry=*p_entry;
entry;
p_entry = &entry->next, entry = *p_entry)
{
if (entry->hash==hash && entry->keylen==keylen &&
memcmp(entry->key, key, keylen)==0)
{
break;
}
}
if (entry || val==NULL)
return p_entry;
/* create a new entry */
entry = pj_pool_alloc(pool, sizeof(pj_hash_entry));
PJ_LOG(5, ("hashtbl", "%p: New p_entry %p created, pool used=%u, cap=%u", ht, entry,
pj_pool_get_used_size(pool), pj_pool_get_capacity(pool)));
entry->next = NULL;
entry->hash = hash;
entry->key = key;
entry->keylen = keylen;
entry->value = val;
*p_entry = entry;
++ht->count;
return p_entry;
}
PJ_DEF(void *) pj_hash_get( pj_hash_table_t *ht,
const void *key, unsigned keylen )
{
pj_hash_entry *entry;
entry = *find_entry( NULL, ht, key, keylen, NULL);
return entry ? entry->value : NULL;
}
PJ_DEF(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht,
const void *key, unsigned keylen,
void *value )
{
pj_hash_entry **p_entry;
p_entry = find_entry( pool, ht, key, keylen, value );
if (*p_entry) {
if (value == NULL) {
/* delete entry */
PJ_LOG(5, ("hashtbl", "%p: p_entry %p deleted", ht, *p_entry));
*p_entry = (*p_entry)->next;
--ht->count;
} else {
/* overwrite */
(*p_entry)->value = value;
PJ_LOG(5, ("hashtbl", "%p: p_entry %p value set to %p", ht, *p_entry, value));
}
}
}
PJ_DEF(unsigned) pj_hash_count( pj_hash_table_t *ht )
{
return ht->count;
}
PJ_DEF(pj_hash_iterator_t*) pj_hash_first( pj_hash_table_t *ht,
pj_hash_iterator_t *it )
{
it->index = 0;
it->entry = NULL;
for (; it->index < ht->rows; ++it->index) {
it->entry = ht->table[it->index];
if (it->entry) {
break;
}
}
return it->entry ? it : NULL;
}
PJ_DEF(pj_hash_iterator_t*) pj_hash_next( pj_hash_table_t *ht,
pj_hash_iterator_t *it )
{
it->entry = it->entry->next;
if (it->entry) {
return it;
}
for (++it->index; it->index < ht->rows; ++it->index) {
it->entry = ht->table[it->index];
if (it->entry) {
break;
}
}
return it->entry ? it : NULL;
}
PJ_DEF(void*) pj_hash_this( pj_hash_table_t *ht, pj_hash_iterator_t *it )
{
PJ_CHECK_STACK();
PJ_UNUSED_ARG(ht);
return it->entry->value;
}
#if 0
void pj_hash_dump_collision( pj_hash_table_t *ht )
{
unsigned min=0xFFFFFFFF, max=0;
unsigned i;
char line[120];
int len, totlen = 0;
for (i=0; i<ht->rows; ++i) {
unsigned count = 0;
pj_hash_entry *entry = ht->table[i];
while (entry) {
++count;
entry = entry->next;
}
if (count < min)
min = count;
if (count > max)
max = count;
len = pj_snprintf( line+totlen, sizeof(line)-totlen, "%3d:%3d ", i, count);
if (len < 1)
break;
totlen += len;
if ((i+1) % 10 == 0) {
line[totlen] = '\0';
PJ_LOG(4,(__FILE__, line));
}
}
PJ_LOG(4,(__FILE__,"Count: %d, min: %d, max: %d\n", ht->count, min, max));
}
#endif

Some files were not shown because too many files have changed in this diff Show More