Commit b94767f8 authored by Slava Monich's avatar Slava Monich

wsputil.c packaged as a shared libary

parent ec989d4d
*~
build
debian/*.log
debian/*substvars
debian/libwspcodec-dev
debian/files
debian/tmp
# -*- Mode: makefile -*-
.PHONY: clean all debug release pkgconfig install install-dev
# Required packages
PKGS = glib-2.0
#
# Default target
#
all: debug release pkgconfig
#
# Library version
#
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_MICRO = 0
VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_MICRO)
LIB_SHORTCUT = libwspcodec.so
LIB_SONAME = $(LIB_SHORTCUT).$(VERSION_MAJOR)
LIB = $(LIB_SHORTCUT).$(VERSION)
#
# Sources
#
SRC = wsputil.c
#
# Directories
#
SRC_DIR = src
BUILD_DIR = build
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
#
# Tools and flags
#
CC = $(CROSS_COMPILE)gcc
LD = $(CC)
WARNINGS = -Wall
INCLUDES = -I$(SRC_DIR)
CFLAGS = -fPIC $(WARNINGS) $(INCLUDES) $(shell pkg-config --cflags $(PKGS))
LDFLAGS = -fPIC -shared -Wl,-soname -Wl,$(LIB_SONAME)
DEBUG_CFLAGS = -g -DDEBUG $(CFLAGS) -MMD -MP
DEBUG_LDFLAGS = -g $(LDFLAGS)
RELEASE_CFLAGS = -O2 $(CFLAGS) -MMD -MP
RELEASE_LDFLAGS = $(LDFLAGS)
ARFLAGS = rc
#
# Files
#
PKGCONFIG = $(BUILD_DIR)/libwspcodec.pc
SRC_FILES = $(SRC:%=$(SRC_DIR)/%)
DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
#
# Dependencies
#
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
endif
#
# Rules
#
DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
debug: $(DEBUG_LIB)
release: $(RELEASE_LIB)
pkgconfig: $(PKGCONFIG)
clean:
rm -fr $(BUILD_DIR) *~ $(SRC_DIR)/*~
$(BUILD_DIR):
mkdir -p $@
$(DEBUG_BUILD_DIR):
mkdir -p $@
$(RELEASE_BUILD_DIR):
mkdir -p $@
$(DEBUG_LIB): $(DEBUG_BUILD_DIR) $(DEBUG_OBJS)
$(LD) -o $@ $(DEBUG_LDFLAGS) $(DEBUG_OBJS)
$(RELEASE_LIB): $(RELEASE_BUILD_DIR) $(RELEASE_OBJS)
$(LD) -o $@ $(RELEASE_LDFLAGS) $(RELEASE_OBJS)
strip $@
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(DEBUG_CFLAGS) -MF"$(@:%.o=%.d)" $< -o $@
$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(RELEASE_CFLAGS) -MF"$(@:%.o=%.d)" $< -o $@
$(PKGCONFIG): libwspcodec.pc.in
sed -e 's/\[version\]/'$(VERSION)/g $< >> $@
#
# Install
#
INSTALL_PERM = 644
INSTALL_OWNER = $(shell id -u)
INSTALL_GROUP = $(shell id -g)
INSTALL = install
INSTALL_DIRS = $(INSTALL) -d
INSTALL_FILES = $(INSTALL) -m $(INSTALL_PERM)
INSTALL_LIB_DIR = $(DESTDIR)/usr/lib
INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/libwspcodec/wspcodec
INSTALL_PKGCONFIG_DIR = $(DESTDIR)/usr/lib/pkgconfig
INSTALL_ALIAS1 = $(INSTALL_LIB_DIR)/$(LIB_SONAME)
INSTALL_ALIAS2 = $(INSTALL_LIB_DIR)/$(LIB_SHORTCUT)
install: $(INSTALL_LIB_DIR)
$(INSTALL_FILES) $(RELEASE_LIB) $(INSTALL_LIB_DIR)
ln -sf $(LIB) $(INSTALL_ALIAS1)
ln -sf $(LIB) $(INSTALL_ALIAS2)
install-dev: install $(INSTALL_INCLUDE_DIR) $(INSTALL_PKGCONFIG_DIR)
$(INSTALL_FILES) $(SRC_DIR)/wsputil.h $(INSTALL_INCLUDE_DIR)
$(INSTALL_FILES) $(SRC_DIR)/wspcodec.h $(INSTALL_INCLUDE_DIR)
$(INSTALL_FILES) $(PKGCONFIG) $(INSTALL_PKGCONFIG_DIR)
$(INSTALL_LIB_DIR):
$(INSTALL_DIRS) $@
$(INSTALL_INCLUDE_DIR):
$(INSTALL_DIRS) $@
$(INSTALL_PKGCONFIG_DIR):
$(INSTALL_DIRS) $@
libwspcodec (1.0.0-1) unstable; urgency=low
* Initial release
-- Slava Monich <s;ava.monich@jolla.com> Sat, 14 Dec 2013 13:20:14 +0200
Source: libwspcodec
Section: libs
Priority: optional
Maintainer: Slava Monich <slava.monich@jolla.com>
Build-Depends: debhelper (>= 7), libglib2.0-dev (>= 2.0)
Standards-Version: 3.8.4
Package: libwspcodec
Section: libs
Architecture: any
Depends: libglib2.0-bin (>= 2.0)
Description: WSP encoder and decoder library
Package: libwspcodec-dev
Section: libdevel
Architecture: any
Depends: libwspcodec (= ${binary:Version})
Description: Development files for libwspcodec
Copyright (C) 2013 Jolla Ltd.
You may use this file under the terms of the BSD license as follows:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Nemo Mobile nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
src/wspcodec.h usr/include/libwspcodec/wspcodec
src/wsputil.h usr/include/libwspcodec/wspcodec
build/libwspcodec.pc usr/lib/pkgconfig
#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@
libdir=/usr/lib
includedir=/usr/include/libwspcodec
Name: libwspcodec
Description: WSP encoder and decoder library
Version: [version]
Requires: glib-2.0
Libs: -L${libdir} -lwspcodec
Cflags: -I${includedir} -I${includedir}/wspcodec
Name: libwspcodec
Version: 1.0.0
Release: 1
Summary: WSP encoder and decoder library
Group: Development/Libraries
License: LGPL
URL: http://github.com/nemomobile
Source: %{name}-%{version}.tar.bz2
Requires: glib2 >= 2.0
BuildRequires: glib2-devel >= 2.0
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%description
Provides utilities to encode and decode WSP PDUs.
%package devel
Summary: Development library for %{name}
Requires: %{name} = %{version}
Requires: pkgconfig
%description devel
This package contains the development library for %{name}.
%prep
%setup -q
%build
make release pkgconfig
%install
rm -rf %{buildroot}
make install-dev DESTDIR=%{buildroot}
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files
%defattr(-,root,root,-)
%{_libdir}/%{name}.so*
%files devel
%defattr(-,root,root,-)
%{_libdir}/%{name}.so*
%{_libdir}/pkgconfig/libwspcodec.pc
%{_includedir}/libwspcodec/wspcodec/wsputil.h
%{_includedir}/libwspcodec/wspcodec/wspcodec.h
/* Copyright (C) 2013 Jolla Ltd.
*
* You may use this file under the terms of the BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WSPCODEC_H
#define WSPCODEC_H
#include <glib.h>
#include "wsputil.h"
#endif /* WSPCODEC_H */
This diff is collapsed.
/*
*
* Multimedia Messaging Service
*
* Copyright (C) 2010-2011 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
enum wsp_header_iter_flag {
WSP_HEADER_ITER_FLAG_REJECT_CP = 0x1,
WSP_HEADER_ITER_FLAG_DETECT_MMS_MULTIPART = 0x2,
};
enum wsp_header_type {
WSP_HEADER_TYPE_WELL_KNOWN,
WSP_HEADER_TYPE_APPLICATION
};
enum wsp_value_type {
WSP_VALUE_TYPE_LONG,
WSP_VALUE_TYPE_SHORT,
WSP_VALUE_TYPE_TEXT,
};
enum wsp_header_token {
WSP_HEADER_TOKEN_APP_ID = 0x2F,
};
enum wsp_parameter_type {
WSP_PARAMETER_TYPE_Q = 0x00,
WSP_PARAMETER_TYPE_CHARSET = 0x01,
WSP_PARAMETER_TYPE_LEVEL = 0x02,
WSP_PARAMETER_TYPE_TYPE = 0x03,
WSP_PARAMETER_TYPE_NAME_DEFUNCT = 0x05,
WSP_PARAMETER_TYPE_FILENAME_DEFUNCT = 0x06,
WSP_PARAMETER_TYPE_DIFFERENCES = 0x07,
WSP_PARAMETER_TYPE_PADDING = 0x08,
WSP_PARAMETER_TYPE_CONTENT_TYPE = 0x09,
WSP_PARAMETER_TYPE_START_DEFUNCT = 0x0A,
WSP_PARAMETER_TYPE_START_INFO_DEFUNCT = 0x0B,
WSP_PARAMETER_TYPE_COMMENT_DEFUNCT = 0x0C,
WSP_PARAMETER_TYPE_DOMAIN_DEFUNCT = 0x0D,
WSP_PARAMETER_TYPE_MAX_AGE = 0x0E,
WSP_PARAMETER_TYPE_PATH_DEFUNCT = 0x0F,
WSP_PARAMETER_TYPE_SECURE = 0x10,
WSP_PARAMETER_TYPE_SEC = 0x11,
WSP_PARAMETER_TYPE_MAC = 0x12,
WSP_PARAMETER_TYPE_CREATION_DATE = 0x13,
WSP_PARAMETER_TYPE_MODIFICATION_DATE = 0x14,
WSP_PARAMETER_TYPE_READ_DATE = 0x15,
WSP_PARAMETER_TYPE_SIZE = 0x16,
WSP_PARAMETER_TYPE_NAME = 0x17,
WSP_PARAMETER_TYPE_FILENAME = 0x18,
WSP_PARAMETER_TYPE_START = 0x19,
WSP_PARAMETER_TYPE_START_INFO = 0x1A,
WSP_PARAMETER_TYPE_COMMENT = 0x1B,
WSP_PARAMETER_TYPE_DOMAIN = 0x1C,
WSP_PARAMETER_TYPE_PATH = 0x1D,
WSP_PARAMETER_TYPE_UNTYPED = 0xFF,
};
enum wsp_parameter_value {
WSP_PARAMETER_VALUE_TEXT,
WSP_PARAMETER_VALUE_INT,
WSP_PARAMETER_VALUE_DATE,
WSP_PARAMETER_VALUE_Q,
};
struct wsp_parameter {
enum wsp_parameter_type type;
enum wsp_parameter_value value;
const char *untyped;
union {
const char *text;
unsigned int integer;
time_t date;
float q;
};
};
struct wsp_header_iter {
const unsigned char *pdu;
unsigned int max;
unsigned int pos;
unsigned int flags;
unsigned char code_page;
enum wsp_header_type header_type;
const void *header;
enum wsp_value_type value_type;
const void *value;
unsigned int len;
};
struct wsp_multipart_iter {
const unsigned char *pdu;
unsigned int max;
unsigned int pos;
const void *content_type;
const void *headers;
const void *body;
unsigned int content_type_len;
unsigned int headers_len;
unsigned int body_len;
};
struct wsp_parameter_iter {
const unsigned char *pdu;
unsigned int max;
unsigned int pos;
};
#define MAX_TEXT_HEADER_SIZE 4096
struct wsp_text_header_iter {
char hdr[MAX_TEXT_HEADER_SIZE + 1];
unsigned int pos;
const char *key;
const char *value;
};
gboolean wsp_decode_uintvar(const unsigned char *pdu, unsigned int len,
unsigned int *out_len, unsigned int *consumed);
gboolean wsp_decode_integer(const unsigned char *pdu, unsigned int len,
unsigned int *out_val, unsigned int *consumed);
gboolean wsp_decode_field(const unsigned char *pdu, unsigned int max,
enum wsp_value_type *out_type,
const void **out_value,
unsigned int *out_len,
unsigned int *consumed);
gboolean wsp_get_well_known_content_type(const char *text,
unsigned int *out_val);
gboolean wsp_get_well_known_charset(const char *text, unsigned int *out_val);
const char *wsp_decode_token_text(const unsigned char *pdu, unsigned int len,
unsigned int *consumed);
const char *wsp_decode_text(const unsigned char *pdu, unsigned int len,
unsigned int *consumed);
const char *wsp_decode_quoted_string(const unsigned char *pdu, unsigned int len,
unsigned int *consumed);
gboolean wsp_decode_content_type(const unsigned char *pdu, unsigned int max,
const void **out_value,
unsigned int *out_read,
unsigned int *out_param_len);
gboolean wsp_decode_application_id(struct wsp_header_iter *iter,
const void **out_value);
gboolean wsp_encode_uintvar(unsigned int value, unsigned char *dest,
unsigned int dest_size, unsigned int *written);
gboolean wsp_encode_value_length(unsigned int len, unsigned char *dest,
unsigned int dest_size, unsigned int *written);
gboolean wsp_encode_integer(unsigned int value, unsigned char *dest,
unsigned int dest_size, unsigned int *written);
void wsp_header_iter_init(struct wsp_header_iter *iter,
const unsigned char *pdu, unsigned int len,
unsigned int flags);
gboolean wsp_header_iter_next(struct wsp_header_iter *iter);
unsigned char wsp_header_iter_get_code_page(struct wsp_header_iter *iter);
gboolean wsp_header_iter_at_end(struct wsp_header_iter *iter);
gboolean wsp_header_iter_is_multipart(struct wsp_header_iter *iter);
enum wsp_header_type wsp_header_iter_get_hdr_type(struct wsp_header_iter *iter);
const unsigned char *wsp_header_iter_get_pdu(struct wsp_header_iter *iter);
const void *wsp_header_iter_get_hdr(struct wsp_header_iter *iter);
enum wsp_value_type wsp_header_iter_get_val_type(struct wsp_header_iter *iter);
const void *wsp_header_iter_get_val(struct wsp_header_iter *iter);
unsigned int wsp_header_iter_get_val_len(struct wsp_header_iter *iter);
gboolean wsp_multipart_iter_init(struct wsp_multipart_iter *mi,
struct wsp_header_iter *hi,
const void **out_content_type,
unsigned int *out_content_type_len);
gboolean wsp_multipart_iter_next(struct wsp_multipart_iter *mi);
const void *wsp_multipart_iter_get_content_type(struct wsp_multipart_iter *mi);
unsigned int wsp_multipart_iter_get_content_type_len(
struct wsp_multipart_iter *mi);
const void *wsp_multipart_iter_get_hdr(struct wsp_multipart_iter *mi);
unsigned int wsp_multipart_iter_get_hdr_len(struct wsp_multipart_iter *mi);
const void *wsp_multipart_iter_get_body(struct wsp_multipart_iter *mi);
unsigned int wsp_multipart_iter_get_body_len(struct wsp_multipart_iter *mi);
gboolean wsp_multipart_iter_close(struct wsp_multipart_iter *mi,
struct wsp_header_iter *hi);
void wsp_parameter_iter_init(struct wsp_parameter_iter *pi,
const unsigned char *pdu, unsigned int len);
gboolean wsp_parameter_iter_next(struct wsp_parameter_iter *pi,
struct wsp_parameter *out_param);
gboolean wsp_text_header_iter_init(struct wsp_text_header_iter *iter,
const char *hdr);
gboolean wsp_text_header_iter_param_next(struct wsp_text_header_iter *iter);
const char *wsp_text_header_iter_get_key(struct wsp_text_header_iter *iter);
const char *wsp_text_header_iter_get_value(struct wsp_text_header_iter *iter);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment