blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 2 268 | content_id stringlengths 40 40 | detected_licenses listlengths 0 58 | license_type stringclasses 2 values | repo_name stringlengths 5 118 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 816 values | visit_date timestamp[us] | revision_date timestamp[us] | committer_date timestamp[us] | github_id int64 2.31k 677M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 23 values | gha_event_created_at timestamp[us] | gha_created_at timestamp[us] | gha_language stringclasses 151 values | src_encoding stringclasses 33 values | language stringclasses 1 value | is_vendor bool 2 classes | is_generated bool 2 classes | length_bytes int64 3 10.3M | extension stringclasses 119 values | content stringlengths 3 10.3M | authors listlengths 1 1 | author_id stringlengths 0 228 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fa0d28e6c0015dca6b1981182fcf2a5dee8b457f | 310945db136ead3432802e99aa10523d174c14a0 | /c/c_02/ex04/ft_str_is_lowercase.c | 9eee267fa80cd433ff9395bc3745deb74c35e5cb | [] | no_license | ldominiq/piscine-42 | daba5d94cce591be267b31295a1d8e261dd63521 | 2064c7012fbf91bcbd47ab186577002e8a39f364 | refs/heads/main | 2023-07-13T23:25:02.562791 | 2021-08-26T18:22:57 | 2021-08-26T18:22:57 | 399,811,326 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,239 | c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_lowercase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldominiq <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/08 19:14:21 by ldominiq #+# #+# */
/* Updated: 2021/08/08 19:22:05 by ldominiq ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int count;
count = 0;
while (*str != '\0')
{
count++;
str++;
}
return (count);
}
int ft_str_is_lowercase(char *str)
{
int count;
count = 1;
if (ft_strlen(str) != 0)
{
while (*str)
{
if (!(*str >= 'a' && *str <= 'z'))
{
count--;
return (count);
}
str++;
}
}
return (count);
}
| [
"ldominiq@c2r7s1.42lausanne.ch"
] | ldominiq@c2r7s1.42lausanne.ch |
fb0c51b9313a4e389554b61aae3a8c5bc5f35b50 | 872d285cdbee7e6e42dd9dd160ef9167b3aafe94 | /10/os/kozos.c | d9e15daaefc5167fbf9e5627fabb194a1711e927 | [] | no_license | wakanapo/12stepOS | f4b64bd72bbddc7dcfbf9262f2f62ca9c1507c32 | 584b3c8ed79507c86f7d9643b8de5d7cbf928ac1 | refs/heads/master | 2021-01-10T01:36:18.811093 | 2015-12-29T09:43:28 | 2015-12-29T09:43:28 | 48,740,038 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 6,452 | c | #include "defines.h"
#include "kozos.h"
#include "intr.h"
#include "interrupt.h"
#include "syscall.h"
#include "memory.h"
#include "lib.h"
#define THREAD_NUM 6
#define PRIORITY_NUM 16
#define THREAD_NAME_SIZE 15
typedef struct _kz_context {
uint32 sp;
} kz_context;
typedef struct _kz_thread {
struct _kz_thread *next;
char name[THREAD_NAME_SIZE + 1];
int priority;
char *stack;
uint32 flags;
#define KZ_THREAD_FLAG_READY (1 << 0)
struct{
kz_func_t func;
int argc;
char **argv;
} init;
struct {
kz_syscall_type_t type;
kz_syscall_param_t *param;
} syscall;
kz_context context;
} kz_thread;
static struct {
kz_thread *head;
kz_thread *tail;
} readyque[PRIORITY_NUM];
static kz_thread *current;
static kz_thread threads[THREAD_NUM];
static kz_handler_t handlers[SOFTVEC_TYPE_NUM];
void dispatch(kz_context *context);
static int getcurrent(void) {
if (current == NULL) {
return -1;
}
if (!(current->flags & KZ_THREAD_FLAG_READY)) {
return -1;
}
readyque[current->priority].head = current->next;
if (readyque[current->priority].head == NULL) {
readyque[current->priority].tail = NULL;
}
current->flags &= ~KZ_THREAD_FLAG_READY;
current->next = NULL;
return 0;
}
static int putcurrent(void) {
if (current == NULL) {
return -1;
}
if (current->flags & KZ_THREAD_FLAG_READY) {
return 1;
}
if (readyque[current->priority].tail) {
readyque[current->priority].tail->next = current;
}
else {
readyque[current->priority].head = current;
}
readyque[current->priority].tail = current;
current->flags |= KZ_THREAD_FLAG_READY;
return 0;
}
static void thread_end(void) {
kz_exit();
}
static void thread_init(kz_thread *thp) {
thp->init.func(thp->init.argc, thp->init.argv);
thread_end();
}
static kz_thread_id_t thread_run(kz_func_t func, char *name, int priority,
int stacksize, int argc, char *argv[]) {
int i;
kz_thread *thp;
uint32 *sp;
extern char userstack;
static char *thread_stack = &userstack;
for (i = 0; i < THREAD_NUM; i++) {
thp = &threads[i];
if(!thp->init.func)
break;
}
if ( i == THREAD_NUM)
return -1;
memset(thp, 0, sizeof(*thp));
strcpy(thp->name, name);
thp->next = NULL;
thp->priority = priority;
thp->flags = 0;
thp->init.func = func;
thp->init.argc = argc;
thp->init.argv = argv;
memset(thread_stack, 0, stacksize);
thread_stack += stacksize;
thp->stack = thread_stack;
sp = (uint32 *)thp->stack;
*(--sp) = (uint32)thread_end;
*(--sp) = (uint32)thread_init | ((uint32)(priority ? 0 : 0xc0) << 24);
*(--sp) = 0;
*(--sp) = 0;
*(--sp) = 0;
*(--sp) = 0;
*(--sp) = 0;
*(--sp) = 0;
*(--sp) = (uint32)thp;
thp->context.sp = (uint32)sp;
putcurrent();
current = thp;
putcurrent();
return (kz_thread_id_t)current;
}
static int thread_exit(void) {
puts(current->name);
puts(" EXIT.\n");
memset(current, 0, sizeof(*current));
return 0;
}
static int thread_wait(void) {
putcurrent();
return 0;
}
static int thread_sleep(void) {
return 0;
}
static int thread_wakeup(kz_thread_id_t id) {
putcurrent();
current = (kz_thread *)id;
putcurrent();
return 0;
}
static kz_thread_id_t thread_getid(void) {
putcurrent();
return (kz_thread_id_t)current;
}
static int thread_chpri(int priority) {
int old = current->priority;
if (priority >= 0)
current->priority = priority;
putcurrent();
return old;
}
static void *thread_kmalloc(int size) {
putcurrent();
return kzmem_alloc(size);
}
static int thread_kmfree(char *p) {
kzmem_free(p);
putcurrent();
return 0;
}
static int setintr(softvec_type_t type, kz_handler_t handler) {
static void thread_intr(softvec_type_t type, unsigned long sp);
softvec_setintr(type, thread_intr);
handlers[type] = handler;
return 0;
}
static void call_functions(kz_syscall_type_t type, kz_syscall_param_t *p) {
switch (type) {
case KZ_SYSCALL_TYPE_RUN:
p->un.run.ret = thread_run(p->un.run.func, p->un.run.name,
p->un.run.priority, p->un.run.stacksize,
p->un.run.argc, p->un.run.argv);
break;
case KZ_SYSCALL_TYPE_EXIT:
thread_exit();
break;
case KZ_SYSCALL_TYPE_WAIT:
p->un.wait.ret = thread_wait();
break;
case KZ_SYSCALL_TYPE_SLEEP:
p->un.sleep.ret = thread_sleep();
break;
case KZ_SYSCALL_TYPE_WAKEUP:
p->un.wakeup.ret = thread_wakeup(p->un.wakeup.id);
break;
case KZ_SYSCALL_TYPE_GETID:
p->un.getid.ret = thread_getid();
break;
case KZ_SYSCALL_TYPE_CHPRI:
p->un.chpri.ret = thread_chpri(p->un.chpri.priority);
break;
case KZ_SYSCALL_TYPE_KMALLOC:
p->un.kmalloc.ret = thread_kmalloc(p->un.kmalloc.size);
break;
case KZ_SYSCALL_TYPE_KMFREE:
p->un.kmfree.ret = thread_kmfree(p->un.kmfree.p);
break;
default:
break;
}
}
static void syscall_proc(kz_syscall_type_t type, kz_syscall_param_t *p) {
getcurrent();
call_functions(type, p);
}
static void schedule(void) {
int i;
for (i = 0; i < PRIORITY_NUM; i++) {
if (readyque[i].head)
break;
}
if (i == PRIORITY_NUM)
kz_sysdown();
current = readyque[i].head;
}
static void syscall_intr(void) {
syscall_proc(current->syscall.type, current->syscall.param);
}
static void softerr_intr(void) {
puts(current->name);
puts(" DOWN.\n");
getcurrent();
thread_exit();
}
static void thread_intr(softvec_type_t type, unsigned long sp) {
current->context.sp = sp;
if (handlers[type])
handlers[type]();
schedule();
dispatch(¤t->context);
}
void kz_start(kz_func_t func, char *name, int priority, int stacksize,
int argc, char *argv[]) {
kzmem_init();
current = NULL;
memset(readyque, 0, sizeof(readyque));
memset(threads, 0, sizeof(threads));
memset(handlers, 0, sizeof(handlers));
setintr(SOFTVEC_TYPE_SYSCALL, syscall_intr);
setintr(SOFTVEC_TYPE_SOFTERR, softerr_intr);
current = (kz_thread *)thread_run(func, name, priority, stacksize,
argc, argv);
dispatch(¤t->context);
}
void kz_sysdown(void) {
puts("system error!\n");
while (1)
;
}
void kz_syscall(kz_syscall_type_t type, kz_syscall_param_t *param) {
current->syscall.type = type;
current->syscall.param = param;
asm volatile ("trapa #0");
}
| [
"wakana.tn16@gmail.com"
] | wakana.tn16@gmail.com |
8edd608cef5601329f769c1e526d5d12d5ff47c2 | a589ac4904030315331b41a624d8603ad86cb2b5 | /utests/ut_timer.h | c93db6445b32da6f1220b3f2bac1df9b58afffd4 | [
"WTFPL"
] | permissive | yapbreak/iot_libtimer | 580683695ceeea1c1ac54eb800c731ac4a8062d3 | 5e27661bf9ed0ce3b39d4938d0a59b09e7bf48f1 | refs/heads/master | 2020-03-23T12:22:53.008355 | 2018-09-19T14:14:39 | 2018-09-19T14:14:43 | 141,555,195 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 8,106 | h | #ifndef UT_TIMER_H_PTS0JNL4
#define UT_TIMER_H_PTS0JNL4
#include <CppUTest/TestHarness.h>
#include "timer.h"
#include "ArduinoFixtures.h"
TEST_GROUP(timer)
{
void setup()
{
fixtures::registerInstance(f);
timer = new arduino_timer_t();
count = 0;
f.set_micros(0);
}
void teardown()
{
delete timer;
timer = NULL;
}
fixtures f;
arduino_timer_t *timer;
int count;
};
void event_counter(void *arg)
{
int *count = static_cast<int *>(arg);
CHECK(count != NULL);
(*count)++;
}
TEST(timer, no_event)
{
timer->loop();
f.set_micros(100);
timer->loop();
};
TEST(timer, one_second_event_no_repeat)
{
f.set_millis(100);
arduino_event_t event(1, "s", 1, event_counter, &count);
timer->add_event(event);
timer->loop();
LONGS_EQUAL(0, count);
f.set_millis(1099);
timer->loop();
LONGS_EQUAL(0, count);
f.set_millis(1100);
timer->loop();
LONGS_EQUAL(1, count);
f.set_millis(1101);
timer->loop();
LONGS_EQUAL(1, count);
f.set_millis(2099);
timer->loop();
LONGS_EQUAL(1, count);
f.set_millis(2100);
timer->loop();
LONGS_EQUAL(1, count);
f.set_millis(2101);
timer->loop();
LONGS_EQUAL(1, count);
}
TEST(timer, one_second_event_no_repeat_copy_constructor)
{
f.set_millis(100);
arduino_event_t event(1, "s", 1, event_counter, &count);
timer->add_event(event);
arduino_timer_t timer2(*timer);
timer2.loop();
LONGS_EQUAL(0, count);
f.set_millis(1099);
timer2.loop();
LONGS_EQUAL(0, count);
f.set_millis(1100);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(1101);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(2099);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(2100);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(2101);
timer2.loop();
LONGS_EQUAL(1, count);
}
TEST(timer, one_second_event_no_repeat_copy_affect)
{
f.set_millis(100);
arduino_event_t event(1, "s", 1, event_counter, &count);
timer->add_event(event);
arduino_timer_t timer2;
timer2.add_event(event);
timer2 = (*timer);
timer2.loop();
LONGS_EQUAL(0, count);
f.set_millis(1099);
timer2.loop();
LONGS_EQUAL(0, count);
f.set_millis(1100);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(1101);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(2099);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(2100);
timer2.loop();
LONGS_EQUAL(1, count);
f.set_millis(2101);
timer2.loop();
LONGS_EQUAL(1, count);
}
TEST(timer, one_millisecond_event_one_repeat)
{
f.set_micros(100);
arduino_event_t event(1, "ms", 2, event_counter, &count);
timer->add_event(event);
timer->loop();
LONGS_EQUAL(0, count);
f.set_micros(1099);
timer->loop();
LONGS_EQUAL(0, count);
f.set_micros(1100);
timer->loop();
LONGS_EQUAL(1, count);
f.set_micros(1101);
timer->loop();
LONGS_EQUAL(1, count);
f.set_micros(2099);
timer->loop();
LONGS_EQUAL(1, count);
f.set_micros(2100);
timer->loop();
LONGS_EQUAL(2, count);
f.set_micros(2101);
timer->loop();
LONGS_EQUAL(2, count);
f.set_micros(3099);
timer->loop();
LONGS_EQUAL(2, count);
f.set_micros(3100);
timer->loop();
LONGS_EQUAL(2, count);
f.set_micros(3101);
timer->loop();
LONGS_EQUAL(2, count);
}
TEST(timer, one_microsecond_event_continuous_repeat)
{
arduino_event_t event(10, "us", -1, event_counter, &count);
timer->add_event(event);
timer->loop();
LONGS_EQUAL(0, count);
for (size_t i = 1; i < 100; i++) {
f.set_micros(i * 10 - 1);
timer->loop();
LONGS_EQUAL(i - 1, count);
f.set_micros(i * 10);
timer->loop();
LONGS_EQUAL(i, count);
f.set_micros(i * 10 + 1);
timer->loop();
LONGS_EQUAL(i, count);
}
}
TEST(timer, malformed_event)
{
arduino_event_t event(10, "ns", -1, event_counter, &count);
timer->add_event(event);
timer->loop();
LONGS_EQUAL(0, count);
for (size_t i = 1; i < 100; i++) {
f.set_micros(i * 10);
timer->loop();
LONGS_EQUAL(0, count);
}
}
TEST(timer, overflow_event_too_far)
{
arduino_event_t event(4295, "s", 1, event_counter, &count);
timer->add_event(event);
f.set_millis(f.get_millis() + 10000);
timer->loop();
LONGS_EQUAL(0, count);
for (size_t i = 0; i < 500; i++) {
f.set_millis(f.get_millis() + 10000);
timer->loop();
}
LONGS_EQUAL(1, count);
}
TEST(timer, overflow_late)
{
f.set_micros(0xfffffffc);
arduino_event_t event(1, "ms", 2, event_counter, &count);
timer->add_event(event);
timer->loop();
LONGS_EQUAL(0, count);
f.set_micros(f.get_micros() + 1);
timer->loop();
LONGS_EQUAL(0, count);
f.set_micros(f.get_micros() + 998);
timer->loop();
LONGS_EQUAL(0, count);
f.set_micros(f.get_micros() + 1);
timer->loop();
LONGS_EQUAL(1, count);
f.set_micros(f.get_micros() + 1);
timer->loop();
LONGS_EQUAL(1, count);
}
TEST(timer, twoevents)
{
int many_count[2] = { };
f.set_micros(0);
for (int i = 0; i < 2; i++) {
timer->add_event(arduino_event_t(i + 1, "ms", 1, event_counter, &many_count[i]));
}
timer->loop();
LONGS_EQUAL(0, many_count[0]);
LONGS_EQUAL(0, many_count[1]);
f.set_micros(f.get_micros() + 999);
timer->loop();
LONGS_EQUAL(0, many_count[0]);
LONGS_EQUAL(0, many_count[1]);
f.set_micros(f.get_micros() + 1);
timer->loop();
LONGS_EQUAL(1, many_count[0]);
LONGS_EQUAL(0, many_count[1]);
f.set_micros(f.get_micros() + 999);
timer->loop();
LONGS_EQUAL(1, many_count[0]);
LONGS_EQUAL(0, many_count[1]);
f.set_micros(f.get_micros() + 1);
timer->loop();
LONGS_EQUAL(1, many_count[0]);
LONGS_EQUAL(1, many_count[1]);
}
TEST(timer, tenevents)
{
int many_count[10] = { };
f.set_micros(0);
for (int i = 0; i < 10; i++) {
timer->add_event(arduino_event_t(i + 1, "ms", 1, event_counter, &many_count[i]));
}
timer->loop();
for (int i = 0; i < 10; i++) {
LONGS_EQUAL(0, many_count[i]);
}
f.set_micros(10001);
timer->loop();
for (int i = 0; i < 10; i++) {
LONGS_EQUAL(1, many_count[i]);
}
}
TEST(timer, twoevents_reverse)
{
int many_count[2] = { };
f.set_micros(0);
for (int i = 0; i < 2; i++) {
timer->add_event(arduino_event_t(2 - i, "ms", 1, event_counter, &many_count[i]));
}
timer->loop();
LONGS_EQUAL(0, many_count[0]);
LONGS_EQUAL(0, many_count[1]);
f.set_micros(f.get_micros() + 999);
timer->loop();
LONGS_EQUAL(0, many_count[0]);
LONGS_EQUAL(0, many_count[1]);
f.set_micros(f.get_micros() + 1);
timer->loop();
LONGS_EQUAL(0, many_count[0]);
LONGS_EQUAL(1, many_count[1]);
f.set_micros(f.get_micros() + 999);
timer->loop();
LONGS_EQUAL(0, many_count[0]);
LONGS_EQUAL(1, many_count[1]);
f.set_micros(f.get_micros() + 1);
timer->loop();
LONGS_EQUAL(1, many_count[0]);
LONGS_EQUAL(1, many_count[1]);
}
TEST_GROUP(timerprint)
{
void setup()
{
fixtures::registerInstance(f);
timer = new arduino_timer_t();
}
void teardown()
{
delete timer;
timer = NULL;
mem.clear();
}
fixtures f;
memory mem;
arduino_timer_t *timer;
};
TEST(timerprint, noevent)
{
timer->printTo(mem);
STRCMP_CONTAINS("Event list #0 / #1\n", mem.getcontent().c_str());
STRCMP_CONTAINS("| | 0 |", mem.getcontent().c_str());
};
TEST(timerprint, oneevent)
{
timer->add_event(arduino_event_t(1, "ms", 1, event_counter, NULL));
timer->printTo(mem);
STRCMP_CONTAINS("Event list #1 / #1\n", mem.getcontent().c_str());
STRCMP_CONTAINS("|X| 0 |", mem.getcontent().c_str());
};
#endif /* end of include guard: UT_TIMER_H_PTS0JNL4 */
| [
"olivaa+gitlab@yapbreak.fr"
] | olivaa+gitlab@yapbreak.fr |
e068ece468648be714e6835467a0c2a334c9da44 | a1beca4556a501f16147155c116babcb204f8752 | /XBAutoLayout/XBAutoLayout/XBAutolayout/XBLayoutDefine.h | 84eab05b614f18c651ff4b450ed54ee68fedb08c | [] | no_license | huisedediao/XBAutolayout | 44a0b6d847018ecd6e1c31e78f0ac8d7a12f110d | 2983d3a46c8686028f3bd39b44a0beaa80421239 | refs/heads/master | 2021-05-07T18:45:03.818173 | 2017-10-30T12:45:52 | 2017-10-30T12:45:52 | 108,825,331 | 2 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,173 | h | //
// XBLayoutDefine.h
// XBAutoLayout
//
// Created by xxb on 2017/10/30.
// Copyright © 2017年 xxb. All rights reserved.
//
#ifndef XBLayoutDefine_h
#define XBLayoutDefine_h
typedef enum
{
XBSideTop = 0, //上
XBSideBottom, //下
XBSideLeft, //左
XBSideRight //右
}XBSide;
#define K_Layout_key_dicM_constraints @"K_Layout_key_dicM_constraints"
#define K_Layout_key_left @"K_Layout_key_left"
#define K_Layout_key_right @"K_Layout_key_right"
#define K_Layout_key_top @"K_Layout_key_top"
#define K_Layout_key_bottom @"K_Layout_key_bottom"
#define K_Layout_key_center @"K_Layout_key_center"
#define K_Layout_key_centerX @"K_Layout_key_centerX"
#define K_Layout_key_centerY @"K_Layout_key_centerY"
#define K_Layout_key_width @"K_Layout_key_width"
#define K_Layout_key_height @"K_Layout_key_height"
#define K_Layout_key_size @"K_Layout_key_size"
#define K_Layout_key_owner @"K_Layout_key_owner"
#define K_Layout_key_constraint @"K_Layout_key_constraint"
#endif /* XBLayoutDefine_h */
| [
"401758785@qq.com"
] | 401758785@qq.com |
e2cea7741290beceec0a293eb1828b41d0aaf142 | a31db7bb55564ea39e4d68fd1d46dca9dd595052 | /linux_c_test/memory_string_ctrl/memccpy.c | 6fb6e32e836088950b52266ea7b70757c114af30 | [] | no_license | pandygui/some_simple_work | 409379c2b3784586d105ec639dae966eb159e50c | 992da1e8dc23a46b67071446bef075853be79673 | refs/heads/master | 2020-03-28T16:42:05.030289 | 2013-02-01T07:28:03 | 2013-02-01T07:28:03 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 160 | c | #include <stdio.h>
#include <string.h>
void main()
{
char a[]="string[a]";
char b[]="string(b)";
memccpy(a,b,'B',sizeof(b));
printf("memccpy():%s\n",a);
}
| [
"imcanoe@gmail.com"
] | imcanoe@gmail.com |
d658c23ec6bbfb320de190edf524c698b3aba09d | 8848a706ae70bf2b88367b45a9d863461003a0fd | /week3/kadai3-2.c | 09027076a30ce9751942f8ec02f0a3b089578b67 | [] | no_license | tamlog06/cpro2020 | 1bb24b7d89a91570993159cd14829607bc48ba2b | 29788563ee05e3138a2e363a18d6269b3d8aa8d8 | refs/heads/master | 2023-01-09T16:04:13.013495 | 2020-11-16T13:26:41 | 2020-11-16T13:26:41 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 216 | c | #include <stdio.h>
int main() {
int n, fact_n;
fact_n = 1;
printf("n:");
scanf("%d", &n);
while (n > 0) {
fact_n *= n;
n -= 1;
}
printf("n!=%d", fact_n);
return 0;
} | [
"tamusyun1006@gmail.com"
] | tamusyun1006@gmail.com |
8415942cd5f36567028f938efdcbffb141751b37 | 756f56945870de76215ba07d4891241028be7eb4 | /FE1 - basics of OS and UNIX programming/ex12a.c | e2ed57e2ba2211cbd69469fcba8d09bc6a2cb602 | [] | no_license | margaridav27/feup-sope | d394da01b3ee588e00fdf66ba09ed0c939ba6db4 | 22a32d74720c7f564b8f183993eb90f63b70f305 | refs/heads/main | 2023-04-04T06:15:20.916533 | 2021-04-19T09:58:21 | 2021-04-19T09:58:21 | 342,920,175 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 693 | c | #include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
int main(int argc, char* argv[], char* env[]) {
DIR *dir;
struct dirent *dp;
if ((dir = opendir(argv[1])) == NULL) {
printf("Failed to open the directory.\n");
}
while((dp = readdir(dir)) != NULL) {
char *path = malloc(sizeof(argv[1]) + sizeof('/') + sizeof(dp->d_name));
strcpy(path, argv[1]);
strcat(path, "/");
strcat(path, dp->d_name);
struct stat s;
stat(path, &s);
printf("Filename: %s - %ld bytes\n", dp->d_name, s.st_size);
}
closedir(dir);
} | [
"margaridajcv.27@gmail.com"
] | margaridajcv.27@gmail.com |
35cdd21b36b44154d681abbc89a75568b6d13e46 | 06a0d989cf2dc78502df4e7f28dfa77200099d4c | /divisione.c | 15c972d8199ba8b4c837d2bcfc7e294246c8ac42 | [] | no_license | gcadau/APA-Exam | 9839be99bad8c42a3fd1f442ca0e533554e671ac | f8e131b5b3be657ceccf96b998cf726a2217b5d5 | refs/heads/master | 2023-01-30T06:35:29.871643 | 2019-02-28T17:07:07 | 2019-02-28T17:07:07 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 2,605 | c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dipendente.h"
#include "divisione.h"
#define I 2
#define OPERAIO 0
#define AMMINISTRATIVO 1
#define TECNICO 2
#define INFORMATICO 3
struct div_s
{
char* sigla;
int* dip;
int dimDip;
int actDimDip;
int* lav;
int dimLav;
int actDimLav;
dipendente_t* rifDipendenti;
};
void getLavoro(divisione_t d, int i, char* lavoro);
void stampaLavoro(int l, FILE* f);
void creaDiv(divisione_t* d)
{
(*d) = malloc(sizeof(struct div_s));
(*d)->dip = malloc(I*sizeof(int));
(*d)->lav = malloc(I*sizeof(int));
(*d)->dimDip = 0;
(*d)->dimLav = 0;
(*d)->actDimDip = I;
(*d)->actDimLav = I;
(*d)->rifDipendenti = NULL;
}
void distruggiDiv(divisione_t d)
{
free(d->sigla);
free(d->dip);
free(d->lav);
free(d);
}
void acquisisciDiv(divisione_t d, char* sigla)
{
d->sigla=strdup(sigla);
}
void insertDip(int i, divisione_t d, dipendente_t* rif, int lavoro)
{
if(d->rifDipendenti==NULL) d->rifDipendenti = rif;
if ( ((d->dimDip)+1) > d->actDimDip )
{
d->actDimDip*=I; d->actDimLav*=I;
d->dip = realloc(d->dip, (d->actDimDip)* sizeof(int));
d->lav = realloc(d->lav, (d->actDimLav)* sizeof(int));
}
d->dip[(d->dimDip)++] = i;
d->lav[(d->dimLav)++] = lavoro;
}
void stampaDivisione(FILE *salv, divisione_t d)
{
int i;
for(i=0; i<d->dimDip; i++)
{
stampaDipendente(d->rifDipendenti[d->dip[i]], salv);
fprintf(salv, " ");
stampaLavoro(d->lav[i], salv);
fprintf(salv, " ");
fprintf(salv, "%s\n", d->sigla);
}
}
char* getSigla(divisione_t d)
{
return strdup(d->sigla);
}
void getLavoro(divisione_t d, int i, char* lavoro)
{
switch(d->lav[i])
{
case OPERAIO:
strcpy(lavoro, "Operaio");
break;
case AMMINISTRATIVO:
strcpy(lavoro, "Amministrativo");
break;
case TECNICO:
strcpy(lavoro, "Tecnico");
break;
case INFORMATICO:
strcpy(lavoro, "Informatico");
break;
default:
strcpy(lavoro, "ND");
}
}
void stampaLavoro(int l, FILE* f)
{
switch(l)
{
case OPERAIO:
fprintf(f, "o");
break;
case AMMINISTRATIVO:
fprintf(f, "a");
break;
case TECNICO:
fprintf(f, "t");
break;
case INFORMATICO:
fprintf(f, "i");
break;
default:
fprintf(f, "ND");
}
}
| [
"noreply@github.com"
] | gcadau.noreply@github.com |
69cf7adf8195272c6d0737079a47b561baf6d992 | 3a13e6d49042252b49c27e33786d42ab7e1247f7 | /src/lapack/ATL_ilaenv.c | bba272c0620ba34801615c36d369a3b0b295321e | [] | no_license | biotrump/ATLAS | eb5ea19b1ff2d125539940930434d0efad131d84 | 72fe37a43a42226335e033c4b4ca3acd3fe679b7 | refs/heads/master | 2021-01-18T14:38:39.042759 | 2015-05-06T10:56:39 | 2015-05-06T10:56:39 | 30,685,399 | 1 | 0 | null | null | null | null | UTF-8 | C | false | false | 21,377 | c | #if !defined(ATL_USEPTHREADS) || (defined(ATL_NCPU) && ATL_NCPU > 1)
#include "atlas_lapack.h"
#include "atlas_level3.h"
#ifdef ATL_USEPTHREADS
#include "atlas_stGetNB_gelqf.h"
#ifdef ATL_stGetNB_gelqf
#define ATL_sGetNB_gelqf ATL_stGetNB_gelqf
#endif
#include "atlas_stGetNB_geqlf.h"
#ifdef ATL_stGetNB_geqlf
#define ATL_sGetNB_geqlf ATL_stGetNB_geqlf
#endif
#include "atlas_stGetNB_gerqf.h"
#ifdef ATL_stGetNB_gerqf
#define ATL_sGetNB_gerqf ATL_stGetNB_gerqf
#endif
#include "atlas_stGetNB_geqrf.h"
#ifdef ATL_stGetNB_geqrf
#define ATL_sGetNB_geqrf ATL_stGetNB_geqrf
#endif
#ifndef ATL_ilaenv
#define ATL_ilaenv ATL_itlaenv
#endif
#else
#include "atlas_sGetNB_gelqf.h"
#include "atlas_sGetNB_geqlf.h"
#include "atlas_sGetNB_gerqf.h"
#include "atlas_sGetNB_geqrf.h"
#endif
/*
* See if any QR rout has been tuned, and if so, set it to default QR tune
*/
#if defined(ATL_sGetNB_geqrf) && !defined(ATL_sGetNB_QR)
#define ATL_sGetNB_QR ATL_sGetNB_geqrf
#endif
#if defined(ATL_sGetNB_geqlf) && !defined(ATL_sGetNB_QR)
#define ATL_sGetNB_QR ATL_sGetNB_geqlf
#endif
#if defined(ATL_sGetNB_gerqf) && !defined(ATL_sGetNB_QR)
#define ATL_sGetNB_QR ATL_sGetNB_gerqf
#endif
#if defined(ATL_sGetNB_gelqf) && !defined(ATL_sGetNB_QR)
#define ATL_sGetNB_QR ATL_sGetNB_gelqf
#endif
/*
* Setup individual QR tunes if they haven't been indiviually tuned
*/
#ifndef ATL_sGetNB_geqrf
#ifdef ATL_sGetNB_QR
#define ATL_sGetNB_geqrf ATL_sGetNB_QR
#else
#define ATL_sGetNB_geqrf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_sGetNB_geqlf
#ifdef ATL_sGetNB_QR
#define ATL_sGetNB_geqlf ATL_sGetNB_QR
#else
#define ATL_sGetNB_geqlf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_sGetNB_gerqf
#ifdef ATL_sGetNB_QR
#define ATL_sGetNB_gerqf ATL_sGetNB_QR
#else
#define ATL_sGetNB_gerqf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_sGetNB_gelqf
#ifdef ATL_sGetNB_QR
#define ATL_sGetNB_gelqf ATL_sGetNB_QR
#else
#define ATL_sGetNB_gelqf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifdef ATL_USEPTHREADS
#include "atlas_dtGetNB_gelqf.h"
#ifdef ATL_dtGetNB_gelqf
#define ATL_dGetNB_gelqf ATL_dtGetNB_gelqf
#endif
#include "atlas_dtGetNB_geqlf.h"
#ifdef ATL_dtGetNB_geqlf
#define ATL_dGetNB_geqlf ATL_dtGetNB_geqlf
#endif
#include "atlas_dtGetNB_gerqf.h"
#ifdef ATL_dtGetNB_gerqf
#define ATL_dGetNB_gerqf ATL_dtGetNB_gerqf
#endif
#include "atlas_dtGetNB_geqrf.h"
#ifdef ATL_dtGetNB_geqrf
#define ATL_dGetNB_geqrf ATL_dtGetNB_geqrf
#endif
#ifndef ATL_ilaenv
#define ATL_ilaenv ATL_itlaenv
#endif
#else
#include "atlas_dGetNB_gelqf.h"
#include "atlas_dGetNB_geqlf.h"
#include "atlas_dGetNB_gerqf.h"
#include "atlas_dGetNB_geqrf.h"
#endif
/*
* See if any QR rout has been tuned, and if so, set it to default QR tune
*/
#if defined(ATL_dGetNB_geqrf) && !defined(ATL_dGetNB_QR)
#define ATL_dGetNB_QR ATL_dGetNB_geqrf
#endif
#if defined(ATL_dGetNB_geqlf) && !defined(ATL_dGetNB_QR)
#define ATL_dGetNB_QR ATL_dGetNB_geqlf
#endif
#if defined(ATL_dGetNB_gerqf) && !defined(ATL_dGetNB_QR)
#define ATL_dGetNB_QR ATL_dGetNB_gerqf
#endif
#if defined(ATL_dGetNB_gelqf) && !defined(ATL_dGetNB_QR)
#define ATL_dGetNB_QR ATL_dGetNB_gelqf
#endif
/*
* Setup individual QR tunes if they haven't been indiviually tuned
*/
#ifndef ATL_dGetNB_geqrf
#ifdef ATL_dGetNB_QR
#define ATL_dGetNB_geqrf ATL_dGetNB_QR
#else
#define ATL_dGetNB_geqrf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_dGetNB_geqlf
#ifdef ATL_dGetNB_QR
#define ATL_dGetNB_geqlf ATL_dGetNB_QR
#else
#define ATL_dGetNB_geqlf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_dGetNB_gerqf
#ifdef ATL_dGetNB_QR
#define ATL_dGetNB_gerqf ATL_dGetNB_QR
#else
#define ATL_dGetNB_gerqf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_dGetNB_gelqf
#ifdef ATL_dGetNB_QR
#define ATL_dGetNB_gelqf ATL_dGetNB_QR
#else
#define ATL_dGetNB_gelqf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifdef ATL_USEPTHREADS
#include "atlas_ctGetNB_gelqf.h"
#ifdef ATL_ctGetNB_gelqf
#define ATL_cGetNB_gelqf ATL_ctGetNB_gelqf
#endif
#include "atlas_ctGetNB_geqlf.h"
#ifdef ATL_ctGetNB_geqlf
#define ATL_cGetNB_geqlf ATL_ctGetNB_geqlf
#endif
#include "atlas_ctGetNB_gerqf.h"
#ifdef ATL_ctGetNB_gerqf
#define ATL_cGetNB_gerqf ATL_ctGetNB_gerqf
#endif
#include "atlas_ctGetNB_geqrf.h"
#ifdef ATL_ctGetNB_geqrf
#define ATL_cGetNB_geqrf ATL_ctGetNB_geqrf
#endif
#ifndef ATL_ilaenv
#define ATL_ilaenv ATL_itlaenv
#endif
#else
#include "atlas_cGetNB_gelqf.h"
#include "atlas_cGetNB_geqlf.h"
#include "atlas_cGetNB_gerqf.h"
#include "atlas_cGetNB_geqrf.h"
#endif
/*
* See if any QR rout has been tuned, and if so, set it to default QR tune
*/
#if defined(ATL_cGetNB_geqrf) && !defined(ATL_cGetNB_QR)
#define ATL_cGetNB_QR ATL_cGetNB_geqrf
#endif
#if defined(ATL_cGetNB_geqlf) && !defined(ATL_cGetNB_QR)
#define ATL_cGetNB_QR ATL_cGetNB_geqlf
#endif
#if defined(ATL_cGetNB_gerqf) && !defined(ATL_cGetNB_QR)
#define ATL_cGetNB_QR ATL_cGetNB_gerqf
#endif
#if defined(ATL_cGetNB_gelqf) && !defined(ATL_cGetNB_QR)
#define ATL_cGetNB_QR ATL_cGetNB_gelqf
#endif
/*
* Setup individual QR tunes if they haven't been indiviually tuned
*/
#ifndef ATL_cGetNB_geqrf
#ifdef ATL_cGetNB_QR
#define ATL_cGetNB_geqrf ATL_cGetNB_QR
#else
#define ATL_cGetNB_geqrf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_cGetNB_geqlf
#ifdef ATL_cGetNB_QR
#define ATL_cGetNB_geqlf ATL_cGetNB_QR
#else
#define ATL_cGetNB_geqlf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_cGetNB_gerqf
#ifdef ATL_cGetNB_QR
#define ATL_cGetNB_gerqf ATL_cGetNB_QR
#else
#define ATL_cGetNB_gerqf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_cGetNB_gelqf
#ifdef ATL_cGetNB_QR
#define ATL_cGetNB_gelqf ATL_cGetNB_QR
#else
#define ATL_cGetNB_gelqf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifdef ATL_USEPTHREADS
#include "atlas_ztGetNB_gelqf.h"
#ifdef ATL_ztGetNB_gelqf
#define ATL_zGetNB_gelqf ATL_ztGetNB_gelqf
#endif
#include "atlas_ztGetNB_geqlf.h"
#ifdef ATL_ztGetNB_geqlf
#define ATL_zGetNB_geqlf ATL_ztGetNB_geqlf
#endif
#include "atlas_ztGetNB_gerqf.h"
#ifdef ATL_ztGetNB_gerqf
#define ATL_zGetNB_gerqf ATL_ztGetNB_gerqf
#endif
#include "atlas_ztGetNB_geqrf.h"
#ifdef ATL_ztGetNB_geqrf
#define ATL_zGetNB_geqrf ATL_ztGetNB_geqrf
#endif
#ifndef ATL_ilaenv
#define ATL_ilaenv ATL_itlaenv
#endif
#else
#include "atlas_zGetNB_gelqf.h"
#include "atlas_zGetNB_geqlf.h"
#include "atlas_zGetNB_gerqf.h"
#include "atlas_zGetNB_geqrf.h"
#endif
/*
* See if any QR rout has been tuned, and if so, set it to default QR tune
*/
#if defined(ATL_zGetNB_geqrf) && !defined(ATL_zGetNB_QR)
#define ATL_zGetNB_QR ATL_zGetNB_geqrf
#endif
#if defined(ATL_zGetNB_geqlf) && !defined(ATL_zGetNB_QR)
#define ATL_zGetNB_QR ATL_zGetNB_geqlf
#endif
#if defined(ATL_zGetNB_gerqf) && !defined(ATL_zGetNB_QR)
#define ATL_zGetNB_QR ATL_zGetNB_gerqf
#endif
#if defined(ATL_zGetNB_gelqf) && !defined(ATL_zGetNB_QR)
#define ATL_zGetNB_QR ATL_zGetNB_gelqf
#endif
/*
* Setup individual QR tunes if they haven't been indiviually tuned
*/
#ifndef ATL_zGetNB_geqrf
#ifdef ATL_zGetNB_QR
#define ATL_zGetNB_geqrf ATL_zGetNB_QR
#else
#define ATL_zGetNB_geqrf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_zGetNB_geqlf
#ifdef ATL_zGetNB_QR
#define ATL_zGetNB_geqlf ATL_zGetNB_QR
#else
#define ATL_zGetNB_geqlf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_zGetNB_gerqf
#ifdef ATL_zGetNB_QR
#define ATL_zGetNB_gerqf ATL_zGetNB_QR
#else
#define ATL_zGetNB_gerqf(n_, nb_) (nb_) = 0;
#endif
#endif
#ifndef ATL_zGetNB_gelqf
#ifdef ATL_zGetNB_QR
#define ATL_zGetNB_gelqf ATL_zGetNB_QR
#else
#define ATL_zGetNB_gelqf(n_, nb_) (nb_) = 0;
#endif
#endif
static int ATL_IEEECHK(int DOALL, float zero, float one)
/*
* Direct translation of LAPACK/SRC/IEEECK into C
* RETURN: 0 if arithmetic produces wrong answer, else 1
*/
{
float nan1, nan2, nan3, nan4, nan5, nan6, neginf, negzro, newzro, posinf;
posinf = one / zero;
if (posinf <= one)
return(0);
neginf = -one / zero;
if (neginf >= zero)
return(0);
negzro = one / (neginf+one);
if (negzro != zero)
return(0);
neginf = one / negzro;
if (neginf >= zero)
return(0);
newzro = negzro + zero;
if (newzro != zero)
return(0);
posinf = one / newzro;
if (posinf <= one)
return(0);
neginf = neginf*posinf;
if (neginf >= zero)
return(0);
posinf = posinf*posinf;
if (posinf <= one)
return(0);
/*
* Check NaN if all checks should be done
*/
if (DOALL)
{
nan1 = posinf + neginf;
nan2 = posinf / neginf;
nan3 = posinf / posinf;
nan4 = posinf * zero;
nan5 = neginf * negzro;
nan6 = nan5 * 0.0;
if (nan1 == nan1)
return(0);
if (nan2 == nan2)
return(0);
if (nan3 == nan3)
return(0);
if (nan4 == nan4)
return(0);
if (nan5 == nan5)
return(0);
if (nan6 == nan6)
return(0);
}
return(1);
}
static int ilg2Floor(unsigned int val)
{
int i;
for (i=30; i >= 0; i--)
if ( ((1<<i) | val) == val)
return(i);
return(0);
}
int ATL_ilaenv(enum ATL_ISPEC ISPEC, enum ATL_LAROUT ROUT, unsigned int OPTS,
int N1, int N2, int N3, int N4)
/*
* NOTE: the following comments only slightly modified from the original
* LAPACK/SRC/ilaenv.f
* Purpose
* =======
*
* ILAENV is called from the LAPACK routines to choose problem-dependent
* parameters for the local environment. See ISPEC for a description of
* the parameters.
*
* This version is tuned only for those cases where the option is satisfied
* by a invocation of an optimized CPP macro provided by tuned header files;
* otherwise, it can almost certainly be further tuned by the user.
*
* ILAENV returns an INTEGER
* if ILAENV >= 0: ILAENV returns the value of the parameter specified by ISPEC
* if ILAENV < 0: if ILAENV = -k, the k-th argument had an illegal value.
*
* Arguments
* =========
*
* ISPEC (input) enum ATL_ISPEC (defined in atlas_lapack.h)
* Specifies the parameter to be returned as the value of
* ILAENV.
* LAIS_MSQRXOVER=8:
* LAIS_OPT_NB=1 : the optimal blocksize; if this value is 1,
an unblocked algorithm will give the best performance.
* LAIS_MIN_NB=2 : the minimum block size for which the block routine
* should be used; if the usable block size is less than
* this value, an unblocked routine should be used.
* LAIS_NBXOVER=3 : the crossover point (in a block routine, for N less
* than this value, an unblocked routine should be used)
* i.e. LAIS_MIN_NB is for NB, but this is for the
* unconstrained dimension (or MIN of them).
* LAIS_NEIGSHFT=4 : the number of shifts, used in the nonsymmetric
* eigenvalue routines (DEPRECATED)
* LAIS_MINCSZ=5 : the minimum column dimension for blocking to be used;
* rectangular blocks must have dimension at least k by m,
* where k is given by ILAENV(2,...) and m by ILAENV(5,..)
* LAIS_SVDXOVER=6 : the crossover point for the SVD (when reducing an MxN
* matrix to bidiagonal form, if max(M,N)/min(M,N) exceeds
* this value, a QR factorization is used first to reduce
* the matrix to a triangular form.)
* LAIS_NPROC=7 : the number of processors
* LAIS_MSQRXOVER=8: the crossover point for the multishift QR method
* for nonsymmetric eigenvalue problems (DEPRECATED)
* LAIS_MAXDCSPSZ=9: maximum size of the subproblems at the bottom of the
* computation tree in the divide-and-conquer algorithm
* (used by xGELSD and xGESDD)
* LAIS_NTNAN=10 : ieee NaN arithmetic can be trusted not to trap
* LAIS_NTINF=11 : infinity arithmetic can be trusted not to trap
* 12 <= ISPEC <= 16:
* xHSEQR or one of its subroutines,
* see IPARMQ for detailed explanation
*
* ROUT (input) enum ATL_LAROUT
* Enumerated type indicating the LAPACK routine query is about
*
* OPTS (input) integer
* Bitmap of all options to routine, as indicated from ATL_LAFLG
* enum (defined in atlas_lapack.h), inlucing the data type/precision.
* Options are:
* LAUpper=1, LALower=2, LARight=4, LALeft=8, LAUnit=16, LANonunit=32,
* LASreal=(1<<28), LADreal=(1<<29), LAScplx=(1<<30), LADcplx=(1<<31).
*
* N1 (input) INTEGER
* N2 (input) INTEGER
* N3 (input) INTEGER
* N4 (input) INTEGER
* Problem dimensions for the LAPACK routine ROUT; these may not all
* be required.
*
* Further Details
* ===============
*
* The following conventions have been used when calling ILAENV from the
* LAPACK routines:
* 1) OPTS is a concatenation of all of the options to the LAPACK ROUT
* even if they are not used in determining
* the value of the parameter specified by ISPEC.
* 2) The problem dimensions N1, N2, N3, N4 are specified in the order
* that they appear in the argument list for NAME. N1 is used
* first, N2 second, and so on, and unused problem dimensions are
* passed a value of -1.
* 3) The parameter value returned by ILAENV is checked for validity in
* the calling subroutine. For example, ILAENV is used to retrieve
* the optimal blocksize for STRTRI as follows:
*
* NB = ILAENV( 1, 'STRTRI', UPLO // DIAG, N, -1, -1, -1 )
* IF( NB.LE.1 ) NB = MAX( 1, N )
*
* =====================================================================
*/
{
int nb, mindim, ns, nh;
switch(ISPEC)
{
case LAIS_OPT_NB:
nb = 0;
if (N2 == -1)
mindim = N1;
else
{
mindim = Mmin(N1, N2);
if (N3 > 0)
{
mindim = Mmin(mindim, N3);
if (N4 > 0)
mindim = Mmin(mindim, N4);
}
}
/*
* Present code treates ORMQR like GEQRF, even though ORMQR might want
* larger NB w/o QR2 dragging it down. This is just to save install time.
*/
if (ROUT & (LAgeqrf | LAormqr))
{
if (OPTS & LADreal)
{
if (OPTS & LARight) /* R/L on right */
{
if (OPTS & LALower) /* QL */
{
ATL_dGetNB_geqlf(mindim, nb);
}
else /* QR */
{
ATL_dGetNB_geqrf(mindim, nb);
}
}
else if (OPTS & LALower) /* LQ */
{
ATL_dGetNB_gelqf(mindim, nb);
}
else /* RQ */
{
ATL_dGetNB_gerqf(mindim, nb);
}
}
else if (OPTS & LASreal)
{
if (OPTS & LARight) /* R/L on right */
{
if (OPTS & LALower) /* QL */
{
ATL_sGetNB_geqlf(mindim, nb);
}
else /* QR */
{
ATL_sGetNB_geqrf(mindim, nb);
}
}
else if (OPTS & LALower) /* LQ */
{
ATL_sGetNB_gelqf(mindim, nb);
}
else /* RQ */
{
ATL_sGetNB_gerqf(mindim, nb);
}
}
else if (OPTS & LADcplx)
{
if (OPTS & LARight) /* R/L on right */
{
if (OPTS & LALower) /* QL */
{
ATL_zGetNB_geqlf(mindim, nb);
}
else /* QR */
{
ATL_zGetNB_geqrf(mindim, nb);
}
}
else if (OPTS & LALower) /* LQ */
{
ATL_zGetNB_gelqf(mindim, nb);
}
else /* RQ */
{
ATL_zGetNB_gerqf(mindim, nb);
}
}
else if (OPTS & LAScplx)
{
if (OPTS & LARight) /* R/L on right */
{
if (OPTS & LALower) /* QL */
{
ATL_cGetNB_geqlf(mindim, nb);
}
else /* QR */
{
ATL_cGetNB_geqrf(mindim, nb);
}
}
else if (OPTS & LALower) /* LQ */
{
ATL_cGetNB_gelqf(mindim, nb);
}
else /* RQ */
{
ATL_cGetNB_gerqf(mindim, nb);
}
}
/*
* For ORMQR, do not accept really small nb, since it doesn't have
* cost of QR2 dragging it down
*/
if (ROUT & LAormqr)
{
if (OPTS & LADreal)
nb = ATL_dlaGetB(mindim, mindim, 0, 2);
else if (OPTS & LASreal)
nb = ATL_slaGetB(mindim, mindim, 0, 2);
else if (OPTS & LAScplx)
nb = ATL_claGetB(mindim, mindim, 0, 2);
else
nb = ATL_zlaGetB(mindim, mindim, 0, 2);
}
}
/*
* If we know nothing else, tell routine to use ATLAS's GEMM blocking factor,
* unless it is an unknown routine, in which case LAPACK returns NB=1
*/
if (!nb)
{
int hint = 1;
if ((LAgeqrf | LAormqr | LAgehrd | LAgebrd |
LAsytrd | LAhetrd | LArorgen | LAcungen) & ROUT)
hint = 2;
if (ROUT & LAstebz)
nb = 1;
else if (OPTS & LADreal)
nb = ATL_dlaGetB(mindim, mindim, 0, hint);
else if (OPTS & LASreal)
nb = ATL_slaGetB(mindim, mindim, 0, hint);
else if (OPTS & LAScplx)
nb = ATL_claGetB(mindim, mindim, 0, hint);
else
nb = ATL_zlaGetB(mindim, mindim, 0, hint);
}
return(nb);
case LAIS_MIN_NB: /* changed from LAPACK to require 4 rather than 2 cols */
nb = 4; /* most GEMMs need at least one MU/NU of 4 */
if (ROUT & LAsytrf)
nb = 8;
return(nb);
case LAIS_NBXOVER: /* unchanged from LAPACK */
nb = 0;
if (ROUT & (LAgeqrf | LAormqr | LAgehrd | LAgebrd))
nb = 128;
else if (ROUT & (LAsytrd | LAhetrd))
nb = 32;
else if (ROUT & (LArorgen | LAcungen))
nb = 128;
return(nb);
case LAIS_NEIGSHFT: /* unchanged from LAPACK */
return(6);
case LAIS_MINCSZ: /* unchanged from LAPACK, says not used */
return(2);
case LAIS_SVDXOVER: /* unchanged from LAPACK */
return((int)(Mmin(N1,N2)*1.6e0));
case LAIS_NPROC:
#ifdef ATL_NPROC
return(ATL_NPROC);
#else
return(1);
#endif
case LAIS_MSQRXOVER: /* unchanged from LAPACK */
return(8);
case LAIS_MAXDCSPSZ: /* unchanged from LAPACK */
return(25);
/*
* These following two commands are swapped in lapack3.1.1, fixed here
*/
case LAIS_NTNAN: /* unchanged from LAPACK, except for fix */
return(ATL_IEEECHK(1, 0.0, 1.0));
case LAIS_NTINF: /* unchanged from LAPACK, except for fix */
return(ATL_IEEECHK(0, 0.0, 1.0));
/*
* Cases 12-13 come from IPARMQ; unchanged from lapack :
* ILAENV = IPARMQ( ISPEC, NAME, OPTS, N1, N2, N3, N4 )
* -> N=N1, ILO=N2, IHI=N3, LWORK=N4
*/
case 13: /* INWIN */
case 15: /* ISHFTS */
case 16: /* IACC22 */
nh = N3 - N2 + 1;
ns = 2;
if (nh >= 6000)
ns = 256;
else if (nh >= 3000)
ns = 128;
else if (nh >= 590)
ns = 64;
else if (nh >= 150)
{
/* ns = nh / ((int)( log(nh)/log(2.0) )); */
ns = nh / ilg2Floor(nh);
ns = (10 >= ns) ? 10 : ns;
/*
* NS must always be even and >= 2 for all nh, but this is only nh
* where that is not known by assignment, so ensure it here
*/
ns = (ns>>1)<<1;
ns = (ns >= 2) ? ns : 2;
/*
ns = ns - ns%2;
ns = (ns >= 2) ? ns : 2;
*/
}
else if (nh >= 60)
ns = 10;
else if (nh >= 30)
ns = 4;
if (ISPEC == 16)
#if 1
return((ns >= 14) ? 2 : 0);
#else
{
nh = 0;
if (ns >= 14) /* NOTE: IPARMQ's KACMIN=14 */
nh = 1;
if (ns >= 14) /* NOTE IPARMQ's K22MIN=14 */
nh = 2;
return(nh);
}
else if (ISPEC == 13)
return( (nh <= 500) ? ns : ((3*ns)>>1) );
#endif
return(ns);
break;
case 12: /* INMIN */
return(75);
case 14: /* INIBL */
return(14);
default:
exit(ISPEC);
}
return(0);
}
#endif /* end protection compiling threaded ilaenv on serial machine */
| [
"thomas@biotrump.com"
] | thomas@biotrump.com |
ef804c383eac4b7c57efa0b9d5202287f9207f57 | 2b0ff7f7529350a00a34de9050d3404be6d588a0 | /060_讀取檔案/64_檔案檢查CRC32_MD5/CB_MD5/md5.c | 267eeb15d322418feac504b6efcb6d0a78fb6347 | [] | no_license | isliulin/jashliao_VC | 6b234b427469fb191884df2def0b47c4948b3187 | 5310f52b1276379b267acab4b609a9467f43d8cb | refs/heads/master | 2023-05-13T09:28:49.756293 | 2021-06-08T13:40:23 | 2021-06-08T13:40:23 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 10,206 | c | /*
**********************************************************************
** md5.c **
** RSA Data Security, Inc. MD5 Message Digest Algorithm **
** Created: 2/17/90 RLR **
** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version **
**********************************************************************
*/
/*
**********************************************************************
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
** **
** License to copy and use this software is granted provided that **
** it is identified as the "RSA Data Security, Inc. MD5 Message **
** Digest Algorithm" in all material mentioning or referencing this **
** software or this function. **
** **
** License is also granted to make and use derivative works **
** provided that such works are identified as "derived from the RSA **
** Data Security, Inc. MD5 Message Digest Algorithm" in all **
** material mentioning or referencing the derived work. **
** **
** RSA Data Security, Inc. makes no representations concerning **
** either the merchantability of this software or the suitability **
** of this software for any particular purpose. It is provided "as **
** is" without express or implied warranty of any kind. **
** **
** These notices must be retained in any copies of any part of this **
** documentation and/or software. **
**********************************************************************
*/
/* -- include the following line if the md5.h header file is separate -- */
/* #include "md5.h" */
/* forward declaration */
#include "md5.h"
static void Transform ();
static unsigned char PADDING[64] = {
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/* F, G and H are basic MD5 functions: selection, majority, parity */
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
/* Rotation is separate from addition to prevent recomputation */
#define FF(a, b, c, d, x, s, ac) \
{(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) \
{(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) \
{(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) \
{(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
void MD5Init (mdContext)
MD5_CTX *mdContext;
{
mdContext->i[0] = mdContext->i[1] = (UINT4)0;
/* Load magic initialization constants.
*/
mdContext->buf[0] = (UINT4)0x67452301;
mdContext->buf[1] = (UINT4)0xefcdab89;
mdContext->buf[2] = (UINT4)0x98badcfe;
mdContext->buf[3] = (UINT4)0x10325476;
}
void MD5Update (mdContext, inBuf, inLen)
MD5_CTX *mdContext;
unsigned char *inBuf;
unsigned int inLen;
{
UINT4 in[16];
int mdi;
unsigned int i, ii;
/* compute number of bytes mod 64 */
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
/* update number of bits */
if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
mdContext->i[1]++;
mdContext->i[0] += ((UINT4)inLen << 3);
mdContext->i[1] += ((UINT4)inLen >> 29);
while (inLen--) {
/* add new character to buffer, increment mdi */
mdContext->in[mdi++] = *inBuf++;
/* transform if necessary */
if (mdi == 0x40) {
for (i = 0, ii = 0; i < 16; i++, ii += 4)
in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
(((UINT4)mdContext->in[ii+2]) << 16) |
(((UINT4)mdContext->in[ii+1]) << 8) |
((UINT4)mdContext->in[ii]);
Transform (mdContext->buf, in);
mdi = 0;
}
}
}
void MD5Final (mdContext)
MD5_CTX *mdContext;
{
UINT4 in[16];
int mdi;
unsigned int i, ii;
unsigned int padLen;
/* save number of bits */
in[14] = mdContext->i[0];
in[15] = mdContext->i[1];
/* compute number of bytes mod 64 */
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
/* pad out to 56 mod 64 */
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
MD5Update (mdContext, PADDING, padLen);
/* append length in bits and transform */
for (i = 0, ii = 0; i < 14; i++, ii += 4)
in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
(((UINT4)mdContext->in[ii+2]) << 16) |
(((UINT4)mdContext->in[ii+1]) << 8) |
((UINT4)mdContext->in[ii]);
Transform (mdContext->buf, in);
/* store buffer in digest */
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
mdContext->digest[ii+1] =
(unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
mdContext->digest[ii+2] =
(unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
mdContext->digest[ii+3] =
(unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
}
}
/* Basic MD5 step. Transform buf based on in.
*/
static void Transform (buf, in)
UINT4 *buf;
UINT4 *in;
{
UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
/* Round 1 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
FF ( a, b, c, d, in[ 0], S11, 3614090360); /* 1 */
FF ( d, a, b, c, in[ 1], S12, 3905402710); /* 2 */
FF ( c, d, a, b, in[ 2], S13, 606105819); /* 3 */
FF ( b, c, d, a, in[ 3], S14, 3250441966); /* 4 */
FF ( a, b, c, d, in[ 4], S11, 4118548399); /* 5 */
FF ( d, a, b, c, in[ 5], S12, 1200080426); /* 6 */
FF ( c, d, a, b, in[ 6], S13, 2821735955); /* 7 */
FF ( b, c, d, a, in[ 7], S14, 4249261313); /* 8 */
FF ( a, b, c, d, in[ 8], S11, 1770035416); /* 9 */
FF ( d, a, b, c, in[ 9], S12, 2336552879); /* 10 */
FF ( c, d, a, b, in[10], S13, 4294925233); /* 11 */
FF ( b, c, d, a, in[11], S14, 2304563134); /* 12 */
FF ( a, b, c, d, in[12], S11, 1804603682); /* 13 */
FF ( d, a, b, c, in[13], S12, 4254626195); /* 14 */
FF ( c, d, a, b, in[14], S13, 2792965006); /* 15 */
FF ( b, c, d, a, in[15], S14, 1236535329); /* 16 */
/* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
GG ( a, b, c, d, in[ 1], S21, 4129170786); /* 17 */
GG ( d, a, b, c, in[ 6], S22, 3225465664); /* 18 */
GG ( c, d, a, b, in[11], S23, 643717713); /* 19 */
GG ( b, c, d, a, in[ 0], S24, 3921069994); /* 20 */
GG ( a, b, c, d, in[ 5], S21, 3593408605); /* 21 */
GG ( d, a, b, c, in[10], S22, 38016083); /* 22 */
GG ( c, d, a, b, in[15], S23, 3634488961); /* 23 */
GG ( b, c, d, a, in[ 4], S24, 3889429448); /* 24 */
GG ( a, b, c, d, in[ 9], S21, 568446438); /* 25 */
GG ( d, a, b, c, in[14], S22, 3275163606); /* 26 */
GG ( c, d, a, b, in[ 3], S23, 4107603335); /* 27 */
GG ( b, c, d, a, in[ 8], S24, 1163531501); /* 28 */
GG ( a, b, c, d, in[13], S21, 2850285829); /* 29 */
GG ( d, a, b, c, in[ 2], S22, 4243563512); /* 30 */
GG ( c, d, a, b, in[ 7], S23, 1735328473); /* 31 */
GG ( b, c, d, a, in[12], S24, 2368359562); /* 32 */
/* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
HH ( a, b, c, d, in[ 5], S31, 4294588738); /* 33 */
HH ( d, a, b, c, in[ 8], S32, 2272392833); /* 34 */
HH ( c, d, a, b, in[11], S33, 1839030562); /* 35 */
HH ( b, c, d, a, in[14], S34, 4259657740); /* 36 */
HH ( a, b, c, d, in[ 1], S31, 2763975236); /* 37 */
HH ( d, a, b, c, in[ 4], S32, 1272893353); /* 38 */
HH ( c, d, a, b, in[ 7], S33, 4139469664); /* 39 */
HH ( b, c, d, a, in[10], S34, 3200236656); /* 40 */
HH ( a, b, c, d, in[13], S31, 681279174); /* 41 */
HH ( d, a, b, c, in[ 0], S32, 3936430074); /* 42 */
HH ( c, d, a, b, in[ 3], S33, 3572445317); /* 43 */
HH ( b, c, d, a, in[ 6], S34, 76029189); /* 44 */
HH ( a, b, c, d, in[ 9], S31, 3654602809); /* 45 */
HH ( d, a, b, c, in[12], S32, 3873151461); /* 46 */
HH ( c, d, a, b, in[15], S33, 530742520); /* 47 */
HH ( b, c, d, a, in[ 2], S34, 3299628645); /* 48 */
/* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
II ( a, b, c, d, in[ 0], S41, 4096336452); /* 49 */
II ( d, a, b, c, in[ 7], S42, 1126891415); /* 50 */
II ( c, d, a, b, in[14], S43, 2878612391); /* 51 */
II ( b, c, d, a, in[ 5], S44, 4237533241); /* 52 */
II ( a, b, c, d, in[12], S41, 1700485571); /* 53 */
II ( d, a, b, c, in[ 3], S42, 2399980690); /* 54 */
II ( c, d, a, b, in[10], S43, 4293915773); /* 55 */
II ( b, c, d, a, in[ 1], S44, 2240044497); /* 56 */
II ( a, b, c, d, in[ 8], S41, 1873313359); /* 57 */
II ( d, a, b, c, in[15], S42, 4264355552); /* 58 */
II ( c, d, a, b, in[ 6], S43, 2734768916); /* 59 */
II ( b, c, d, a, in[13], S44, 1309151649); /* 60 */
II ( a, b, c, d, in[ 4], S41, 4149444226); /* 61 */
II ( d, a, b, c, in[11], S42, 3174756917); /* 62 */
II ( c, d, a, b, in[ 2], S43, 718787259); /* 63 */
II ( b, c, d, a, in[ 9], S44, 3951481745); /* 64 */
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
/*
**********************************************************************
** End of md5.c **
******************************* (cut) ********************************
*/
| [
"jash.liao@gmail.com"
] | jash.liao@gmail.com |
0ace3d39580c456d8e124b5f82fa108fddcc2dae | b3f1917790cc271cc481fa60f69b670ba873b1ee | /src/tallypi.h | 634ac38eaa91c06d0e7743afb8570f021c150cd6 | [] | no_license | rlutz/voctoknopf | 46a6eeb8e8f04561e120468cf889e4e46ba74ca8 | 2a203f81ba6be50f1119dfb810c0b4b7e6bca059 | refs/heads/master | 2021-05-11T08:03:30.899049 | 2018-11-06T16:09:27 | 2018-11-06T16:09:27 | 118,038,794 | 9 | 0 | null | null | null | null | UTF-8 | C | false | false | 977 | h | /* Voctoknopf - video mixer control device for Chaos conferences
Copyright (C) 2018 Roland Lutz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef TALLYPI_H
#define TALLYPI_H
enum led {
led_red,
led_green,
LED_COUNT
};
enum button {
BUTTON_COUNT = 0
};
enum irq {
IRQ_COUNT = 0
};
#endif
| [
"rlutz@hedmen.org"
] | rlutz@hedmen.org |
a93b4be8b6047c65da505a9bb7912de1e0101011 | f4d663e7be0631af0d13578936cd6e34e2989bd4 | /ATLAS/intel_i7/src/blas/gemm/KERNEL/ATL_cupKBmm40_8_1_b0.c | a3c5e2955d294e52c69498273b759309557306d7 | [] | no_license | forrest898/Linpack_PAPI_Testing | 5606c7b395d7cb16b6b5aff1a1ed3e4f5cd6b7b9 | 163c1648c8a0a2e7458529433d561ca13b5def42 | refs/heads/master | 2020-03-19T07:13:25.861801 | 2018-07-30T17:07:31 | 2018-07-30T17:07:31 | 136,097,294 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 10,540 | c | #define ATL_USERMM ATL_cupKBmm40_8_1_b0
#define ATL_USERMM_b1 ATL_cupKBmm40_8_1_b1
#define ATL_USERMM_bn1 ATL_cupKBmm40_8_1_bn1
#define ATL_USERMM_b0 ATL_cupKBmm40_8_1_b0
#define ATL_USERMM_bX ATL_cupKBmm40_8_1_bX
#define BETA0
#define SCPLX
#define MB 80
#define NB 80
#define KB 40
#define MBMB 6400
#define NBNB 6400
#define KBKB 1600
#define MB2 160
#define NB2 160
#define KB2 80
#define MB3 240
#define NB3 240
#define KB3 120
#define MB4 320
#define NB4 320
#define KB4 160
#define MB5 400
#define NB5 400
#define KB5 200
#define MB6 480
#define NB6 480
#define KB6 240
#define MB7 560
#define NB7 560
#define KB7 280
#define MB8 640
#define NB8 640
#define KB8 320
/*
* Automatically Tuned Linear Algebra Software v3.10.3
* Copyright (C) 2011 R. Clint Whaley
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. The name of the ATLAS group or the names of its contributers may
* not be used to endorse or promote products derived from this
* software without specific 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 ATLAS GROUP OR ITS 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 ATL_AVX
#error "This kernel requires AVX"
#endif
#if !defined(KB) || KB < 1
#error "This kernel requires a constant KB"
#endif
#if defined(NB) && (NB/2)*2 != NB
#error "NB must be a multiple of 2"
#endif
#if defined(MB) && (MB/4)*4 != MB
#error "MB must be a multiple of 2"
#endif
#include "atlas_misc.h"
// #include <wmmintrin.h>
// #include <bmmintrin.h>
#include <immintrin.h>
#ifndef ATL_RESTRICT
#if defined(__STDC_VERSION__) && (__STDC_VERSION__/100 >= 1999)
#define ATL_RESTRICT restrict
#else
#define ATL_RESTRICT
#endif
#endif
void ATL_USERMM
(const int M, const int N, const int K, const float alpha,
const float * ATL_RESTRICT A, const int lda,
const float * ATL_RESTRICT B, const int ldb, const float beta,
float * ATL_RESTRICT C, const int ldc)
/*
* matmul with TA=T, TB=N, MB=0, NB=0, KB=56,
* lda=56, ldb=56, ldc=0, mu=4, nu=2, ku=1, pf=0
* Generated by ATLAS/tune/blas/gemm/emit_mm.c (3.9.39)
*/
{
const int Mb = (M>>2)<<2;
const int Nb = (N>>1)<<1;
const float *stM = A + (KB*(Mb));
const float *stN = B + (KB*(Nb));
const float *pfA = stM;
const int incAm = 3*KB, incAn = -(KB*(Mb));
const int incBm = -KB, incBn = 2*KB;
const int incCn = ((((ldc) << 1)) - (Mb))SHIFT;
float *pC0=C, *pC1=pC0+(ldc SHIFT);
const float *pA0=A;
const float *pB0=B;
register int k;
register __m256 rA0, rA1, rA2, rA3;
register __m256 rB0, rB1, t0;
register __m256 rC0_0, rC1_0, rC2_0, rC3_0, rC0_1, rC1_1, rC2_1, rC3_1;
#if defined(TCPLX)
float V[24], *v, *z;
v = ATL_AlignPtr(V);
/* v[0] = v[2] = v[4] = v[6] = beta;
v[1] = v[3] = v[5] = v[7] = ATL_rone; */
#endif
do /* N-loop */
{
do /* M-loop */
{
rC0_0 = _mm256_setzero_ps();
rC1_0 = _mm256_setzero_ps();
rC2_0 = _mm256_setzero_ps();
rC3_0 = _mm256_setzero_ps();
rC0_1 = _mm256_setzero_ps();
rC1_1 = _mm256_setzero_ps();
rC2_1 = _mm256_setzero_ps();
rC3_1 = _mm256_setzero_ps();
for (k=0; k < KB; k += 8) /* easy loop to unroll */
{
rA0 = _mm256_load_ps(pA0);
rB0 = _mm256_load_ps(pB0);
rA1 = _mm256_load_ps(pA0+KB);
rA2 = _mm256_load_ps(pA0+2*KB);
rA3 = _mm256_load_ps(pA0+3*KB);
rB1 = _mm256_load_ps(pB0+KB);
t0 = _mm256_mul_ps(rA0, rB0);
rC0_0 = _mm256_add_ps(rC0_0, t0);
pA0 += 8;
t0 = _mm256_mul_ps(rA1, rB0);
rC1_0 = _mm256_add_ps(rC1_0, t0);
pB0 += 8;
t0 = _mm256_mul_ps(rA2, rB0);
rC2_0 = _mm256_add_ps(rC2_0, t0);
t0 = _mm256_mul_ps(rA3, rB0);
rC3_0 = _mm256_add_ps(rC3_0, t0);
t0 = _mm256_mul_ps(rA0, rB1);
rC0_1 = _mm256_add_ps(rC0_1, t0);
t0 = _mm256_mul_ps(rA1, rB1);
rC1_1 = _mm256_add_ps(rC1_1, t0);
t0 = _mm256_mul_ps(rA2, rB1);
rC2_1 = _mm256_add_ps(rC2_1, t0);
t0 = _mm256_mul_ps(rA3, rB1);
rC3_1 = _mm256_add_ps(rC3_1, t0);
}
pA0 += incAm;
#if !defined(BETA0) && !defined(TCPLX)
t0 = _mm256_loadu_ps(pC1);
#endif
rC0_0 = _mm256_hadd_ps(rC0_0, rC1_0);
rC0_1 = _mm256_hadd_ps(rC0_1, rC1_1);
pB0 += incBm;
/* c10gh c10ef c00gh c00ef c10cd c10ab c00cd c00ab */
rC2_0 = _mm256_hadd_ps(rC2_0, rC3_0);
rC2_1 = _mm256_hadd_ps(rC2_1, rC3_1);
_mm_prefetch(pfA, 1);
/* c30gh c30ef c20gh c20ef c30cd c30ab c20cd c20ab */
rC0_0 = _mm256_hadd_ps(rC0_0, rC2_0);
rC0_1 = _mm256_hadd_ps(rC0_1, rC2_1);
pfA += 8;
/* c30efgh c20efgh c10efgh c00efgh c30abcd c20abcd c10abcd c00abcd */
#ifdef TCPLX
rC2_0 = _mm256_castps128_ps256(_mm256_extractf128_ps(rC0_0, 1));
/* xx xx xx xx c30efgh c20efgh c10efgh c00efgh */
rC0_0 = _mm256_add_ps(rC0_0, rC2_0);
/* xx xx xx xx c30a-h c20a-h c10a-h c00a-h */
rC2_1 = _mm256_castps128_ps256(_mm256_extractf128_ps(rC0_1, 1));
/* xx xx xx xx c31efgh c21efgh c11efgh c01efgh */
rC0_1 = _mm256_add_ps(rC0_1, rC2_1);
/* xx xx xx xx c31a-h c21a-h c11a-h c01a-h */
#if 1 /* bogus thru-mem workaround to buggy code below */
_mm256_store_ps(v, rC0_0);
_mm256_store_ps(v+8, rC0_1);
#ifdef BETA0
*pC0 = v[0];
pC0[2] = v[1];
pC0[4] = v[2];
pC0[6] = v[3];
*pC1 = v[8];
pC1[2] = v[9];
pC1[4] = v[10];
pC1[6] = v[11];
#elif defined(BETAX)
*pC0 = beta*(*pC0) + v[0];
pC0[2] = beta*pC0[2] + v[1];
pC0[4] = beta*pC0[4] + v[2];
pC0[6] = beta*pC0[6] + v[3];
*pC1 = beta*(*pC1) + v[8];
pC1[2] = beta*pC1[2] + v[9];
pC1[4] = beta*pC1[4] + v[10];
pC1[6] = beta*pC1[6] + v[11];
#else
*pC0 += v[0];
pC0[2] += v[1];
pC0[4] += v[2];
pC0[6] += v[3];
*pC1 += v[8];
pC1[2] += v[9];
pC1[4] += v[10];
pC1[6] += v[11];
#endif
pC0 += 8; pC1 += 8;
#else /* this code seems right, but does not work */
v[0] = v[2] = v[4] = v[6] = beta;
v[1] = v[3] = v[5] = v[7] = ATL_rone;
rC1_0 = _mm256_loadu_ps(pC0); /* zz C30 yy C20 xx C10 rr C00 */
t0 = _mm256_setzero_ps(); /* 0 0 0 0 0 0 0 0 */
rC1_1 = _mm256_loadu_ps(pC1); /* zz C31 yy C21 xx C11 rr C01 */
#ifdef BETA0
rC1_0 = _mm256_blend_ps(rC1_0, t0, 0x55/*0b0101 0101*/);
rC1_1 = _mm256_blend_ps(rC1_1, t0, 0x55/*0b0101 0101*/);
/* zz 0 yy 0 xx 0 rr 0 */
#elif defined(BETAX)
rC3_0 = _mm256_load_ps(v); /* 1 beta 1 beta 1 beta 1 beta */
rC1_0 = _mm256_mul_ps(rC1_0, rC3_0);
rC1_1 = _mm256_mul_ps(rC1_1, rC3_0);
/* zz b*C3 yy b*C20 xx b*C10 rr b*c00 */
#endif
rC0_0 = _mm256_unpacklo_ps(rC0_0, t0);
/* 0 c3a-h 0 c2a-h 0 c1a-h 0 c0a-h */
rC0_0 = _mm256_add_ps(rC0_0, rC1_0);
/* zz c3a-h yy c2a-h xx c1a-h rr c0a-h */
_mm256_storeu_ps(pC0, rC0_0);
pC0 += 8;
rC0_1 = _mm256_unpacklo_ps(rC0_1, t0);
rC0_1 = _mm256_add_ps(rC0_1, rC1_1);
_mm256_storeu_ps(pC1, rC0_1);
pC1 += 8;
#endif
#else
{
__m128 a, b;
#ifdef BETAX
__m128 bet;
#endif
a = _mm256_castps256_ps128(rC0_0);
/* c30abcd c20abcd c10abcd c00abcd */
b = _mm256_extractf128_ps(rC0_0, 1);
/* c30efgh c20efgh c10efgh c00efgh */
a = _mm_add_ps(a, b); /* c30a-h c20a-h c10a-h c00a-h */
#if !defined(BETA0)
b = _mm_loadu_ps(pC0);
#ifdef BETAX
bet = _mm_load1_ps(&beta);
b = _mm_mul_ps(b, bet);
#endif
a = _mm_add_ps(a, b);
#endif
_mm_storeu_ps(pC0, a);
pC0 += 4;
a = _mm256_castps256_ps128(rC0_1);
b = _mm256_extractf128_ps(rC0_1, 1);
a = _mm_add_ps(a, b);
#if !defined(BETA0)
b = _mm_loadu_ps(pC1);
#ifdef BETAX
b = _mm_mul_ps(b, bet);
#endif
a = _mm_add_ps(a, b);
#endif
_mm_storeu_ps(pC1, a);
pC1 += 4;
}
#endif
}
while(pA0 != stM);
pC0 += incCn;
pC1 += incCn;
pA0 += incAn;
pB0 += incBn;
}
while(pB0 != stN);
}
| [
"fwsmith898@gmail.com"
] | fwsmith898@gmail.com |
ca832a26462f07758c40bb2dd3f658d2de2a6146 | 4e67d73e609c197451579e11bea9f0189ccb042d | /SDK/Official Examples/CH554/eg16-ch554-Compound_Dev/main.c | f856341f092dae538656ceab7a090d49d5f5c434 | [] | no_license | Ilgrim/WCH_CH55X | a7f5f30ebb277e7ece64e8588834d30f0a1fdb17 | a13b19e8c1845b521e427a09ece7bfe281399dc0 | refs/heads/master | 2023-05-07T18:31:25.852539 | 2021-06-02T06:02:28 | 2021-06-02T06:02:28 | null | 0 | 0 | null | null | null | null | GB18030 | C | false | false | 1,693 | c | /********************************** (C) COPYRIGHT ******************************
* File Name :Compound_Dev.C
* Author : WCH
* Version : V1.0
* Date : 2017/03/15
* Description : A demo for USB compound device created by CH554, support
keyboard and mouse, and HID compatible device.
********************************************************************************/
#include ".\Public\CH554.H"
#include ".\Public\debug.h"
#include "Compound.h"
#include ".\Touch_Key\Touch_Key.H"
#include "stdio.h"
extern UINT8 FLAG; // Trans complete flag
extern UINT8 EnumOK; // Enum ok flag
UINT16I TouchKeyButton = 0;
void main( void ) {
CfgFsys(); //Configure sys
mDelaymS(5); //
mInitSTDIO( ); // Init UART0
#if DE_PRINTF
printf( "Start config.\r\n" );
printf( "Init USB device.\r\n" );
#endif
USBDeviceInit(); // Configure the USB module,the Endpoint and the USB Interrupt
EA = 1;
UEP1_T_LEN = 0; // Reset the trans length register
UEP2_T_LEN = 0;
FLAG = 0;
EnumOK = 0;
TouchKeyQueryCylSet1Or2ms(1); //set query cycle
TouchKeyChanelSelect(3); //set query chanel
while(1) {
if( EnumOK == 1 ) {
HIDValueHandle();
} else {
if(TKEY_CTRL&bTKC_IF) { //wait query finsh,max 2ms 获取键值基准值,多采样几次
TouchKeyButton = TKEY_DAT; //
#ifdef DE_PRINTF
printf("A.= %04x\n",TouchKeyButton&0x7FFF);
#endif
}
}
}
}
/**************************** END *************************************/
| [
"info@electrodragon.com"
] | info@electrodragon.com |
b72df92a645fc3700336215af9ed6d5f39e87cd6 | 74565478993da6b2d6c8232539d905f7810caa29 | /display.h | 739be892f11271119136dd7386b8aeaa335c7bd2 | [] | no_license | GregHHH/MDLP | 191c273431a50d6d5504bbaafa9fc0d7599d88f5 | 5d9dcfc68096e10477c4a97734f2f499d0c3565b | refs/heads/master | 2020-04-07T12:26:33.374579 | 2018-12-06T20:55:46 | 2018-12-06T20:55:46 | 158,368,105 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 320 | h | #ifndef DISPLAY_H___
#define DISPLAY_H___
#include "word.h"
void Display_round (int attemptsLeft, Word *guessed);
char Display_askChar ();
void Display_alreadyTried (char guess);
void Display_congrats (char guess);
void Display_sorry (char guess);
void Display_won ();
void Display_lost ();
#endif /* DISPLAY_H___ */
| [
"noreply@github.com"
] | GregHHH.noreply@github.com |
d6a77ac078e0c0a4ae159a3252f4355fbb09c556 | 438cd59a4138cd87d79dcd62d699d563ed976eb9 | /mame/src/mame/video/amspdwy.c | bab851281bc76a9d721d7667cf956049ec1bfb85 | [] | no_license | clobber/UME | 031c677d49634b40b5db27fbc6e15d51c97de1c5 | 9d4231358d519eae294007133ab3eb45ae7e4f41 | refs/heads/master | 2021-01-20T05:31:28.376152 | 2013-05-01T18:42:59 | 2013-05-01T18:42:59 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 3,896 | c | /***************************************************************************
-= American Speedway =-
driver by Luca Elia (l.elia@tin.it)
- 8x8 4 Color Tiles (with 8 palettes) used for both:
- 1 256x256 non scrolling layer
- 64 (32?) Sprites
***************************************************************************/
#include "emu.h"
#include "includes/amspdwy.h"
WRITE8_MEMBER(amspdwy_state::amspdwy_paletteram_w)
{
data ^= 0xff;
paletteram_BBGGGRRR_byte_w(space, offset, data);
// paletteram_RRRGGGBB_byte_w(offset, data);
}
WRITE8_MEMBER(amspdwy_state::amspdwy_flipscreen_w)
{
m_flipscreen ^= 1;
flip_screen_set(m_flipscreen);
}
/***************************************************************************
Callbacks for the TileMap code
[ Tiles Format ]
Videoram: 76543210 Code Low Bits
Colorram: 765-----
---43--- Code High Bits
-----210 Color
***************************************************************************/
TILE_GET_INFO_MEMBER(amspdwy_state::get_tile_info)
{
UINT8 code = m_videoram[tile_index];
UINT8 color = m_colorram[tile_index];
SET_TILE_INFO_MEMBER(
0,
code + ((color & 0x18)<<5),
color & 0x07,
0);
}
WRITE8_MEMBER(amspdwy_state::amspdwy_videoram_w)
{
m_videoram[offset] = data;
m_bg_tilemap->mark_tile_dirty(offset);
}
WRITE8_MEMBER(amspdwy_state::amspdwy_colorram_w)
{
m_colorram[offset] = data;
m_bg_tilemap->mark_tile_dirty(offset);
}
/* logical (col,row) -> memory offset */
TILEMAP_MAPPER_MEMBER(amspdwy_state::tilemap_scan_cols_back)
{
return col * num_rows + (num_rows - row - 1);
}
void amspdwy_state::video_start()
{
m_bg_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(amspdwy_state::get_tile_info),this), tilemap_mapper_delegate(FUNC(amspdwy_state::tilemap_scan_cols_back),this), 8, 8, 0x20, 0x20);
}
/***************************************************************************
Sprites Drawing
Offset: Format: Value:
0 Y
1 X
2 Code Low Bits
3 7------- Flip X
-6------ Flip Y
--5-----
---4---- ?
----3--- Code High Bit?
-----210 Color
***************************************************************************/
static void draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
{
amspdwy_state *state = machine.driver_data<amspdwy_state>();
UINT8 *spriteram = state->m_spriteram;
int i;
int max_x = machine.primary_screen->width() - 1;
int max_y = machine.primary_screen->height() - 1;
for (i = 0; i < state->m_spriteram.bytes() ; i += 4)
{
int y = spriteram[i + 0];
int x = spriteram[i + 1];
int code = spriteram[i + 2];
int attr = spriteram[i + 3];
int flipx = attr & 0x80;
int flipy = attr & 0x40;
if (state->flip_screen())
{
x = max_x - x - 8;
y = max_y - y - 8;
flipx = !flipx;
flipy = !flipy;
}
drawgfx_transpen(bitmap,cliprect,machine.gfx[0],
// code + ((attr & 0x18)<<5),
code + ((attr & 0x08)<<5),
attr,
flipx, flipy,
x,y,0 );
}
}
/***************************************************************************
Screen Drawing
***************************************************************************/
UINT32 amspdwy_state::screen_update_amspdwy(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
m_bg_tilemap->draw(bitmap, cliprect, 0, 0);
draw_sprites(machine(), bitmap, cliprect);
return 0;
}
| [
"brymaster@gmail.com"
] | brymaster@gmail.com |
faaf500733db7a9eea3b9073657015349d8cb93e | 64e4fabf9b43b6b02b14b9df7e1751732b30ad38 | /src/chromium/gen/gen_combined/services/network/public/mojom/cors.mojom-blink-import-headers.h | f7e94f76f1d9d54b0fb037c7eba5ff2e91d6e5aa | [
"BSD-3-Clause"
] | permissive | ivan-kits/skia-opengl-emscripten | 8a5ee0eab0214c84df3cd7eef37c8ba54acb045e | 79573e1ee794061bdcfd88cacdb75243eff5f6f0 | refs/heads/master | 2023-02-03T16:39:20.556706 | 2020-12-25T14:00:49 | 2020-12-25T14:00:49 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 388 | h | // Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_NETWORK_PUBLIC_MOJOM_CORS_MOJOM_BLINK_IMPORT_HEADERS_H_
#define SERVICES_NETWORK_PUBLIC_MOJOM_CORS_MOJOM_BLINK_IMPORT_HEADERS_H_
#endif // SERVICES_NETWORK_PUBLIC_MOJOM_CORS_MOJOM_BLINK_IMPORT_HEADERS_H_ | [
"trofimov_d_a@magnit.ru"
] | trofimov_d_a@magnit.ru |
5407b25717d222f01c6959c77748ecd05e7249ba | 1c6a7ae5dca2a38c68fde97a676478c6573bca02 | /linux-3.0.1/drivers/scsi/qla4xxx/ql4_iocb.c | 75fcd82a8fcae40b2f56bec6d7aeacb67cbe50ee | [
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] | permissive | tonghua209/samsun6410_linux_3_0_0_1_for_aws | fab70b79dc3e506dc03ac1149e2356137869c6ca | 31aa0dc27c4aab51a92309a74fd84ca65e8c6a58 | refs/heads/master | 2020-04-02T04:24:32.928744 | 2019-01-20T13:51:34 | 2019-01-20T13:51:34 | 154,015,176 | 0 | 0 | Apache-2.0 | 2018-10-24T14:51:04 | 2018-10-21T14:07:31 | C | UTF-8 | C | false | false | 10,172 | c | /*
* QLogic iSCSI HBA Driver
* Copyright (c) 2003-2010 QLogic Corporation
*
* See LICENSE.qla4xxx for copyright and licensing details.
*/
#include "ql4_def.h"
#include "ql4_glbl.h"
#include "ql4_dbg.h"
#include "ql4_inline.h"
#include <scsi/scsi_tcq.h>
static int
qla4xxx_space_in_req_ring(struct scsi_qla_host *ha, uint16_t req_cnt)
{
uint16_t cnt;
/* Calculate number of free request entries. */
if ((req_cnt + 2) >= ha->req_q_count) {
cnt = (uint16_t) ha->isp_ops->rd_shdw_req_q_out(ha);
if (ha->request_in < cnt)
ha->req_q_count = cnt - ha->request_in;
else
ha->req_q_count = REQUEST_QUEUE_DEPTH -
(ha->request_in - cnt);
}
/* Check if room for request in request ring. */
if ((req_cnt + 2) < ha->req_q_count)
return 1;
else
return 0;
}
static void qla4xxx_advance_req_ring_ptr(struct scsi_qla_host *ha)
{
/* Advance request queue pointer */
if (ha->request_in == (REQUEST_QUEUE_DEPTH - 1)) {
ha->request_in = 0;
ha->request_ptr = ha->request_ring;
} else {
ha->request_in++;
ha->request_ptr++;
}
}
/**
* qla4xxx_get_req_pkt - returns a valid entry in request queue.
* @ha: Pointer to host adapter structure.
* @queue_entry: Pointer to pointer to queue entry structure
*
* This routine performs the following tasks:
* - returns the current request_in pointer (if queue not full)
* - advances the request_in pointer
* - checks for queue full
**/
static int qla4xxx_get_req_pkt(struct scsi_qla_host *ha,
struct queue_entry **queue_entry)
{
uint16_t req_cnt = 1;
if (qla4xxx_space_in_req_ring(ha, req_cnt)) {
*queue_entry = ha->request_ptr;
memset(*queue_entry, 0, sizeof(**queue_entry));
qla4xxx_advance_req_ring_ptr(ha);
ha->req_q_count -= req_cnt;
return QLA_SUCCESS;
}
return QLA_ERROR;
}
/**
* qla4xxx_send_marker_iocb - issues marker iocb to HBA
* @ha: Pointer to host adapter structure.
* @ddb_entry: Pointer to device database entry
* @lun: SCSI LUN
* @marker_type: marker identifier
*
* This routine issues a marker IOCB.
**/
int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha,
struct ddb_entry *ddb_entry, int lun, uint16_t mrkr_mod)
{
struct qla4_marker_entry *marker_entry;
unsigned long flags = 0;
uint8_t status = QLA_SUCCESS;
/* Acquire hardware specific lock */
spin_lock_irqsave(&ha->hardware_lock, flags);
/* Get pointer to the queue entry for the marker */
if (qla4xxx_get_req_pkt(ha, (struct queue_entry **) &marker_entry) !=
QLA_SUCCESS) {
status = QLA_ERROR;
goto exit_send_marker;
}
/* Put the marker in the request queue */
marker_entry->hdr.entryType = ET_MARKER;
marker_entry->hdr.entryCount = 1;
marker_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index);
marker_entry->modifier = cpu_to_le16(mrkr_mod);
int_to_scsilun(lun, &marker_entry->lun);
wmb();
/* Tell ISP it's got a new I/O request */
ha->isp_ops->queue_iocb(ha);
exit_send_marker:
spin_unlock_irqrestore(&ha->hardware_lock, flags);
return status;
}
static struct continuation_t1_entry *
qla4xxx_alloc_cont_entry(struct scsi_qla_host *ha)
{
struct continuation_t1_entry *cont_entry;
cont_entry = (struct continuation_t1_entry *)ha->request_ptr;
qla4xxx_advance_req_ring_ptr(ha);
/* Load packet defaults */
cont_entry->hdr.entryType = ET_CONTINUE;
cont_entry->hdr.entryCount = 1;
cont_entry->hdr.systemDefined = (uint8_t) cpu_to_le16(ha->request_in);
return cont_entry;
}
static uint16_t qla4xxx_calc_request_entries(uint16_t dsds)
{
uint16_t iocbs;
iocbs = 1;
if (dsds > COMMAND_SEG) {
iocbs += (dsds - COMMAND_SEG) / CONTINUE_SEG;
if ((dsds - COMMAND_SEG) % CONTINUE_SEG)
iocbs++;
}
return iocbs;
}
static void qla4xxx_build_scsi_iocbs(struct srb *srb,
struct command_t3_entry *cmd_entry,
uint16_t tot_dsds)
{
struct scsi_qla_host *ha;
uint16_t avail_dsds;
struct data_seg_a64 *cur_dsd;
struct scsi_cmnd *cmd;
struct scatterlist *sg;
int i;
cmd = srb->cmd;
ha = srb->ha;
if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
/* No data being transferred */
cmd_entry->ttlByteCnt = __constant_cpu_to_le32(0);
return;
}
avail_dsds = COMMAND_SEG;
cur_dsd = (struct data_seg_a64 *) & (cmd_entry->dataseg[0]);
scsi_for_each_sg(cmd, sg, tot_dsds, i) {
dma_addr_t sle_dma;
/* Allocate additional continuation packets? */
if (avail_dsds == 0) {
struct continuation_t1_entry *cont_entry;
cont_entry = qla4xxx_alloc_cont_entry(ha);
cur_dsd =
(struct data_seg_a64 *)
&cont_entry->dataseg[0];
avail_dsds = CONTINUE_SEG;
}
sle_dma = sg_dma_address(sg);
cur_dsd->base.addrLow = cpu_to_le32(LSDW(sle_dma));
cur_dsd->base.addrHigh = cpu_to_le32(MSDW(sle_dma));
cur_dsd->count = cpu_to_le32(sg_dma_len(sg));
avail_dsds--;
cur_dsd++;
}
}
/**
* qla4_8xxx_queue_iocb - Tell ISP it's got new request(s)
* @ha: pointer to host adapter structure.
*
* This routine notifies the ISP that one or more new request
* queue entries have been placed on the request queue.
**/
void qla4_8xxx_queue_iocb(struct scsi_qla_host *ha)
{
uint32_t dbval = 0;
dbval = 0x14 | (ha->func_num << 5);
dbval = dbval | (0 << 8) | (ha->request_in << 16);
qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, ha->request_in);
}
/**
* qla4_8xxx_complete_iocb - Tell ISP we're done with response(s)
* @ha: pointer to host adapter structure.
*
* This routine notifies the ISP that one or more response/completion
* queue entries have been processed by the driver.
* This also clears the interrupt.
**/
void qla4_8xxx_complete_iocb(struct scsi_qla_host *ha)
{
writel(ha->response_out, &ha->qla4_8xxx_reg->rsp_q_out);
readl(&ha->qla4_8xxx_reg->rsp_q_out);
}
/**
* qla4xxx_queue_iocb - Tell ISP it's got new request(s)
* @ha: pointer to host adapter structure.
*
* This routine is notifies the ISP that one or more new request
* queue entries have been placed on the request queue.
**/
void qla4xxx_queue_iocb(struct scsi_qla_host *ha)
{
writel(ha->request_in, &ha->reg->req_q_in);
readl(&ha->reg->req_q_in);
}
/**
* qla4xxx_complete_iocb - Tell ISP we're done with response(s)
* @ha: pointer to host adapter structure.
*
* This routine is notifies the ISP that one or more response/completion
* queue entries have been processed by the driver.
* This also clears the interrupt.
**/
void qla4xxx_complete_iocb(struct scsi_qla_host *ha)
{
writel(ha->response_out, &ha->reg->rsp_q_out);
readl(&ha->reg->rsp_q_out);
}
/**
* qla4xxx_send_command_to_isp - issues command to HBA
* @ha: pointer to host adapter structure.
* @srb: pointer to SCSI Request Block to be sent to ISP
*
* This routine is called by qla4xxx_queuecommand to build an ISP
* command and pass it to the ISP for execution.
**/
int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb)
{
struct scsi_cmnd *cmd = srb->cmd;
struct ddb_entry *ddb_entry;
struct command_t3_entry *cmd_entry;
int nseg;
uint16_t tot_dsds;
uint16_t req_cnt;
unsigned long flags;
uint32_t index;
char tag[2];
/* Get real lun and adapter */
ddb_entry = srb->ddb;
tot_dsds = 0;
/* Acquire hardware specific lock */
spin_lock_irqsave(&ha->hardware_lock, flags);
index = (uint32_t)cmd->request->tag;
/*
* Check to see if adapter is online before placing request on
* request queue. If a reset occurs and a request is in the queue,
* the firmware will still attempt to process the request, retrieving
* garbage for pointers.
*/
if (!test_bit(AF_ONLINE, &ha->flags)) {
DEBUG2(printk("scsi%ld: %s: Adapter OFFLINE! "
"Do not issue command.\n",
ha->host_no, __func__));
goto queuing_error;
}
/* Calculate the number of request entries needed. */
nseg = scsi_dma_map(cmd);
if (nseg < 0)
goto queuing_error;
tot_dsds = nseg;
req_cnt = qla4xxx_calc_request_entries(tot_dsds);
if (!qla4xxx_space_in_req_ring(ha, req_cnt))
goto queuing_error;
/* total iocbs active */
if ((ha->iocb_cnt + req_cnt) >= REQUEST_QUEUE_DEPTH)
goto queuing_error;
/* Build command packet */
cmd_entry = (struct command_t3_entry *) ha->request_ptr;
memset(cmd_entry, 0, sizeof(struct command_t3_entry));
cmd_entry->hdr.entryType = ET_COMMAND;
cmd_entry->handle = cpu_to_le32(index);
cmd_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index);
cmd_entry->connection_id = cpu_to_le16(ddb_entry->connection_id);
int_to_scsilun(cmd->device->lun, &cmd_entry->lun);
cmd_entry->cmdSeqNum = cpu_to_le32(ddb_entry->CmdSn);
cmd_entry->ttlByteCnt = cpu_to_le32(scsi_bufflen(cmd));
memcpy(cmd_entry->cdb, cmd->cmnd, cmd->cmd_len);
cmd_entry->dataSegCnt = cpu_to_le16(tot_dsds);
cmd_entry->hdr.entryCount = req_cnt;
/* Set data transfer direction control flags
* NOTE: Look at data_direction bits iff there is data to be
* transferred, as the data direction bit is sometimed filled
* in when there is no data to be transferred */
cmd_entry->control_flags = CF_NO_DATA;
if (scsi_bufflen(cmd)) {
if (cmd->sc_data_direction == DMA_TO_DEVICE)
cmd_entry->control_flags = CF_WRITE;
else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
cmd_entry->control_flags = CF_READ;
ha->bytes_xfered += scsi_bufflen(cmd);
if (ha->bytes_xfered & ~0xFFFFF){
ha->total_mbytes_xferred += ha->bytes_xfered >> 20;
ha->bytes_xfered &= 0xFFFFF;
}
}
/* Set tagged queueing control flags */
cmd_entry->control_flags |= CF_SIMPLE_TAG;
if (scsi_populate_tag_msg(cmd, tag))
switch (tag[0]) {
case MSG_HEAD_TAG:
cmd_entry->control_flags |= CF_HEAD_TAG;
break;
case MSG_ORDERED_TAG:
cmd_entry->control_flags |= CF_ORDERED_TAG;
break;
}
qla4xxx_advance_req_ring_ptr(ha);
qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds);
wmb();
srb->cmd->host_scribble = (unsigned char *)(unsigned long)index;
/* update counters */
srb->state = SRB_ACTIVE_STATE;
srb->flags |= SRB_DMA_VALID;
/* Track IOCB used */
ha->iocb_cnt += req_cnt;
srb->iocb_cnt = req_cnt;
ha->req_q_count -= req_cnt;
ha->isp_ops->queue_iocb(ha);
spin_unlock_irqrestore(&ha->hardware_lock, flags);
return QLA_SUCCESS;
queuing_error:
if (tot_dsds)
scsi_dma_unmap(cmd);
spin_unlock_irqrestore(&ha->hardware_lock, flags);
return QLA_ERROR;
}
| [
"kyh1022@163.com"
] | kyh1022@163.com |
5c87c5824c300ea3e02f9456f98964df6e4a24c8 | 958d7fc38adc026cf1104ae4771a744562a8d758 | /process/fork/p_03_sharedfork.c | 12a57a250fec0758e48602dddc896254f8f7f310 | [] | no_license | junpfeng/LinuxSysProgram | 1045963d7ab11aebcfdedb2a2c42aaf1bd403beb | 3c2d7782d34e7cfb1b191bff69cf861d8d632b69 | refs/heads/master | 2022-04-09T17:46:22.687848 | 2019-06-26T14:18:13 | 2019-06-26T14:18:13 | 189,677,785 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 746 | c | /*************************************************************************
> File Name: p_03_sharedfork.c
> Author:
> Mail:
> Created Time: 2019年06月12日 星期三 19时01分28秒
> 父子进程之间的用户空间是独立的,原则:写时复制,读时共享
************************************************************************/
#include <stdlib.h>
#include <unistd.h>
#include<stdio.h>
// 用于测试:全局变量不共享
int a = 100;
int main()
{
pid_t pid;
pid = fork();
if (pid == 0) //子进程
{
a = 1;
printf("这是子进程,id = %d, a = %d\n", getpid(), a);
}
else
{
printf("这是父进程,id = %d, a = %d\n", getpid(), a);
}
return 0;
}
| [
"867607989@qq.com"
] | 867607989@qq.com |
7d3000c3ec86dede074c49bdcc1e3e333dd05b4e | 5994826002c75b0bb51994eadcef7762c3f309e0 | /src/result.c | e4df9578b968781cc6f1e53697cc865a583429d1 | [
"ISC"
] | permissive | cuulee/plproxy | 42e7171a5977a19922ade1c2e615af674679a87d | c3c0326faf622241269c0a3a5163b1373f54268d | refs/heads/master | 2020-12-02T22:18:07.956381 | 2017-06-28T14:21:01 | 2017-06-28T14:21:01 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 5,378 | c | /*
* PL/Proxy - easy access to partitioned database.
*
* Copyright (c) 2006 Sven Suursoho, Skype Technologies OÜ
* Copyright (c) 2007 Marko Kreen, Skype Technologies OÜ
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Conversion from PGresult to Datum.
*
* Functions here are called with CurrentMemoryContext == query context
* so that palloc()-ed memory stays valid after return to postgres.
*/
#include "plproxy.h"
static bool
name_matches(ProxyFunction *func, const char *aname, PGresult *res, int col)
{
const char *fname = PQfname(res, col);
if (fname == NULL)
plproxy_error(func, "Unnamed result column %d", col + 1);
if (strcmp(aname, fname) == 0)
return true;
return false;
}
/* fill func->result_map */
static void
map_results(ProxyFunction *func, PGresult *res)
{
int i, /* non-dropped column index */
xi, /* tupdesc index */
j, /* result column index */
natts,
nfields = PQnfields(res);
Form_pg_attribute a;
const char *aname;
if (func->ret_scalar)
{
if (nfields != 1)
plproxy_error(func,
"single field function but got record");
return;
}
natts = func->ret_composite->tupdesc->natts;
if (nfields < func->ret_composite->nfields)
plproxy_error(func, "Got too few fields from remote end");
if (nfields > func->ret_composite->nfields)
plproxy_error(func, "Got too many fields from remote end");
for (i = -1, xi = 0; xi < natts; xi++)
{
/* ->name_list has quoted names, take unquoted from ->tupdesc */
a = func->ret_composite->tupdesc->attrs[xi];
func->result_map[xi] = -1;
if (a->attisdropped)
continue;
i++;
aname = NameStr(a->attname);
if (name_matches(func, aname, res, i))
/* fast case: 1:1 mapping */
func->result_map[xi] = i;
else
{
/* slow case: messed up ordering */
for (j = 0; j < nfields; j++)
{
/* already tried this one */
if (j == i)
continue;
/*
* fixme: somehow remember the ones that are already mapped?
*/
if (name_matches(func, aname, res, j))
{
func->result_map[xi] = j;
break;
}
}
}
if (func->result_map[xi] < 0)
plproxy_error(func,
"Field %s does not exists in result", aname);
}
}
/* Return connection where are unreturned rows */
static ProxyConnection *
walk_results(ProxyFunction *func, ProxyCluster *cluster)
{
ProxyConnection *conn;
for (; cluster->ret_cur_conn < cluster->active_count;
cluster->ret_cur_conn++)
{
conn = cluster->active_list[cluster->ret_cur_conn];
if (conn->res == NULL)
continue;
if (conn->pos == PQntuples(conn->res))
continue;
/* first time on this connection? */
if (conn->pos == 0)
map_results(func, conn->res);
return conn;
}
plproxy_error(func, "bug: no result");
return NULL;
}
/* Return a tuple */
static Datum
return_composite(ProxyFunction *func, ProxyConnection *conn, FunctionCallInfo fcinfo)
{
int i,
col;
char **values;
int *fmts;
int *lengths;
HeapTuple tup;
ProxyComposite *meta = func->ret_composite;
values = palloc(meta->tupdesc->natts * sizeof(char *));
fmts = palloc(meta->tupdesc->natts * sizeof(int));
lengths = palloc(meta->tupdesc->natts * sizeof(int));
for (i = 0; i < meta->tupdesc->natts; i++)
{
col = func->result_map[i];
if (col < 0 || PQgetisnull(conn->res, conn->pos, col))
{
values[i] = NULL;
lengths[i] = 0;
fmts[i] = 0;
}
else
{
values[i] = PQgetvalue(conn->res, conn->pos, col);
lengths[i] = PQgetlength(conn->res, conn->pos, col);
fmts[i] = PQfformat(conn->res, col);
}
}
tup = plproxy_recv_composite(meta, values, lengths, fmts);
pfree(lengths);
pfree(fmts);
pfree(values);
return HeapTupleGetDatum(tup);
}
/* Return scalar value */
static Datum
return_scalar(ProxyFunction *func, ProxyConnection *conn, FunctionCallInfo fcinfo)
{
Datum dat;
char *val;
PGresult *res = conn->res;
int row = conn->pos;
if (func->ret_scalar->type_oid == VOIDOID)
{
dat = (Datum) NULL;
}
else if (PQgetisnull(res, row, 0))
{
fcinfo->isnull = true;
dat = (Datum) NULL;
}
else
{
val = PQgetvalue(res, row, 0);
if (val == NULL)
plproxy_error(func, "unexcpected NULL");
dat = plproxy_recv_type(func->ret_scalar, val,
PQgetlength(res, row, 0),
PQfformat(res, 0));
}
return dat;
}
/* Return next result Datum */
Datum
plproxy_result(ProxyFunction *func, FunctionCallInfo fcinfo)
{
Datum dat;
ProxyCluster *cluster = func->cur_cluster;
ProxyConnection *conn;
conn = walk_results(func, cluster);
if (func->ret_composite)
dat = return_composite(func, conn, fcinfo);
else
dat = return_scalar(func, conn, fcinfo);
cluster->ret_total--;
conn->pos++;
return dat;
}
| [
"markokr@gmail.com"
] | markokr@gmail.com |
790d2a6df2c999fe64fbfba1c399be07207d4c49 | 31bfb394d7914cc59ef4744e57adf564648bbf2a | /comline.c | e03768c8ac9abc2a9975bafcdc2a627b78624de5 | [] | no_license | Mr-ari/All-C-Programs | c9a4c389c9576ea69cb4b6475b6c9302b73e3fe8 | 3daa90004727c8c873d3ad26e78a287bb9240daf | refs/heads/master | 2021-09-07T07:25:48.911439 | 2018-02-19T15:07:26 | 2018-02-19T15:07:26 | 115,312,221 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 854 | c | #include<stdio.h>
#include<conio.h>
#include<string.h>
int main(int argc,char* argv[]){
//gets(argv);
char temp[20];
int i,j,F;
if(argc==1)
printf("please use a command line argument:)");
else{
for (i = 0; i < argc ; i++)
{
for (j = i + 1; i < argc; j++)
{
if (strcmp(argv[i], argv[j]) > 0)
{
strcpy(temp, argv[i]);
strcpy(argv[i], argv[j]);
strcpy(argv[j], temp);
}
}
}
}
printf("-----------------------------------------------------------------------------------------\n\n\t\t\tSorted Names are \n\n----------------------------------------------------------------------------");
for(i=0;i<argc;i++)
printf("%s\n",argv[i]);
getch();
return 0;
}
| [
"noreply@github.com"
] | Mr-ari.noreply@github.com |
b44278cfd3e43ca5dff64ae25a9f81b4e49f2230 | ed444c4a0ed1fe679da64b81ec6aa1ddf885a185 | /Foundation/Render/Common/Material/import.h | bd09708f7361afda3b21d891927df048afe00263 | [] | no_license | swaphack/CodeLib | 54e07db129d38be0fd55504ef917bbe522338aa6 | fff8ed54afc334e1ff5e3dd34ec5cfcf6ce7bdc9 | refs/heads/master | 2022-05-16T20:31:45.123321 | 2022-05-12T03:38:45 | 2022-05-12T03:38:45 | 58,099,874 | 1 | 0 | null | 2016-05-11T09:46:07 | 2016-05-05T02:57:24 | C++ | UTF-8 | C | false | false | 144 | h | #pragma once
#include "macros.h"
#include "MaterialGlobalParameter.h"
#include "MaterialSetting.h"
#include "Material.h"
#include "Materials.h" | [
"809406730@qq.com"
] | 809406730@qq.com |
4aefbdfdbf6da700549cc8c521acf73fb1670909 | 09140c9111164e1c6418893e0e62172fc5ef3b4f | /findpat/algo/mtf.h | aa294a7b09b2214c81a9278cdf80a52548cc944d | [
"MIT"
] | permissive | yoriyuki-aist/findpat | 1c3088f4a8fe5c519feeaf7b7f878e58c08a29a6 | 6975efb4414197bf91babd7775bb8c48d2befd0f | refs/heads/main | 2023-08-30T15:44:59.868961 | 2021-11-13T17:31:57 | 2021-11-13T17:31:57 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,959 | h | #ifndef __MTF_H__
#define __MTF_H__
#include "tipos.h"
/** mtf_bf: Move-To-Front Fuerza-Bruta
* Implementa MTF manteniendo la lista de elementos en un arreglo físico.
* Es la implementación mas simple y corre en O(N*256) (en realidad corre
* en tiempo O(N + sumatoria(output_i)). La implementación es simple.
*/
void mtf_bf(uchar* src, uchar* dst, uint size);
/** imtf_bf: Inverse Move-To-Front Fuerza-Bruta
* Misma idea que mtf_bf. Es sólo una simulación del algoritmo sobre un
* arreglo estático.
*/
void imtf_bf(uchar* src, uchar* dst, uint size);
/** mtf_sqr: Move-To-Front sobre listas enlazadas de longitud sqrt.
* Implementa la lista del algoritmo como 16 listas enlazadas de longitud
* 16. De este modo, uno puedo ubicar un elemento en qué lista está, y
* luego buscar el elemento linealmente dentro de la lista. Esto
* provee un orden de complejidad de O(N*sqrt(256)). El overhead
* de las listas enlazadas hace que la constante sea aún grande
* pero funciona bien en caso promedio.
*/
void mtf_sqr(uchar* src, uchar* dst, uint size);
/** mtf_log: Move-To-Front sobre conjunto de elementos.
* Implementa la inversa de la lista del algorimo sobre un conjunto
* indicando la última iteración en la que se usó un caracter dado. La
* posición entonces se interpreta como cuántos elementos hay en el conjunto
* mayores que su última aparición. El conjunto se implementa sobre
* arreglo de bool de 0 a X con una estructura de árbol sobre arreglo
* para garantizar tiempo log en la consulta cuántos mayores que "i" hay
* en el conjunto. Cuando los números llegan a X, se comprimen todos los
* números al rango 0 a 255 y se continúa con la misma implementación.
* Provee un orden O(N * log(X) + X*N/(X-256)). En este caso X = 2048.
* El overhead es considerablemente bajo pues la estructura es muy simple.
* returns the number of 0 in the output
*/
uint mtf_log(uchar* src, uchar* dst, uint size);
#endif
| [
"placiana@dc.uba.ar"
] | placiana@dc.uba.ar |
336221f7a9e9235d92285094a4c16b03a0f09c89 | 61387be85711cf03ca2cc4144c15369ee9a46796 | /zo-mb-es-defender/project.IOs/Project.IOs/Classes/Native/mscorlib_System_Runtime_Remoting_Messaging_ObjRefSu968727986MethodDeclarations.h | cdbaae2836f0a4002d59a63376ea2e09b2c8a817 | [] | no_license | hoangwin/raci-ngc-ar_Du-o-iHin-hBa-tC-Hu | 6bb6b64052f05bc4026e1cfc6e10844c3dfc574b | 29c4f918482e9b850503d9912ebdf7afdafcafed | refs/heads/master | 2021-01-10T10:00:33.196405 | 2016-08-14T23:06:31 | 2016-08-14T23:06:31 | 44,680,146 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,327 | h | #pragma once
#include "il2cpp-config.h"
#ifndef _MSC_VER
# include <alloca.h>
#else
# include <malloc.h>
#endif
#include <stdint.h>
#include <assert.h>
#include <exception>
// System.Runtime.Remoting.Messaging.ObjRefSurrogate
struct ObjRefSurrogate_t968727986_0;
// System.Object
struct Object_t;
// System.Runtime.Serialization.SerializationInfo
struct SerializationInfo_t_2018490193_0;
// System.Runtime.Serialization.ISurrogateSelector
struct ISurrogateSelector_t_400063483_0;
#include "codegen/il2cpp-codegen.h"
#include "mscorlib_System_Runtime_Serialization_StreamingCon2060733842.h"
// System.Void System.Runtime.Remoting.Messaging.ObjRefSurrogate::.ctor()
extern "C" void ObjRefSurrogate__ctor_m_562329356_0 (ObjRefSurrogate_t968727986_0 * __this, const MethodInfo* method) IL2CPP_METHOD_ATTR;
// System.Object System.Runtime.Remoting.Messaging.ObjRefSurrogate::SetObjectData(System.Object,System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext,System.Runtime.Serialization.ISurrogateSelector)
extern "C" Object_t * ObjRefSurrogate_SetObjectData_m1873902916_0 (ObjRefSurrogate_t968727986_0 * __this, Object_t * ___obj, SerializationInfo_t_2018490193_0 * ___si, StreamingContext_t2060733842_0 ___sc, Object_t * ___selector, const MethodInfo* method) IL2CPP_METHOD_ATTR;
| [
"hoang.nguyenmau@hotmail.com"
] | hoang.nguyenmau@hotmail.com |
c6014c6ecd26f2f3864c6be6bd23a1a2ad7d46a8 | b98cf58b0becca483adcbb90e62e388557d8ea54 | /Examples/10/10.c | 0ab9036a6fcced88f8b1e468b11b8bda7c6da018 | [] | no_license | LMladenovic/Error_fixing_tool | 7b392bae5c37a69978981a43803a89a058e0e573 | f8903ab40a18d3331f5a7b25e46f9caeb571b073 | refs/heads/master | 2023-02-04T10:50:02.499353 | 2020-12-27T12:47:38 | 2020-12-27T12:47:38 | 280,123,424 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,207 | c | #include <stdio.h>
#include <stdlib.h>
int zbir(int **P,int n){
int i,j,be=0;
for (i=0;i<n;i++){
for (j=n-i;j<n;j++){
be+=P[i][j];
}
}
return be;
}
int main(int argc, char *argv[]){
FILE *in=NULL;
int **P=NULL;
int n;
int i,j;
if (argc==1){
fprintf(stderr,"Premalo argumenata!\n");
exit(EXIT_FAILURE);
}
if ((in=fopen(argv[1],"r"))==NULL){
fprintf(stderr,"Greska prilikom otvaranja datoteke %s!\n", argv[1]);
exit(EXIT_FAILURE);
}
//ALOCIRAMO MATRICU
fscanf(in,"%d", &n);
if(( P=malloc(n*sizeof(int*)))==NULL){
fprintf(stderr,"Greska malloc()!\n");
exit(EXIT_FAILURE);
}
for(i=0;i<n;i++)
if ((P[i]=malloc(n*sizeof(int)))==NULL){
fprintf(stderr,"Greska malloc()!\n");
for (j=0;j<i;j++)
free(P[j]);
free(P);
exit(EXIT_FAILURE);
}
//UCITAVAMO MATRICU
for(i=0;i<n;i++)
for(j=0;j<n;j++)
fscanf(in,"%d ",&P[i][j]);
for(i=0;i<n;i++){
for(j=0;j<=n;j++)
printf("%d ",P[i][j]);
printf("\n");
}
printf ("Zbir elemenata ispod sporedne dijagonale je %d\n", zbir(P,n));
//OSLOBADJAMO MATRICU
for(i=0;i<n;i++)
free(P[i]);
free(P);
fclose(in);
return 0;
}
| [
"lazar.s.mladenovic@hotmail.com"
] | lazar.s.mladenovic@hotmail.com |
78a487f4573ee3eda4994b27c7a46d301db932b0 | feb04221b7e4ab463c1aa5f2de6a10ce260c1e93 | /onvif/src/stdsoap2.c | 2607c33d894c105d01b9dacdc5a044f1faff339e | [] | no_license | EyecloudAi/openncc_ipc | ee8c6ae2196288332e7c0431b23181cd9318ed0a | b998816cf5885685ec6dd131741d943a4e004da7 | refs/heads/master | 2023-02-25T23:58:01.775077 | 2021-02-05T11:19:42 | 2021-02-05T11:19:42 | 329,571,890 | 3 | 0 | null | null | null | null | UTF-8 | C | false | false | 502,649 | c | /*
stdsoap2.c[pp] 2.8.17r
gSOAP runtime engine
gSOAP XML Web services tools
Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved.
This part of the software is released under ONE of the following licenses:
GPL, or the gSOAP public license, or Genivia's license for commercial use.
--------------------------------------------------------------------------------
Contributors:
Wind River Systems Inc., for the following additions under gSOAP public license:
- vxWorks compatible options
--------------------------------------------------------------------------------
gSOAP public license.
The contents of this file are subject to the gSOAP Public License Version 1.3
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.cs.fsu.edu/~engelen/soaplicense.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Initial Developer of the Original Code is Robert A. van Engelen.
Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved.
--------------------------------------------------------------------------------
GPL license.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
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., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
Author contact information:
engelen@genivia.com / engelen@acm.org
This program is released under the GPL with the additional exemption that
compiling, linking, and/or using OpenSSL is allowed.
--------------------------------------------------------------------------------
A commercial use license is available from Genivia, Inc., contact@genivia.com
--------------------------------------------------------------------------------
*/
#define GSOAP_LIB_VERSION 20817
#ifdef AS400
# pragma convert(819) /* EBCDIC to ASCII */
#endif
#include "stdsoap2.h"
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
#include <ipcom_key_db.h>
#endif
#if GSOAP_VERSION != GSOAP_LIB_VERSION
# error "GSOAP VERSION MISMATCH IN LIBRARY: PLEASE REINSTALL PACKAGE"
#endif
#ifdef __BORLANDC__
# pragma warn -8060
#else
# ifdef WIN32
# ifdef UNDER_CE
# pragma comment(lib, "ws2.lib") /* WinCE */
# else
# pragma comment(lib, "ws2_32.lib")
# endif
# pragma warning(disable : 4996) /* disable deprecation warnings */
# endif
#endif
#ifdef __cplusplus
SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.8.17r 2013-12-18 00:00:00 GMT")
extern "C" {
#else
SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.17r 2013-12-18 00:00:00 GMT")
#endif
/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */
#ifndef SOAP_UNKNOWN_CHAR
#define SOAP_UNKNOWN_CHAR (127)
#endif
/* EOF=-1 */
#define SOAP_LT (soap_wchar)(-2) /* XML-specific '<' */
#define SOAP_TT (soap_wchar)(-3) /* XML-specific '</' */
#define SOAP_GT (soap_wchar)(-4) /* XML-specific '>' */
#define SOAP_QT (soap_wchar)(-5) /* XML-specific '"' */
#define SOAP_AP (soap_wchar)(-6) /* XML-specific ''' */
#define soap_blank(c) ((c)+1 > 0 && (c) <= 32)
#define soap_notblank(c) ((c) > 32)
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
static void soap_init_logs(struct soap*);
#endif
#ifdef SOAP_DEBUG
static void soap_close_logfile(struct soap*, int);
static void soap_set_logfile(struct soap*, int, const char*);
#endif
#ifdef SOAP_MEM_DEBUG
static void soap_init_mht(struct soap*);
static void soap_free_mht(struct soap*);
static void soap_track_unlink(struct soap*, const void*);
#endif
#ifndef PALM_2
static int soap_set_error(struct soap*, const char*, const char*, const char*, const char*, int);
static int soap_copy_fault(struct soap*, const char*, const char*, const char*, const char*);
static int soap_getattrval(struct soap*, char*, size_t, soap_wchar);
#endif
#ifndef PALM_1
static void soap_free_ns(struct soap *soap);
static soap_wchar soap_char(struct soap*);
static soap_wchar soap_get_pi(struct soap*);
static int soap_isxdigit(int);
static void *fplugin(struct soap*, const char*);
static size_t soap_count_attachments(struct soap *soap);
static int soap_try_connect_command(struct soap*, int http_command, const char *endpoint, const char *action);
#ifdef WITH_NTLM
static int soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const char *host, int port);
#endif
#ifndef WITH_NOIDREF
static int soap_has_copies(struct soap*, const char*, const char*);
static void soap_init_iht(struct soap*);
static void soap_free_iht(struct soap*);
static void soap_init_pht(struct soap*);
static void soap_free_pht(struct soap*);
#endif
#endif
#ifndef WITH_LEAN
static const char *soap_set_validation_fault(struct soap*, const char*, const char*);
static int soap_isnumeric(struct soap*, const char*);
static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized);
static void soap_utilize_ns(struct soap *soap, const char *tag);
#endif
#ifndef WITH_LEANER
#ifndef PALM_1
static struct soap_multipart *soap_new_multipart(struct soap*, struct soap_multipart**, struct soap_multipart**, char*, size_t);
static int soap_putdimefield(struct soap*, const char*, size_t);
static char *soap_getdimefield(struct soap*, size_t);
static void soap_select_mime_boundary(struct soap*);
static int soap_valid_mime_boundary(struct soap*);
static void soap_resolve_attachment(struct soap*, struct soap_multipart*);
#endif
#endif
#ifdef WITH_GZIP
static int soap_getgziphdr(struct soap*);
#endif
#ifdef WITH_OPENSSL
# ifndef SOAP_SSL_RSA_BITS
# define SOAP_SSL_RSA_BITS 2048
# endif
static int soap_ssl_init_done = 0;
static int ssl_auth_init(struct soap*);
static int ssl_verify_callback(int, X509_STORE_CTX*);
static int ssl_verify_callback_allow_expired_certificate(int, X509_STORE_CTX*);
static int ssl_password(char*, int, int, void *);
#endif
#ifdef WITH_GNUTLS
# ifndef SOAP_SSL_RSA_BITS
# define SOAP_SSL_RSA_BITS 2048
# endif
static int soap_ssl_init_done = 0;
static const char *ssl_verify(struct soap *soap, const char *host);
# if defined(HAVE_PTHREAD_H)
# include <pthread.h>
/* make GNUTLS thread safe with pthreads */
GCRY_THREAD_OPTION_PTHREAD_IMPL;
# elif defined(HAVE_PTH_H)
#include <pth.h>
/* make GNUTLS thread safe with PTH */
GCRY_THREAD_OPTION_PTH_IMPL;
# endif
#endif
#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER)
#ifndef PALM_1
static const char *soap_decode(char*, size_t, const char*, const char*);
#endif
#endif
#ifndef WITH_NOHTTP
#ifndef PALM_1
static soap_wchar soap_getchunkchar(struct soap*);
static const char *http_error(struct soap*, int);
static int http_get(struct soap*);
static int http_405(struct soap*);
static int http_200(struct soap*);
static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
static int http_send_header(struct soap*, const char*);
static int http_post_header(struct soap*, const char*, const char*);
static int http_response(struct soap*, int, size_t);
static int http_parse(struct soap*);
static int http_parse_header(struct soap*, const char*, const char*);
#endif
#endif
#ifndef WITH_NOIO
#ifndef PALM_1
static int fsend(struct soap*, const char*, size_t);
static size_t frecv(struct soap*, char*, size_t);
static int tcp_init(struct soap*);
static const char *tcp_error(struct soap*);
#ifndef WITH_IPV6
static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr);
#endif
static SOAP_SOCKET tcp_connect(struct soap*, const char *endpoint, const char *host, int port);
static SOAP_SOCKET tcp_accept(struct soap*, SOAP_SOCKET, struct sockaddr*, int*);
static int tcp_select(struct soap*, SOAP_SOCKET, int, int);
static int tcp_disconnect(struct soap*);
static int tcp_closesocket(struct soap*, SOAP_SOCKET);
static int tcp_shutdownsocket(struct soap*, SOAP_SOCKET, int);
static const char *soap_strerror(struct soap*);
#endif
#define SOAP_TCP_SELECT_RCV 0x1
#define SOAP_TCP_SELECT_SND 0x2
#define SOAP_TCP_SELECT_ERR 0x4
#define SOAP_TCP_SELECT_ALL 0x7
#if defined(WIN32)
#define SOAP_SOCKBLOCK(fd) \
{ u_long blocking = 0; \
ioctlsocket(fd, FIONBIO, &blocking); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ u_long nonblocking = 1; \
ioctlsocket(fd, FIONBIO, &nonblocking); \
}
#elif defined(VXWORKS)
#define SOAP_SOCKBLOCK(fd) \
{ u_long blocking = 0; \
ioctl(fd, FIONBIO, (int)(&blocking)); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ u_long nonblocking = 1; \
ioctl(fd, FIONBIO, (int)(&nonblocking)); \
}
#elif defined(__VMS)
#define SOAP_SOCKBLOCK(fd) \
{ int blocking = 0; \
ioctl(fd, FIONBIO, &blocking); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ int nonblocking = 1; \
ioctl(fd, FIONBIO, &nonblocking); \
}
#elif defined(PALM)
#define SOAP_SOCKBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)&~O_NONBLOCK);
#define SOAP_SOCKNONBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)|O_NONBLOCK);
#elif defined(SYMBIAN)
#define SOAP_SOCKBLOCK(fd) \
{ long blocking = 0; \
ioctl(fd, 0/*FIONBIO*/, &blocking); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ long nonblocking = 1; \
ioctl(fd, 0/*FIONBIO*/, &nonblocking); \
}
#else
#define SOAP_SOCKBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)&~O_NONBLOCK);
#define SOAP_SOCKNONBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
#endif
#endif
#if defined(PALM) && !defined(PALM_2)
unsigned short errno;
#endif
#ifndef PALM_1
static const char soap_env1[42] = "http://schemas.xmlsoap.org/soap/envelope/";
static const char soap_enc1[42] = "http://schemas.xmlsoap.org/soap/encoding/";
static const char soap_env2[40] = "http://www.w3.org/2003/05/soap-envelope";
static const char soap_enc2[40] = "http://www.w3.org/2003/05/soap-encoding";
static const char soap_rpc[35] = "http://www.w3.org/2003/05/soap-rpc";
#endif
#ifndef PALM_1
const union soap_double_nan soap_double_nan = {{0xFFFFFFFF, 0xFFFFFFFF}};
const char soap_base64o[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char soap_base64i[81] = "\76XXX\77\64\65\66\67\70\71\72\73\74\75XXXXXXX\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31XXXXXX\32\33\34\35\36\37\40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\60\61\62\63";
#endif
#ifndef WITH_LEAN
static const char soap_indent[11] = "\n\t\t\t\t\t\t\t\t\t";
/* Alternative indentation form for SOAP_XML_INDENT:
static const char soap_indent[21] = "\n ";
*/
#endif
#ifndef SOAP_CANARY
# define SOAP_CANARY (0xC0DE)
#endif
static const char soap_padding[4] = "\0\0\0";
#define SOAP_STR_PADDING (soap_padding)
#define SOAP_STR_EOS (soap_padding)
#define SOAP_NON_NULL (soap_padding)
#ifndef WITH_LEAN
static const struct soap_code_map html_entity_codes[] = /* entities for XHTML parsing */
{ { 160, "nbsp" },
{ 161, "iexcl" },
{ 162, "cent" },
{ 163, "pound" },
{ 164, "curren" },
{ 165, "yen" },
{ 166, "brvbar" },
{ 167, "sect" },
{ 168, "uml" },
{ 169, "copy" },
{ 170, "ordf" },
{ 171, "laquo" },
{ 172, "not" },
{ 173, "shy" },
{ 174, "reg" },
{ 175, "macr" },
{ 176, "deg" },
{ 177, "plusmn" },
{ 178, "sup2" },
{ 179, "sup3" },
{ 180, "acute" },
{ 181, "micro" },
{ 182, "para" },
{ 183, "middot" },
{ 184, "cedil" },
{ 185, "sup1" },
{ 186, "ordm" },
{ 187, "raquo" },
{ 188, "frac14" },
{ 189, "frac12" },
{ 190, "frac34" },
{ 191, "iquest" },
{ 192, "Agrave" },
{ 193, "Aacute" },
{ 194, "Acirc" },
{ 195, "Atilde" },
{ 196, "Auml" },
{ 197, "Aring" },
{ 198, "AElig" },
{ 199, "Ccedil" },
{ 200, "Egrave" },
{ 201, "Eacute" },
{ 202, "Ecirc" },
{ 203, "Euml" },
{ 204, "Igrave" },
{ 205, "Iacute" },
{ 206, "Icirc" },
{ 207, "Iuml" },
{ 208, "ETH" },
{ 209, "Ntilde" },
{ 210, "Ograve" },
{ 211, "Oacute" },
{ 212, "Ocirc" },
{ 213, "Otilde" },
{ 214, "Ouml" },
{ 215, "times" },
{ 216, "Oslash" },
{ 217, "Ugrave" },
{ 218, "Uacute" },
{ 219, "Ucirc" },
{ 220, "Uuml" },
{ 221, "Yacute" },
{ 222, "THORN" },
{ 223, "szlig" },
{ 224, "agrave" },
{ 225, "aacute" },
{ 226, "acirc" },
{ 227, "atilde" },
{ 228, "auml" },
{ 229, "aring" },
{ 230, "aelig" },
{ 231, "ccedil" },
{ 232, "egrave" },
{ 233, "eacute" },
{ 234, "ecirc" },
{ 235, "euml" },
{ 236, "igrave" },
{ 237, "iacute" },
{ 238, "icirc" },
{ 239, "iuml" },
{ 240, "eth" },
{ 241, "ntilde" },
{ 242, "ograve" },
{ 243, "oacute" },
{ 244, "ocirc" },
{ 245, "otilde" },
{ 246, "ouml" },
{ 247, "divide" },
{ 248, "oslash" },
{ 249, "ugrave" },
{ 250, "uacute" },
{ 251, "ucirc" },
{ 252, "uuml" },
{ 253, "yacute" },
{ 254, "thorn" },
{ 255, "yuml" },
{ 0, NULL }
};
#endif
#ifndef WITH_NOIO
#ifndef WITH_LEAN
static const struct soap_code_map h_error_codes[] =
{
#ifdef HOST_NOT_FOUND
{ HOST_NOT_FOUND, "Host not found" },
#endif
#ifdef TRY_AGAIN
{ TRY_AGAIN, "Try Again" },
#endif
#ifdef NO_RECOVERY
{ NO_RECOVERY, "No Recovery" },
#endif
#ifdef NO_DATA
{ NO_DATA, "No Data" },
#endif
#ifdef NO_ADDRESS
{ NO_ADDRESS, "No Address" },
#endif
{ 0, NULL }
};
#endif
#endif
#ifndef WITH_NOHTTP
#ifndef WITH_LEAN
static const struct soap_code_map h_http_error_codes[] =
{ { 200, "OK" },
{ 201, "Created" },
{ 202, "Accepted" },
{ 203, "Non-Authoritative Information" },
{ 204, "No Content" },
{ 205, "Reset Content" },
{ 206, "Partial Content" },
{ 300, "Multiple Choices" },
{ 301, "Moved Permanently" },
{ 302, "Found" },
{ 303, "See Other" },
{ 304, "Not Modified" },
{ 305, "Use Proxy" },
{ 307, "Temporary Redirect" },
{ 400, "Bad Request" },
{ 401, "Unauthorized" },
{ 402, "Payment Required" },
{ 403, "Forbidden" },
{ 404, "Not Found" },
{ 405, "Method Not Allowed" },
{ 406, "Not Acceptable" },
{ 407, "Proxy Authentication Required" },
{ 408, "Request Time-out" },
{ 409, "Conflict" },
{ 410, "Gone" },
{ 411, "Length Required" },
{ 412, "Precondition Failed" },
{ 413, "Request Entity Too Large" },
{ 414, "Request-URI Too Large" },
{ 415, "Unsupported Media Type" },
{ 416, "Requested range not satisfiable" },
{ 417, "Expectation Failed" },
{ 500, "Internal Server Error" },
{ 501, "Not Implemented" },
{ 502, "Bad Gateway" },
{ 503, "Service Unavailable" },
{ 504, "Gateway Time-out" },
{ 505, "HTTP Version not supported" },
{ 0, NULL }
};
#endif
#endif
#ifdef WITH_OPENSSL
static const struct soap_code_map h_ssl_error_codes[] =
{
#define _SSL_ERROR(e) { e, #e }
_SSL_ERROR(SSL_ERROR_SSL),
_SSL_ERROR(SSL_ERROR_ZERO_RETURN),
_SSL_ERROR(SSL_ERROR_WANT_READ),
_SSL_ERROR(SSL_ERROR_WANT_WRITE),
_SSL_ERROR(SSL_ERROR_WANT_CONNECT),
_SSL_ERROR(SSL_ERROR_WANT_X509_LOOKUP),
_SSL_ERROR(SSL_ERROR_SYSCALL),
{ 0, NULL }
};
#endif
#ifndef WITH_LEANER
static const struct soap_code_map mime_codes[] =
{ { SOAP_MIME_7BIT, "7bit" },
{ SOAP_MIME_8BIT, "8bit" },
{ SOAP_MIME_BINARY, "binary" },
{ SOAP_MIME_QUOTED_PRINTABLE, "quoted-printable" },
{ SOAP_MIME_BASE64, "base64" },
{ SOAP_MIME_IETF_TOKEN, "ietf-token" },
{ SOAP_MIME_X_TOKEN, "x-token" },
{ 0, NULL }
};
#endif
#ifdef WIN32
static int tcp_done = 0;
#endif
#if defined(HP_UX) && defined(HAVE_GETHOSTBYNAME_R)
extern int h_errno;
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
fsend(struct soap *soap, const char *s, size_t n)
{ register int nwritten, err;
SOAP_SOCKET sk;
// int i=0;/*Sean Hou: 用于tcp/udp打印计数 */
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
if (soap->os)
{ soap->os->write(s, (std::streamsize)n);
if (soap->os->good())
return SOAP_OK;
soap->errnum = 0;
return SOAP_EOF;
}
#endif
sk = soap->sendsk;
if (!soap_valid_socket(sk))
sk = soap->socket;
while (n)
{ if (soap_valid_socket(sk))
{
if (soap->send_timeout)
{ for (;;)
{ register int r;
#ifdef WITH_OPENSSL
if (soap->ssl)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL, soap->send_timeout);
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL, soap->send_timeout);
else
#endif
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout);
if (r > 0)
break;
if (!r)
return SOAP_EOF;
err = soap->errnum;
if (!err)
return soap->error;
if (err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
return SOAP_EOF;
}
}
#ifdef WITH_OPENSSL
if (soap->ssl)
nwritten = SSL_write(soap->ssl, s, (int)n);
else if (soap->bio)
nwritten = BIO_write(soap->bio, s, (int)n);
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
nwritten = gnutls_record_send(soap->session, s, n);
else
#endif
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
{
/* :TODO:Saturday, July 05, 2014 10:32:57 HKT:SeanHou: 打印发出的udp/tcp包 */
// printf("\nto ip[%s]UDP[\n",inet_ntoa((soap->peer).sin_addr));
// for(i=0;i<n;i++)
// printf("%c", s[i]);
// printf("]sendto [%d]n[%d]\n", nwritten, n);
/* :TODO:End--- */
if (soap->peerlen)
nwritten = sendto(sk, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
else
nwritten = send(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
/* retry and back-off algorithm */
/* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */
if (nwritten < 0)
{ int udp_repeat;
int udp_delay;
if ((soap->connect_flags & SO_BROADCAST))
udp_repeat = 2; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */
else
udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */
udp_delay = ((unsigned int)soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */
do
{ tcp_select(soap, sk, SOAP_TCP_SELECT_ERR, -1000 * udp_delay);
if (soap->peerlen)
nwritten = sendto(sk, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
else
nwritten = send(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
udp_delay <<= 1;
if (udp_delay > 500) /* UDP_UPPER_DELAY */
udp_delay = 500;
}
while (nwritten < 0 && --udp_repeat > 0);
}
if (nwritten < 0)
{ err = soap_socket_errno(sk);
if (err && err != SOAP_EINTR)
{ soap->errnum = err;
return SOAP_EOF;
}
nwritten = 0; /* and call write() again */
}
}
else
#endif
#if !defined(PALM) && !defined(AS400)
nwritten = send(sk, s, (int)n, soap->socket_flags);
#else
nwritten = send(sk, (void*)s, n, soap->socket_flags);
#endif
/* :TODO:Saturday, July 05, 2014 10:32:57 HKT:SeanHou: 打印发出的udp/tcp包 */
// printf("\nto ip[%s]TCP[\n",inet_ntoa((soap->peer).sin_addr));
// for(i=0;i<n;i++)
// printf("%c", s[i]);
// printf("]send [%d]n[%d]\n", nwritten, n);
/* :TODO:End--- */
if (nwritten <= 0)
{
register int r = 0;
err = soap_socket_errno(sk);
#ifdef WITH_OPENSSL
if (soap->ssl && (r = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE)
{ soap->errnum = err;
return SOAP_EOF;
}
#endif
#ifdef WITH_GNUTLS
if (soap->session)
{ if (nwritten == GNUTLS_E_INTERRUPTED)
err = SOAP_EINTR;
else if (nwritten == GNUTLS_E_AGAIN)
err = SOAP_EAGAIN;
}
#endif
if (err == SOAP_EWOULDBLOCK || err == SOAP_EAGAIN)
{
#if defined(WITH_OPENSSL)
if (soap->ssl && r == SSL_ERROR_WANT_READ)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
else
#elif defined(WITH_GNUTLS)
if (soap->session && !gnutls_record_get_direction(soap->session))
r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
else
#endif
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
if (!r && soap->send_timeout)
return SOAP_EOF;
if (r < 0)
return SOAP_EOF;
}
else if (err && err != SOAP_EINTR)
{ soap->errnum = err;
return SOAP_EOF;
}
nwritten = 0; /* and call write() again */
}
}
else
{
#ifdef WITH_FASTCGI
nwritten = fwrite((void*)s, 1, n, stdout);
fflush(stdout);
#else
#ifdef UNDER_CE
nwritten = fwrite(s, 1, n, soap->sendfd);
#else
#ifdef VXWORKS
#ifdef WMW_RPM_IO
if (soap->rpmreqid)
nwritten = (httpBlockPut(soap->rpmreqid, (char*)s, n) == 0) ? n : -1;
else
#endif
nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
#else
#ifdef WIN32
nwritten = _write(soap->sendfd, s, (unsigned int)n);
#else
nwritten = write(soap->sendfd, s, (unsigned int)n);
#endif
#endif
#endif
#endif
if (nwritten <= 0)
{
#ifndef WITH_FASTCGI
err = soap_errno;
#else
err = EOF;
#endif
if (err && err != SOAP_EINTR && err != SOAP_EWOULDBLOCK && err != SOAP_EAGAIN)
{ soap->errnum = err;
return SOAP_EOF;
}
nwritten = 0; /* and call write() again */
}
}
n -= nwritten;
s += nwritten;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send_raw(struct soap *soap, const char *s, size_t n)
{ if (!n)
return SOAP_OK;
#ifndef WITH_LEANER
if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE && (soap->mode & SOAP_IO_LENGTH) && (soap->error = soap->fpreparesend(soap, s, n)))
return soap->error;
if (soap->ffiltersend && (soap->error = soap->ffiltersend(soap, &s, &n)))
return soap->error;
#endif
if (soap->mode & SOAP_IO_LENGTH)
soap->count += n;
else if (soap->mode & SOAP_IO)
{ register size_t i = SOAP_BUFLEN - soap->bufidx;
while (n >= i)
{ memcpy(soap->buf + soap->bufidx, s, i);
soap->bufidx = SOAP_BUFLEN;
if (soap_flush(soap))
return soap->error;
s += i;
n -= i;
i = SOAP_BUFLEN;
}
memcpy(soap->buf + soap->bufidx, s, n);
soap->bufidx += n;
}
else
return soap_flush_raw(soap, s, n);
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_flush(struct soap *soap)
{ register size_t n = soap->bufidx;
if (n)
{
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
{ register int r;
if (soap->fpreparesend && (r = soap->fpreparesend(soap, soap->buf, n)))
return soap->error = r;
}
#endif
soap->bufidx = 0;
#ifdef WITH_ZLIB
if (soap->mode & SOAP_ENC_ZLIB)
{ soap->d_stream->next_in = (Byte*)soap->buf;
soap->d_stream->avail_in = (unsigned int)n;
#ifdef WITH_GZIP
soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)n);
#endif
do
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream->avail_in));
if (deflate(soap->d_stream, Z_NO_FLUSH) != Z_OK)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
return soap->error = SOAP_ZLIB_ERROR;
}
if (!soap->d_stream->avail_out)
{ if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN))
return soap->error;
soap->d_stream->next_out = (Byte*)soap->z_buf;
soap->d_stream->avail_out = SOAP_BUFLEN;
}
} while (soap->d_stream->avail_in);
}
else
#endif
return soap_flush_raw(soap, soap->buf, n);
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_flush_raw(struct soap *soap, const char *s, size_t n)
{ if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
{ register char *t;
if (!(t = (char*)soap_push_block(soap, NULL, n)))
return soap->error = SOAP_EOM;
memcpy(t, s, n);
return SOAP_OK;
}
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
{ char t[16];
#ifdef HAVE_SNPRINTF
soap_snprintf(t, sizeof(t), &"\r\n%lX\r\n"[soap->chunksize ? 0 : 2], (unsigned long)n);
#else
sprintf(t, &"\r\n%lX\r\n"[soap->chunksize ? 0 : 2], (unsigned long)n);
#endif
DBGMSG(SENT, t, strlen(t));
if ((soap->error = soap->fsend(soap, t, strlen(t))))
return soap->error;
soap->chunksize += n;
}
DBGMSG(SENT, s, n);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Send %u bytes to socket=%d/fd=%d\n", (unsigned int)n, soap->socket, soap->sendfd));
#endif
return soap->error = soap->fsend(soap, s, n);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send(struct soap *soap, const char *s)
{ if (s)
return soap_send_raw(soap, s, strlen(s));
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send2(struct soap *soap, const char *s1, const char *s2)
{ if (soap_send(soap, s1))
return soap->error;
return soap_send(soap, s2);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send3(struct soap *soap, const char *s1, const char *s2, const char *s3)
{ if (soap_send(soap, s1)
|| soap_send(soap, s2))
return soap->error;
return soap_send(soap, s3);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static size_t
frecv(struct soap *soap, char *s, size_t n)
{ register int r;
register int retries = 100; /* max 100 retries with non-blocking sockets */
SOAP_SOCKET sk;
soap->errnum = 0;
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
if (soap->is)
{ if (soap->is->good())
return soap->is->read(s, (std::streamsize)n).gcount();
return 0;
}
#endif
sk = soap->recvsk;
if (!soap_valid_socket(sk))
sk = soap->socket;
if (soap_valid_socket(sk))
{ for (;;)
{
#ifdef WITH_OPENSSL
register int err = 0;
#endif
#ifdef WITH_OPENSSL
if (soap->recv_timeout && !soap->ssl) /* SSL: sockets are nonblocking */
#else
if (soap->recv_timeout)
#endif
{ for (;;)
{ r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout);
if (r > 0)
break;
if (!r)
return 0;
r = soap->errnum;
if (r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK)
return 0;
}
}
#ifdef WITH_OPENSSL
if (soap->ssl)
{ r = SSL_read(soap->ssl, s, (int)n);
if (r > 0)
return (size_t)r;
err = SSL_get_error(soap->ssl, r);
if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
return 0;
}
else if (soap->bio)
{ r = BIO_read(soap->bio, s, (int)n);
if (r > 0)
return (size_t)r;
return 0;
}
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
{ r = (int)gnutls_record_recv(soap->session, s, n);
if (r >= 0)
return (size_t)r;
}
else
#endif
{
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
{ SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer);
memset((void*)&soap->peer, 0, sizeof(soap->peer));
r = recvfrom(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
soap->peerlen = (size_t)k;
#ifndef WITH_IPV6
soap->ip = ntohl(soap->peer.sin_addr.s_addr);
#endif
}
else
#endif
{
/* :TODO:Tuesday, December 02, 2014 10:10:53 HKT:SeanHou:
extern char *g_onvif_buffer;
memcpy(s, g_onvif_buffer, n);
r = n;
:TODO:End--- */
r = recv(sk, s, (int)n, soap->socket_flags);
}
#ifdef PALM
/* CycleSyncDisplay(curStatusMsg); */
#endif
if (r >= 0)
return (size_t)r;
r = soap_socket_errno(sk);
if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK)
{ soap->errnum = r;
return 0;
}
}
#if defined(WITH_OPENSSL)
if (soap->ssl && err == SSL_ERROR_WANT_WRITE)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
else
#elif defined(WITH_GNUTLS)
if (soap->session && gnutls_record_get_direction(soap->session))
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
else
#endif
r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
if (!r && soap->recv_timeout)
return 0;
if (r < 0)
{ r = soap->errnum;
if (r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK)
return 0;
}
if (retries-- <= 0)
return 0;
#ifdef PALM
r = soap_socket_errno(sk);
if (r != SOAP_EINTR && retries-- <= 0)
{ soap->errnum = r;
return 0;
}
#endif
}
}
#ifdef WITH_FASTCGI
return fread(s, 1, n, stdin);
#else
#ifdef UNDER_CE
return fread(s, 1, n, soap->recvfd);
#else
#ifdef WMW_RPM_IO
if (soap->rpmreqid)
r = httpBlockRead(soap->rpmreqid, s, n);
else
#endif
#ifdef WIN32
r = _read(soap->recvfd, s, (unsigned int)n);
#else
r = read(soap->recvfd, s, (unsigned int)n);
#endif
if (r >= 0)
return (size_t)r;
soap->errnum = soap_errno;
return 0;
#endif
#endif
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static soap_wchar
soap_getchunkchar(struct soap *soap)
{ if (soap->bufidx < soap->buflen)
return soap->buf[soap->bufidx++];
soap->bufidx = 0;
soap->buflen = soap->chunkbuflen = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket=%d/fd=%d\n", (unsigned int)soap->buflen, soap->socket, soap->recvfd));
DBGMSG(RECV, soap->buf, soap->buflen);
if (soap->buflen)
return soap->buf[soap->bufidx++];
return EOF;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
static int
soap_isxdigit(int c)
{ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_recv_raw(struct soap *soap)
{ register size_t ret;
#if !defined(WITH_LEANER) || defined(WITH_ZLIB)
register int r;
#endif
#ifdef WITH_ZLIB
if (soap->mode & SOAP_ENC_ZLIB)
{ if (soap->d_stream->next_out == Z_NULL)
{ soap->bufidx = soap->buflen = 0;
return EOF;
}
if (soap->d_stream->avail_in || !soap->d_stream->avail_out)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflating\n"));
soap->d_stream->next_out = (Byte*)soap->buf;
soap->d_stream->avail_out = SOAP_BUFLEN;
r = inflate(soap->d_stream, Z_NO_FLUSH);
if (r == Z_NEED_DICT && soap->z_dict)
r = inflateSetDictionary(soap->d_stream, (const Bytef*)soap->z_dict, soap->z_dict_len);
if (r == Z_OK || r == Z_STREAM_END)
{ soap->bufidx = 0;
ret = soap->buflen = SOAP_BUFLEN - soap->d_stream->avail_out;
if (soap->zlib_in == SOAP_ZLIB_GZIP)
soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)ret);
if (r == Z_STREAM_END)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream->total_in, soap->d_stream->total_out));
soap->z_ratio_in = (float)soap->d_stream->total_in / (float)soap->d_stream->total_out;
soap->d_stream->next_out = Z_NULL;
}
if (ret)
{ soap->count += ret;
DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n"));
DBGMSG(RECV, soap->buf, ret);
DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n----\n"));
#ifndef WITH_LEANER
if (soap->fpreparerecv && (r = soap->fpreparerecv(soap, soap->buf, ret)))
return soap->error = r;
#endif
return SOAP_OK;
}
}
else if (r != Z_BUF_ERROR)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
soap->d_stream->next_out = Z_NULL;
return soap->error = SOAP_ZLIB_ERROR;
}
}
zlib_again:
if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK && !soap->chunksize)
{ memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
soap->buflen = soap->z_buflen;
}
DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- compressed ----\n"));
}
#endif
#ifndef WITH_NOHTTP
if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) /* read HTTP chunked transfer */
{ for (;;)
{ register soap_wchar c;
char *t, tmp[17];
if (soap->chunksize)
{ soap->buflen = ret = soap->frecv(soap, soap->buf, soap->chunksize > SOAP_BUFLEN ? SOAP_BUFLEN : soap->chunksize);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk: read %u bytes\n", (unsigned int)ret));
DBGMSG(RECV, soap->buf, ret);
soap->bufidx = 0;
soap->chunksize -= ret;
break;
}
t = tmp;
if (!soap->chunkbuflen)
{ soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes (chunked) from socket=%d\n", (unsigned int)ret, soap->socket));
DBGMSG(RECV, soap->buf, ret);
soap->bufidx = 0;
if (!ret)
{ soap->ahead = EOF;
return EOF;
}
}
else
soap->bufidx = soap->buflen;
soap->buflen = soap->chunkbuflen;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen));
while (!soap_isxdigit((int)(c = soap_getchunkchar(soap))))
{ if ((int)c == EOF)
{ soap->ahead = EOF;
return EOF;
}
}
do
*t++ = (char)c;
while (soap_isxdigit((int)(c = soap_getchunkchar(soap))) && (size_t)(t - tmp) < sizeof(tmp)-1);
while ((int)c != EOF && c != '\n')
c = soap_getchunkchar(soap);
if ((int)c == EOF)
{ soap->ahead = EOF;
return EOF;
}
*t = '\0';
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunk size = %s (hex)\n", tmp));
soap->chunksize = (size_t)soap_strtoul(tmp, &t, 16);
if (!soap->chunksize)
{ soap->bufidx = soap->buflen = soap->chunkbuflen = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of chunked message\n"));
while ((int)c != EOF && c != '\n')
c = soap_getchunkchar(soap);
ret = 0;
soap->ahead = EOF;
break;
}
soap->buflen = soap->bufidx + soap->chunksize;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to idx=%u len=%u (%s)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen, tmp));
if (soap->buflen > soap->chunkbuflen)
{ soap->buflen = soap->chunkbuflen;
soap->chunksize -= soap->buflen - soap->bufidx;
soap->chunkbuflen = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Passed end of buffer for chunked HTTP (%u bytes left)\n", (unsigned int)(soap->buflen - soap->bufidx)));
}
else if (soap->chunkbuflen)
soap->chunksize = 0;
ret = soap->buflen - soap->bufidx;
if (ret)
break;
}
}
else
#endif
{ soap->bufidx = 0;
soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket=%d/fd=%d\n", (unsigned int)ret, soap->socket, soap->recvfd));
DBGMSG(RECV, soap->buf, ret);
}
#ifdef WITH_ZLIB
if (soap->mode & SOAP_ENC_ZLIB)
{ memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
soap->d_stream->next_in = (Byte*)(soap->z_buf + soap->bufidx);
soap->d_stream->avail_in = (unsigned int)ret;
soap->d_stream->next_out = (Byte*)soap->buf;
soap->d_stream->avail_out = SOAP_BUFLEN;
r = inflate(soap->d_stream, Z_NO_FLUSH);
if (r == Z_NEED_DICT && soap->z_dict)
r = inflateSetDictionary(soap->d_stream, (const Bytef*)soap->z_dict, soap->z_dict_len);
if (r == Z_OK || r == Z_STREAM_END)
{ soap->bufidx = 0;
soap->z_buflen = soap->buflen;
soap->buflen = SOAP_BUFLEN - soap->d_stream->avail_out;
if (soap->zlib_in == SOAP_ZLIB_GZIP)
soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %u bytes\n", (unsigned int)soap->buflen));
if (ret && !soap->buflen && r != Z_STREAM_END)
goto zlib_again;
ret = soap->buflen;
if (r == Z_STREAM_END)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated total %lu->%lu bytes\n", soap->d_stream->total_in, soap->d_stream->total_out));
soap->z_ratio_in = (float)soap->d_stream->total_in / (float)soap->d_stream->total_out;
soap->d_stream->next_out = Z_NULL;
}
DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n"));
DBGMSG(RECV, soap->buf, ret);
#ifndef WITH_LEANER
if (soap->fpreparerecv && (r = soap->fpreparerecv(soap, soap->buf, ret)))
return soap->error = r;
#endif
}
else
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
soap->d_stream->next_out = Z_NULL;
return soap->error = SOAP_ZLIB_ERROR;
}
}
#endif
#ifndef WITH_LEANER
if (soap->fpreparerecv
#ifdef WITH_ZLIB
&& soap->zlib_in == SOAP_ZLIB_NONE
#endif
&& (r = soap->fpreparerecv(soap, soap->buf + soap->bufidx, ret)))
return soap->error = r;
#endif
soap->count += ret;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read count=%lu (+%lu)\n", (unsigned long)soap->count, (unsigned long)ret));
return !ret;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_recv(struct soap *soap)
{
#ifndef WITH_LEANER
if (soap->mode & SOAP_ENC_DIME)
{ if (soap->dime.buflen)
{ char *s;
int i;
unsigned char tmp[12];
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME hdr for chunked DIME is in buffer\n"));
soap->count += soap->dime.buflen - soap->buflen;
soap->buflen = soap->dime.buflen;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Skip padding (%ld bytes)\n", -(long)soap->dime.size&3));
for (i = -(long)soap->dime.size&3; i > 0; i--)
{ soap->bufidx++;
if (soap->bufidx >= soap->buflen)
if (soap_recv_raw(soap))
return EOF;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME hdr for next chunk\n"));
s = (char*)tmp;
for (i = 12; i > 0; i--)
{ *s++ = soap->buf[soap->bufidx++];
if (soap->bufidx >= soap->buflen)
if (soap_recv_raw(soap))
return EOF;
}
soap->dime.flags = tmp[0] & 0x7;
soap->dime.size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME chunk (%u bytes)\n", (unsigned int)soap->dime.size));
if (soap->dime.flags & SOAP_DIME_CF)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "More chunking\n"));
soap->dime.chunksize = soap->dime.size;
if (soap->buflen - soap->bufidx >= soap->dime.size)
{ soap->dime.buflen = soap->buflen;
soap->buflen = soap->bufidx + soap->dime.chunksize;
}
else
soap->dime.chunksize -= soap->buflen - soap->bufidx;
}
else
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Last chunk\n"));
soap->dime.buflen = 0;
soap->dime.chunksize = 0;
}
soap->count = soap->buflen - soap->bufidx;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%u bytes remaining\n", (unsigned int)soap->count));
return SOAP_OK;
}
if (soap->dime.chunksize)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get next DIME hdr for chunked DIME (%u bytes chunk)\n", (unsigned int)soap->dime.chunksize));
if (soap_recv_raw(soap))
return EOF;
if (soap->buflen - soap->bufidx >= soap->dime.chunksize)
{ soap->dime.buflen = soap->buflen;
soap->count -= soap->buflen - soap->bufidx - soap->dime.chunksize;
soap->buflen = soap->bufidx + soap->dime.chunksize;
}
else
soap->dime.chunksize -= soap->buflen - soap->bufidx;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%lu bytes remaining, count=%lu\n", (unsigned long)(soap->buflen-soap->bufidx), (unsigned long)soap->count));
return SOAP_OK;
}
}
while (soap->ffilterrecv)
{ int err, last = soap->filterstop;
if (last)
soap->bufidx = soap->buflen = 0;
if ((err = soap->ffilterrecv(soap, soap->buf, &soap->buflen, sizeof(soap->buf))))
return soap->error = err;
if (soap->buflen)
{ soap->bufidx = 0;
soap->filterstop = last;
return SOAP_OK;
}
if (last)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Returning postponed error %d\n", last));
soap->filterstop = SOAP_OK;
return last;
}
soap->filterstop = soap_recv_raw(soap); /* do not call again after EOF */
}
#endif
return soap_recv_raw(soap);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
soap_wchar
SOAP_FMAC2
soap_getchar(struct soap *soap)
{ register soap_wchar c;
c = soap->ahead;
if (c)
{ if (c != EOF)
soap->ahead = 0;
return c;
}
return soap_get1(soap);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
const struct soap_code_map*
SOAP_FMAC2
soap_code(const struct soap_code_map *code_map, const char *str)
{ if (code_map && str)
{ while (code_map->string)
{ if (!strcmp(str, code_map->string)) /* case sensitive */
return code_map;
code_map++;
}
}
return NULL;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
long
SOAP_FMAC2
soap_code_int(const struct soap_code_map *code_map, const char *str, long other)
{ if (code_map)
{ while (code_map->string)
{ if (!soap_tag_cmp(str, code_map->string)) /* case insensitive */
return code_map->code;
code_map++;
}
}
return other;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_code_str(const struct soap_code_map *code_map, long code)
{ if (!code_map)
return NULL;
while (code_map->code != code && code_map->string)
code_map++;
return code_map->string;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
long
SOAP_FMAC2
soap_code_bits(const struct soap_code_map *code_map, const char *str)
{ register long bits = 0;
if (code_map)
{ while (str && *str)
{ const struct soap_code_map *p;
for (p = code_map; p->string; p++)
{ register size_t n = strlen(p->string);
if (!strncmp(p->string, str, n) && soap_blank((soap_wchar)str[n]))
{ bits |= p->code;
str += n;
while (*str > 0 && *str <= 32)
str++;
break;
}
}
if (!p->string)
return 0;
}
}
return bits;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_code_list(struct soap *soap, const struct soap_code_map *code_map, long code)
{ register char *t = soap->tmpbuf;
if (code_map)
{ while (code_map->string)
{ if (code_map->code & code)
{ register const char *s = code_map->string;
if (t != soap->tmpbuf)
*t++ = ' ';
while (*s && t < soap->tmpbuf + sizeof(soap->tmpbuf) - 1)
*t++ = *s++;
if (t == soap->tmpbuf + sizeof(soap->tmpbuf) - 1)
break;
}
code_map++;
}
}
*t = '\0';
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef PALM_1
static soap_wchar
soap_char(struct soap *soap)
{ char tmp[8];
register int i;
register soap_wchar c;
register char *s = tmp;
for (i = 0; i < 7; i++)
{ c = soap_get1(soap);
if (c == ';' || (int)c == EOF)
break;
*s++ = (char)c;
}
*s = '\0';
if (*tmp == '#')
{ if (tmp[1] == 'x' || tmp[1] == 'X')
return (soap_wchar)soap_strtol(tmp + 2, NULL, 16);
return (soap_wchar)soap_strtol(tmp + 1, NULL, 10);
}
if (!strcmp(tmp, "lt"))
return '<';
if (!strcmp(tmp, "gt"))
return '>';
if (!strcmp(tmp, "amp"))
return '&';
if (!strcmp(tmp, "quot"))
return '"';
if (!strcmp(tmp, "apos"))
return '\'';
#ifndef WITH_LEAN
return (soap_wchar)soap_code_int(html_entity_codes, tmp, SOAP_UNKNOWN_CHAR);
#else
return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */
#endif
}
#endif
/******************************************************************************/
#ifdef WITH_LEAN
#ifndef PALM_1
soap_wchar
soap_get0(struct soap *soap)
{ if (soap->bufidx >= soap->buflen && soap_recv(soap))
return EOF;
return (unsigned char)soap->buf[soap->bufidx];
}
#endif
#endif
/******************************************************************************/
#ifdef WITH_LEAN
#ifndef PALM_1
soap_wchar
soap_get1(struct soap *soap)
{ if (soap->bufidx >= soap->buflen && soap_recv(soap))
return EOF;
return (unsigned char)soap->buf[soap->bufidx++];
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
soap_wchar
SOAP_FMAC2
soap_get(struct soap *soap)
{ register soap_wchar c;
c = soap->ahead;
if (c)
{ if ((int)c != EOF)
soap->ahead = 0;
}
else
c = soap_get1(soap);
while ((int)c != EOF)
{ if (soap->cdata)
{ if (c == ']')
{ c = soap_get1(soap);
if (c == ']')
{ c = soap_get0(soap);
if (c == '>')
{ soap->cdata = 0;
c = soap_get1(soap);
c = soap_get1(soap);
}
else
{ soap_unget(soap, ']');
return ']';
}
}
else
{ soap_revget1(soap);
return ']';
}
}
else
return c;
}
switch (c)
{ case '<':
do c = soap_get1(soap);
while (soap_blank(c));
if (c == '!' || c == '?' || c == '%')
{ register int k = 1;
if (c == '!')
{ c = soap_get1(soap);
if (c == '[')
{ do c = soap_get1(soap);
while ((int)c != EOF && c != '[');
if ((int)c == EOF)
break;
soap->cdata = 1;
c = soap_get1(soap);
continue;
}
if (c == '-' && (c = soap_get1(soap)) == '-')
{ do
{ c = soap_get1(soap);
if (c == '-' && (c = soap_get1(soap)) == '-')
break;
} while ((int)c != EOF);
}
}
else if (c == '?')
c = soap_get_pi(soap);
while ((int)c != EOF)
{ if (c == '<')
k++;
else if (c == '>')
{ if (--k <= 0)
break;
}
c = soap_get1(soap);
}
if ((int)c == EOF)
break;
c = soap_get1(soap);
continue;
}
if (c == '/')
return SOAP_TT;
soap_revget1(soap);
return SOAP_LT;
case '>':
return SOAP_GT;
case '"':
return SOAP_QT;
case '\'':
return SOAP_AP;
case '&':
return soap_char(soap) | 0x80000000;
}
break;
}
return c;
}
#endif
/******************************************************************************/
#ifndef PALM_1
static soap_wchar
soap_get_pi(struct soap *soap)
{ char buf[64];
register char *s = buf;
register int i = sizeof(buf);
register soap_wchar c = soap_getchar(soap);
/* This is a quick way to parse XML PI and we could use a callback instead to
* enable applications to intercept processing instructions */
while ((int)c != EOF && c != '?')
{ if (--i > 0)
{ if (soap_blank(c))
c = ' ';
*s++ = (char)c;
}
c = soap_getchar(soap);
}
*s = '\0';
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI <?%s?>\n", buf));
if (!strncmp(buf, "xml ", 4))
{ s = strstr(buf, " encoding=");
if (s && s[10])
{ if (!soap_tag_cmp(s + 11, "iso-8859-1*")
|| !soap_tag_cmp(s + 11, "latin1*"))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to latin1 encoding\n"));
soap->mode |= SOAP_ENC_LATIN;
}
else if (!soap_tag_cmp(s + 11, "utf-8*"))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to utf-8 encoding\n"));
soap->mode &= ~SOAP_ENC_LATIN;
}
}
}
if ((int)c != EOF)
c = soap_getchar(soap);
return c;
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_move(struct soap *soap, size_t n)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %lu bytes forward\n", (unsigned long)n));
for (; n; n--)
if ((int)soap_getchar(soap) == EOF)
return SOAP_EOF;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
size_t
SOAP_FMAC2
soap_tell(struct soap *soap)
{ return soap->count - soap->buflen + soap->bufidx - (soap->ahead != 0);
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_pututf8(struct soap *soap, register unsigned long c)
{ char tmp[16];
if (c < 0x80 && c > 0)
{ *tmp = (char)c;
return soap_send_raw(soap, tmp, 1);
}
#ifndef WITH_LEAN
if (c >= 0x80)
{ register char *t = tmp;
if (c < 0x0800)
*t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
else
{ if (c < 0x010000)
*t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
else
{ if (c < 0x200000)
*t++ = (char)(0xF0 | ((c >> 18) & 0x07));
else
{ if (c < 0x04000000)
*t++ = (char)(0xF8 | ((c >> 24) & 0x03));
else
{ *t++ = (char)(0xFC | ((c >> 30) & 0x01));
*t++ = (char)(0x80 | ((c >> 24) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 18) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 12) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 6) & 0x3F));
}
*t++ = (char)(0x80 | (c & 0x3F));
*t = '\0';
}
else
#endif
#ifdef HAVE_SNPRINTF
soap_snprintf(tmp, sizeof(tmp), "&#%lu;", c);
#else
sprintf(tmp, "&#%lu;", c);
#endif
return soap_send(soap, tmp);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
soap_wchar
SOAP_FMAC2
soap_getutf8(struct soap *soap)
{ register soap_wchar c, c1, c2, c3, c4;
c = soap->ahead;
if (c >= 0x80)
soap->ahead = 0;
else
c = soap_get(soap);
if (c < 0x80 || c > 0xFF || (soap->mode & SOAP_ENC_LATIN))
return c;
c1 = soap_get1(soap);
if (c1 < 0x80)
{ soap_revget1(soap); /* doesn't look like this is UTF8 */
return c;
}
c1 &= 0x3F;
if (c < 0xE0)
return ((soap_wchar)(c & 0x1F) << 6) | c1;
c2 = (soap_wchar)soap_get1(soap) & 0x3F;
if (c < 0xF0)
return ((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2;
c3 = (soap_wchar)soap_get1(soap) & 0x3F;
if (c < 0xF8)
return ((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
c4 = (soap_wchar)soap_get1(soap) & 0x3F;
if (c < 0xFC)
return ((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4;
return ((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(soap_get1(soap) & 0x3F);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_puthex(struct soap *soap, const unsigned char *s, int n)
{ char d[2];
register int i;
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ if (!(soap->dom->data = soap_s2hex(soap, s, NULL, n)))
return soap->error;
return SOAP_OK;
}
#endif
for (i = 0; i < n; i++)
{ register int m = *s++;
d[0] = (char)((m >> 4) + (m > 159 ? '7' : '0'));
m &= 0x0F;
d[1] = (char)(m + (m > 9 ? '7' : '0'));
if (soap_send_raw(soap, d, 2))
return soap->error;
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
unsigned char*
SOAP_FMAC2
soap_gethex(struct soap *soap, int *n)
{
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ soap->dom->data = soap_string_in(soap, 0, -1, -1);
return (unsigned char*)soap_hex2s(soap, soap->dom->data, NULL, 0, n);
}
#endif
#ifdef WITH_FAST
soap->labidx = 0;
for (;;)
{ register char *s;
register size_t i, k;
if (soap_append_lab(soap, NULL, 0))
return NULL;
s = soap->labbuf + soap->labidx;
k = soap->lablen - soap->labidx;
soap->labidx = soap->lablen;
for (i = 0; i < k; i++)
{ register char d1, d2;
register soap_wchar c;
c = soap_get(soap);
if (soap_isxdigit(c))
{ d1 = (char)c;
c = soap_get(soap);
if (soap_isxdigit(c))
d2 = (char)c;
else
{ soap->error = SOAP_TYPE;
return NULL;
}
}
else
{ unsigned char *p;
soap_unget(soap, c);
if (n)
*n = (int)(soap->lablen + i - k);
p = (unsigned char*)soap_malloc(soap, soap->lablen + i - k);
if (p)
memcpy(p, soap->labbuf, soap->lablen + i - k);
return p;
}
*s++ = (char)(((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'));
}
}
#else
if (soap_new_block(soap) == NULL)
return NULL;
for (;;)
{ register int i;
register char *s = (char*)soap_push_block(soap, NULL, SOAP_BLKLEN);
if (!s)
{ soap_end_block(soap, NULL);
return NULL;
}
for (i = 0; i < SOAP_BLKLEN; i++)
{ register char d1, d2;
register soap_wchar c = soap_get(soap);
if (soap_isxdigit(c))
{ d1 = (char)c;
c = soap_get(soap);
if (soap_isxdigit(c))
d2 = (char)c;
else
{ soap_end_block(soap, NULL);
soap->error = SOAP_TYPE;
return NULL;
}
}
else
{ unsigned char *p;
soap_unget(soap, c);
if (n)
*n = (int)soap_size_block(soap, NULL, i);
p = (unsigned char*)soap_save_block(soap, NULL, 0);
return p;
}
*s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
}
}
#endif
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_putbase64(struct soap *soap, const unsigned char *s, int n)
{ register int i;
register unsigned long m;
char d[4];
if (!s)
return SOAP_OK;
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ if (!(soap->dom->data = soap_s2base64(soap, s, NULL, n)))
return soap->error;
return SOAP_OK;
}
#endif
for (; n > 2; n -= 3, s += 3)
{ m = s[0];
m = (m << 8) | s[1];
m = (m << 8) | s[2];
for (i = 4; i > 0; m >>= 6)
d[--i] = soap_base64o[m & 0x3F];
if (soap_send_raw(soap, d, 4))
return soap->error;
}
if (n > 0)
{ m = 0;
for (i = 0; i < n; i++)
m = (m << 8) | *s++;
for (; i < 3; i++)
m <<= 8;
for (i++; i > 0; m >>= 6)
d[--i] = soap_base64o[m & 0x3F];
for (i = 3; i > n; i--)
d[i] = '=';
if (soap_send_raw(soap, d, 4))
return soap->error;
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
unsigned char*
SOAP_FMAC2
soap_getbase64(struct soap *soap, int *n, int malloc_flag)
{ (void)malloc_flag;
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ soap->dom->data = soap_string_in(soap, 0, -1, -1);
return (unsigned char*)soap_base642s(soap, soap->dom->data, NULL, 0, n);
}
#endif
#ifdef WITH_FAST
soap->labidx = 0;
for (;;)
{ register size_t i, k;
register char *s;
if (soap_append_lab(soap, NULL, 2))
return NULL;
s = soap->labbuf + soap->labidx;
k = soap->lablen - soap->labidx;
soap->labidx = 3 * (soap->lablen / 3);
if (!s)
return NULL;
if (k > 2)
{ for (i = 0; i < k - 2; i += 3)
{ register unsigned long m = 0;
register int j = 0;
do
{ register soap_wchar c = soap_get(soap);
if (c < SOAP_AP)
c &= 0x7FFFFFFF;
if (c == '=' || c < 0)
{ unsigned char *p;
switch (j)
{ case 2:
*s++ = (char)((m >> 4) & 0xFF);
i++;
break;
case 3:
*s++ = (char)((m >> 10) & 0xFF);
*s++ = (char)((m >> 2) & 0xFF);
i += 2;
}
if (n)
*n = (int)(soap->lablen + i - k);
p = (unsigned char*)soap_malloc(soap, soap->lablen + i - k);
if (p)
memcpy(p, soap->labbuf, soap->lablen + i - k);
if (c >= 0)
{ while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
;
}
soap_unget(soap, c);
return p;
}
c -= '+';
if (c >= 0 && c <= 79)
{ register int b = soap_base64i[c];
if (b >= 64)
{ soap->error = SOAP_TYPE;
return NULL;
}
m = (m << 6) + b;
j++;
}
else if (!soap_blank(c + '+'))
{ soap->error = SOAP_TYPE;
return NULL;
}
} while (j < 4);
*s++ = (char)((m >> 16) & 0xFF);
*s++ = (char)((m >> 8) & 0xFF);
*s++ = (char)(m & 0xFF);
}
}
}
#else
if (soap_new_block(soap) == NULL)
return NULL;
for (;;)
{ register int i;
register char *s = (char*)soap_push_block(soap, NULL, 3 * SOAP_BLKLEN); /* must be multiple of 3 */
if (!s)
{ soap_end_block(soap, NULL);
return NULL;
}
for (i = 0; i < SOAP_BLKLEN; i++)
{ register unsigned long m = 0;
register int j = 0;
do
{ register soap_wchar c = soap_get(soap);
if (c == '=' || c < 0)
{ unsigned char *p;
i *= 3;
switch (j)
{ case 2:
*s++ = (char)((m >> 4) & 0xFF);
i++;
break;
case 3:
*s++ = (char)((m >> 10) & 0xFF);
*s++ = (char)((m >> 2) & 0xFF);
i += 2;
}
if (n)
*n = (int)soap_size_block(soap, NULL, i);
p = (unsigned char*)soap_save_block(soap, NULL, 0);
if (c >= 0)
{ while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
;
}
soap_unget(soap, c);
return p;
}
c -= '+';
if (c >= 0 && c <= 79)
{ int b = soap_base64i[c];
if (b >= 64)
{ soap->error = SOAP_TYPE;
return NULL;
}
m = (m << 6) + b;
j++;
}
else if (!soap_blank(c))
{ soap->error = SOAP_TYPE;
return NULL;
}
} while (j < 4);
*s++ = (char)((m >> 16) & 0xFF);
*s++ = (char)((m >> 8) & 0xFF);
*s++ = (char)(m & 0xFF);
}
}
#endif
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options)
{ /* Check MTOM xop:Include element (within hex/base64Binary) */
/* TODO: this code to be obsoleted with new import/xop.h conventions */
short body = soap->body; /* should save type too? */
if (!soap_peek_element(soap))
{ if (!soap_element_begin_in(soap, "xop:Include", 0, NULL))
{ if (soap_dime_forward(soap, ptr, size, id, type, options)
|| (soap->body && soap_element_end_in(soap, "xop:Include")))
return soap->error;
}
}
soap->body = body;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_dime_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options)
{ struct soap_xlist *xp;
*ptr = NULL;
*size = 0;
*id = NULL;
*type = NULL;
*options = NULL;
if (!*soap->href)
return SOAP_OK;
*id = soap_strdup(soap, soap->href);
xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist));
if (!xp)
return soap->error = SOAP_EOM;
xp->next = soap->xlist;
xp->ptr = ptr;
xp->size = size;
xp->id = *id;
xp->type = type;
xp->options = options;
soap->xlist = xp;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
char *
SOAP_FMAC2
soap_strdup(struct soap *soap, const char *s)
{ char *t = NULL;
if (s && (t = (char*)soap_malloc(soap, strlen(s) + 1)))
strcpy(t, s);
return t;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
wchar_t *
SOAP_FMAC2
soap_wstrdup(struct soap *soap, const wchar_t *s)
{ wchar_t *t = NULL;
if (s)
{ size_t n = 0;
while (s[n])
n++;
if ((t = (wchar_t*)soap_malloc(soap, sizeof(wchar_t)*(n+1))))
memcpy(t, s, sizeof(wchar_t)*(n+1));
}
return t;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
struct soap_blist*
SOAP_FMAC2
soap_new_block(struct soap *soap)
{ struct soap_blist *p;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New block sequence (prev=%p)\n", soap->blist));
if (!(p = (struct soap_blist*)SOAP_MALLOC(soap, sizeof(struct soap_blist))))
{ soap->error = SOAP_EOM;
return NULL;
}
p->next = soap->blist;
p->ptr = NULL;
p->size = 0;
soap->blist = p;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void*
SOAP_FMAC2
soap_push_block(struct soap *soap, struct soap_blist *b, size_t n)
{ char *p;
if (!b)
b = soap->blist;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push block of %u bytes (%u bytes total)\n", (unsigned int)n, (unsigned int)b->size + (unsigned int)n));
if (!(p = (char*)SOAP_MALLOC(soap, n + sizeof(char*) + sizeof(size_t))))
{ soap->error = SOAP_EOM;
return NULL;
}
*(char**)p = b->ptr;
*(size_t*)(p + sizeof(char*)) = n;
b->ptr = p;
b->size += n;
return p + sizeof(char*) + sizeof(size_t);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_pop_block(struct soap *soap, struct soap_blist *b)
{ char *p;
if (!b)
b = soap->blist;
if (!b->ptr)
return;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop block\n"));
p = b->ptr;
b->size -= *(size_t*)(p + sizeof(char*));
b->ptr = *(char**)p;
SOAP_FREE(soap, p);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_update_pointers(struct soap *soap, char *start, char *end, char *p1, char *p2)
{
#ifndef WITH_NOIDREF
int i;
register struct soap_ilist *ip = NULL;
register struct soap_flist *fp = NULL;
#ifndef WITH_LEANER
register struct soap_xlist *xp = NULL;
#endif
register void *p, **q;
for (i = 0; i < SOAP_IDHASH; i++)
{ for (ip = soap->iht[i]; ip; ip = ip->next)
{ if (ip->ptr && (char*)ip->ptr >= start && (char*)ip->ptr < end)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", ip->id, ip->ptr, (char*)ip->ptr + (p1-p2)));
ip->ptr = (char*)ip->ptr + (p1-p2);
}
for (q = &ip->link; q; q = (void**)p)
{ p = *q;
if (p && (char*)p >= start && (char*)p < end)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Link update id='%s' %p\n", ip->id, p));
*q = (char*)p + (p1-p2);
}
}
for (q = &ip->copy; q; q = (void**)p)
{ p = *q;
if (p && (char*)p >= start && (char*)p < end)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy chain update id='%s' %p\n", ip->id, p));
*q = (char*)p + (p1-p2);
}
}
for (fp = ip->flist; fp; fp = fp->next)
{ if ((char*)fp->ptr >= start && (char*)fp->ptr < end)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy list update id='%s' %p\n", ip->id, fp));
fp->ptr = (char*)fp->ptr + (p1-p2);
}
}
}
}
#ifndef WITH_LEANER
for (xp = soap->xlist; xp; xp = xp->next)
{ if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id ? xp->id : SOAP_STR_EOS, xp->ptr, (char*)xp->ptr + (p1-p2)));
xp->ptr = (unsigned char**)((char*)xp->ptr + (p1-p2));
xp->size = (int*)((char*)xp->size + (p1-p2));
xp->type = (char**)((char*)xp->type + (p1-p2));
xp->options = (char**)((char*)xp->options + (p1-p2));
}
}
#endif
#else
(void)soap; (void)start; (void)end; (void)p1; (void)p2;
#endif
}
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_1
static int
soap_has_copies(struct soap *soap, register const char *start, register const char *end)
{ register int i;
register struct soap_ilist *ip = NULL;
register struct soap_flist *fp = NULL;
register const char *p;
for (i = 0; i < SOAP_IDHASH; i++)
{ for (ip = soap->iht[i]; ip; ip = ip->next)
{ for (p = (const char*)ip->copy; p; p = *(const char**)p)
if (p >= start && p < end)
return SOAP_ERR;
for (fp = ip->flist; fp; fp = fp->next)
if ((const char*)fp->ptr >= start && (const char*)fp->ptr < end)
return SOAP_ERR;
}
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_resolve(struct soap *soap)
{ register int i;
register struct soap_ilist *ip = NULL;
register struct soap_flist *fp = NULL;
short flag;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data\n"));
for (i = 0; i < SOAP_IDHASH; i++)
{ for (ip = soap->iht[i]; ip; ip = ip->next)
{ if (ip->ptr)
{ register void *p, **q, *r;
q = (void**)ip->link;
ip->link = NULL;
r = ip->ptr;
DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing link chain to resolve id='%s'\n", ip->id));
while (q)
{ p = *q;
*q = r;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "... link %p -> %p\n", q, r));
q = (void**)p;
}
}
else if (*ip->id == '#')
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Missing data for id='%s'\n", ip->id));
strcpy(soap->id, ip->id + 1);
return soap->error = SOAP_MISSING_ID;
}
}
}
do
{ flag = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution phase\n"));
for (i = 0; i < SOAP_IDHASH; i++)
{ for (ip = soap->iht[i]; ip; ip = ip->next)
{ if (ip->ptr && !soap_has_copies(soap, (const char*)ip->ptr, (const char*)ip->ptr + ip->size))
{ if (ip->copy)
{ register void *p, **q = (void**)ip->copy;
DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing copy chain to resolve id='%s'\n", ip->id));
ip->copy = NULL;
do
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... copy %p -> %p (%u bytes)\n", ip->ptr, q, (unsigned int)ip->size));
p = *q;
memcpy(q, ip->ptr, ip->size);
q = (void**)p;
} while (q);
flag = 1;
}
for (fp = ip->flist; fp; fp = ip->flist)
{ register unsigned int k = fp->level;
register void *p = ip->ptr;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data type=%d location=%p level=%u,%u id='%s'\n", ip->type, p, ip->level, fp->level, ip->id));
while (ip->level < k)
{ register void **q = (void**)soap_malloc(soap, sizeof(void*));
if (!q)
return soap->error;
*q = p;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level, new location=%p holds=%p...\n", q, *q));
p = (void*)q;
k--;
}
if (fp->fcopy)
fp->fcopy(soap, ip->type, fp->type, fp->ptr, fp->len, p, ip->size);
else
soap_fcopy(soap, ip->type, fp->type, fp->ptr, fp->len, p, ip->size);
ip->flist = fp->next;
SOAP_FREE(soap, fp);
flag = 1;
}
}
}
}
} while (flag);
#ifdef SOAP_DEBUG
for (i = 0; i < SOAP_IDHASH; i++)
{ for (ip = soap->iht[i]; ip; ip = ip->next)
{ if (ip->copy || ip->flist)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution error: forwarded data for id='%s' could not be propagated, please report this problem to the developers\n", ip->id));
}
}
}
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution done\n"));
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
size_t
SOAP_FMAC2
soap_size_block(struct soap *soap, struct soap_blist *b, size_t n)
{ if (!b)
b = soap->blist;
if (b->ptr)
{ b->size -= *(size_t*)(b->ptr + sizeof(char*)) - n;
*(size_t*)(b->ptr + sizeof(char*)) = n;
}
return b->size;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
char*
SOAP_FMAC2
soap_first_block(struct soap *soap, struct soap_blist *b)
{ char *p, *q, *r;
if (!b)
b = soap->blist;
p = b->ptr;
if (!p)
return NULL;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "First block\n"));
r = NULL;
do
{ q = *(char**)p;
*(char**)p = r;
r = p;
p = q;
} while (p);
b->ptr = r;
return r + sizeof(char*) + sizeof(size_t);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
char*
SOAP_FMAC2
soap_next_block(struct soap *soap, struct soap_blist *b)
{ char *p;
if (!b)
b = soap->blist;
p = b->ptr;
if (p)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Next block\n"));
b->ptr = *(char**)p;
SOAP_FREE(soap, p);
if (b->ptr)
return b->ptr + sizeof(char*) + sizeof(size_t);
}
return NULL;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
size_t
SOAP_FMAC2
soap_block_size(struct soap *soap, struct soap_blist *b)
{ if (!b)
b = soap->blist;
return *(size_t*)(b->ptr + sizeof(char*));
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_end_block(struct soap *soap, struct soap_blist *b)
{ char *p, *q;
if (!b)
b = soap->blist;
if (b)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of block sequence, free all remaining blocks\n"));
for (p = b->ptr; p; p = q)
{ q = *(char**)p;
SOAP_FREE(soap, p);
}
if (soap->blist == b)
soap->blist = b->next;
else
{ struct soap_blist *bp;
for (bp = soap->blist; bp; bp = bp->next)
{ if (bp->next == b)
{ bp->next = b->next;
break;
}
}
}
SOAP_FREE(soap, b);
}
DBGLOG(TEST, if (soap->blist) SOAP_MESSAGE(fdebug, "Restore previous block sequence\n"));
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
char*
SOAP_FMAC2
soap_save_block(struct soap *soap, struct soap_blist *b, char *p, int flag)
{ register size_t n;
register char *q, *s;
if (!b)
b = soap->blist;
if (b->size)
{ if (!p)
p = (char*)soap_malloc(soap, b->size);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Save all blocks in contiguous memory space of %u bytes (%p->%p)\n", (unsigned int)b->size, b->ptr, p));
if (p)
{ for (s = p, q = soap_first_block(soap, b); q; q = soap_next_block(soap, b))
{ n = soap_block_size(soap, b);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy %u bytes from %p to %p\n", (unsigned int)n, q, s));
#ifndef WITH_NOIDREF
if (flag)
soap_update_pointers(soap, q, q + n, s, q);
#endif
memcpy(s, q, n);
s += n;
}
}
else
soap->error = SOAP_EOM;
}
soap_end_block(soap, b);
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char *
SOAP_FMAC2
soap_putsize(struct soap *soap, const char *type, int size)
{ return soap_putsizes(soap, type, &size, 1);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char *
SOAP_FMAC2
soap_putsizes(struct soap *soap, const char *type, const int *size, int dim)
{ return soap_putsizesoffsets(soap, type, size, NULL, dim);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char *
SOAP_FMAC2
soap_putsizesoffsets(struct soap *soap, const char *type, const int *size, const int *offset, int dim)
{ register int i;
register size_t l;
if (!type || strlen(type) + 13 > sizeof(soap->type)) /* prevent overruns */
return NULL;
if (soap->version == 2)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->type, sizeof(soap->type) - 1, "%s[%d", type, size[0]);
#else
sprintf(soap->type, "%s[%d", type, size[0]);
#endif
for (i = 1; i < dim; i++)
{
#ifdef HAVE_SNPRINTF
l = strlen(soap->type);
soap_snprintf(soap->type + l, sizeof(soap->type) - l - 1, " %d", size[i]);
#else
if ((l = strlen(soap->type)) + 13 > sizeof(soap->type))
return NULL;
sprintf(soap->type + l, " %d", size[i]);
#endif
}
}
else
{ if (offset)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->type, sizeof(soap->type) - 1, "%s[%d", type, size[0] + offset[0]);
#else
sprintf(soap->type, "%s[%d", type, size[0] + offset[0]);
#endif
for (i = 1; i < dim; i++)
{
#ifdef HAVE_SNPRINTF
l = strlen(soap->type);
soap_snprintf(soap->type + l, sizeof(soap->type) - l - 1, ",%d", size[i] + offset[i]);
#else
if ((l = strlen(soap->type)) + 13 > sizeof(soap->type))
return NULL;
sprintf(soap->type + l, ",%d", size[i] + offset[i]);
#endif
}
}
else
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->type, sizeof(soap->type) - 1, "%s[%d", type, size[0]);
#else
sprintf(soap->type, "%s[%d", type, size[0]);
#endif
for (i = 1; i < dim; i++)
{
#ifdef HAVE_SNPRINTF
l = strlen(soap->type);
soap_snprintf(soap->type + l, sizeof(soap->type) - l - 1, ",%d", size[i]);
#else
if ((l = strlen(soap->type)) + 13 > sizeof(soap->type))
return NULL;
sprintf(soap->type + l, ",%d", size[i]);
#endif
}
}
}
strcat(soap->type, "]");
return soap->type;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char *
SOAP_FMAC2
soap_putoffset(struct soap *soap, int offset)
{ return soap_putoffsets(soap, &offset, 1);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char *
SOAP_FMAC2
soap_putoffsets(struct soap *soap, const int *offset, int dim)
{ register int i;
register size_t l;
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->arrayOffset, sizeof(soap->arrayOffset) - 1, "[%d", offset[0]);
#else
if (sizeof(soap->arrayOffset) < 13) /* prevent overruns */
return NULL;
sprintf(soap->arrayOffset, "[%d", offset[0]);
#endif
for (i = 1; i < dim; i++)
{
#ifdef HAVE_SNPRINTF
l = strlen(soap->arrayOffset);
soap_snprintf(soap->arrayOffset + l, sizeof(soap->arrayOffset) - l - 1, ",%d", offset[i]);
#else
if ((l = strlen(soap->arrayOffset)) + 13 > sizeof(soap->arrayOffset))
return NULL;
sprintf(soap->arrayOffset + l, ",%d", offset[i]);
#endif
}
strcat(soap->arrayOffset, "]");
return soap->arrayOffset;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_size(const int *size, int dim)
{ register int i, n = size[0];
for (i = 1; i < dim; i++)
n *= size[i];
return n;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_getoffsets(const char *attr, const int *size, int *offset, int dim)
{ register int i, j = 0;
if (offset)
for (i = 0; i < dim && attr && *attr; i++)
{ attr++;
j *= size[i];
j += offset[i] = (int)soap_strtol(attr, NULL, 10);
attr = strchr(attr, ',');
}
else
for (i = 0; i < dim && attr && *attr; i++)
{ attr++;
j *= size[i];
j += (int)soap_strtol(attr, NULL, 10);
attr = strchr(attr, ',');
}
return j;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_getsize(const char *attr1, const char *attr2, int *j)
{ register int n, k;
char *s;
*j = 0;
if (!*attr1)
return -1;
if (*attr1 == '[')
attr1++;
n = 1;
for (;;)
{ k = (int)soap_strtol(attr1, &s, 10);
n *= k;
if (k < 0 || n > SOAP_MAXARRAYSIZE || s == attr1)
return -1;
attr1 = strchr(s, ',');
if (!attr1)
attr1 = strchr(s, ' ');
if (attr2 && *attr2)
{ attr2++;
*j *= k;
k = (int)soap_strtol(attr2, &s, 10);
*j += k;
if (k < 0)
return -1;
attr2 = s;
}
if (!attr1)
break;
attr1++;
}
return n - *j;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_getsizes(const char *attr, int *size, int dim)
{ register int i, k, n;
if (!*attr)
return -1;
i = (int)strlen(attr);
n = 1;
do
{ for (i = i-1; i >= 0; i--)
if (attr[i] == '[' || attr[i] == ',' || attr[i] == ' ')
break;
k = (int)soap_strtol(attr + i + 1, NULL, 10);
n *= size[--dim] = k;
if (k < 0 || n > SOAP_MAXARRAYSIZE)
return -1;
} while (i >= 0 && attr[i] != '[');
return n;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_getposition(const char *attr, int *pos)
{ register int i, n;
if (!*attr)
return -1;
n = 0;
i = 1;
do
{ pos[n++] = (int)soap_strtol(attr + i, NULL, 10);
while (attr[i] && attr[i] != ',' && attr[i] != ']')
i++;
if (attr[i] == ',')
i++;
} while (n < SOAP_MAXDIMS && attr[i] && attr[i] != ']');
return n;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
struct soap_nlist *
SOAP_FMAC2
soap_push_namespace(struct soap *soap, const char *id, const char *ns)
{ register struct soap_nlist *np;
register struct Namespace *p;
register short i = -1;
register size_t n, k;
n = strlen(id);
k = strlen(ns) + 1;
p = soap->local_namespaces;
if (p)
{ for (i = 0; p->id; p++, i++)
{ if (p->ns && !strcmp(ns, p->ns))
break;
if (p->out)
{ if (!strcmp(ns, p->out))
break;
}
else if (p->in)
{ if (!soap_tag_cmp(ns, p->in))
{ if ((p->out = (char*)SOAP_MALLOC(soap, k)))
strcpy(p->out, ns);
break;
}
}
}
if (!p || !p->id)
i = -1;
}
if (i >= 0)
k = 0;
np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k);
if (!np)
{ soap->error = SOAP_EOM;
return NULL;
}
np->next = soap->nlist;
soap->nlist = np;
np->level = soap->level;
np->index = i;
strcpy((char*)np->id, id);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns));
if (i < 0)
{ np->ns = strcpy((char*)np->id + n + 1, ns);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns));
}
else
{ np->ns = NULL;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id));
}
return np;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_pop_namespace(struct soap *soap)
{ register struct soap_nlist *np, *nq;
for (np = soap->nlist; np && np->level >= soap->level; np = nq)
{ nq = np->next;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop namespace binding (level=%u) '%s'\n", soap->level, np->id));
SOAP_FREE(soap, np);
}
soap->nlist = np;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_match_namespace(struct soap *soap, const char *id1, const char *id2, size_t n1, size_t n2)
{ register struct soap_nlist *np = soap->nlist;
const char *s;
while (np && (strncmp(np->id, id1, n1) || np->id[n1]))
np = np->next;
if (np)
{ if (!(soap->mode & SOAP_XML_IGNORENS))
if (np->index < 0
|| ((s = soap->local_namespaces[np->index].id) && (strncmp(s, id2, n2) || (s[n2] && s[n2] != '_'))))
return SOAP_NAMESPACE;
return SOAP_OK;
}
if (n1 == 0)
return (soap->mode & SOAP_XML_IGNORENS) ? SOAP_OK : SOAP_NAMESPACE;
if ((n1 == 3 && n1 == n2 && !strncmp(id1, "xml", 3) && !strncmp(id1, id2, 3))
|| (soap->mode & SOAP_XML_IGNORENS))
return SOAP_OK;
return soap->error = SOAP_SYNTAX_ERROR;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_current_namespace(struct soap *soap, const char *tag)
{ register struct soap_nlist *np;
register const char *s;
if (!tag || !strncmp(tag, "xml", 3))
return NULL;
np = soap->nlist;
if (!(s = strchr(tag, ':')))
{ while (np && *np->id) /* find default namespace, if present */
np = np->next;
}
else
{ while (np && (strncmp(np->id, tag, s - tag) || np->id[s - tag]))
np = np->next;
if (!np)
soap->error = SOAP_NAMESPACE;
}
if (np)
{ if (np->index >= 0)
return soap->namespaces[np->index].ns;
if (np->ns)
return soap_strdup(soap, np->ns);
}
return NULL;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_tag_cmp(const char *s, const char *t)
{ for (;;)
{ register int c1 = *s;
register int c2 = *t;
if (!c1 || c1 == '"')
break;
if (c2 != '-')
{ if (c1 != c2)
{ if (c1 >= 'A' && c1 <= 'Z')
c1 += 'a' - 'A';
if (c2 >= 'A' && c2 <= 'Z')
c2 += 'a' - 'A';
}
if (c1 != c2)
{ if (c2 != '*')
return 1;
c2 = *++t;
if (!c2)
return 0;
if (c2 >= 'A' && c2 <= 'Z')
c2 += 'a' - 'A';
for (;;)
{ c1 = *s;
if (!c1 || c1 == '"')
break;
if (c1 >= 'A' && c1 <= 'Z')
c1 += 'a' - 'A';
if (c1 == c2 && !soap_tag_cmp(s + 1, t + 1))
return 0;
s++;
}
break;
}
}
s++;
t++;
}
if (*t == '*' && !t[1])
return 0;
return *t;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_match_tag(struct soap *soap, const char *tag1, const char *tag2)
{ register const char *s, *t;
register int err;
if (!tag1 || !tag2 || !*tag2)
return SOAP_OK;
s = strchr(tag1, ':');
t = strchr(tag2, ':');
if (t)
{ if (s)
{ if (t[1] && SOAP_STRCMP(s + 1, t + 1))
return SOAP_TAG_MISMATCH;
if (t != tag2 && (err = soap_match_namespace(soap, tag1, tag2, s - tag1, t - tag2)))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
if (err == SOAP_NAMESPACE)
return SOAP_TAG_MISMATCH;
return err;
}
}
else if (!t[1])
{ err = soap_match_namespace(soap, tag1, tag2, 0, t - tag2);
if (err == SOAP_NAMESPACE)
return SOAP_TAG_MISMATCH;
}
else if (SOAP_STRCMP(tag1, t + 1))
{ return SOAP_TAG_MISMATCH;
}
else if (t != tag2 && (err = soap_match_namespace(soap, tag1, tag2, 0, t - tag2)))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
if (err == SOAP_NAMESPACE)
return SOAP_TAG_MISMATCH;
return err;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags and (default) namespaces match: '%s' '%s'\n", tag1, tag2));
return SOAP_OK;
}
if (s)
{ if (SOAP_STRCMP(s + 1, tag2))
return SOAP_TAG_MISMATCH;
}
else if (SOAP_STRCMP(tag1, tag2))
return SOAP_TAG_MISMATCH;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags match: '%s' '%s'\n", tag1, tag2));
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_match_array(struct soap *soap, const char *type)
{ if (*soap->arrayType)
if (soap_match_tag(soap, soap->arrayType, type)
&& soap_match_tag(soap, soap->arrayType, "xsd:anyType")
&& soap_match_tag(soap, soap->arrayType, "xsd:ur-type")
)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array type mismatch: '%s' '%s'\n", soap->arrayType, type));
return SOAP_TAG_MISMATCH;
}
return SOAP_OK;
}
#endif
/******************************************************************************\
*
* SSL/TLS
*
\******************************************************************************/
/******************************************************************************/
#ifdef WITH_OPENSSL
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_rand()
{ unsigned char buf[4];
if (!soap_ssl_init_done)
soap_ssl_init();
RAND_pseudo_bytes(buf, 4);
return *(int*)buf;
}
#endif
#endif
/******************************************************************************/
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *keyid, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid)
#else
soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid)
#endif
{ int err;
soap->keyfile = keyfile;
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
soap->keyid = keyid;
#endif
soap->password = password;
soap->cafile = cafile;
soap->capath = capath;
soap->crlfile = NULL;
#ifdef WITH_OPENSSL
soap->dhfile = dhfile;
soap->randfile = randfile;
#endif
soap->ssl_flags = flags | (dhfile == NULL ? SOAP_SSL_RSA : 0);
#ifdef WITH_GNUTLS
if (dhfile)
{ char *s;
int n = (int)soap_strtoul(dhfile, &s, 10);
if (!soap->dh_params)
gnutls_dh_params_init(&soap->dh_params);
/* if dhfile is numeric, treat it as a key length to generate DH params which can take a while */
if (n >= 512 && s && *s == '\0')
gnutls_dh_params_generate2(soap->dh_params, (unsigned int)n);
else
{ unsigned int dparams_len;
unsigned char dparams_buf[1024];
FILE *fd = fopen(dhfile, "r");
if (!fd)
return soap_set_receiver_error(soap, "SSL/TLS error", "Invalid DH file", SOAP_SSL_ERROR);
dparams_len = (unsigned int)fread(dparams_buf, 1, sizeof(dparams_buf), fd);
fclose(fd);
gnutls_datum_t dparams = { dparams_buf, dparams_len };
if (gnutls_dh_params_import_pkcs3(soap->dh_params, &dparams, GNUTLS_X509_FMT_PEM))
return soap_set_receiver_error(soap, "SSL/TLS error", "Invalid DH file", SOAP_SSL_ERROR);
}
}
else
{ if (!soap->rsa_params)
gnutls_rsa_params_init(&soap->rsa_params);
gnutls_rsa_params_generate2(soap->rsa_params, SOAP_SSL_RSA_BITS);
}
if (soap->session)
{ gnutls_deinit(soap->session);
soap->session = NULL;
}
if (soap->xcred)
{ gnutls_certificate_free_credentials(soap->xcred);
soap->xcred = NULL;
}
#endif
err = soap->fsslauth(soap);
#ifdef WITH_OPENSSL
if (!err)
{ if (sid)
SSL_CTX_set_session_id_context(soap->ctx, (unsigned char*)sid, (unsigned int)strlen(sid));
else
SSL_CTX_set_session_cache_mode(soap->ctx, SSL_SESS_CACHE_OFF);
}
#endif
return err;
}
#endif
#endif
/******************************************************************************/
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *keyid, const char *password, const char *cafile, const char *capath, const char *randfile)
#else
soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *randfile)
#endif
{ soap->keyfile = keyfile;
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
soap->keyid = keyid;
#endif
soap->password = password;
soap->cafile = cafile;
soap->capath = capath;
soap->ssl_flags = SOAP_SSL_CLIENT | flags;
#ifdef WITH_OPENSSL
soap->dhfile = NULL;
soap->randfile = randfile;
soap->fsslverify = (flags & SOAP_SSL_ALLOW_EXPIRED_CERTIFICATE) == 0 ? ssl_verify_callback : ssl_verify_callback_allow_expired_certificate;
#endif
#ifdef WITH_GNUTLS
if (soap->session)
{ gnutls_deinit(soap->session);
soap->session = NULL;
}
if (soap->xcred)
{ gnutls_certificate_free_credentials(soap->xcred);
soap->xcred = NULL;
}
#endif
return soap->fsslauth(soap);
}
#endif
#endif
/******************************************************************************/
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_ssl_init()
{ /* Note: for MT systems, the main program MUST call soap_ssl_init() before any threads are started */
if (!soap_ssl_init_done)
{ soap_ssl_init_done = 1;
#ifdef WITH_OPENSSL
SSL_library_init();
OpenSSL_add_all_algorithms(); /* 2.8.1 change (wsseapi.c) */
OpenSSL_add_all_digests();
#ifndef WITH_LEAN
SSL_load_error_strings();
#endif
if (!RAND_load_file("/dev/urandom", 1024))
{ char buf[1024];
RAND_seed(buf, sizeof(buf));
while (!RAND_status())
{ int r = rand();
RAND_seed(&r, sizeof(int));
}
}
#endif
#ifdef WITH_GNUTLS
# if defined(HAVE_PTHREAD_H)
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
# elif defined(HAVE_PTH_H)
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pth);
# endif
gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0);
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); /* libgcrypt init done */
gnutls_global_init();
#endif
}
}
#endif
#endif
/******************************************************************************/
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
#ifndef PALM_1
SOAP_FMAC1
const char *
SOAP_FMAC2
soap_ssl_error(struct soap *soap, int ret)
{
#ifdef WITH_OPENSSL
int err = SSL_get_error(soap->ssl, ret);
const char *msg = soap_code_str(h_ssl_error_codes, err);
if (msg)
strcpy(soap->msgbuf, msg);
else
return ERR_error_string(err, soap->msgbuf);
if (ERR_peek_error())
{ unsigned long r;
strcat(soap->msgbuf, "\n");
while ((r = ERR_get_error()))
ERR_error_string_n(r, soap->msgbuf + strlen(soap->msgbuf), sizeof(soap->msgbuf) - strlen(soap->msgbuf));
}
else
{ switch (ret)
{ case 0:
strcpy(soap->msgbuf, "EOF was observed that violates the SSL/TLS protocol. The client probably provided invalid authentication information.");
break;
case -1:
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Error observed by underlying SSL/TLS BIO: %s", strerror(errno));
#else
{ const char *s = strerror(errno);
size_t l = strlen(s);
sprintf(soap->msgbuf, "Error observed by underlying SSL/TLS BIO: %s", l + 44 < sizeof(soap->msgbuf) ? s : SOAP_STR_EOS);
}
#endif
break;
}
}
return soap->msgbuf;
#endif
#ifdef WITH_GNUTLS
return gnutls_strerror(ret);
#endif
}
#endif
#endif
/******************************************************************************/
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
#ifndef PALM_1
static int
ssl_auth_init(struct soap *soap)
{
#ifdef WITH_OPENSSL
long flags;
int mode;
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
EVP_PKEY* pkey;
#endif
if (!soap_ssl_init_done)
soap_ssl_init();
ERR_clear_error();
if (!soap->ctx)
{ if (!(soap->ctx = SSL_CTX_new(SSLv23_method())))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't setup context", SOAP_SSL_ERROR);
/* The following alters the behavior of SSL read/write: */
#if 0
SSL_CTX_set_mode(soap->ctx, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY);
#endif
}
if (soap->randfile)
{ if (!RAND_load_file(soap->randfile, -1))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't load randomness", SOAP_SSL_ERROR);
}
if (soap->cafile || soap->capath)
{ if (!SSL_CTX_load_verify_locations(soap->ctx, soap->cafile, soap->capath))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read CA file", SOAP_SSL_ERROR);
if (soap->cafile && (soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION))
SSL_CTX_set_client_CA_list(soap->ctx, SSL_load_client_CA_file(soap->cafile));
}
if (!(soap->ssl_flags & SOAP_SSL_NO_DEFAULT_CA_PATH))
{ if (!SSL_CTX_set_default_verify_paths(soap->ctx))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read default CA file and/or directory", SOAP_SSL_ERROR);
}
/* This code assumes a typical scenario, see alternative code below */
if (soap->keyfile)
{ if (!SSL_CTX_use_certificate_chain_file(soap->ctx, soap->keyfile))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read certificate key file", SOAP_SSL_ERROR);
if (soap->password)
{ SSL_CTX_set_default_passwd_cb_userdata(soap->ctx, (void*)soap->password);
SSL_CTX_set_default_passwd_cb(soap->ctx, ssl_password);
}
if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read key file", SOAP_SSL_ERROR);
#ifndef WM_SECURE_KEY_STORAGE
if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read key file", SOAP_SSL_ERROR);
#endif
}
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
if (NULL == (pkey = ipcom_key_db_pkey_get(soap->keyid)))
return soap_set_receiver_error(soap, "SSL error", "Can't find key", SOAP_SSL_ERROR);
if (0 == SSL_CTX_use_PrivateKey(soap->ctx, pkey))
return soap_set_receiver_error(soap, "SSL error", "Can't read key", SOAP_SSL_ERROR);
#endif
/* Suggested alternative approach to check the key file for certs (cafile=NULL):*/
#if 0
if (soap->password)
{ SSL_CTX_set_default_passwd_cb_userdata(soap->ctx, (void*)soap->password);
SSL_CTX_set_default_passwd_cb(soap->ctx, ssl_password);
}
if (!soap->cafile || !SSL_CTX_use_certificate_chain_file(soap->ctx, soap->cafile))
{ if (soap->keyfile)
{ if (!SSL_CTX_use_certificate_chain_file(soap->ctx, soap->keyfile))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read certificate or key file", SOAP_SSL_ERROR);
if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read key file", SOAP_SSL_ERROR);
}
}
#endif
if ((soap->ssl_flags & SOAP_SSL_RSA))
{ RSA *rsa = RSA_generate_key(SOAP_SSL_RSA_BITS, RSA_F4, NULL, NULL);
if (!SSL_CTX_set_tmp_rsa(soap->ctx, rsa))
{ if (rsa)
RSA_free(rsa);
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't set RSA key", SOAP_SSL_ERROR);
}
RSA_free(rsa);
}
else if (soap->dhfile)
{ DH *dh = 0;
char *s;
int n = (int)soap_strtoul(soap->dhfile, &s, 10);
/* if dhfile is numeric, treat it as a key length to generate DH params which can take a while */
if (n >= 512 && s && *s == '\0')
#if defined(VXWORKS)
DH_generate_parameters_ex(dh, n, 2/*or 5*/, NULL);
#else
dh = DH_generate_parameters(n, 2/*or 5*/, NULL, NULL);
#endif
else
{ BIO *bio;
bio = BIO_new_file(soap->dhfile, "r");
if (!bio)
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read DH file", SOAP_SSL_ERROR);
dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
BIO_free(bio);
}
if (!dh || DH_check(dh, &n) != 1 || SSL_CTX_set_tmp_dh(soap->ctx, dh) < 0)
{ if (dh)
DH_free(dh);
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't set DH parameters", SOAP_SSL_ERROR);
}
DH_free(dh);
}
flags = (SSL_OP_ALL | SSL_OP_NO_SSLv2); /* disable SSL v2 */
if ((soap->ssl_flags & SOAP_SSLv3))
flags |= SSL_OP_NO_TLSv1;
if ((soap->ssl_flags & SOAP_TLSv1))
flags |= SSL_OP_NO_SSLv3;
#ifdef SSL_OP_NO_TICKET
/* TLS extension is enabled by default in OPENSSL v0.9.8k
Disable it by adding SSL_OP_NO_TICKET */
flags |= SSL_OP_NO_TICKET;
#endif
SSL_CTX_set_options(soap->ctx, flags);
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION))
mode = (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
else if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION))
mode = SSL_VERIFY_PEER;
else
mode = SSL_VERIFY_NONE;
SSL_CTX_set_verify(soap->ctx, mode, soap->fsslverify);
#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
SSL_CTX_set_verify_depth(soap->ctx, 1);
#else
SSL_CTX_set_verify_depth(soap->ctx, 9);
#endif
#endif
#ifdef WITH_GNUTLS
int ret;
if (!soap_ssl_init_done)
soap_ssl_init();
if (!soap->xcred)
{ gnutls_certificate_allocate_credentials(&soap->xcred);
if (soap->cafile)
{ if (gnutls_certificate_set_x509_trust_file(soap->xcred, soap->cafile, GNUTLS_X509_FMT_PEM) < 0)
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read CA file", SOAP_SSL_ERROR);
}
if (soap->crlfile)
{ if (gnutls_certificate_set_x509_crl_file(soap->xcred, soap->crlfile, GNUTLS_X509_FMT_PEM) < 0)
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read CRL file", SOAP_SSL_ERROR);
}
if (soap->keyfile)
{ if (gnutls_certificate_set_x509_key_file(soap->xcred, soap->keyfile, soap->keyfile, GNUTLS_X509_FMT_PEM) < 0) /* TODO: GNUTLS need to concat cert and key in single key file */
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read key file", SOAP_SSL_ERROR);
}
}
if ((soap->ssl_flags & SOAP_SSL_CLIENT))
{ gnutls_init(&soap->session, GNUTLS_CLIENT);
if (soap->cafile || soap->crlfile || soap->keyfile)
{ ret = gnutls_priority_set_direct(soap->session, "PERFORMANCE", NULL);
if (ret < 0)
return soap_set_receiver_error(soap, soap_ssl_error(soap, ret), "SSL/TLS set priority error", SOAP_SSL_ERROR);
gnutls_credentials_set(soap->session, GNUTLS_CRD_CERTIFICATE, soap->xcred);
}
else
{ if (!soap->acred)
gnutls_anon_allocate_client_credentials(&soap->acred);
gnutls_init(&soap->session, GNUTLS_CLIENT);
gnutls_priority_set_direct(soap->session, "PERFORMANCE:+ANON-DH:!ARCFOUR-128", NULL);
gnutls_credentials_set(soap->session, GNUTLS_CRD_ANON, soap->acred);
}
}
else
{ if (!soap->keyfile)
return soap_set_receiver_error(soap, "SSL/TLS error", "No key file: anonymous server authentication not supported in this release", SOAP_SSL_ERROR);
if ((soap->ssl_flags & SOAP_SSL_RSA) && soap->rsa_params)
gnutls_certificate_set_rsa_export_params(soap->xcred, soap->rsa_params);
else if (soap->dh_params)
gnutls_certificate_set_dh_params(soap->xcred, soap->dh_params);
if (!soap->cache)
gnutls_priority_init(&soap->cache, "NORMAL", NULL);
gnutls_init(&soap->session, GNUTLS_SERVER);
gnutls_priority_set(soap->session, soap->cache);
gnutls_credentials_set(soap->session, GNUTLS_CRD_CERTIFICATE, soap->xcred);
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION))
gnutls_certificate_server_set_request(soap->session, GNUTLS_CERT_REQUEST);
gnutls_session_enable_compatibility_mode(soap->session);
if ((soap->ssl_flags & SOAP_TLSv1))
{ int protocol_priority[] = { GNUTLS_TLS1_0, 0 };
if (gnutls_protocol_set_priority(soap->session, protocol_priority) != GNUTLS_E_SUCCESS)
return soap_set_receiver_error(soap, "SSL/TLS error", "Can't set TLS v1.0 protocol", SOAP_SSL_ERROR);
}
}
#endif
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifdef WITH_OPENSSL
#ifndef PALM_1
static int
ssl_password(char *buf, int num, int rwflag, void *userdata)
{ if (num < (int)strlen((char*)userdata) + 1)
return 0;
return (int)strlen(strcpy(buf, (char*)userdata));
}
#endif
#endif
/******************************************************************************/
#ifdef WITH_OPENSSL
#ifndef PALM_1
static int
ssl_verify_callback(int ok, X509_STORE_CTX *store)
{
#ifdef SOAP_DEBUG
if (!ok)
{ char buf[1024];
int err = X509_STORE_CTX_get_error(store);
X509 *cert = X509_STORE_CTX_get_current_cert(store);
fprintf(stderr, "SSL verify error or warning with certificate at depth %d: %s\n", X509_STORE_CTX_get_error_depth(store), X509_verify_cert_error_string(err));
X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf));
fprintf(stderr, "certificate issuer %s\n", buf);
X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf));
fprintf(stderr, "certificate subject %s\n", buf);
/* accept self signed certificates and certificates out of date */
switch (err)
{ case X509_V_ERR_CERT_NOT_YET_VALID:
case X509_V_ERR_CERT_HAS_EXPIRED:
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
X509_STORE_CTX_set_error(store, X509_V_OK);
ok = 1;
}
}
#endif
/* Note: return 1 to continue, but unsafe progress will be terminated by OpenSSL */
return ok;
}
#endif
#endif
/******************************************************************************/
#ifdef WITH_OPENSSL
#ifndef PALM_1
static int
ssl_verify_callback_allow_expired_certificate(int ok, X509_STORE_CTX *store)
{ ok = ssl_verify_callback(ok, store);
if (!ok)
{ /* accept self signed certificates and certificates out of date */
switch (X509_STORE_CTX_get_error(store))
{ case X509_V_ERR_CERT_NOT_YET_VALID:
case X509_V_ERR_CERT_HAS_EXPIRED:
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
X509_STORE_CTX_set_error(store, X509_V_OK);
ok = 1;
}
}
/* Note: return 1 to continue, but unsafe progress will be terminated by SSL */
return ok;
}
#endif
#endif
/******************************************************************************/
#ifdef WITH_GNUTLS
static const char *
ssl_verify(struct soap *soap, const char *host)
{ unsigned int status;
const char *err = NULL;
int r = gnutls_certificate_verify_peers2(soap->session, &status);
if (r < 0)
err = "Certificate verify error";
else if ((status & GNUTLS_CERT_INVALID))
err = "The certificate is not trusted";
else if ((status & GNUTLS_CERT_SIGNER_NOT_FOUND))
err = "The certificate hasn't got a known issuer";
else if ((status & GNUTLS_CERT_REVOKED))
err = "The certificate has been revoked";
else if (gnutls_certificate_type_get(soap->session) == GNUTLS_CRT_X509)
{ gnutls_x509_crt_t cert;
const gnutls_datum_t *cert_list;
unsigned int cert_list_size;
if (gnutls_x509_crt_init(&cert) < 0)
err = "Could not get X509 certificates";
else if ((cert_list = gnutls_certificate_get_peers(soap->session, &cert_list_size)) == NULL)
err = "Could not get X509 certificates";
else if (gnutls_x509_crt_import(cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0)
err = "Error parsing X509 certificate";
else if (!(soap->ssl_flags & SOAP_SSL_ALLOW_EXPIRED_CERTIFICATE) && gnutls_x509_crt_get_expiration_time(cert) < time(NULL))
err = "The certificate has expired";
else if (!(soap->ssl_flags & SOAP_SSL_ALLOW_EXPIRED_CERTIFICATE) && gnutls_x509_crt_get_activation_time(cert) > time(NULL))
err = "The certificate is not yet activated";
else if (host && !(soap->ssl_flags & SOAP_SSL_SKIP_HOST_CHECK))
{ if (!gnutls_x509_crt_check_hostname(cert, host))
err = "Certificate host name mismatch";
}
gnutls_x509_crt_deinit(cert);
}
return err;
}
#endif
/******************************************************************************/
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
#ifndef WITH_NOIO
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_ssl_accept(struct soap *soap)
{ SOAP_SOCKET sk = soap->socket;
#ifdef WITH_OPENSSL
BIO *bio;
int retries, r, s;
if (!soap_valid_socket(sk))
return soap_set_receiver_error(soap, "SSL/TLS error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
soap->ssl_flags &= ~SOAP_SSL_CLIENT;
if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
return soap->error;
if (!soap->ssl)
{ soap->ssl = SSL_new(soap->ctx);
if (!soap->ssl)
return soap_set_receiver_error(soap, "SSL/TLS error", "SSL_new() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
}
else
SSL_clear(soap->ssl);
bio = BIO_new_socket((int)sk, BIO_NOCLOSE);
SSL_set_bio(soap->ssl, bio, bio);
/* Set SSL sockets to non-blocking */
retries = 0;
if (soap->accept_timeout)
{ SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->accept_timeout;
}
if (retries <= 0)
retries = 100; /* timeout: 10 sec retries, 100 times 0.1 sec */
while ((r = SSL_accept(soap->ssl)) <= 0)
{ int err;
if (retries-- <= 0)
break;
err = SSL_get_error(soap->ssl, r);
if (err == SSL_ERROR_WANT_ACCEPT || err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
{ if (err == SSL_ERROR_WANT_READ)
s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0)
break;
}
else
{ soap->errnum = soap_socket_errno(sk);
break;
}
}
if (r <= 0)
{ soap_set_receiver_error(soap, soap_ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
soap_closesock(soap);
return SOAP_SSL_ERROR;
}
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION))
{ X509 *peer;
int err;
if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
{ soap_closesock(soap);
return soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL certificate presented by peer cannot be verified in soap_ssl_accept()", SOAP_SSL_ERROR);
}
peer = SSL_get_peer_certificate(soap->ssl);
if (!peer)
{ soap_closesock(soap);
return soap_set_sender_error(soap, "SSL/TLS error", "No SSL certificate was presented by the peer in soap_ssl_accept()", SOAP_SSL_ERROR);
}
X509_free(peer);
}
#endif
#ifdef WITH_GNUTLS
int retries = 0, r;
if (!soap_valid_socket(sk))
return soap_set_receiver_error(soap, "SSL/TLS error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
soap->ssl_flags &= ~SOAP_SSL_CLIENT;
if (!soap->session && (soap->error = soap->fsslauth(soap)))
{ soap_closesock(soap);
return soap->error;
}
gnutls_transport_set_ptr(soap->session, (gnutls_transport_ptr_t)(long)sk);
/* Set SSL sockets to non-blocking */
if (soap->accept_timeout)
{ SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->accept_timeout;
}
if (retries <= 0)
retries = 100; /* timeout: 10 sec retries, 100 times 0.1 sec */
while ((r = gnutls_handshake(soap->session)))
{ int s;
/* GNUTLS repeat handhake when GNUTLS_E_AGAIN */
if (retries-- <= 0)
break;
if (r == GNUTLS_E_AGAIN || r == GNUTLS_E_INTERRUPTED)
{ if (!gnutls_record_get_direction(soap->session))
s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0)
break;
}
else
{ soap->errnum = soap_socket_errno(sk);
break;
}
}
if (r)
{ soap_closesock(soap);
return soap_set_receiver_error(soap, soap_ssl_error(soap, r), "SSL/TLS handshake failed", SOAP_SSL_ERROR);
}
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION))
{ const char *err = ssl_verify(soap, NULL);
if (err)
{ soap_closesock(soap);
return soap_set_receiver_error(soap, "SSL/TLS error", err, SOAP_SSL_ERROR);
}
}
#endif
if (soap->recv_timeout || soap->send_timeout)
SOAP_SOCKNONBLOCK(sk)
else
SOAP_SOCKBLOCK(sk)
soap->imode |= SOAP_ENC_SSL;
soap->omode |= SOAP_ENC_SSL;
return SOAP_OK;
}
#endif
#endif
#endif
/******************************************************************************\
*
* TCP/UDP [SSL/TLS] IPv4 and IPv6
*
\******************************************************************************/
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_init(struct soap *soap)
{ soap->errmode = 1;
#ifdef WIN32
if (tcp_done)
return 0;
else
{ WSADATA w;
if (WSAStartup(MAKEWORD(1, 1), &w))
return -1;
tcp_done = 1;
}
#endif
return 0;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static const char*
tcp_error(struct soap *soap)
{ register const char *msg = NULL;
switch (soap->errmode)
{ case 0:
msg = soap_strerror(soap);
break;
case 1:
msg = "WSAStartup failed";
break;
case 2:
{
#ifndef WITH_LEAN
msg = soap_code_str(h_error_codes, soap->errnum);
if (!msg)
#endif
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "TCP/UDP IP error %d", soap->errnum);
#else
sprintf(soap->msgbuf, "TCP/UDP IP error %d", soap->errnum);
#endif
msg = soap->msgbuf;
}
}
}
return msg;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_IPV6
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr)
{ soap_int32 iadd = -1;
struct hostent hostent, *host = &hostent;
#ifdef VXWORKS
int hostint;
/* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */
iadd = inet_addr((char*)addr);
#else
#if defined(_AIX43) || ((defined(TRU64) || defined(HP_UX)) && defined(HAVE_GETHOSTBYNAME_R))
struct hostent_data ht_data;
#endif
#ifdef AS400
iadd = inet_addr((void*)addr);
#else
iadd = inet_addr(addr);
#endif
#endif
if (iadd != -1)
{ memcpy(inaddr, &iadd, sizeof(iadd));
return SOAP_OK;
}
#if defined(__GLIBC__) || (defined(HAVE_GETHOSTBYNAME_R) && (defined(FREEBSD) || defined(__FreeBSD__))) || defined(__ANDROID__)
if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0)
host = NULL;
#elif defined(_AIX43) || ((defined(TRU64) || defined(HP_UX)) && defined(HAVE_GETHOSTBYNAME_R))
memset((void*)&ht_data, 0, sizeof(ht_data));
if (gethostbyname_r(addr, &hostent, &ht_data) < 0)
{ host = NULL;
soap->errnum = h_errno;
}
#elif defined(HAVE_GETHOSTBYNAME_R)
host = gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &soap->errnum);
#elif defined(VXWORKS)
/* If the DNS resolver library resolvLib has been configured in the vxWorks
* image, a query for the host IP address is sent to the DNS server, if the
* name was not found in the local host table. */
hostint = hostGetByName((char*)addr);
if (hostint == ERROR)
{ host = NULL;
soap->errnum = soap_errno;
}
#else
#ifdef AS400
if (!(host = gethostbyname((void*)addr)))
soap->errnum = h_errno;
#else
if (!(host = gethostbyname(addr)))
soap->errnum = h_errno;
#endif
#endif
if (!host)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n"));
return SOAP_ERR;
}
#ifdef VXWORKS
inaddr->s_addr = hostint;
#else
memcpy(inaddr, host->h_addr, host->h_length);
#endif
return SOAP_OK;
}
#endif
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static SOAP_SOCKET
tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port)
{
#ifdef WITH_IPV6
struct addrinfo hints, *res, *ressave;
#endif
SOAP_SOCKET sk;
int err = 0;
#ifndef WITH_LEAN
#ifndef WIN32
int len = SOAP_BUFLEN;
#else
int len = SOAP_BUFLEN + 1; /* speeds up windows xfer */
#endif
int set = 1;
#endif
#if !defined(WITH_LEAN) || defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
int retries;
#endif
if (soap_valid_socket(soap->socket))
soap->fclosesocket(soap, soap->socket);
soap->socket = SOAP_INVALID_SOCKET;
if (tcp_init(soap))
{ soap->errnum = 0;
soap_set_sender_error(soap, tcp_error(soap), "TCP init failed in tcp_connect()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
soap->errmode = 0;
#ifdef WITH_IPV6
memset((void*)&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
hints.ai_socktype = SOCK_DGRAM;
else
#endif
hints.ai_socktype = SOCK_STREAM;
soap->errmode = 2;
if (soap->proxy_host)
err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &res);
else
err = getaddrinfo(host, soap_int2s(soap, port), &hints, &res);
if (err)
{ soap_set_sender_error(soap, SOAP_GAI_STRERROR(err), "getaddrinfo failed in tcp_connect()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
ressave = res;
again:
sk = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
soap->errmode = 0;
#else
#ifndef WITH_LEAN
again:
#endif
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
sk = socket(AF_INET, SOCK_DGRAM, 0);
else
#endif
sk = socket(AF_INET, SOCK_STREAM, 0);
#endif
if (!soap_valid_socket(sk))
{
#ifdef WITH_IPV6
if (res->ai_next)
{ res = res->ai_next;
goto again;
}
#endif
soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "socket failed in tcp_connect()", SOAP_TCP_ERROR);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#ifdef SOCKET_CLOSE_ON_EXEC
#ifdef WIN32
#ifndef UNDER_CE
SetHandleInformation((HANDLE)sk, HANDLE_FLAG_INHERIT, 0);
#endif
#else
fcntl(sk, F_SETFD, 1);
#endif
#endif
#ifndef WITH_LEAN
if (soap->connect_flags == SO_LINGER)
{ struct linger linger;
memset((void*)&linger, 0, sizeof(linger));
linger.l_onoff = 1;
linger.l_linger = soap->linger_time;
if (setsockopt(sk, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
}
else if (soap->connect_flags && setsockopt(sk, SOL_SOCKET, soap->connect_flags, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
if ((soap->keep_alive || soap->tcp_keep_alive) && setsockopt(sk, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
if (setsockopt(sk, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
if (setsockopt(sk, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#ifdef TCP_KEEPIDLE
if (soap->tcp_keep_idle && setsockopt((SOAP_SOCKET)sk, IPPROTO_TCP, TCP_KEEPIDLE, (char*)&(soap->tcp_keep_idle), sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPIDLE failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, (SOAP_SOCKET)sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#endif
#ifdef TCP_KEEPINTVL
if (soap->tcp_keep_intvl && setsockopt((SOAP_SOCKET)sk, IPPROTO_TCP, TCP_KEEPINTVL, (char*)&(soap->tcp_keep_intvl), sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPINTVL failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, (SOAP_SOCKET)sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#endif
#ifdef TCP_KEEPCNT
if (soap->tcp_keep_cnt && setsockopt((SOAP_SOCKET)sk, IPPROTO_TCP, TCP_KEEPCNT, (char*)&(soap->tcp_keep_cnt), sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPCNT failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, (SOAP_SOCKET)sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#endif
#ifdef TCP_NODELAY
if (!(soap->omode & SOAP_IO_UDP) && setsockopt(sk, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#endif
#ifdef WITH_IPV6
if ((soap->omode & SOAP_IO_UDP) && soap->ipv6_multicast_if)
{ struct sockaddr_in6 *in6addr = (struct sockaddr_in6*)res->ai_addr;
in6addr->sin6_scope_id = soap->ipv6_multicast_if;
}
#endif
#ifdef IP_MULTICAST_TTL
if ((soap->omode & SOAP_IO_UDP))
{ if (soap->ipv4_multicast_ttl)
{ unsigned char ttl = soap->ipv4_multicast_ttl;
if (setsockopt(sk, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ttl, sizeof(ttl)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt IP_MULTICAST_TTL failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
if ((soap->omode & SOAP_IO_UDP) && soap->ipv4_multicast_if && !soap->ipv6_multicast_if)
{ if (setsockopt(sk, IPPROTO_IP, IP_MULTICAST_IF, (char*)soap->ipv4_multicast_if, sizeof(struct in_addr)))
#ifndef WINDOWS
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt IP_MULTICAST_IF failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
#else
#ifndef IP_MULTICAST_IF
#define IP_MULTICAST_IF 2
#endif
if (setsockopt(sk, IPPROTO_IP, IP_MULTICAST_IF, (char*)soap->ipv4_multicast_if, sizeof(struct in_addr)))
{ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt IP_MULTICAST_IF failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
#endif
}
}
#endif
#endif
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket=%d to host='%s' port=%d\n", sk, host, port));
#ifndef WITH_IPV6
soap->peerlen = sizeof(soap->peer);
memset((void*)&soap->peer, 0, sizeof(soap->peer));
soap->peer.sin_family = AF_INET;
soap->errmode = 2;
if (soap->proxy_host)
{ if (soap->fresolve(soap, soap->proxy_host, &soap->peer.sin_addr))
{ soap_set_sender_error(soap, tcp_error(soap), "get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
soap->peer.sin_port = htons((short)soap->proxy_port);
}
else
{ if (soap->fresolve(soap, host, &soap->peer.sin_addr))
{ soap_set_sender_error(soap, tcp_error(soap), "get host by name failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
soap->peer.sin_port = htons((short)port);
}
soap->errmode = 0;
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
return sk;
#endif
#else
if ((soap->omode & SOAP_IO_UDP))
{ memcpy(&soap->peer, res->ai_addr, res->ai_addrlen);
soap->peerlen = res->ai_addrlen;
freeaddrinfo(ressave);
return sk;
}
#endif
#ifndef WITH_LEAN
if (soap->connect_timeout)
SOAP_SOCKNONBLOCK(sk)
else
SOAP_SOCKBLOCK(sk)
retries = 10;
#endif
for (;;)
{
#ifdef WITH_IPV6
if (connect(sk, res->ai_addr, (int)res->ai_addrlen))
#else
if (connect(sk, (struct sockaddr*)&soap->peer, sizeof(soap->peer)))
#endif
{ err = soap_socket_errno(sk);
#ifndef WITH_LEAN
if (err == SOAP_EADDRINUSE)
{ soap->fclosesocket(soap, sk);
if (retries-- > 0)
goto again;
}
else if (soap->connect_timeout && (err == SOAP_EINPROGRESS || err == SOAP_EAGAIN || err == SOAP_EWOULDBLOCK))
{
SOAP_SOCKLEN_T k;
for (;;)
{ register int r;
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND, soap->connect_timeout);
if (r > 0)
break;
if (!r)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
soap_set_sender_error(soap, "Timeout", "connect failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
r = soap->errnum = soap_socket_errno(sk);
if (r != SOAP_EINTR)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
}
k = (SOAP_SOCKLEN_T)sizeof(soap->errnum);
if (!getsockopt(sk, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
break;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
if (!soap->errnum)
soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#endif
#ifdef WITH_IPV6
if (res->ai_next)
{ res = res->ai_next;
soap->fclosesocket(soap, sk);
goto again;
}
#endif
if (err && err != SOAP_EINTR)
{ soap->errnum = err;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
}
else
break;
}
#ifdef WITH_IPV6
soap->peerlen = 0; /* IPv6: already connected so use send() */
freeaddrinfo(ressave);
#endif
soap->socket = sk;
soap->imode &= ~SOAP_ENC_SSL;
soap->omode &= ~SOAP_ENC_SSL;
if (!soap_tag_cmp(endpoint, "https:*"))
{
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
#ifdef WITH_OPENSSL
BIO *bio;
#endif
int r;
if (soap->proxy_host)
{ soap_mode m = soap->mode; /* preserve settings */
soap_mode om = soap->omode; /* make sure we only parse HTTP */
size_t n = soap->count; /* save the content length */
const char *userid, *passwd;
int status = soap->status; /* save the current status/command */
short keep_alive = soap->keep_alive; /* save the KA status */
soap->omode &= ~SOAP_ENC; /* mask IO and ENC */
soap->omode |= SOAP_IO_BUFFER;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to %s proxy server %s for destination endpoint %s\n", soap->proxy_http_version, soap->proxy_host, endpoint));
#ifdef WITH_NTLM
if (soap->ntlm_challenge)
{ if (soap_ntlm_handshake(soap, SOAP_CONNECT, endpoint, host, port))
return soap->error;
}
#endif
if (soap_begin_send(soap))
{ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
soap->status = SOAP_CONNECT;
soap->keep_alive = 1;
if ((soap->error = soap->fpost(soap, endpoint, host, port, NULL, NULL, 0))
|| soap_end_send_flush(soap))
{ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
soap->keep_alive = keep_alive;
soap->omode = om;
om = soap->imode;
soap->imode &= ~SOAP_ENC; /* mask IO and ENC */
userid = soap->userid; /* preserve */
passwd = soap->passwd; /* preserve */
if ((soap->error = soap->fparse(soap)))
{ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
soap->status = status; /* restore */
soap->userid = userid; /* restore */
soap->passwd = passwd; /* restore */
soap->imode = om; /* restore */
soap->count = n; /* restore */
if (soap_begin_send(soap))
{ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if (endpoint)
{ strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint)); /* restore */
soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
}
soap->mode = m;
}
#ifdef WITH_OPENSSL
soap->ssl_flags |= SOAP_SSL_CLIENT;
if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "SSL required, but no ctx set\n"));
soap->fclosesocket(soap, sk);
soap->error = SOAP_SSL_ERROR;
return SOAP_INVALID_SOCKET;
}
if (!soap->ssl)
{ soap->ssl = SSL_new(soap->ctx);
if (!soap->ssl)
{ soap->fclosesocket(soap, sk);
soap->error = SOAP_SSL_ERROR;
return SOAP_INVALID_SOCKET;
}
}
else
SSL_clear(soap->ssl);
if (soap->session)
{ if (!strcmp(soap->session_host, host) && soap->session_port == port)
SSL_set_session(soap->ssl, soap->session);
SSL_SESSION_free(soap->session);
soap->session = NULL;
}
soap->imode |= SOAP_ENC_SSL;
soap->omode |= SOAP_ENC_SSL;
bio = BIO_new_socket((int)sk, BIO_NOCLOSE);
SSL_set_bio(soap->ssl, bio, bio);
/* Connect timeout: set SSL sockets to non-blocking */
retries = 0;
if (soap->connect_timeout)
{ SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->connect_timeout;
}
else
SOAP_SOCKBLOCK(sk)
if (retries <= 0)
retries = 100; /* timeout: 10 sec retries, 100 times 0.1 sec */
/* Try connecting until success or timeout (when nonblocking) */
do
{ if ((r = SSL_connect(soap->ssl)) <= 0)
{ int err = SSL_get_error(soap->ssl, r);
if (err == SSL_ERROR_WANT_CONNECT || err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
{ register int s;
if (err == SSL_ERROR_WANT_READ)
s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "SSL_connect/select error in tcp_connect\n"));
soap_set_sender_error(soap, soap_ssl_error(soap, r), "SSL_connect failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if (s == 0 && retries-- <= 0)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "SSL/TLS connect timeout\n"));
soap_set_sender_error(soap, "Timeout", "SSL_connect failed in tcp_connect()", SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
else
{ soap_set_sender_error(soap, soap_ssl_error(soap, r), "SSL_connect error in tcp_connect()", SOAP_SSL_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
} while (!SSL_is_init_finished(soap->ssl));
/* Set SSL sockets to nonblocking */
SOAP_SOCKNONBLOCK(sk)
/* Check server credentials when required */
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION))
{ int err;
if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
{ soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL/TLS certificate presented by peer cannot be verified in tcp_connect()", SOAP_SSL_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if (!(soap->ssl_flags & SOAP_SSL_SKIP_HOST_CHECK))
{ X509_NAME *subj;
STACK_OF(CONF_VALUE) *val = NULL;
#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
GENERAL_NAMES *names = NULL;
#else
int ext_count;
#endif
int ok = 0;
X509 *peer = SSL_get_peer_certificate(soap->ssl);
if (!peer)
{ soap_set_sender_error(soap, "SSL/TLS error", "No SSL/TLS certificate was presented by the peer in tcp_connect()", SOAP_SSL_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
#if (OPENSSL_VERSION_NUMBER < 0x0090800fL)
ext_count = X509_get_ext_count(peer);
if (ext_count > 0)
{ int i;
for (i = 0; i < ext_count; i++)
{ X509_EXTENSION *ext = X509_get_ext(peer, i);
const char *ext_str = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext)));
if (ext_str && !strcmp(ext_str, "subjectAltName"))
{ X509V3_EXT_METHOD *meth = (X509V3_EXT_METHOD*)X509V3_EXT_get(ext);
unsigned char *data;
if (!meth)
break;
data = ext->value->data;
if (data)
{
#if (OPENSSL_VERSION_NUMBER > 0x00907000L)
void *ext_data;
if (meth->it)
ext_data = ASN1_item_d2i(NULL, &data, ext->value->length, ASN1_ITEM_ptr(meth->it));
else
{ /* OpenSSL is not portable at this point (?):
Some compilers appear to prefer
meth->d2i(NULL, (const unsigned char**)&data, ...
and others prefer
meth->d2i(NULL, &data, ext->value->length);
*/
ext_data = meth->d2i(NULL, &data, ext->value->length);
}
if (ext_data)
val = meth->i2v(meth, ext_data, NULL);
else
val = NULL;
if (meth->it)
ASN1_item_free((ASN1_VALUE*)ext_data, ASN1_ITEM_ptr(meth->it));
else
meth->ext_free(ext_data);
#else
void *ext_data = meth->d2i(NULL, &data, ext->value->length);
if (ext_data)
val = meth->i2v(meth, ext_data, NULL);
meth->ext_free(ext_data);
#endif
if (val)
{ int j;
for (j = 0; j < sk_CONF_VALUE_num(val); j++)
{ CONF_VALUE *nval = sk_CONF_VALUE_value(val, j);
if (nval && !strcmp(nval->name, "DNS") && !strcmp(nval->value, host))
{ ok = 1;
break;
}
}
sk_CONF_VALUE_pop_free(val, X509V3_conf_free);
}
}
}
if (ok)
break;
}
}
#else
names = (GENERAL_NAMES*)X509_get_ext_d2i(peer, NID_subject_alt_name, NULL, NULL);
if (names)
{ val = i2v_GENERAL_NAMES(NULL, names, val);
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
}
if (val)
{ int j;
for (j = 0; j < sk_CONF_VALUE_num(val); j++)
{ CONF_VALUE *nval = sk_CONF_VALUE_value(val, j);
if (nval && !strcmp(nval->name, "DNS") && !strcmp(nval->value, host))
{ ok = 1;
break;
}
}
sk_CONF_VALUE_pop_free(val, X509V3_conf_free);
}
#endif
if (!ok && (subj = X509_get_subject_name(peer)))
{ int i = -1;
do
{ ASN1_STRING *name;
i = X509_NAME_get_index_by_NID(subj, NID_commonName, i);
if (i == -1)
break;
name = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(subj, i));
if (name)
{ if (!soap_tag_cmp(host, (const char*)M_ASN1_STRING_data(name)))
ok = 1;
else
{ unsigned char *tmp = NULL;
ASN1_STRING_to_UTF8(&tmp, name);
if (tmp)
{ if (!soap_tag_cmp(host, (const char*)tmp))
ok = 1;
else if (tmp[0] == '*') /* wildcard domain */
{ const char *t = strchr(host, '.');
if (t && !soap_tag_cmp(t, (const char*)tmp+1))
ok = 1;
}
OPENSSL_free(tmp);
}
}
}
} while (!ok);
}
X509_free(peer);
if (!ok)
{ soap_set_sender_error(soap, "SSL/TLS error", "SSL/TLS certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
}
#endif
#ifdef WITH_GNUTLS
soap->ssl_flags |= SOAP_SSL_CLIENT;
if (!soap->session && (soap->error = soap->fsslauth(soap)))
{ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
gnutls_transport_set_ptr(soap->session, (gnutls_transport_ptr_t)(long)sk);
/* Set SSL sockets to non-blocking */
if (soap->connect_timeout)
{ SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->connect_timeout;
}
else
SOAP_SOCKBLOCK(sk)
if (retries <= 0)
retries = 100; /* timeout: 10 sec retries, 100 times 0.1 sec */
while ((r = gnutls_handshake(soap->session)))
{ int s;
/* GNUTLS repeat handhake when GNUTLS_E_AGAIN */
if (retries-- <= 0)
break;
if (r == GNUTLS_E_AGAIN || r == GNUTLS_E_INTERRUPTED)
{ if (!gnutls_record_get_direction(soap->session))
s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0)
break;
}
else
{ soap->errnum = soap_socket_errno(sk);
break;
}
}
if (r)
{ soap_set_sender_error(soap, soap_ssl_error(soap, r), "SSL/TLS handshake failed", SOAP_SSL_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION))
{ const char *err = ssl_verify(soap, host);
if (err)
{ soap->fclosesocket(soap, sk);
soap->error = soap_set_sender_error(soap, "SSL/TLS error", err, SOAP_SSL_ERROR);
return SOAP_INVALID_SOCKET;
}
}
#endif
#else
soap->fclosesocket(soap, sk);
soap->error = SOAP_SSL_ERROR;
return SOAP_INVALID_SOCKET;
#endif
}
if (soap->recv_timeout || soap->send_timeout)
SOAP_SOCKNONBLOCK(sk)
else
SOAP_SOCKBLOCK(sk)
return sk;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout)
{ int r;
struct timeval tv;
fd_set fd[3], *rfd, *sfd, *efd;
int retries = 0;
int eintr = SOAP_MAXEINTR;
soap->errnum = 0;
#ifndef WIN32
#if !defined(FD_SETSIZE) || defined(__QNX__) || defined(QNX)
/* no FD_SETSIZE or select() is not MT safe on some QNX: always poll */
if (1)
#else
/* if fd max set size exceeded, use poll() */
if ((int)sk >= (int)FD_SETSIZE)
#endif
#ifdef HAVE_POLL
{ struct pollfd pollfd;
pollfd.fd = (int)sk;
pollfd.events = 0;
if (flags & SOAP_TCP_SELECT_RCV)
pollfd.events |= POLLIN;
if (flags & SOAP_TCP_SELECT_SND)
pollfd.events |= POLLOUT;
if (flags & SOAP_TCP_SELECT_ERR)
pollfd.events |= POLLERR;
if (timeout <= 0)
timeout /= -1000; /* -usec -> ms */
else
{ retries = timeout - 1;
timeout = 1000;
}
do
{ r = poll(&pollfd, 1, timeout);
if (r < 0 && (soap->errnum = soap_socket_errno(sk)) == SOAP_EINTR && eintr--)
continue;
} while (r == 0 && retries--);
if (r > 0)
{ r = 0;
if ((flags & SOAP_TCP_SELECT_RCV) && (pollfd.revents & POLLIN))
r |= SOAP_TCP_SELECT_RCV;
if ((flags & SOAP_TCP_SELECT_SND) && (pollfd.revents & POLLOUT))
r |= SOAP_TCP_SELECT_SND;
if ((flags & SOAP_TCP_SELECT_ERR) && (pollfd.revents & POLLERR))
r |= SOAP_TCP_SELECT_ERR;
}
return r;
}
#else
{ soap->error = SOAP_FD_EXCEEDED;
return -1;
}
#endif
#endif
if (timeout > 0)
retries = timeout - 1;
do
{ rfd = sfd = efd = NULL;
if (flags & SOAP_TCP_SELECT_RCV)
{ rfd = &fd[0];
FD_ZERO(rfd);
FD_SET(sk, rfd);
}
if (flags & SOAP_TCP_SELECT_SND)
{ sfd = &fd[1];
FD_ZERO(sfd);
FD_SET(sk, sfd);
}
if (flags & SOAP_TCP_SELECT_ERR)
{ efd = &fd[2];
FD_ZERO(efd);
FD_SET(sk, efd);
}
if (timeout <= 0)
{ tv.tv_sec = -timeout / 1000000;
tv.tv_usec = -timeout % 1000000;
}
else
{ tv.tv_sec = 1;
tv.tv_usec = 0;
}
r = select((int)sk + 1, rfd, sfd, efd, &tv);
if (r < 0 && (soap->errnum = soap_socket_errno(sk)) == SOAP_EINTR && eintr--)
continue;
} while (r == 0 && retries--);
if (r > 0)
{ r = 0;
if ((flags & SOAP_TCP_SELECT_RCV) && FD_ISSET(sk, rfd))
r |= SOAP_TCP_SELECT_RCV;
if ((flags & SOAP_TCP_SELECT_SND) && FD_ISSET(sk, sfd))
r |= SOAP_TCP_SELECT_SND;
if ((flags & SOAP_TCP_SELECT_ERR) && FD_ISSET(sk, efd))
r |= SOAP_TCP_SELECT_ERR;
}
return r;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static SOAP_SOCKET
tcp_accept(struct soap *soap, SOAP_SOCKET s, struct sockaddr *a, int *n)
{ SOAP_SOCKET sk;
(void)soap;
sk = accept(s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
#ifdef SOCKET_CLOSE_ON_EXEC
#ifdef WIN32
#ifndef UNDER_CE
SetHandleInformation((HANDLE)sk, HANDLE_FLAG_INHERIT, 0);
#endif
#else
fcntl(sk, F_SETFD, FD_CLOEXEC);
#endif
#endif
return sk;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_disconnect(struct soap *soap)
{
#ifdef WITH_OPENSSL
if (soap->ssl)
{ int r, s = 0;
if (soap->session)
{ SSL_SESSION_free(soap->session);
soap->session = NULL;
}
if (*soap->host)
{ soap->session = SSL_get1_session(soap->ssl);
if (soap->session)
{ strcpy(soap->session_host, soap->host);
soap->session_port = soap->port;
}
}
r = SSL_shutdown(soap->ssl);
/* SSL shutdown does not work when reads are pending, non-blocking */
if (r == 0)
{ while (SSL_want_read(soap->ssl))
{ if (SSL_read(soap->ssl, NULL, 0)
|| soap_socket_errno(soap->socket) != SOAP_EAGAIN)
{ r = SSL_shutdown(soap->ssl);
break;
}
}
}
if (r == 0)
{ if (soap_valid_socket(soap->socket))
{ if (!soap->fshutdownsocket(soap, soap->socket, SOAP_SHUT_WR))
{
#if !defined(WITH_LEAN) && !defined(WIN32)
/*
wait up to 5 seconds for close_notify to be sent by peer (if peer not
present, this avoids calling SSL_shutdown() which has a lengthy return
timeout)
*/
r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, 5);
if (r <= 0)
{ soap->errnum = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connection lost...\n"));
soap->fclosesocket(soap, soap->socket);
soap->socket = SOAP_INVALID_SOCKET;
ERR_remove_state(0);
SSL_free(soap->ssl);
soap->ssl = NULL;
return SOAP_OK;
}
#else
r = SSL_shutdown(soap->ssl);
#endif
}
}
}
if (r != 1)
{ s = ERR_get_error();
if (s)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r)));
if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP))
{ soap->fclosesocket(soap, soap->socket);
soap->socket = SOAP_INVALID_SOCKET;
}
}
}
SSL_free(soap->ssl);
soap->ssl = NULL;
if (s)
return SOAP_SSL_ERROR;
ERR_remove_state(0);
}
#endif
#ifdef WITH_GNUTLS
if (soap->session)
{ gnutls_bye(soap->session, GNUTLS_SHUT_RDWR);
gnutls_deinit(soap->session);
soap->session = NULL;
}
#endif
if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP))
{ soap->fshutdownsocket(soap, soap->socket, SOAP_SHUT_RDWR);
soap->fclosesocket(soap, soap->socket);
soap->socket = SOAP_INVALID_SOCKET;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_closesocket(struct soap *soap, SOAP_SOCKET sk)
{ (void)soap;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket=%d\n", (int)sk));
return soap_closesocket(sk);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET sk, int how)
{ (void)soap;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket=%d how=%d\n", (int)sk, how));
return shutdown(sk, how);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
SOAP_FMAC1
SOAP_SOCKET
SOAP_FMAC2
soap_bind(struct soap *soap, const char *host, int port, int backlog)
{
#ifdef WITH_IPV6
struct addrinfo *addrinfo = NULL;
struct addrinfo hints;
struct addrinfo res;
int err;
#ifdef WITH_NO_IPV6_V6ONLY
int unset = 0;
#endif
#endif
#ifndef WITH_LEAN
#ifndef WIN32
int len = SOAP_BUFLEN;
#else
int len = SOAP_BUFLEN + 1; /* speeds up windows xfer */
#endif
int set = 1;
#endif
if (soap_valid_socket(soap->master))
{ soap->fclosesocket(soap, soap->master);
soap->master = SOAP_INVALID_SOCKET;
}
soap->socket = SOAP_INVALID_SOCKET;
soap->errmode = 1;
if (tcp_init(soap))
{ soap_set_receiver_error(soap, tcp_error(soap), "TCP init failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#ifdef WITH_IPV6
memset((void*)&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
hints.ai_socktype = SOCK_DGRAM;
else
#endif
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
soap->errmode = 2;
err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
if (err || !addrinfo)
{ soap_set_receiver_error(soap, SOAP_GAI_STRERROR(err), "getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
res = *addrinfo;
memcpy(&soap->peer, addrinfo->ai_addr, addrinfo->ai_addrlen);
soap->peerlen = addrinfo->ai_addrlen;
res.ai_addr = (struct sockaddr*)&soap->peer;
res.ai_addrlen = soap->peerlen;
freeaddrinfo(addrinfo);
soap->master = (int)socket(res.ai_family, res.ai_socktype, res.ai_protocol);
#else
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
soap->master = (int)socket(AF_INET, SOCK_DGRAM, 0);
else
#endif
soap->master = (int)socket(AF_INET, SOCK_STREAM, 0);
#endif
soap->errmode = 0;
if (!soap_valid_socket(soap->master))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
soap->port = port;
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
soap->socket = soap->master;
#endif
#ifdef SOCKET_CLOSE_ON_EXEC
#ifdef WIN32
#ifndef UNDER_CE
SetHandleInformation((HANDLE)soap->master, HANDLE_FLAG_INHERIT, 0);
#endif
#else
fcntl(soap->master, F_SETFD, 1);
#endif
#endif
#ifndef WITH_LEAN
#if 1
if (soap->bind_flags && setsockopt(soap->master, SOL_SOCKET, soap->bind_flags, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#else //add by duke 2020.2.19
int optval=1;
printf(" %s:%s SO_REUSEADDR \n",__FILE__,__FUNCTION__);
if (setsockopt(soap->master,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval)) < 0)
{
soap->errnum = soap_socket_errno(soap->master);
//DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
soap_closesock(soap);
soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR);
// return SOAP_INVALID_SOCKET;
}
//add end
#endif
if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && (!((soap->imode | soap->omode) & SOAP_IO_UDP)) && setsockopt(soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
if (setsockopt(soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
if (setsockopt(soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#ifdef TCP_NODELAY
if (!(soap->omode & SOAP_IO_UDP) && setsockopt(soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#endif
#endif
#ifdef WITH_IPV6
#ifdef WITH_IPV6_V6ONLY
if (setsockopt(soap->master, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt set IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#endif
#ifdef WITH_NO_IPV6_V6ONLY
if (setsockopt(soap->master, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&unset, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt unset IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#endif
soap->errmode = 0;
if (bind(soap->master, res.ai_addr, (int)res.ai_addrlen))
{ soap->errnum = soap_socket_errno(soap->master);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
soap_closesock(soap);
soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#else
soap->peerlen = sizeof(soap->peer);
memset((void*)&soap->peer, 0, sizeof(soap->peer));
soap->peer.sin_family = AF_INET;
soap->errmode = 2;
if (host)
{ if (soap->fresolve(soap, host, &soap->peer.sin_addr))
{ soap_set_receiver_error(soap, tcp_error(soap), "get host by name failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
}
else
soap->peer.sin_addr.s_addr = htonl(INADDR_ANY);
soap->peer.sin_port = htons((short)port);
soap->errmode = 0;
if (bind(soap->master, (struct sockaddr*)&soap->peer, (int)soap->peerlen))
{ soap->errnum = soap_socket_errno(soap->master);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
soap_closesock(soap);
soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#endif
if (!(soap->omode & SOAP_IO_UDP) && listen(soap->master, backlog))
{ soap->errnum = soap_socket_errno(soap->master);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
soap_closesock(soap);
soap_set_receiver_error(soap, tcp_error(soap), "listen failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
return soap->master;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_poll(struct soap *soap)
{
#ifndef WITH_LEAN
register int r;
if (soap_valid_socket(soap->socket))
{ r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_ALL, 0);
if (r > 0 && (r & SOAP_TCP_SELECT_ERR))
r = -1;
}
else if (soap_valid_socket(soap->master))
r = tcp_select(soap, soap->master, SOAP_TCP_SELECT_SND, 0);
else
return SOAP_OK; /* OK when no socket! */
if (r > 0)
{
#ifdef WITH_OPENSSL
if (soap->imode & SOAP_ENC_SSL)
{
if (soap_valid_socket(soap->socket)
&& (r & SOAP_TCP_SELECT_SND)
&& (!(r & SOAP_TCP_SELECT_RCV)
|| SSL_peek(soap->ssl, soap->tmpbuf, 1) > 0))
return SOAP_OK;
}
else
#endif
{ int t;
if (soap_valid_socket(soap->socket)
&& (r & SOAP_TCP_SELECT_SND)
&& (!(r & SOAP_TCP_SELECT_RCV)
|| recv(soap->socket, (char*)&t, 1, MSG_PEEK) > 0))
return SOAP_OK;
}
}
else if (r < 0)
{ if ((soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno(soap->master) != SOAP_EINTR)
{ soap_set_receiver_error(soap, tcp_error(soap), "select failed in soap_poll()", SOAP_TCP_ERROR);
return soap->error = SOAP_TCP_ERROR;
}
}
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Polling: other end down on socket=%d select=%d\n", soap->socket, r));
return SOAP_EOF;
#else
return SOAP_OK;
#endif
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
SOAP_FMAC1
SOAP_SOCKET
SOAP_FMAC2
soap_accept(struct soap *soap)
{ int n = (int)sizeof(soap->peer);
register int err;
#ifndef WITH_LEAN
#ifndef WIN32
int len = SOAP_BUFLEN;
#else
int len = SOAP_BUFLEN + 1; /* speeds up windows xfer */
#endif
int set = 1;
#endif
soap->error = SOAP_OK;
memset((void*)&soap->peer, 0, sizeof(soap->peer));
soap->socket = SOAP_INVALID_SOCKET;
soap->errmode = 0;
soap->keep_alive = 0;
if (!soap_valid_socket(soap->master))
{ soap->errnum = 0;
soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
return soap->socket = soap->master;
#endif
for (;;)
{ if (soap->accept_timeout || soap->send_timeout || soap->recv_timeout)
{ for (;;)
{ register int r;
r = tcp_select(soap, soap->master, SOAP_TCP_SELECT_ALL, soap->accept_timeout ? soap->accept_timeout : 60);
if (r > 0)
break;
if (!r && soap->accept_timeout)
{ soap_set_receiver_error(soap, "Timeout", "accept failed in soap_accept()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
if (r < 0)
{ r = soap->errnum;
if (r != SOAP_EINTR)
{ soap_closesock(soap);
soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
}
}
}
if (soap->accept_timeout)
SOAP_SOCKNONBLOCK(soap->master)
else
SOAP_SOCKBLOCK(soap->master)
soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n);
soap->peerlen = (size_t)n;
if (soap_valid_socket(soap->socket))
{
#ifdef WITH_IPV6
unsigned int ip1, ip2, ip3, ip4;
char port[16];
getnameinfo((struct sockaddr*)&soap->peer, n, soap->host, sizeof(soap->host), port, 16, NI_NUMERICHOST | NI_NUMERICSERV);
sscanf(soap->host, "%u.%u.%u.%u", &ip1, &ip2, &ip3, &ip4);
soap->ip = (unsigned long)ip1 << 24 | (unsigned long)ip2 << 16 | (unsigned long)ip3 << 8 | (unsigned long)ip4;
soap->port = soap_strtol(port, NULL, 10);
#else
soap->ip = ntohl(soap->peer.sin_addr.s_addr);
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->host, sizeof(soap->host), "%u.%u.%u.%u", (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
#else
sprintf(soap->host, "%u.%u.%u.%u", (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
#endif
soap->port = (int)ntohs(soap->peer.sin_port); /* does not return port number on some systems */
#endif
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket=%d at port=%d from IP='%s'\n", soap->socket, soap->port, soap->host));
#ifndef WITH_LEAN
if (soap->accept_flags == SO_LINGER)
{ struct linger linger;
memset((void*)&linger, 0, sizeof(linger));
linger.l_onoff = 1;
linger.l_linger = soap->linger_time;
if (setsockopt(soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
{ soap->errnum = soap_socket_errno(soap->socket);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
}
else if (soap->accept_flags && setsockopt(soap->socket, SOL_SOCKET, soap->accept_flags, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->socket);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->socket);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
if (setsockopt(soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->socket);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
if (setsockopt(soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->socket);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
#ifdef TCP_NODELAY
if (setsockopt(soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->socket);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
#endif
#endif
soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
if (soap->send_timeout || soap->recv_timeout)
SOAP_SOCKNONBLOCK(soap->socket)
else
SOAP_SOCKBLOCK(soap->socket)
return soap->socket;
}
err = soap_socket_errno(soap->socket);
if (err != 0 && err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host));
soap->errnum = err;
soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
}
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_closesock(struct soap *soap)
{ register int status = soap->error;
#ifndef WITH_LEANER
if (status) /* close on error: attachment state is not to be trusted */
{ soap->mime.first = NULL;
soap->mime.last = NULL;
soap->dime.first = NULL;
soap->dime.last = NULL;
}
#endif
if (soap->fdisconnect && (soap->error = soap->fdisconnect(soap)))
return soap->error;
if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive)
{ if (soap->fclose && (soap->error = soap->fclose(soap)))
return soap->error;
soap->keep_alive = 0;
}
#ifdef WITH_ZLIB
if (!(soap->mode & SOAP_MIME_POSTCHECK))
{ if (soap->zlib_state == SOAP_ZLIB_DEFLATE)
deflateEnd(soap->d_stream);
else if (soap->zlib_state == SOAP_ZLIB_INFLATE)
inflateEnd(soap->d_stream);
soap->zlib_state = SOAP_ZLIB_NONE;
}
#endif
return soap->error = status;
}
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_force_closesock(struct soap *soap)
{ soap->keep_alive = 0;
if (soap_valid_socket(soap->socket))
return soap_closesocket(soap->socket);
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_cleanup(struct soap *soap)
{ soap_done(soap);
#ifdef WIN32
if (!tcp_done)
return;
tcp_done = 0;
WSACleanup();
#endif
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_done(struct soap *soap)
{
#ifdef SOAP_DEBUG
int i;
#endif
if (soap_check_state(soap))
return;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Done with context%s\n", soap->state == SOAP_COPY ? " copy" : ""));
soap_free_temp(soap);
while (soap->clist)
{ struct soap_clist *p = soap->clist->next;
SOAP_FREE(soap, soap->clist);
soap->clist = p;
}
if (soap->state == SOAP_INIT)
soap->omode &= ~SOAP_IO_UDP; /* to force close the socket */
soap->keep_alive = 0; /* to force close the socket */
if (soap->master == soap->socket) /* do not close twice */
soap->master = SOAP_INVALID_SOCKET;
soap_closesock(soap);
#ifdef WITH_COOKIES
soap_free_cookies(soap);
#endif
while (soap->plugins)
{ register struct soap_plugin *p = soap->plugins->next;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Removing plugin '%s'\n", soap->plugins->id));
if (soap->plugins->fcopy || soap->state == SOAP_INIT)
soap->plugins->fdelete(soap, soap->plugins);
SOAP_FREE(soap, soap->plugins);
soap->plugins = p;
}
soap->fplugin = fplugin;
soap->fmalloc = NULL;
#ifndef WITH_NOHTTP
soap->fpost = http_post;
soap->fget = http_get;
soap->fput = http_405;
soap->fdel = http_405;
soap->fopt = http_200;
soap->fhead = http_200;
soap->fform = NULL;
soap->fposthdr = http_post_header;
soap->fresponse = http_response;
soap->fparse = http_parse;
soap->fparsehdr = http_parse_header;
#endif
soap->fheader = NULL;
#ifndef WITH_NOIO
#ifndef WITH_IPV6
soap->fresolve = tcp_gethost;
#else
soap->fresolve = NULL;
#endif
soap->faccept = tcp_accept;
soap->fopen = tcp_connect;
soap->fclose = tcp_disconnect;
soap->fclosesocket = tcp_closesocket;
soap->fshutdownsocket = tcp_shutdownsocket;
soap->fsend = fsend;
soap->frecv = frecv;
soap->fpoll = soap_poll;
#else
soap->fopen = NULL;
soap->fclose = NULL;
soap->fpoll = NULL;
#endif
#ifndef WITH_LEANER
soap->feltbegin = NULL;
soap->feltendin = NULL;
soap->feltbegout = NULL;
soap->feltendout = NULL;
soap->fprepareinitsend = NULL;
soap->fprepareinitrecv = NULL;
soap->fpreparesend = NULL;
soap->fpreparerecv = NULL;
soap->fpreparefinalsend = NULL;
soap->fpreparefinalrecv = NULL;
soap->ffiltersend = NULL;
soap->ffilterrecv = NULL;
#endif
soap->fseterror = NULL;
soap->fignore = NULL;
soap->fserveloop = NULL;
#ifdef WITH_OPENSSL
if (soap->session)
{ SSL_SESSION_free(soap->session);
soap->session = NULL;
}
#endif
if (soap->state == SOAP_INIT)
{ if (soap_valid_socket(soap->master))
{ soap->fclosesocket(soap, soap->master);
soap->master = SOAP_INVALID_SOCKET;
}
}
#ifdef WITH_OPENSSL
if (soap->ssl)
{ SSL_free(soap->ssl);
soap->ssl = NULL;
}
if (soap->state == SOAP_INIT)
{ if (soap->ctx)
{ SSL_CTX_free(soap->ctx);
soap->ctx = NULL;
}
}
ERR_remove_state(0);
#endif
#ifdef WITH_GNUTLS
if (soap->state == SOAP_INIT)
{ if (soap->xcred)
{ gnutls_certificate_free_credentials(soap->xcred);
soap->xcred = NULL;
}
if (soap->acred)
{ gnutls_anon_free_client_credentials(soap->acred);
soap->acred = NULL;
}
if (soap->cache)
{ gnutls_priority_deinit(soap->cache);
soap->cache = NULL;
}
if (soap->dh_params)
{ gnutls_dh_params_deinit(soap->dh_params);
soap->dh_params = NULL;
}
if (soap->rsa_params)
{ gnutls_rsa_params_deinit(soap->rsa_params);
soap->rsa_params = NULL;
}
}
if (soap->session)
{ gnutls_deinit(soap->session);
soap->session = NULL;
}
#endif
#ifdef WITH_C_LOCALE
# ifdef WIN32
_free_locale(soap->c_locale);
# else
freelocale(soap->c_locale);
# endif
#endif
#ifdef WITH_ZLIB
if (soap->d_stream)
{ SOAP_FREE(soap, (void*)soap->d_stream);
soap->d_stream = NULL;
}
if (soap->z_buf)
{ SOAP_FREE(soap, (void*)soap->z_buf);
soap->z_buf = NULL;
}
#endif
#ifdef SOAP_DEBUG
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free logfiles\n"));
for (i = 0; i < SOAP_MAXLOGS; i++)
{ if (soap->logfile[i])
{ SOAP_FREE(soap, (void*)soap->logfile[i]);
soap->logfile[i] = NULL;
}
soap_close_logfile(soap, i);
}
soap->state = SOAP_NONE;
#endif
#ifdef SOAP_MEM_DEBUG
soap_free_mht(soap);
#endif
}
#endif
/******************************************************************************\
*
* HTTP
*
\******************************************************************************/
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_parse(struct soap *soap)
{ char header[SOAP_HDRLEN], *s;
unsigned short httpcmd = 0;
int status = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n"));
*soap->endpoint = '\0';
#ifdef WITH_NTLM
if (!soap->ntlm_challenge)
#endif
{ soap->userid = NULL;
soap->passwd = NULL;
soap->authrealm = NULL;
}
#ifdef WITH_NTLM
soap->ntlm_challenge = NULL;
#endif
soap->proxy_from = NULL;
do
{ soap->length = 0;
soap->http_content = NULL;
soap->action = NULL;
soap->status = 0;
soap->body = 1;
if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
{ if (soap->error == SOAP_EOF)
return SOAP_EOF;
return soap->error = 414;
}
if ((s = strchr(soap->msgbuf, ' ')))
{ soap->status = (unsigned short)soap_strtoul(s, &s, 10);
if (!soap_blank((soap_wchar)*s))
soap->status = 0;
}
else
soap->status = 0;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP status: %s\n", soap->msgbuf));
for (;;)
{ if (soap_getline(soap, header, SOAP_HDRLEN))
{ if (soap->error == SOAP_EOF)
{ soap->error = SOAP_OK;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "EOF in HTTP header, continue anyway\n"));
break;
}
return soap->error;
}
if (!*header)
break;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP header: %s\n", header));
s = strchr(header, ':');
if (s)
{ char *t;
*s = '\0';
do s++;
while (*s && *s <= 32);
if (*s == '"')
s++;
t = s + strlen(s) - 1;
while (t > s && *t <= 32)
t--;
if (t >= s && *t == '"')
t--;
t[1] = '\0';
if ((soap->error = soap->fparsehdr(soap, header, s)))
{ if (soap->error < SOAP_STOP)
return soap->error;
status = soap->error;
soap->error = SOAP_OK;
}
}
}
} while (soap->status == 100);
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing, status = %d\n", soap->status));
s = strstr(soap->msgbuf, "HTTP/");
if (s && s[7] != '1')
{ if (soap->keep_alive == 1)
soap->keep_alive = 0;
if (soap->status == 0 && (soap->omode & SOAP_IO) == SOAP_IO_CHUNK) /* soap->status == 0 for HTTP request */
soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE; /* HTTP 1.0 does not support chunked transfers */
}
if (soap->keep_alive < 0)
soap->keep_alive = 1;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Keep alive connection = %d\n", soap->keep_alive));
if (soap->status == 0)
{ size_t l = 0;
if (s)
{ if (!strncmp(soap->msgbuf, "POST ", l = 5))
httpcmd = 1;
else if (!strncmp(soap->msgbuf, "PUT ", l = 4))
httpcmd = 2;
else if (!strncmp(soap->msgbuf, "GET ", l = 4))
httpcmd = 3;
else if (!strncmp(soap->msgbuf, "DELETE ", l = 7))
httpcmd = 4;
else if (!strncmp(soap->msgbuf, "OPTIONS ", l = 8))
httpcmd = 5;
else if (!strncmp(soap->msgbuf, "HEAD ", l = 5))
httpcmd = 6;
}
if (s && httpcmd)
{ size_t m = strlen(soap->endpoint);
size_t n = m + (s - soap->msgbuf) - l - 1;
size_t k;
if (n >= sizeof(soap->endpoint))
n = sizeof(soap->endpoint) - 1;
if (m > n)
m = n;
k = n - m + 1;
if (k > sizeof(soap->path))
k = sizeof(soap->path);
strncpy(soap->path, soap->msgbuf + l, k);
soap->path[k - 1] = '\0';
if (*soap->path && *soap->path != '/')
*soap->endpoint = '\0';
strcat(soap->endpoint, soap->path);
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint));
if (httpcmd > 1)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP %s handler\n", soap->msgbuf));
switch (httpcmd)
{ case 2: soap->error = soap->fput(soap); break;
case 3: soap->error = soap->fget(soap); break;
case 4: soap->error = soap->fdel(soap); break;
case 5: soap->error = soap->fopt(soap); break;
case 6: soap->error = soap->fhead(soap); break;
default: soap->error = 405; break;
}
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP handler return = %d\n", soap->error));
if (soap->error == SOAP_OK)
soap->error = SOAP_STOP; /* prevents further processing */
return soap->error;
}
if (status)
return soap->error = status;
}
else if (status)
return soap->error = status;
else if (s)
return soap->error = 405;
return SOAP_OK;
}
#if 0
if (soap->length > 0 || (soap->http_content && (!soap->keep_alive || soap->recv_timeout)) || (soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
#endif
if (soap->body)
{ if ((soap->status >= 200 && soap->status <= 299) /* OK, Accepted, etc */
|| soap->status == 400 /* Bad Request */
|| soap->status == 500) /* Internal Server Error */
return SOAP_OK;
/* force close afterwards in soap_closesock() */
soap->keep_alive = 0;
#ifndef WITH_LEAN
/* read HTTP body for error details */
s = soap_get_http_body(soap, NULL);
if (s)
return soap_set_receiver_error(soap, soap->msgbuf, s, soap->status);
#endif
}
else if (soap->status >= 200 && soap->status <= 299)
return soap->error = soap->status;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP error %d\n", soap->status));
return soap_set_receiver_error(soap, "HTTP Error", soap->msgbuf, soap->status);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_parse_header(struct soap *soap, const char *key, const char *val)
{ if (!soap_tag_cmp(key, "Host"))
{
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
if (soap->imode & SOAP_ENC_SSL)
strcpy(soap->endpoint, "https://");
else
#endif
strcpy(soap->endpoint, "http://");
strncat(soap->endpoint, val, sizeof(soap->endpoint) - 8);
}
#ifndef WITH_LEANER
else if (!soap_tag_cmp(key, "Content-Type"))
{ const char *action;
soap->http_content = soap_strdup(soap, val);
if (soap_get_header_attribute(soap, val, "application/dime"))
soap->imode |= SOAP_ENC_DIME;
else if (soap_get_header_attribute(soap, val, "multipart/related")
|| soap_get_header_attribute(soap, val, "multipart/form-data"))
{ soap->mime.boundary = soap_strdup(soap, soap_get_header_attribute(soap, val, "boundary"));
soap->mime.start = soap_strdup(soap, soap_get_header_attribute(soap, val, "start"));
soap->imode |= SOAP_ENC_MIME;
}
action = soap_get_header_attribute(soap, val, "action");
if (action)
{ if (*action == '"')
{ soap->action = soap_strdup(soap, action + 1);
if (*soap->action)
soap->action[strlen(soap->action) - 1] = '\0';
}
else
soap->action = soap_strdup(soap, action);
}
}
#endif
else if (!soap_tag_cmp(key, "Content-Length"))
{ soap->length = soap_strtoul(val, NULL, 10);
if (!soap->length)
soap->body = 0;
}
else if (!soap_tag_cmp(key, "Content-Encoding"))
{ if (!soap_tag_cmp(val, "deflate"))
#ifdef WITH_ZLIB
soap->zlib_in = SOAP_ZLIB_DEFLATE;
#else
return SOAP_ZLIB_ERROR;
#endif
else if (!soap_tag_cmp(val, "gzip"))
#ifdef WITH_GZIP
soap->zlib_in = SOAP_ZLIB_GZIP;
#else
return SOAP_ZLIB_ERROR;
#endif
}
#ifdef WITH_ZLIB
else if (!soap_tag_cmp(key, "Accept-Encoding"))
{
#ifdef WITH_GZIP
if (strchr(val, '*') || soap_get_header_attribute(soap, val, "gzip"))
soap->zlib_out = SOAP_ZLIB_GZIP;
else
#endif
if (strchr(val, '*') || soap_get_header_attribute(soap, val, "deflate"))
soap->zlib_out = SOAP_ZLIB_DEFLATE;
else
soap->zlib_out = SOAP_ZLIB_NONE;
}
#endif
else if (!soap_tag_cmp(key, "Transfer-Encoding"))
{ soap->imode &= ~SOAP_IO;
if (!soap_tag_cmp(val, "chunked"))
soap->imode |= SOAP_IO_CHUNK;
}
else if (!soap_tag_cmp(key, "Connection"))
{ if (!soap_tag_cmp(val, "keep-alive"))
soap->keep_alive = -soap->keep_alive;
else if (!soap_tag_cmp(val, "close"))
soap->keep_alive = 0;
}
#ifndef WITH_LEAN
else if (!soap_tag_cmp(key, "Authorization") || !soap_tag_cmp(key, "Proxy-Authorization"))
{
#ifdef WITH_NTLM
if (!soap_tag_cmp(val, "NTLM*"))
soap->ntlm_challenge = soap_strdup(soap, val + 4);
else
#endif
if (!soap_tag_cmp(val, "Basic *"))
{ int n;
char *s;
soap_base642s(soap, val + 6, soap->tmpbuf, sizeof(soap->tmpbuf) - 1, &n);
soap->tmpbuf[n] = '\0';
if ((s = strchr(soap->tmpbuf, ':')))
{ *s = '\0';
soap->userid = soap_strdup(soap, soap->tmpbuf);
soap->passwd = soap_strdup(soap, s + 1);
}
}
}
else if (!soap_tag_cmp(key, "WWW-Authenticate") || !soap_tag_cmp(key, "Proxy-Authenticate"))
{
#ifdef WITH_NTLM
if (!soap_tag_cmp(val, "NTLM*"))
soap->ntlm_challenge = soap_strdup(soap, val + 4);
else
#endif
soap->authrealm = soap_strdup(soap, soap_get_header_attribute(soap, val + 6, "realm"));
}
else if (!soap_tag_cmp(key, "Expect"))
{ if (!soap_tag_cmp(val, "100-continue"))
{ if ((soap->error = soap->fposthdr(soap, "HTTP/1.1 100 Continue", NULL))
|| (soap->error = soap->fposthdr(soap, NULL, NULL)))
return soap->error;
}
}
#endif
else if (!soap_tag_cmp(key, "SOAPAction"))
{ if (*val == '"')
{ soap->action = soap_strdup(soap, val + 1);
if (*soap->action)
soap->action[strlen(soap->action) - 1] = '\0';
}
else
soap->action = soap_strdup(soap, val);
}
else if (!soap_tag_cmp(key, "Location"))
{ strncpy(soap->endpoint, val, sizeof(soap->endpoint));
soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
}
else if (!soap_tag_cmp(key, "X-Forwarded-For"))
{ soap->proxy_from = soap_strdup(soap, val);
}
#ifdef WITH_COOKIES
else if (!soap_tag_cmp(key, "Cookie")
|| !soap_tag_cmp(key, "Cookie2")
|| !soap_tag_cmp(key, "Set-Cookie")
|| !soap_tag_cmp(key, "Set-Cookie2"))
{ soap_getcookies(soap, val);
}
#endif
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER)
#ifndef PALM_1
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_get_header_attribute(struct soap *soap, const char *line, const char *key)
{ register const char *s = line;
if (s)
{ while (*s)
{ register short flag;
s = soap_decode_key(soap->tmpbuf, sizeof(soap->tmpbuf), s);
flag = soap_tag_cmp(soap->tmpbuf, key);
s = soap_decode_val(soap->tmpbuf, sizeof(soap->tmpbuf), s);
if (!flag)
return soap->tmpbuf;
}
}
return NULL;
}
#endif
#endif
/******************************************************************************/
#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER)
#ifndef PALM_1
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_decode_key(char *buf, size_t len, const char *val)
{ return soap_decode(buf, len, val, "=,;");
}
#endif
#endif
/******************************************************************************/
#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER)
#ifndef PALM_1
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_decode_val(char *buf, size_t len, const char *val)
{ if (*val != '=')
{ *buf = '\0';
return val;
}
return soap_decode(buf, len, val + 1, ",;");
}
#endif
#endif
/******************************************************************************/
#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER)
#ifndef PALM_1
static const char*
soap_decode(char *buf, size_t len, const char *val, const char *sep)
{ const char *s;
char *t = buf;
size_t i = len;
for (s = val; *s; s++)
if (*s != ' ' && *s != '\t' && !strchr(sep, *s))
break;
if (len > 0)
{ if (*s == '"')
{ s++;
while (*s && *s != '"' && --i)
*t++ = *s++;
}
else
{ while (*s && !soap_blank((soap_wchar)*s) && !strchr(sep, *s) && --i)
{ if (*s == '%' && s[1] && s[2])
{ *t++ = ((s[1] >= 'A' ? (s[1] & 0x7) + 9 : s[1] - '0') << 4)
+ (s[2] >= 'A' ? (s[2] & 0x7) + 9 : s[2] - '0');
s += 3;
}
else
*t++ = *s++;
}
}
buf[len - 1] = '\0'; /* appease */
}
*t = '\0';
while (*s && !strchr(sep, *s))
s++;
return s;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static const char*
http_error(struct soap *soap, int status)
{ register const char *msg = SOAP_STR_EOS;
(void)soap;
#ifndef WITH_LEAN
msg = soap_code_str(h_http_error_codes, status);
if (!msg)
msg = SOAP_STR_EOS;
#endif
return msg;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_get(struct soap *soap)
{ (void)soap;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "HTTP GET request\n"));
return SOAP_GET_METHOD;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_405(struct soap *soap)
{ (void)soap;
return 405;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_200(struct soap *soap)
{ return soap_send_empty_response(soap, 200);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_post(struct soap *soap, const char *endpoint, const char *host, int port, const char *path, const char *action, size_t count)
{ register const char *s;
register int err;
switch (soap->status)
{ case SOAP_GET:
s = "GET";
break;
case SOAP_PUT:
s = "PUT";
break;
case SOAP_DEL:
s = "DELETE";
break;
case SOAP_CONNECT:
s = "CONNECT";
break;
default:
s = "POST";
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "HTTP %s to %s\n", s, endpoint ? endpoint : "(null)"));
#ifdef PALM
if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8))
#else
if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6)))
#endif
return SOAP_OK;
if (strlen(endpoint) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80
|| strlen(host) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80)
return soap->error = SOAP_EOM; /* prevent overrun (note that 'host' and 'soap->host' are substrings of 'endpoint') */
if (soap->status == SOAP_CONNECT)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s %s:%d HTTP/%s", s, soap->host, soap->port, soap->http_version);
#else
sprintf(soap->tmpbuf, "%s %s:%d HTTP/%s", s, soap->host, soap->port, soap->http_version);
#endif
}
else if (soap->proxy_host && endpoint)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s %s HTTP/%s", s, endpoint, soap->http_version);
#else
sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version);
#endif
}
else
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : path), soap->http_version);
#else
sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : path), soap->http_version);
#endif
}
if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
return err;
#ifdef WITH_OPENSSL
if ((soap->ssl && port != 443) || (!soap->ssl && port != 80))
#else
if (port != 80)
#endif
{
#ifdef WITH_IPV6
if (*host != '[' && strchr(host, ':'))
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "[%s]:%d", host, port); /* RFC 2732 */
#else
sprintf(soap->tmpbuf, "[%s]:%d", host, port); /* RFC 2732 */
#endif
}
else
#endif
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s:%d", host, port);
#else
sprintf(soap->tmpbuf, "%s:%d", host, port);
#endif
}
}
else
{
#ifdef WITH_IPV6
if (*host != '[' && strchr(host, ':'))
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "[%s]", host); /* RFC 2732 */
#else
sprintf(soap->tmpbuf, "[%s]", host); /* RFC 2732 */
#endif
}
else
#endif
strcpy(soap->tmpbuf, host);
}
if ((err = soap->fposthdr(soap, "Host", soap->tmpbuf)))
return err;
if ((err = soap->fposthdr(soap, "User-Agent", "gSOAP/2.8")))
return err;
if ((err = soap_puthttphdr(soap, SOAP_OK, count)))
return err;
#ifdef WITH_ZLIB
#ifdef WITH_GZIP
if ((err = soap->fposthdr(soap, "Accept-Encoding", "gzip, deflate")))
#else
if ((err = soap->fposthdr(soap, "Accept-Encoding", "deflate")))
#endif
return err;
#endif
#ifndef WITH_LEAN
#ifdef WITH_NTLM
if (soap->ntlm_challenge && strlen(soap->ntlm_challenge) + 6 < sizeof(soap->tmpbuf))
{ if (*soap->ntlm_challenge)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "NTLM %s", soap->ntlm_challenge);
#else
sprintf(soap->tmpbuf, "NTLM %s", soap->ntlm_challenge);
#endif
if (soap->proxy_host)
{ if ((err = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
return err;
}
else if ((err = soap->fposthdr(soap, "Authorization", soap->tmpbuf)))
return err;
}
}
else
{
#endif
if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761)
{ strcpy(soap->tmpbuf, "Basic ");
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf + 262, sizeof(soap->tmpbuf) - 262, "%s:%s", soap->userid, soap->passwd);
#else
sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd);
#endif
soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262));
if ((err = soap->fposthdr(soap, "Authorization", soap->tmpbuf)))
return err;
}
if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
{ strcpy(soap->tmpbuf, "Basic ");
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf + 262, sizeof(soap->tmpbuf) - 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
#else
sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
#endif
soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262));
if ((err = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
return err;
}
#ifdef WITH_NTLM
}
#endif
#endif
#ifdef WITH_COOKIES
#ifdef WITH_OPENSSL
if (soap_putcookies(soap, host, path, soap->ssl != NULL))
return soap->error;
#else
if (soap_putcookies(soap, host, path, 0))
return soap->error;
#endif
#endif
if (action && soap->status != SOAP_GET && soap->status != SOAP_DEL)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "\"%s\"", action);
#else
sprintf(soap->tmpbuf, "\"%s\"", strlen(action) < sizeof(soap->tmpbuf) - 3 ? action : SOAP_STR_EOS);
#endif
if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf)))
return err;
}
return soap->fposthdr(soap, NULL, NULL);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_send_header(struct soap *soap, const char *s)
{ register const char *t;
do
{ t = strchr(s, '\n'); /* disallow \n in HTTP headers */
if (!t)
t = s + strlen(s);
if (soap_send_raw(soap, s, t - s))
return soap->error;
s = t + 1;
} while (*t);
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_post_header(struct soap *soap, const char *key, const char *val)
{ if (key)
{ if (http_send_header(soap, key))
return soap->error;
if (val && (soap_send_raw(soap, ": ", 2) || http_send_header(soap, val)))
return soap->error;
}
return soap_send_raw(soap, "\r\n", 2);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_response(struct soap *soap, int status, size_t count)
{ register int err;
char http[10];
int code = status;
const char *line;
#ifdef WMW_RPM_IO
if (soap->rpmreqid)
httpOutputEnable(soap->rpmreqid);
#endif
if (!soap->http_version || strlen(soap->http_version) > 4)
return soap->error = SOAP_EOM;
#ifdef WMW_RPM_IO
if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
#else
if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application (socket) or CGI (stdin/out)? */
#endif
{
#ifdef HAVE_SNPRINTF
soap_snprintf(http, sizeof(http), "HTTP/%s", soap->http_version);
#else
sprintf(http, "HTTP/%s", soap->http_version);
#endif
}
else
strcpy(http, "Status:");
if (!status || status == SOAP_HTML || status == SOAP_FILE)
{ if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK))
code = 200;
else
code = 202;
}
else if (status < 200 || status >= 600)
{ const char *s = *soap_faultcode(soap);
if (status >= SOAP_GET_METHOD && status <= SOAP_HTTP_METHOD)
code = 405;
else if (soap->version == 2 && (!s || !strcmp(s, "SOAP-ENV:Sender")))
code = 400;
else
code = 500;
}
line = http_error(soap, code);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "HTTP Status = %d %s\n", code, line));
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s %d %s", http, code, line);
#else
sprintf(soap->tmpbuf, "%s %d %s", http, code, line);
#endif
if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
return err;
#ifndef WITH_LEAN
if (status == 401)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "Basic realm=\"%s\"", (soap->authrealm && strlen(soap->authrealm) < sizeof(soap->tmpbuf) - 14) ? soap->authrealm : "gSOAP Web Service");
#else
sprintf(soap->tmpbuf, "Basic realm=\"%s\"", (soap->authrealm && strlen(soap->authrealm) < sizeof(soap->tmpbuf) - 14) ? soap->authrealm : "gSOAP Web Service");
#endif
if ((err = soap->fposthdr(soap, "WWW-Authenticate", soap->tmpbuf)))
return err;
}
else if ((status >= 301 && status <= 303) || status == 307)
{ if ((err = soap->fposthdr(soap, "Location", soap->endpoint)))
return err;
}
#endif
if ((err = soap->fposthdr(soap, "Server", "gSOAP/2.8"))
|| (err = soap_puthttphdr(soap, status, count)))
return err;
#ifdef WITH_COOKIES
if (soap_putsetcookies(soap))
return soap->error;
#endif
return soap->fposthdr(soap, NULL, NULL);
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_response(struct soap *soap, int status)
{ register size_t count;
if (!(soap->omode & (SOAP_ENC_XML | SOAP_IO_STORE /* this tests for chunking too */))
&& (status == SOAP_HTML || status == SOAP_FILE))
soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE;
soap->status = status;
count = soap_count_attachments(soap);
if (soap_begin_send(soap))
return soap->error;
#ifndef WITH_NOHTTP
if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML))
{ register int n = soap->mode;
soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
if ((n & SOAP_IO) != SOAP_IO_FLUSH)
soap->mode |= SOAP_IO_BUFFER;
if ((soap->error = soap->fresponse(soap, status, count)))
return soap->error;
#ifndef WITH_LEANER
if ((n & SOAP_IO) == SOAP_IO_CHUNK)
{ if (soap_flush(soap))
return soap->error;
}
#endif
soap->mode = n;
}
#endif
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_url(struct soap *soap, const char *s, const char *t)
{ if (!t || (*t != '/' && *t != '?') || strlen(s) + strlen(t) >= sizeof(soap->msgbuf))
return s;
strcpy(soap->msgbuf, s);
strcat(soap->msgbuf, t);
return soap->msgbuf;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
size_t
SOAP_FMAC2
soap_encode_url(const char *s, char *t, size_t len)
{ register int c;
register size_t n = len;
while ((c = *s++) && --n > 0)
{ if (c > ' ' && c < 128 && !strchr("()<>@,;:\\\"/[]?={}#!$&'*+", c))
*t++ = c;
else if (n > 2)
{ *t++ = '%';
*t++ = (c >> 4) + (c > 159 ? '7' : '0');
c &= 0xF;
*t++ = c + (c > 9 ? '7' : '0');
n -= 2;
}
else
break;
}
*t = '\0';
return len - n;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_encode_url_string(struct soap *soap, const char *s)
{ if (s)
{ size_t n = 3*strlen(s)+1;
char *t = (char*)soap_malloc(soap, n);
if (t)
{ soap_encode_url(s, t, n);
return t;
}
}
return SOAP_STR_EOS;
}
#endif
/******************************************************************************\
*
* HTTP Cookies
*
\******************************************************************************/
#ifdef WITH_COOKIES
/******************************************************************************/
SOAP_FMAC1
struct soap_cookie*
SOAP_FMAC2
soap_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
{ struct soap_cookie *p;
if (!domain)
domain = soap->cookie_domain;
if (!path)
path = soap->cookie_path;
if (!path)
path = SOAP_STR_EOS;
else if (*path == '/')
path++;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie='%s' domain='%s' path='%s'\n", name, domain ? domain : "(null)", path ? path : "(null)"));
for (p = soap->cookies; p; p = p->next)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s='%s' domain='%s' path='%s' env=%hd\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->env));
if (!strcmp(p->name, name)
&& p->domain
&& p->path
&& !strcmp(p->domain, domain)
&& (!*p->path || !strncmp(p->path, path, strlen(p->path))))
break;
}
return p;
}
/******************************************************************************/
SOAP_FMAC1
struct soap_cookie*
SOAP_FMAC2
soap_set_cookie(struct soap *soap, const char *name, const char *value, const char *domain, const char *path)
{ struct soap_cookie **p, *q;
int n;
if (!domain)
domain = soap->cookie_domain;
if (!path)
path = soap->cookie_path;
if (!path)
path = SOAP_STR_EOS;
else if (*path == '/')
path++;
q = soap_cookie(soap, name, domain, path);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set %scookie: %s='%s' domain='%s' path='%s'\n", q ? SOAP_STR_EOS : "new ", name, value ? value : "(null)", domain ? domain : "(null)", path ? path : "(null)"));
if (!q)
{ if ((q = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie))))
{ if ((q->name = (char*)SOAP_MALLOC(soap, strlen(name)+1)))
strcpy(q->name, name);
q->value = NULL;
q->domain = NULL;
q->path = NULL;
q->expire = 0;
q->maxage = -1;
q->version = 1;
q->secure = 0;
q->modified = 0;
for (p = &soap->cookies, n = soap->cookie_max; *p && n; p = &(*p)->next, n--)
if (!strcmp((*p)->name, name) && (*p)->path && path && strcmp((*p)->path, path) < 0)
break;
if (n)
{ q->next = *p;
*p = q;
}
else
{ SOAP_FREE(soap, q->name);
SOAP_FREE(soap, q);
q = NULL;
}
}
}
else
q->modified = 1;
if (q)
{ if (q->value)
{ if (!value || strcmp(value, q->value))
{ SOAP_FREE(soap, q->value);
q->value = NULL;
}
}
if (value && *value && !q->value && (q->value = (char*)SOAP_MALLOC(soap, strlen(value)+1)))
strcpy(q->value, value);
if (q->domain)
{ if (!domain || strcmp(domain, q->domain))
{ SOAP_FREE(soap, q->domain);
q->domain = NULL;
}
}
if (domain && !q->domain && (q->domain = (char*)SOAP_MALLOC(soap, strlen(domain)+1)))
strcpy(q->domain, domain);
if (q->path)
{ if (!path || strncmp(path, q->path, strlen(q->path)))
{ SOAP_FREE(soap, q->path);
q->path = NULL;
}
}
if (path && !q->path && (q->path = (char*)SOAP_MALLOC(soap, strlen(path)+1)))
strcpy(q->path, path);
q->session = 1;
q->env = 0;
}
return q;
}
/******************************************************************************/
SOAP_FMAC1
void
SOAP_FMAC2
soap_clr_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
{ struct soap_cookie **p, *q;
if (!domain)
domain = soap->cookie_domain;
if (!domain)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie='%s': cookie domain not set\n", name ? name : "(null)"));
return;
}
if (!path)
path = soap->cookie_path;
if (!path)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie='%s': cookie path not set\n", name ? name : "(null)"));
return;
}
if (*path == '/')
path++;
for (p = &soap->cookies, q = *p; q; q = *p)
{ if (!strcmp(q->name, name) && !strcmp(q->domain, domain) && !strncmp(q->path, path, strlen(q->path)))
{ if (q->value)
SOAP_FREE(soap, q->value);
if (q->domain)
SOAP_FREE(soap, q->domain);
if (q->path)
SOAP_FREE(soap, q->path);
*p = q->next;
SOAP_FREE(soap, q);
}
else
p = &q->next;
}
}
/******************************************************************************/
SOAP_FMAC1
char *
SOAP_FMAC2
soap_cookie_value(struct soap *soap, const char *name, const char *domain, const char *path)
{ struct soap_cookie *p;
if ((p = soap_cookie(soap, name, domain, path)))
return p->value;
return NULL;
}
/******************************************************************************/
SOAP_FMAC1
char *
SOAP_FMAC2
soap_env_cookie_value(struct soap *soap, const char *name, const char *domain, const char *path)
{ struct soap_cookie *p;
if ((p = soap_cookie(soap, name, domain, path)) && p->env)
return p->value;
return NULL;
}
/******************************************************************************/
SOAP_FMAC1
time_t
SOAP_FMAC2
soap_cookie_expire(struct soap *soap, const char *name, const char *domain, const char *path)
{ struct soap_cookie *p;
if ((p = soap_cookie(soap, name, domain, path)))
return p->expire;
return -1;
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_cookie_expire(struct soap *soap, const char *name, long expire, const char *domain, const char *path)
{ struct soap_cookie *p;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age=%ld: cookie='%s' domain='%s' path='%s'\n", expire, name, domain ? domain : "(null)", path ? path : "(null)"));
if ((p = soap_cookie(soap, name, domain, path)))
{ p->maxage = expire;
p->modified = 1;
return SOAP_OK;
}
return SOAP_ERR;
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
{ struct soap_cookie *p;
if ((p = soap_cookie(soap, name, domain, path)))
{ p->session = 1;
p->modified = 1;
return SOAP_OK;
}
return SOAP_ERR;
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_clr_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
{ struct soap_cookie *p;
if ((p = soap_cookie(soap, name, domain, path)))
{ p->session = 0;
p->modified = 1;
return SOAP_OK;
}
return SOAP_ERR;
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_putsetcookies(struct soap *soap)
{ struct soap_cookie *p;
char *s, tmp[4096];
const char *t;
for (p = soap->cookies; p; p = p->next)
{
if (p->modified
#ifdef WITH_OPENSSL
|| (!p->env && !soap->ssl == !p->secure)
#endif
)
{ s = tmp;
if (p->name)
s += soap_encode_url(p->name, s, tmp-s+4064);
if (p->value && *p->value)
{ *s++ = '=';
s += soap_encode_url(p->value, s, tmp-s+4064);
}
if (p->domain && (int)strlen(p->domain) < tmp-s+4064)
{ strcpy(s, ";Domain=");
strcat(s, p->domain);
}
else if (soap->cookie_domain && (int)strlen(soap->cookie_domain) < tmp-s+4064)
{ strcpy(s, ";Domain=");
strcat(s, soap->cookie_domain);
}
strcat(s, ";Path=/");
s += strlen(s);
if (p->path)
t = p->path;
else
t = soap->cookie_path;
if (t)
{ if (*t == '/')
t++;
if ((int)strlen(t) < tmp-s+4064)
{ if (strchr(t, '%')) /* already URL encoded? */
{ strcpy(s, t);
s += strlen(s);
}
else
s += soap_encode_url(t, s, tmp-s+4064);
}
}
if (p->version > 0 && s-tmp < 4060)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(s, 4096 - (s-tmp), ";Version=%u", p->version);
#else
sprintf(s, ";Version=%u", p->version);
#endif
s += strlen(s);
}
if (p->maxage >= 0 && s-tmp < 4060)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(s, 4096 - (s-tmp), ";Max-Age=%ld", p->maxage);
#else
sprintf(s, ";Max-Age=%ld", p->maxage);
#endif
s += strlen(s);
}
if (s-tmp < 4073
&& (p->secure
#ifdef WITH_OPENSSL
|| soap->ssl
#endif
))
strcpy(s, ";Secure");
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp));
if ((soap->error = soap->fposthdr(soap, "Set-Cookie", tmp)))
return soap->error;
}
}
return SOAP_OK;
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_putcookies(struct soap *soap, const char *domain, const char *path, int secure)
{ struct soap_cookie **p, *q;
unsigned int version = 0;
time_t now = time(NULL);
char *s, tmp[4096];
if (!domain || !path)
return SOAP_OK;
s = tmp;
p = &soap->cookies;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain='%s' path='%s'\n", domain, path));
if (*path == '/')
path++;
while ((q = *p))
{ if (q->expire && now > q->expire)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name));
SOAP_FREE(soap, q->name);
if (q->value)
SOAP_FREE(soap, q->value);
if (q->domain)
SOAP_FREE(soap, q->domain);
if (q->path)
SOAP_FREE(soap, q->path);
*p = q->next;
SOAP_FREE(soap, q);
}
else
{ int flag;
char *t = q->domain;
size_t n = 0;
if (!t)
flag = 1;
else
{ const char *r = strchr(t, ':');
if (r)
n = r - t;
else
n = strlen(t);
flag = !strncmp(t, domain, n);
}
/* domain-level cookies, cannot compile when WITH_NOIO set */
#ifndef WITH_NOIO
if (!flag)
{ struct hostent *hostent = gethostbyname((char*)domain);
if (hostent)
{ const char *r = strchr(hostent->h_name, '.');
if (!r)
r = hostent->h_name;
flag = !strncmp(t, r, n);
}
}
#endif
if (flag
&& (!q->path || !strncmp(q->path, path, strlen(q->path)))
&& (!q->secure || secure))
{ size_t n = 12;
if (q->name)
n += 3*strlen(q->name);
if (q->value && *q->value)
n += 3*strlen(q->value) + 1;
if (q->path && *q->path)
n += strlen(q->path) + 9;
if (q->domain)
n += strlen(q->domain) + 11;
if (tmp - s + n > sizeof(tmp))
{ if (s == tmp)
return SOAP_OK; /* HTTP header size overflow */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp));
if ((soap->error = soap->fposthdr(soap, "Cookie", tmp)))
return soap->error;
s = tmp;
}
else if (s != tmp)
{ strcat(s, " ");
s++;
}
if (q->version != version && s-tmp < 4060)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(s, 4096 - (s-tmp), "$Version=%u;", q->version);
#else
sprintf(s, "$Version=%u;", q->version);
#endif
version = q->version;
s += strlen(s);
}
if (q->name)
s += soap_encode_url(q->name, s, tmp+sizeof(tmp)-s-16);
if (q->value && *q->value)
{ *s++ = '=';
s += soap_encode_url(q->value, s, tmp+sizeof(tmp)-s-16);
}
if (q->path && (s-tmp) + strlen(q->path) < 4060)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(s, 4096 - (s-tmp), ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : q->path));
#else
sprintf(s, ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : q->path));
#endif
s += strlen(s);
}
if (q->domain && (s-tmp) + strlen(q->domain) < 4060)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(s, 4096 - (s-tmp), ";$Domain=\"%s\"", q->domain);
#else
sprintf(s, ";$Domain=\"%s\"", q->domain);
#endif
s += strlen(s);
}
}
p = &q->next;
}
}
if (s != tmp)
if ((soap->error = soap->fposthdr(soap, "Cookie", tmp)))
return soap->error;
return SOAP_OK;
}
/******************************************************************************/
SOAP_FMAC1
void
SOAP_FMAC2
soap_getcookies(struct soap *soap, const char *val)
{ struct soap_cookie *p = NULL, *q;
const char *s;
char *t, tmp[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
char *domain = NULL;
char *path = NULL;
unsigned int version = 0;
time_t now = time(NULL);
if (!val)
return;
s = val;
while (*s)
{ s = soap_decode_key(tmp, sizeof(tmp), s);
if (!soap_tag_cmp(tmp, "$Version"))
{ if ((s = soap_decode_val(tmp, sizeof(tmp), s)))
{ if (p)
p->version = (int)soap_strtol(tmp, NULL, 10);
else
version = (int)soap_strtol(tmp, NULL, 10);
}
}
else if (!soap_tag_cmp(tmp, "$Path"))
{ s = soap_decode_val(tmp, sizeof(tmp), s);
if (*tmp)
{ if ((t = (char*)SOAP_MALLOC(soap, strlen(tmp)+1)))
strcpy(t, tmp);
}
else
t = NULL;
if (p)
{ if (p->path)
SOAP_FREE(soap, p->path);
p->path = t;
}
else
{ if (path)
SOAP_FREE(soap, path);
path = t;
}
}
else if (!soap_tag_cmp(tmp, "$Domain"))
{ s = soap_decode_val(tmp, sizeof(tmp), s);
if (*tmp)
{ if ((t = (char*)SOAP_MALLOC(soap, strlen(tmp)+1)))
strcpy(t, tmp);
}
else
t = NULL;
if (p)
{ if (p->domain)
SOAP_FREE(soap, p->domain);
p->domain = t;
}
else
{ if (domain)
SOAP_FREE(soap, domain);
domain = t;
}
}
else if (p && !soap_tag_cmp(tmp, "Path"))
{ if (p->path)
SOAP_FREE(soap, p->path);
s = soap_decode_val(tmp, sizeof(tmp), s);
if (*tmp)
{ if ((p->path = (char*)SOAP_MALLOC(soap, strlen(tmp)+1)))
strcpy(p->path, tmp);
}
else
p->path = NULL;
}
else if (p && !soap_tag_cmp(tmp, "Domain"))
{ if (p->domain)
SOAP_FREE(soap, p->domain);
s = soap_decode_val(tmp, sizeof(tmp), s);
if (*tmp)
{ if ((p->domain = (char*)SOAP_MALLOC(soap, strlen(tmp)+1)))
strcpy(p->domain, tmp);
}
else
p->domain = NULL;
}
else if (p && !soap_tag_cmp(tmp, "Version"))
{ s = soap_decode_val(tmp, sizeof(tmp), s);
p->version = (unsigned int)soap_strtoul(tmp, NULL, 10);
}
else if (p && !soap_tag_cmp(tmp, "Max-Age"))
{ s = soap_decode_val(tmp, sizeof(tmp), s);
p->expire = now + soap_strtol(tmp, NULL, 10);
}
else if (p && !soap_tag_cmp(tmp, "Expires"))
{ struct tm T;
char a[3];
static const char mns[] = "anebarprayunulugepctovec";
s = soap_decode_val(tmp, sizeof(tmp), s);
if (strlen(tmp) > 20)
{ memset((void*)&T, 0, sizeof(T));
a[0] = tmp[4];
a[1] = tmp[5];
a[2] = '\0';
T.tm_mday = (int)soap_strtol(a, NULL, 10);
a[0] = tmp[8];
a[1] = tmp[9];
T.tm_mon = (int)(strstr(mns, a) - mns) / 2;
a[0] = tmp[11];
a[1] = tmp[12];
T.tm_year = 100 + (int)soap_strtol(a, NULL, 10);
a[0] = tmp[13];
a[1] = tmp[14];
T.tm_hour = (int)soap_strtol(a, NULL, 10);
a[0] = tmp[16];
a[1] = tmp[17];
T.tm_min = (int)soap_strtol(a, NULL, 10);
a[0] = tmp[19];
a[1] = tmp[20];
T.tm_sec = (int)soap_strtol(a, NULL, 10);
p->expire = soap_timegm(&T);
}
}
else if (p && !soap_tag_cmp(tmp, "Secure"))
p->secure = 1;
else
{ if (p)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie='%s' value='%s' domain='%s' path='%s' expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure));
if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
{ q->version = p->version;
q->expire = p->expire;
q->secure = p->secure;
q->env = 1;
}
if (p->name)
SOAP_FREE(soap, p->name);
if (p->value)
SOAP_FREE(soap, p->value);
if (p->domain)
SOAP_FREE(soap, p->domain);
if (p->path)
SOAP_FREE(soap, p->path);
SOAP_FREE(soap, p);
}
if ((p = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie))))
{ p->name = (char*)SOAP_MALLOC(soap, strlen(tmp)+1);
strcpy(p->name, tmp);
s = soap_decode_val(tmp, sizeof(tmp), s);
if (*tmp)
{ p->value = (char*)SOAP_MALLOC(soap, strlen(tmp)+1);
strcpy(p->value, tmp);
}
else
p->value = NULL;
if (domain)
p->domain = domain;
else if (*soap->host)
{ p->domain = (char*)SOAP_MALLOC(soap, strlen(soap->host)+1);
strcpy(p->domain, soap->host);
}
else
p->domain = NULL;
if (path)
p->path = path;
else if (soap->path && *soap->path)
{ p->path = (char*)SOAP_MALLOC(soap, strlen(soap->path)+1);
strcpy(p->path, soap->path);
}
else
{ p->path = (char*)SOAP_MALLOC(soap, 2);
strcpy(p->path, "/");
}
p->expire = 0;
p->secure = 0;
p->version = version;
}
}
}
if (p)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie='%s' value='%s' domain='%s' path='%s' expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure));
if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
{ q->version = p->version;
q->expire = p->expire;
q->secure = p->secure;
q->env = 1;
}
if (p->name)
SOAP_FREE(soap, p->name);
if (p->value)
SOAP_FREE(soap, p->value);
if (p->domain)
SOAP_FREE(soap, p->domain);
if (p->path)
SOAP_FREE(soap, p->path);
SOAP_FREE(soap, p);
}
if (domain)
SOAP_FREE(soap, domain);
if (path)
SOAP_FREE(soap, path);
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_getenv_cookies(struct soap *soap)
{ struct soap_cookie *p;
const char *s;
char key[4096], val[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
if (!(s = getenv("HTTP_COOKIE")))
return SOAP_ERR;
do
{ s = soap_decode_key(key, sizeof(key), s);
s = soap_decode_val(val, sizeof(val), s);
p = soap_set_cookie(soap, key, val, NULL, NULL);
if (p)
p->env = 1;
} while (*s);
return SOAP_OK;
}
/******************************************************************************/
SOAP_FMAC1
struct soap_cookie*
SOAP_FMAC2
soap_copy_cookies(struct soap *copy, const struct soap *soap)
{ struct soap_cookie *p, **q, *r;
q = &r;
for (p = soap->cookies; p; p = p->next)
{ if (!(*q = (struct soap_cookie*)SOAP_MALLOC(copy, sizeof(struct soap_cookie))))
return r;
**q = *p;
if (p->name)
{ if (((*q)->name = (char*)SOAP_MALLOC(copy, strlen(p->name)+1)))
strcpy((*q)->name, p->name);
}
if (p->value)
{ if (((*q)->value = (char*)SOAP_MALLOC(copy, strlen(p->value)+1)))
strcpy((*q)->value, p->value);
}
if (p->domain)
{ if (((*q)->domain = (char*)SOAP_MALLOC(copy, strlen(p->domain)+1)))
strcpy((*q)->domain, p->domain);
}
if (p->path)
{ if (((*q)->path = (char*)SOAP_MALLOC(copy, strlen(p->path)+1)))
strcpy((*q)->path, p->path);
}
q = &(*q)->next;
}
*q = NULL;
return r;
}
/******************************************************************************/
SOAP_FMAC1
void
SOAP_FMAC2
soap_free_cookies(struct soap *soap)
{ struct soap_cookie *p;
for (p = soap->cookies; p; p = soap->cookies)
{ soap->cookies = p->next;
SOAP_FREE(soap, p->name);
if (p->value)
SOAP_FREE(soap, p->value);
if (p->domain)
SOAP_FREE(soap, p->domain);
if (p->path)
SOAP_FREE(soap, p->path);
SOAP_FREE(soap, p);
}
}
/******************************************************************************/
#endif /* WITH_COOKIES */
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
size_t
SOAP_FMAC2
soap_hash(register const char *s)
{ register size_t h = 0;
while (*s)
h = 65599*h + *s++;
return h % SOAP_IDHASH;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_1
static void
soap_init_pht(struct soap *soap)
{ register int i;
soap->pblk = NULL;
soap->pidx = 0;
for (i = 0; i < (int)SOAP_PTRHASH; i++)
soap->pht[i] = NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
struct soap*
SOAP_FMAC2
soap_versioning(soap_new)(soap_mode imode, soap_mode omode)
{ struct soap *soap = (struct soap*)malloc(sizeof(struct soap));
if (soap)
soap_versioning(soap_init)(soap, imode, omode);
return soap;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_free(struct soap *soap)
{ soap_done(soap);
free(soap);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_del(struct soap *soap)
{ free(soap);
}
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_1
static void
soap_free_pht(struct soap *soap)
{ register struct soap_pblk *pb, *next;
register int i;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n"));
for (pb = soap->pblk; pb; pb = next)
{ next = pb->next;
SOAP_FREE(soap, pb);
}
soap->pblk = NULL;
soap->pidx = 0;
for (i = 0; i < (int)SOAP_PTRHASH; i++)
soap->pht[i] = NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_embed(struct soap *soap, const void *p, const struct soap_array *a, int n, const char *tag, int type)
{ register int i;
struct soap_plist *pp;
(void)soap;
if (soap->version == 2)
soap->encoding = 1;
if (a)
i = soap_array_pointer_lookup(soap, p, a, n, type, &pp);
else
i = soap_pointer_lookup(soap, p, type, &pp);
if (i)
{ if (soap_is_embedded(soap, pp)
|| soap_is_single(soap, pp))
return 0;
soap_set_embedded(soap, pp);
}
return i;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_pointer_lookup(struct soap *soap, const void *p, int type, struct soap_plist **ppp)
{ register struct soap_plist *pp;
*ppp = NULL;
if (p)
{ for (pp = soap->pht[soap_hash_ptr(p)]; pp; pp = pp->next)
{ if (pp->ptr == p && pp->type == type)
{ *ppp = pp;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d id=%d\n", p, type, pp->id));
return pp->id;
}
}
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d: not found\n", p, type));
return 0;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
{ register size_t h;
register struct soap_plist *pp;
(void)n;
if (!soap->pblk || soap->pidx >= SOAP_PTRBLK)
{ register struct soap_pblk *pb = (struct soap_pblk*)SOAP_MALLOC(soap, sizeof(struct soap_pblk));
if (!pb)
{ soap->error = SOAP_EOM;
return 0;
}
pb->next = soap->pblk;
soap->pblk = pb;
soap->pidx = 0;
}
*ppp = pp = &soap->pblk->plist[soap->pidx++];
if (a)
h = soap_hash_ptr(a->__ptr);
else
h = soap_hash_ptr(p);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pointer enter location=%p array=%p size=%d dim=%d type=%d id=%d\n", p, a ? a->__ptr : NULL, a ? a->__size : 0, n, type, soap->idnum+1));
pp->next = soap->pht[h];
pp->type = type;
pp->mark1 = 0;
pp->mark2 = 0;
pp->ptr = p;
pp->array = a;
soap->pht[h] = pp;
pp->id = ++soap->idnum;
return pp->id;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_array_pointer_lookup(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
{ register struct soap_plist *pp;
*ppp = NULL;
if (!p || !a->__ptr)
return 0;
for (pp = soap->pht[soap_hash_ptr(a->__ptr)]; pp; pp = pp->next)
{ if (pp->type == type && pp->array && pp->array->__ptr == a->__ptr)
{ register int i;
for (i = 0; i < n; i++)
if (((const int*)&pp->array->__size)[i] != ((const int*)&a->__size)[i])
break;
if (i == n)
{ *ppp = pp;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d id=%d\n", a->__ptr, type, pp->id));
return pp->id;
}
}
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d: not found\n", a->__ptr, type));
return 0;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_begin_count(struct soap *soap)
{ soap_free_ns(soap);
#ifndef WITH_LEANER
if ((soap->mode & SOAP_ENC_DIME) || (soap->omode & SOAP_ENC_DIME))
soap->mode = soap->omode | SOAP_IO_LENGTH | SOAP_ENC_DIME;
else
#endif
{ soap->mode = soap->omode;
if ((soap->mode & SOAP_IO_UDP))
soap->mode |= SOAP_ENC_XML;
if ((soap->mode & SOAP_IO) == SOAP_IO_STORE
|| (((soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_ENC_XML))
#ifndef WITH_LEANER
&& !soap->fpreparesend
#endif
))
soap->mode &= ~SOAP_IO_LENGTH;
else
soap->mode |= SOAP_IO_LENGTH;
}
#ifdef WITH_ZLIB
if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
{ if (!(soap->mode & SOAP_ENC_DIME))
soap->mode &= ~SOAP_IO_LENGTH;
if (soap->mode & SOAP_ENC_XML)
soap->mode |= SOAP_IO_BUFFER;
else
soap->mode |= SOAP_IO_STORE;
}
#endif
#ifndef WITH_LEANER
if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME))
soap->mode |= SOAP_ENC_MIME;
else if (!(soap->mode & SOAP_ENC_MIME))
soap->mode &= ~SOAP_ENC_MTOM;
if (soap->mode & SOAP_ENC_MIME)
soap_select_mime_boundary(soap);
soap->dime.list = soap->dime.last; /* keep track of last DIME attachment */
#endif
soap->count = 0;
soap->ns = 0;
soap->null = 0;
soap->position = 0;
soap->mustUnderstand = 0;
soap->encoding = 0;
soap->part = SOAP_BEGIN;
soap->event = 0;
soap->evlev = 0;
soap->idnum = 0;
soap_clr_attr(soap);
soap_set_local_namespaces(soap);
#ifndef WITH_LEANER
soap->dime.count = 0; /* count # of attachments */
soap->dime.size = 0; /* accumulate total size of attachments */
if (soap->fprepareinitsend && (soap->mode & SOAP_IO) != SOAP_IO_STORE && (soap->error = soap->fprepareinitsend(soap)))
return soap->error;
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, (unsigned int)soap->mode, (unsigned long)soap->count));
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_end_count(struct soap *soap)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of count phase\n"));
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO_LENGTH))
{ if (soap->fpreparefinalsend && (soap->error = soap->fpreparefinalsend(soap)))
return soap->error;
}
#endif
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_begin_send(struct soap *soap)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for output to socket=%d/fd=%d\n", soap->socket, soap->sendfd));
soap_free_ns(soap);
soap->error = SOAP_OK;
soap->mode = soap->omode | (soap->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME));
#ifdef WITH_ZLIB
if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
{ if (soap->mode & SOAP_ENC_XML)
soap->mode |= SOAP_IO_BUFFER;
else
soap->mode |= SOAP_IO_STORE;
}
#endif
#ifndef WITH_LEAN
if ((soap->mode & SOAP_IO_UDP))
{ soap->mode |= SOAP_ENC_XML;
if (soap->count > SOAP_BUFLEN)
return soap->error = SOAP_UDP_ERROR;
}
#endif
if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket))
{ if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML))
soap->mode |= SOAP_IO_BUFFER;
else
soap->mode |= SOAP_IO_STORE;
}
soap->mode &= ~SOAP_IO_LENGTH;
if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
if (soap_new_block(soap) == NULL)
return soap->error;
if (!(soap->mode & SOAP_IO_KEEPALIVE))
soap->keep_alive = 0;
#ifndef WITH_LEANER
if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME))
{ soap->mode |= SOAP_ENC_MIME;
soap->mode &= ~SOAP_ENC_DIME;
}
else if (!(soap->mode & SOAP_ENC_MIME))
soap->mode &= ~SOAP_ENC_MTOM;
if (soap->mode & SOAP_ENC_MIME)
soap_select_mime_boundary(soap);
#ifdef WIN32
#ifndef UNDER_CE
#ifndef WITH_FASTCGI
if (!soap_valid_socket(soap->socket) && !soap->os) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
#ifdef __BORLANDC__
setmode(soap->sendfd, _O_BINARY);
#else
_setmode(soap->sendfd, _O_BINARY);
#endif
#endif
#endif
#endif
#endif
if (soap->mode & SOAP_IO)
{ soap->bufidx = 0;
soap->buflen = 0;
}
soap->chunksize = 0;
soap->ns = 0;
soap->null = 0;
soap->position = 0;
soap->mustUnderstand = 0;
soap->encoding = 0;
soap->idnum = 0;
soap->level = 0;
soap_clr_attr(soap);
soap_set_local_namespaces(soap);
#ifdef WITH_ZLIB
soap->z_ratio_out = 1.0;
if ((soap->mode & SOAP_ENC_ZLIB) && soap->zlib_state != SOAP_ZLIB_DEFLATE)
{ if (!soap->z_buf)
soap->z_buf = (char*)SOAP_MALLOC(soap, SOAP_BUFLEN);
soap->d_stream->next_out = (Byte*)soap->z_buf;
soap->d_stream->avail_out = SOAP_BUFLEN;
#ifdef WITH_GZIP
if (soap->zlib_out != SOAP_ZLIB_DEFLATE)
{ memcpy(soap->z_buf, "\37\213\10\0\0\0\0\0\0\377", 10);
soap->d_stream->next_out = (Byte*)soap->z_buf + 10;
soap->d_stream->avail_out = SOAP_BUFLEN - 10;
soap->z_crc = crc32(0L, NULL, 0);
soap->zlib_out = SOAP_ZLIB_GZIP;
if (soap->z_dict)
*((Byte*)soap->z_buf + 2) = 0xff;
if (deflateInit2(soap->d_stream, soap->z_level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
}
else
#endif
if (deflateInit(soap->d_stream, soap->z_level) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
if (soap->z_dict)
{ if (deflateSetDictionary(soap->d_stream, (const Bytef*)soap->z_dict, soap->z_dict_len) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflate initialized\n"));
soap->zlib_state = SOAP_ZLIB_DEFLATE;
}
#endif
#ifdef WITH_OPENSSL
if (soap->ssl)
ERR_clear_error();
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin send phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
soap->part = SOAP_BEGIN;
#ifndef WITH_LEANER
if (soap->fprepareinitsend && (soap->mode & SOAP_IO) == SOAP_IO_STORE && (soap->error = soap->fprepareinitsend(soap)))
return soap->error;
#endif
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_embedded(struct soap *soap, const void *p, int t)
{ struct soap_plist *pp;
if (soap_pointer_lookup(soap, p, t, &pp))
{ pp->mark1 = 1;
pp->mark2 = 1;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded %p type=%d mark set to 1\n", p, t));
}
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_reference(struct soap *soap, const void *p, int t)
{ struct soap_plist *pp;
if (!p || (!soap->encodingStyle && !(soap->omode & (SOAP_ENC_DIME|SOAP_ENC_MIME|SOAP_ENC_MTOM|SOAP_XML_GRAPH))) || (soap->omode & SOAP_XML_TREE))
return 1;
if (soap_pointer_lookup(soap, p, t, &pp))
{ if (pp->mark1 == 0)
{ pp->mark1 = 2;
pp->mark2 = 2;
}
}
else if (!soap_pointer_enter(soap, p, NULL, 0, t, &pp))
return 1;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reference %p type=%d (%d %d)\n", p, t, (int)pp->mark1, (int)pp->mark2));
return pp->mark1;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_array_reference(struct soap *soap, const void *p, const struct soap_array *a, int n, int t)
{ struct soap_plist *pp;
if (!p || !a->__ptr || (!soap->encodingStyle && !(soap->omode & (SOAP_ENC_DIME|SOAP_ENC_MIME|SOAP_ENC_MTOM|SOAP_XML_GRAPH))) || (soap->omode & SOAP_XML_TREE))
return 1;
if (soap_array_pointer_lookup(soap, p, a, n, t, &pp))
{ if (pp->mark1 == 0)
{ pp->mark1 = 2;
pp->mark2 = 2;
}
}
else if (!soap_pointer_enter(soap, p, a, n, t, &pp))
return 1;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array reference %p ptr=%p dim=%d type=%d (%d %d)\n", p, a->__ptr, n, t, (int)pp->mark1, (int)pp->mark2));
return pp->mark1;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_embedded_id(struct soap *soap, int id, const void *p, int t)
{ struct soap_plist *pp = NULL;
if (!id || (!soap->encodingStyle && !(soap->omode & SOAP_XML_GRAPH)) || (soap->omode & SOAP_XML_TREE))
return id;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id %p type=%d id=%d\n", p, t, id));
if (soap->version == 1 && soap->part != SOAP_IN_HEADER)
{ if (id < 0)
{ id = soap_pointer_lookup(soap, p, t, &pp);
if (id)
{ if (soap->mode & SOAP_IO_LENGTH)
pp->mark1 = 2;
else
pp->mark2 = 2;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id multiref id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
}
return -1;
}
return id;
}
if (id < 0)
id = soap_pointer_lookup(soap, p, t, &pp);
else if (id && !soap_pointer_lookup(soap, p, t, &pp))
return 0;
if (id && pp)
{ if (soap->mode & SOAP_IO_LENGTH)
pp->mark1 = 1;
else
pp->mark2 = 1;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id embedded ref id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
}
return id;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_is_embedded(struct soap *soap, struct soap_plist *pp)
{ if (!pp)
return 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Is embedded? %d %d\n", (int)pp->mark1, (int)pp->mark2));
if (soap->version == 1 && soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH) && soap->part != SOAP_IN_HEADER)
{ if (soap->mode & SOAP_IO_LENGTH)
return pp->mark1 != 0;
return pp->mark2 != 0;
}
if (soap->mode & SOAP_IO_LENGTH)
return pp->mark1 == 1;
return pp->mark2 == 1;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_is_single(struct soap *soap, struct soap_plist *pp)
{ if (soap->part == SOAP_IN_HEADER)
return 1;
if (!pp)
return 0;
if (soap->mode & SOAP_IO_LENGTH)
return pp->mark1 == 0;
return pp->mark2 == 0;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_embedded(struct soap *soap, struct soap_plist *pp)
{ if (!pp)
return;
if (soap->mode & SOAP_IO_LENGTH)
pp->mark1 = 1;
else
pp->mark2 = 1;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_attachment(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, const char *aid, const char *atype, const char *aoptions, int n, const char *type, int t)
{
#ifndef WITH_NOIDREF
struct soap_plist *pp;
int i;
if (!p || !a->__ptr || (!aid && !atype))
return soap_element_id(soap, tag, id, p, a, n, type, t);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Attachment tag='%s' id='%s' (%d) type='%s'\n", tag, aid ? aid : SOAP_STR_EOS, id, atype ? atype : SOAP_STR_EOS));
i = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
if (!i)
{ i = soap_pointer_enter(soap, p, a, n, t, &pp);
if (!i)
{ soap->error = SOAP_EOM;
return -1;
}
}
if (id <= 0)
id = i;
if (!aid)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), soap->dime_id_format, id);
#else
sprintf(soap->tmpbuf, soap->dime_id_format, id);
#endif
aid = soap_strdup(soap, soap->tmpbuf);
}
/* Add MTOM xop:Include element when necessary */
/* TODO: this code to be obsoleted with new import/xop.h conventions */
if ((soap->mode & SOAP_ENC_MTOM) && strcmp(tag, "xop:Include"))
{ if (soap_element_begin_out(soap, tag, 0, type)
|| soap_element_href(soap, "xop:Include", 0, "xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href", aid)
|| soap_element_end_out(soap, tag))
return soap->error;
}
else if (soap_element_href(soap, tag, 0, "href", aid))
return soap->error;
if (soap->mode & SOAP_IO_LENGTH)
{ if (pp->mark1 != 3)
{ struct soap_multipart *content;
if (soap->mode & SOAP_ENC_MTOM)
content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, (char*)a->__ptr, a->__size);
else
content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size);
if (!content)
{ soap->error = SOAP_EOM;
return -1;
}
if (!strncmp(aid, "cid:", 4)) /* RFC 2111 */
{ if (soap->mode & SOAP_ENC_MTOM)
{ char *s = (char*)soap_malloc(soap, strlen(aid) - 1);
if (s)
{ *s = '<';
strcpy(s + 1, aid + 4);
strcat(s, ">");
content->id = s;
}
}
else
content->id = aid + 4;
}
else
content->id = aid;
content->type = atype;
content->options = aoptions;
content->encoding = SOAP_MIME_BINARY;
pp->mark1 = 3;
}
}
else
pp->mark2 = 3;
#endif
return -1;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_1
static void
soap_init_iht(struct soap *soap)
{ register int i;
for (i = 0; i < SOAP_IDHASH; i++)
soap->iht[i] = NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_1
static void
soap_free_iht(struct soap *soap)
{ register int i;
register struct soap_ilist *ip = NULL, *p = NULL;
register struct soap_flist *fp = NULL, *fq = NULL;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free ID hashtable\n"));
for (i = 0; i < SOAP_IDHASH; i++)
{ for (ip = soap->iht[i]; ip; ip = p)
{ for (fp = ip->flist; fp; fp = fq)
{ fq = fp->next;
SOAP_FREE(soap, fp);
}
p = ip->next;
SOAP_FREE(soap, ip);
}
soap->iht[i] = NULL;
}
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
struct soap_ilist *
SOAP_FMAC2
soap_lookup(struct soap *soap, const char *id)
{ register struct soap_ilist *ip = NULL;
for (ip = soap->iht[soap_hash(id)]; ip; ip = ip->next)
if (!strcmp(ip->id, id))
return ip;
return NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
struct soap_ilist *
SOAP_FMAC2
soap_enter(struct soap *soap, const char *id)
{ register size_t h;
register struct soap_ilist *ip;
ip = (struct soap_ilist*)SOAP_MALLOC(soap, sizeof(struct soap_ilist) + strlen(id));
if (ip)
{ strcpy((char*)ip->id, id);
h = soap_hash(id); /* h = (HASH(id) % SOAP_IDHASH) so soap->iht[h] is safe */
ip->next = soap->iht[h];
soap->iht[h] = ip;
}
return ip;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void*
SOAP_FMAC2
soap_malloc(struct soap *soap, size_t n)
{ register char *p;
if (!n)
return (void*)SOAP_NON_NULL;
if (!soap)
return SOAP_MALLOC(soap, n);
if (soap->fmalloc)
p = (char*)soap->fmalloc(soap, n);
else
{ n += sizeof(short);
n += (-(long)n) & (sizeof(void*)-1); /* align at 4-, 8- or 16-byte boundary */
if (!(p = (char*)SOAP_MALLOC(soap, n + sizeof(void*) + sizeof(size_t))))
{ soap->error = SOAP_EOM;
return NULL;
}
/* set the canary to detect corruption */
*(unsigned short*)(p + n - sizeof(unsigned short)) = (unsigned short)SOAP_CANARY;
/* keep chain of alloced cells for destruction */
*(void**)(p + n) = soap->alist;
*(size_t*)(p + n + sizeof(void*)) = n;
soap->alist = p + n;
}
soap->alloced = 1;
return p;
}
#endif
/******************************************************************************/
#ifdef SOAP_MEM_DEBUG
static void
soap_init_mht(struct soap *soap)
{ register int i;
for (i = 0; i < (int)SOAP_PTRHASH; i++)
soap->mht[i] = NULL;
}
#endif
/******************************************************************************/
#ifdef SOAP_MEM_DEBUG
static void
soap_free_mht(struct soap *soap)
{ register int i;
register struct soap_mlist *mp, *mq;
for (i = 0; i < (int)SOAP_PTRHASH; i++)
{ for (mp = soap->mht[i]; mp; mp = mq)
{ mq = mp->next;
if (mp->live)
fprintf(stderr, "%s(%d): malloc() = %p not freed (memory leak or forgot to call soap_end()?)\n", mp->file, mp->line, mp->ptr);
free(mp);
}
soap->mht[i] = NULL;
}
}
#endif
/******************************************************************************/
#ifdef SOAP_MEM_DEBUG
SOAP_FMAC1
void*
SOAP_FMAC2
soap_track_malloc(struct soap *soap, const char *file, int line, size_t size)
{ register void *p = malloc(size);
if (soap)
{ register size_t h = soap_hash_ptr(p);
register struct soap_mlist *mp = (struct soap_mlist*)malloc(sizeof(struct soap_mlist));
if (soap->fdebug[SOAP_INDEX_TEST])
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): malloc(%lu) = %p\n", file, line, (unsigned long)size, p));
}
mp->next = soap->mht[h];
mp->ptr = p;
mp->file = file;
mp->line = line;
mp->live = 1;
soap->mht[h] = mp;
}
return p;
}
#endif
/******************************************************************************/
#ifdef SOAP_MEM_DEBUG
SOAP_FMAC1
void
SOAP_FMAC2
soap_track_free(struct soap *soap, const char *file, int line, void *p)
{ register size_t h = soap_hash_ptr(p);
register struct soap_mlist *mp;
for (mp = soap->mht[h]; mp; mp = mp->next)
if (mp->ptr == p)
break;
if (mp)
{ if (mp->live)
{ free(p);
if (soap->fdebug[SOAP_INDEX_TEST])
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): free(%p)\n", file, line, p));
}
mp->live = 0;
}
else
fprintf(stderr, "%s(%d): free(%p) double free of pointer malloced at %s(%d)\n", file, line, p, mp->file, mp->line);
}
else
fprintf(stderr, "%s(%d): free(%p) pointer not malloced\n", file, line, p);
}
#endif
/******************************************************************************/
#ifdef SOAP_MEM_DEBUG
static void
soap_track_unlink(struct soap *soap, const void *p)
{ register size_t h = soap_hash_ptr(p);
register struct soap_mlist *mp;
for (mp = soap->mht[h]; mp; mp = mp->next)
if (mp->ptr == p)
break;
if (mp)
mp->live = 0;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_dealloc(struct soap *soap, void *p)
{ if (soap_check_state(soap))
return;
if (p)
{ register char **q;
for (q = (char**)&soap->alist; *q; q = *(char***)q)
{
if (*(unsigned short*)(char*)(*q - sizeof(unsigned short)) != (unsigned short)SOAP_CANARY)
{
#ifdef SOAP_MEM_DEBUG
fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n");
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n"));
DBGHEX(TEST, *q - 200, 200);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n"));
soap->error = SOAP_MOE;
return;
}
if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
{ *q = **(char***)q;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Freed data at %p\n", p));
SOAP_FREE(soap, p);
return;
}
}
soap_delete(soap, p);
}
else
{ register char *q;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free all soap_malloc() data\n"));
while (soap->alist)
{ q = (char*)soap->alist;
if (*(unsigned short*)(char*)(q - sizeof(unsigned short)) != (unsigned short)SOAP_CANARY)
{
#ifdef SOAP_MEM_DEBUG
fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n");
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n"));
DBGHEX(TEST, q - 200, 200);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n"));
soap->error = SOAP_MOE;
return;
}
soap->alist = *(void**)q;
q -= *(size_t*)(q + sizeof(void*));
SOAP_FREE(soap, q);
}
/* we must assume these were deallocated: */
soap->http_content = NULL;
soap->action = NULL;
soap->fault = NULL;
soap->header = NULL;
soap->userid = NULL;
soap->passwd = NULL;
soap->authrealm = NULL;
#ifdef WITH_NTLM
soap->ntlm_challenge = NULL;
#endif
#ifndef WITH_LEANER
soap_clr_mime(soap);
#endif
}
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_delete(struct soap *soap, void *p)
{ register struct soap_clist **cp;
if (soap_check_state(soap))
return;
cp = &soap->clist;
if (p)
{ while (*cp)
{ if (p == (*cp)->ptr)
{ register struct soap_clist *q = *cp;
*cp = q->next;
if (q->fdelete(q))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: deletion callback failed for object type %d\n", q->ptr, q->type));
#ifdef SOAP_MEM_DEBUG
fprintf(stderr, "new(object type = %d) = %p not freed: deletion callback failed\n", q->type, q->ptr);
#endif
}
SOAP_FREE(soap, q);
return;
}
cp = &(*cp)->next;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: address not in list\n", p));
}
else
{ while (*cp)
{ register struct soap_clist *q = *cp;
*cp = q->next;
if (q->fdelete(q))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: deletion callback failed for object type %d\n", q->ptr, q->type));
#ifdef SOAP_MEM_DEBUG
fprintf(stderr, "new(object type = %d) = %p not freed: deletion callback failed\n", q->type, q->ptr);
#endif
}
SOAP_FREE(soap, q);
}
}
soap->fault = NULL; /* this was possibly deallocated */
soap->header = NULL; /* this was possibly deallocated */
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_delegate_deletion(struct soap *soap, struct soap *soap_to)
{ register struct soap_clist *cp;
register char **q;
#ifdef SOAP_MEM_DEBUG
register void *p;
register struct soap_mlist **mp, *mq;
size_t h;
#endif
for (q = (char**)&soap->alist; *q; q = *(char***)q)
{
if (*(unsigned short*)(char*)(*q - sizeof(unsigned short)) != (unsigned short)SOAP_CANARY)
{
#ifdef SOAP_MEM_DEBUG
fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n");
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n"));
DBGHEX(TEST, *q - 200, 200);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n"));
soap->error = SOAP_MOE;
return;
}
#ifdef SOAP_MEM_DEBUG
p = (void*)(*q - *(size_t*)(*q + sizeof(void*)));
h = soap_hash_ptr(p);
for (mp = &soap->mht[h]; *mp; mp = &(*mp)->next)
{ if ((*mp)->ptr == p)
{ mq = *mp;
*mp = mq->next;
mq->next = soap_to->mht[h];
soap_to->mht[h] = mq;
break;
}
}
#endif
}
*q = (char*)soap_to->alist;
soap_to->alist = soap->alist;
soap->alist = NULL;
#ifdef SOAP_MEM_DEBUG
cp = soap->clist;
while (cp)
{ h = soap_hash_ptr(cp);
for (mp = &soap->mht[h]; *mp; mp = &(*mp)->next)
{ if ((*mp)->ptr == cp)
{ mq = *mp;
*mp = mq->next;
mq->next = soap_to->mht[h];
soap_to->mht[h] = mq;
break;
}
}
cp = cp->next;
}
#endif
cp = soap_to->clist;
if (cp)
{ while (cp->next)
cp = cp->next;
cp->next = soap->clist;
}
else
soap_to->clist = soap->clist;
soap->clist = NULL;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
struct soap_clist *
SOAP_FMAC2
soap_link(struct soap *soap, void *p, int t, int n, int (*fdelete)(struct soap_clist*))
{ register struct soap_clist *cp;
if ((cp = (struct soap_clist*)SOAP_MALLOC(soap, sizeof(struct soap_clist))))
{ cp->next = soap->clist;
cp->type = t;
cp->size = n;
cp->ptr = p;
cp->fdelete = fdelete;
soap->clist = cp;
}
return cp;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_unlink(struct soap *soap, const void *p)
{ register char **q;
register struct soap_clist **cp;
if (soap && p)
{ for (q = (char**)&soap->alist; *q; q = *(char***)q)
{ if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
{ *q = **(char***)q;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked data %p\n", p));
#ifdef SOAP_MEM_DEBUG
soap_track_unlink(soap, p);
#endif
return SOAP_OK; /* found and removed from dealloc chain */
}
}
for (cp = &soap->clist; *cp; cp = &(*cp)->next)
{ if (p == (*cp)->ptr)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked class instance %p\n", p));
q = (char**)*cp;
*cp = (*cp)->next;
SOAP_FREE(soap, q);
return SOAP_OK; /* found and removed from dealloc chain */
}
}
}
return SOAP_ERR;
}
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_lookup_type(struct soap *soap, const char *id)
{ register struct soap_ilist *ip;
if (id && *id)
{ ip = soap_lookup(soap, id);
if (ip)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup id='%s' type=%d\n", id, ip->type));
return ip->type;
}
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "lookup type id='%s' NOT FOUND! Need to get it from xsi:type\n", id));
return 0;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
void*
SOAP_FMAC2
soap_id_lookup(struct soap *soap, const char *id, void **p, int t, size_t n, unsigned int k)
{ struct soap_ilist *ip;
void **q;
if (!p || !id || !*id)
return p;
ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
if (!ip)
{ if (!(ip = soap_enter(soap, id))) /* new hash table entry for string id */
return NULL;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding first href='%s' type=%d %p (%u bytes)\n", id, t, p, (unsigned int)n));
ip->type = t;
ip->size = n;
ip->link = p;
ip->copy = NULL;
ip->flist = NULL;
ip->ptr = NULL;
ip->level = k;
*p = NULL;
}
else if (ip->ptr)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolved href='%s' type=%d location=%p (%u bytes)\n", id, t, ip->ptr, (unsigned int)n));
if (ip->type != t)
{ strcpy(soap->id, id);
soap->error = SOAP_HREF;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility: href='%s' id-type=%d href-type=%d\n", id, ip->type, t));
return NULL;
}
while (ip->level < k)
{ q = (void**)soap_malloc(soap, sizeof(void*));
if (!q)
return NULL;
*p = (void*)q;
p = q;
k--;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
}
*p = ip->ptr;
}
else if (ip->level > k)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving level %u pointers to href='%s'\n", ip->level, id));
while (ip->level > k)
{ void *s, **r = &ip->link;
q = (void**)ip->link;
while (q)
{ *r = (void*)soap_malloc(soap, sizeof(void*));
if (!*r)
return NULL;
s = *q;
*q = *r;
r = (void**)*r;
q = (void**)s;
}
*r = NULL;
ip->size = n;
ip->copy = NULL;
ip->level = ip->level - 1;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
}
q = (void**)ip->link;
ip->link = p;
*p = (void*)q;
}
else
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarded href='%s' type=%d location=%p (%u bytes)\n", id, t, p, (unsigned int)n));
while (ip->level < k)
{ q = (void**)soap_malloc(soap, sizeof(void*));
if (!q)
return NULL;
*p = q;
p = q;
k--;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
}
q = (void**)ip->link;
ip->link = p;
*p = (void*)q;
}
return p;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIDREF
#ifndef PALM_2
SOAP_FMAC1
void*
SOAP_FMAC2
soap_id_forward(struct soap *soap, const char *href, void *p, size_t len, int st, int tt, size_t n, unsigned int k, void (*fcopy)(struct soap*, int, int, void*, size_t, const void*, size_t))
{ struct soap_ilist *ip;
if (!p || !href || !*href)
return p;
ip = soap_lookup(soap, href); /* lookup pointer to hash table entry for string id */
if (!ip)
{ if (!(ip = soap_enter(soap, href))) /* new hash table entry for string id */
return NULL;
ip->type = st;
ip->size = n;
ip->link = NULL;
ip->copy = NULL;
ip->ptr = NULL;
ip->level = 0;
ip->flist = NULL;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry href='%s' type=%d size=%lu level=%d location=%p\n", href, st, (unsigned long)n, k, p));
}
else if (ip->type != st || (ip->level == k && ip->size != n))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility id='%s' expect type=%d size=%lu level=%u got type=%d size=%lu\n", href, ip->type, (unsigned long)ip->size, k, st, (unsigned long)n));
strcpy(soap->id, href);
soap->error = SOAP_HREF;
return NULL;
}
if (fcopy || n < sizeof(void*) || *href != '#')
{ register struct soap_flist *fp = (struct soap_flist*)SOAP_MALLOC(soap, sizeof(struct soap_flist));
if (!fp)
{ soap->error = SOAP_EOM;
return NULL;
}
fp->next = ip->flist;
fp->type = tt;
fp->ptr = p;
fp->level = k;
fp->len = len;
if (fcopy)
fp->fcopy = fcopy;
else
fp->fcopy = soap_fcopy;
ip->flist = fp;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding type=%d (target type=%d) size=%lu location=%p level=%u len=%lu href='%s'\n", st, tt, (unsigned long)n, p, k, (unsigned long)len, href));
}
else
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding copying address %p for type=%d href='%s'\n", p, st, href));
*(void**)p = ip->copy;
ip->copy = p;
}
return p;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void*
SOAP_FMAC2
soap_id_enter(struct soap *soap, const char *id, void *p, int t, size_t n, unsigned int k, const char *type, const char *arrayType, void *(*finstantiate)(struct soap*, int, const char*, const char*, size_t*))
{
#ifndef WITH_NOIDREF
struct soap_ilist *ip;
#endif
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Enter id='%s' type=%d loc=%p size=%lu level=%u\n", id, t, p, (unsigned long)n, k));
soap->alloced = 0;
if (!p)
{ if (finstantiate)
p = finstantiate(soap, t, type, arrayType, &n);
else
p = soap_malloc(soap, n);
if (p)
soap->alloced = 1;
}
#ifndef WITH_NOIDREF
if (!id || !*id)
#endif
return p;
#ifndef WITH_NOIDREF
ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Lookup entry id='%s for location=%p'\n", id, p));
if (!ip)
{ if (!(ip = soap_enter(soap, id))) /* new hash table entry for string id */
return NULL;
ip->type = t;
ip->link = NULL;
ip->copy = NULL;
ip->flist = NULL;
ip->size = n;
ip->ptr = p;
ip->level = k;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry id='%s' type=%d size=%lu level=%u location=%p\n", id, t, (unsigned long)n, k, p));
}
else if ((ip->type != t || (ip->level == k && ip->size != n)) && (ip->copy || ip->flist))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility id='%s' expect type=%d size=%lu level=%u got type=%d size=%lu\n", id, ip->type, (unsigned long)ip->size, k, t, (unsigned long)n));
strcpy(soap->id, id);
soap->error = SOAP_HREF;
return NULL;
}
else if (ip->ptr)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Multiply defined id='%s'\n", id));
strcpy(soap->id, id);
soap->error = SOAP_DUPLICATE_ID;
return NULL;
}
else
{ ip->size = n;
ip->ptr = p;
ip->level = k;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update entry id='%s' type=%d location=%p size=%lu level=%u\n", id, t, p, (unsigned long)n, k));
}
return ip->ptr;
#endif
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Copying data type=%d (target type=%d) %p -> %p (%lu bytes)\n", st, tt, q, p, (unsigned long)n));
memcpy(p, q, n);
(void)soap; (void)st; (void)tt; (void)len;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_end_send(struct soap *soap)
{
#ifndef WITH_LEANER
int err;
if (soap->dime.list)
{ /* SOAP body referenced attachments must appear first */
soap->dime.last->next = soap->dime.first;
soap->dime.first = soap->dime.list->next;
soap->dime.list->next = NULL;
soap->dime.last = soap->dime.list;
}
if (!(err = soap_putdime(soap)))
err = soap_putmime(soap);
soap->mime.list = NULL;
soap->mime.first = NULL;
soap->mime.last = NULL;
soap->dime.list = NULL;
soap->dime.first = NULL;
soap->dime.last = NULL;
if (err)
return err;
#endif
return soap_end_send_flush(soap);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_end_send_flush(struct soap *soap)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send mode=0x%x\n", soap->mode));
if (soap->mode & SOAP_IO) /* need to flush the remaining data in buffer */
{ if (soap_flush(soap))
#ifdef WITH_ZLIB
{ if (soap->mode & SOAP_ENC_ZLIB && soap->zlib_state == SOAP_ZLIB_DEFLATE)
{ soap->zlib_state = SOAP_ZLIB_NONE;
deflateEnd(soap->d_stream);
}
return soap->error;
}
#else
return soap->error;
#endif
#ifdef WITH_ZLIB
if (soap->mode & SOAP_ENC_ZLIB)
{ int r;
soap->d_stream->avail_in = 0;
do
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating remainder\n"));
r = deflate(soap->d_stream, Z_FINISH);
if (soap->d_stream->avail_out != SOAP_BUFLEN)
{ if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN - soap->d_stream->avail_out))
{ soap->zlib_state = SOAP_ZLIB_NONE;
deflateEnd(soap->d_stream);
return soap->error;
}
soap->d_stream->next_out = (Byte*)soap->z_buf;
soap->d_stream->avail_out = SOAP_BUFLEN;
}
} while (r == Z_OK);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflated total %lu->%lu bytes\n", soap->d_stream->total_in, soap->d_stream->total_out));
soap->z_ratio_out = (float)soap->d_stream->total_out / (float)soap->d_stream->total_in;
soap->mode &= ~SOAP_ENC_ZLIB;
soap->zlib_state = SOAP_ZLIB_NONE;
if (deflateEnd(soap->d_stream) != Z_OK || r != Z_STREAM_END)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
return soap->error = SOAP_ZLIB_ERROR;
}
#ifdef WITH_GZIP
if (soap->zlib_out != SOAP_ZLIB_DEFLATE)
{ soap->z_buf[0] = soap->z_crc & 0xFF;
soap->z_buf[1] = (soap->z_crc >> 8) & 0xFF;
soap->z_buf[2] = (soap->z_crc >> 16) & 0xFF;
soap->z_buf[3] = (soap->z_crc >> 24) & 0xFF;
soap->z_buf[4] = soap->d_stream->total_in & 0xFF;
soap->z_buf[5] = (soap->d_stream->total_in >> 8) & 0xFF;
soap->z_buf[6] = (soap->d_stream->total_in >> 16) & 0xFF;
soap->z_buf[7] = (soap->d_stream->total_in >> 24) & 0xFF;
if (soap_flush_raw(soap, soap->z_buf, 8))
return soap->error;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip crc32=%lu\n", (unsigned long)soap->z_crc));
}
#endif
}
#endif
if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
{ char *p;
#ifndef WITH_NOHTTP
if (!(soap->mode & SOAP_ENC_XML))
{ soap->mode--;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending buffered message of length %u\n", (unsigned int)soap->blist->size));
if (soap->status >= SOAP_POST)
soap->error = soap->fpost(soap, soap->endpoint, soap->host, soap->port, soap->path, soap->action, soap->blist->size);
else if (soap->status != SOAP_STOP)
soap->error = soap->fresponse(soap, soap->status, soap->blist->size);
if (soap->error || soap_flush(soap))
return soap->error;
soap->mode++;
}
#endif
for (p = soap_first_block(soap, NULL); p; p = soap_next_block(soap, NULL))
{ DBGMSG(SENT, p, soap_block_size(soap, NULL));
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Send %u bytes to socket=%d/fd=%d\n", (unsigned int)soap_block_size(soap, NULL), soap->socket, soap->sendfd));
if ((soap->error = soap->fsend(soap, p, soap_block_size(soap, NULL))))
{ soap_end_block(soap, NULL);
return soap->error;
}
}
soap_end_block(soap, NULL);
if (soap->fpreparefinalsend && (soap->error = soap->fpreparefinalsend(soap)))
return soap->error;
}
#ifndef WITH_LEANER
else if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
{ DBGMSG(SENT, "\r\n0\r\n\r\n", 7);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Send 7 bytes to socket=%d/fd=%d\n", soap->socket, soap->sendfd));
if ((soap->error = soap->fsend(soap, "\r\n0\r\n\r\n", 7)))
return soap->error;
}
#endif
}
#ifdef WITH_TCPFIN
#ifdef WITH_OPENSSL
if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP))
soap->fshutdownsocket(soap, soap->socket, SOAP_SHUT_WR); /* Send TCP FIN */
#else
if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP))
soap->fshutdownsocket(soap, soap->socket, SOAP_SHUT_WR); /* Send TCP FIN */
#endif
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n"));
soap->omode &= ~SOAP_SEC_WSUID;
soap->count = 0;
soap->part = SOAP_END;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_end_recv(struct soap *soap)
{ soap->part = SOAP_END;
#ifndef WITH_LEAN
soap->wsuid = NULL; /* reset before next send */
soap->c14nexclude = NULL; /* reset before next send */
#endif
#ifndef WITH_LEANER
soap->ffilterrecv = NULL;
if ((soap->mode & SOAP_ENC_DIME) && soap_getdime(soap))
{ soap->dime.first = NULL;
soap->dime.last = NULL;
return soap->error;
}
soap->dime.list = soap->dime.first;
soap->dime.first = NULL;
soap->dime.last = NULL;
/* Check if MIME attachments and mime-post-check flag is set, if so call soap_resolve() and return */
if (soap->mode & SOAP_ENC_MIME)
{ if (soap->mode & SOAP_MIME_POSTCHECK)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Post checking MIME attachments\n"));
if (!soap->keep_alive)
soap->keep_alive = -1;
#ifndef WITH_NOIDREF
soap_resolve(soap);
#endif
return SOAP_OK;
}
if (soap_getmime(soap))
return soap->error;
}
soap->mime.list = soap->mime.first;
soap->mime.first = NULL;
soap->mime.last = NULL;
soap->mime.boundary = NULL;
if (soap->xlist)
{ struct soap_multipart *content;
for (content = soap->mime.list; content; content = content->next)
soap_resolve_attachment(soap, content);
}
#endif
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "End of receive message ok\n"));
#ifdef WITH_ZLIB
if (soap->mode & SOAP_ENC_ZLIB)
{ /* Make sure end of compressed content is reached */
while (soap->d_stream->next_out != Z_NULL)
if ((int)soap_get1(soap) == EOF)
break;
soap->mode &= ~SOAP_ENC_ZLIB;
memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
soap->bufidx = (char*)soap->d_stream->next_in - soap->z_buf;
soap->buflen = soap->z_buflen;
soap->zlib_state = SOAP_ZLIB_NONE;
if (inflateEnd(soap->d_stream) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Inflate end ok\n"));
#ifdef WITH_GZIP
if (soap->zlib_in == SOAP_ZLIB_GZIP)
{ soap_wchar c;
short i;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Inflate gzip crc check\n"));
for (i = 0; i < 8; i++)
{ if ((int)(c = soap_get1(soap)) == EOF)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: unable to read crc value\n"));
return soap->error = SOAP_ZLIB_ERROR;
}
soap->z_buf[i] = (char)c;
}
if (soap->z_crc != ((uLong)(unsigned char)soap->z_buf[0] | ((uLong)(unsigned char)soap->z_buf[1] << 8) | ((uLong)(unsigned char)soap->z_buf[2] << 16) | ((uLong)(unsigned char)soap->z_buf[3] << 24)))
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip inflate error: crc check failed, message corrupted? (crc32=%lu)\n", (unsigned long)soap->z_crc));
return soap->error = SOAP_ZLIB_ERROR;
}
if (soap->d_stream->total_out != ((uLong)(unsigned char)soap->z_buf[4] | ((uLong)(unsigned char)soap->z_buf[5] << 8) | ((uLong)(unsigned char)soap->z_buf[6] << 16) | ((uLong)(unsigned char)soap->z_buf[7] << 24)))
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip inflate error: incorrect message length\n"));
return soap->error = SOAP_ZLIB_ERROR;
}
}
soap->zlib_in = SOAP_ZLIB_NONE;
#endif
}
#endif
if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
while (soap->ahead != EOF && !soap_recv_raw(soap))
;
#ifndef WITH_NOIDREF
if (soap_resolve(soap))
return soap->error;
#endif
#ifndef WITH_LEANER
if (soap->xlist)
{ if (soap->mode & SOAP_ENC_MTOM)
return soap->error = SOAP_MIME_HREF;
return soap->error = SOAP_DIME_HREF;
}
#endif
soap_free_ns(soap);
#ifndef WITH_LEANER
if (soap->fpreparefinalrecv)
return soap->error = soap->fpreparefinalrecv(soap);
#endif
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_free_temp(struct soap *soap)
{ register struct soap_attribute *tp, *tq;
register struct Namespace *ns;
soap_free_ns(soap);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free any remaining temp blocks\n"));
while (soap->blist)
soap_end_block(soap, NULL);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attribute storage\n"));
for (tp = soap->attributes; tp; tp = tq)
{ tq = tp->next;
if (tp->value)
SOAP_FREE(soap, tp->value);
SOAP_FREE(soap, tp);
}
soap->attributes = NULL;
#ifdef WITH_FAST
if (soap->labbuf)
SOAP_FREE(soap, soap->labbuf);
soap->labbuf = NULL;
soap->lablen = 0;
soap->labidx = 0;
#endif
ns = soap->local_namespaces;
if (ns)
{ for (; ns->id; ns++)
{ if (ns->out)
{ SOAP_FREE(soap, ns->out);
ns->out = NULL;
}
}
SOAP_FREE(soap, soap->local_namespaces);
soap->local_namespaces = NULL;
}
#ifndef WITH_LEANER
while (soap->xlist)
{ struct soap_xlist *xp = soap->xlist->next;
SOAP_FREE(soap, soap->xlist);
soap->xlist = xp;
}
#endif
#ifndef WITH_NOIDREF
soap_free_pht(soap);
soap_free_iht(soap);
#endif
}
#endif
/******************************************************************************/
#ifndef PALM_1
static void
soap_free_ns(struct soap *soap)
{ register struct soap_nlist *np, *nq;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n"));
for (np = soap->nlist; np; np = nq)
{ nq = np->next;
SOAP_FREE(soap, np);
}
soap->nlist = NULL;
}
#endif
/******************************************************************************/
#ifndef PALM_1
#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
static void
soap_init_logs(struct soap *soap)
{ int i;
for (i = 0; i < SOAP_MAXLOGS; i++)
{ soap->logfile[i] = NULL;
soap->fdebug[i] = NULL;
}
}
#endif
#endif
/******************************************************************************/
#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
SOAP_FMAC1
void
SOAP_FMAC2
soap_open_logfile(struct soap *soap, int i)
{ if (soap->logfile[i])
soap->fdebug[i] = fopen(soap->logfile[i], i < 2 ? "ab" : "a");
}
#endif
/******************************************************************************/
#ifdef SOAP_DEBUG
static void
soap_close_logfile(struct soap *soap, int i)
{ if (soap->fdebug[i])
{ fclose(soap->fdebug[i]);
soap->fdebug[i] = NULL;
}
}
#endif
/******************************************************************************/
#ifdef SOAP_DEBUG
SOAP_FMAC1
void
SOAP_FMAC2
soap_close_logfiles(struct soap *soap)
{ int i;
for (i = 0; i < SOAP_MAXLOGS; i++)
soap_close_logfile(soap, i);
}
#endif
/******************************************************************************/
#ifdef SOAP_DEBUG
static void
soap_set_logfile(struct soap *soap, int i, const char *logfile)
{ const char *s;
char *t = NULL;
soap_close_logfile(soap, i);
s = soap->logfile[i];
soap->logfile[i] = logfile;
if (s)
SOAP_FREE(soap, (void*)s);
if (logfile)
if ((t = (char*)SOAP_MALLOC(soap, strlen(logfile) + 1)))
strcpy(t, logfile);
soap->logfile[i] = t;
}
#endif
/******************************************************************************/
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_recv_logfile(struct soap *soap, const char *logfile)
{
#ifdef SOAP_DEBUG
soap_set_logfile(soap, SOAP_INDEX_RECV, logfile);
#endif
}
/******************************************************************************/
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_sent_logfile(struct soap *soap, const char *logfile)
{
#ifdef SOAP_DEBUG
soap_set_logfile(soap, SOAP_INDEX_SENT, logfile);
#endif
}
/******************************************************************************/
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_test_logfile(struct soap *soap, const char *logfile)
{
#ifdef SOAP_DEBUG
soap_set_logfile(soap, SOAP_INDEX_TEST, logfile);
#endif
}
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
struct soap*
SOAP_FMAC2
soap_copy(const struct soap *soap)
{ return soap_copy_context((struct soap*)malloc(sizeof(struct soap)), soap);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
struct soap*
SOAP_FMAC2
soap_copy_context(struct soap *copy, const struct soap *soap)
{ if (copy == soap)
return copy;
if (soap_check_state(soap))
return NULL;
if (copy)
{ register struct soap_plugin *p = NULL;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying context\n"));
#ifdef __cplusplus
*copy = *soap;
#else
memcpy(copy, soap, sizeof(struct soap));
#endif
copy->state = SOAP_COPY;
copy->error = SOAP_OK;
copy->userid = NULL;
copy->passwd = NULL;
#ifdef WITH_NTLM
copy->ntlm_challenge = NULL;
#endif
copy->nlist = NULL;
copy->blist = NULL;
copy->clist = NULL;
copy->alist = NULL;
copy->attributes = NULL;
copy->labbuf = NULL;
copy->lablen = 0;
copy->labidx = 0;
#ifdef SOAP_MEM_DEBUG
soap_init_mht(copy);
#endif
#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
soap_init_logs(copy);
#endif
#ifdef SOAP_DEBUG
soap_set_test_logfile(copy, soap->logfile[SOAP_INDEX_TEST]);
soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]);
soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]);
#endif
copy->namespaces = soap->local_namespaces;
copy->local_namespaces = NULL;
soap_set_local_namespaces(copy); /* copy content of soap->local_namespaces */
copy->namespaces = soap->namespaces; /* point to shared read-only namespaces table */
#ifdef WITH_C_LOCALE
# ifdef WIN32
copy->c_locale = _create_locale(LC_ALL, "C");
# else
copy->c_locale = duplocale(soap->c_locale);
# endif
#else
copy->c_locale = NULL;
#endif
#ifdef WITH_OPENSSL
copy->bio = NULL;
copy->ssl = NULL;
copy->session = NULL;
#endif
#ifdef WITH_GNUTLS
copy->session = NULL;
#endif
#ifdef WITH_ZLIB
copy->d_stream = (z_stream*)SOAP_MALLOC(copy, sizeof(z_stream));
copy->d_stream->zalloc = Z_NULL;
copy->d_stream->zfree = Z_NULL;
copy->d_stream->opaque = Z_NULL;
copy->z_buf = NULL;
#endif
#ifndef WITH_NOIDREF
soap_init_iht(copy);
soap_init_pht(copy);
#endif
copy->header = NULL;
copy->fault = NULL;
copy->action = NULL;
#ifndef WITH_LEAN
#ifdef WITH_COOKIES
copy->cookies = soap_copy_cookies(copy, soap);
#else
copy->cookies = NULL;
#endif
#endif
copy->plugins = NULL;
for (p = soap->plugins; p; p = p->next)
{ register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(copy, sizeof(struct soap_plugin));
if (!q)
return NULL;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying plugin '%s'\n", p->id));
*q = *p;
if (p->fcopy && p->fcopy(copy, q, p))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not copy plugin '%s'\n", p->id));
SOAP_FREE(copy, q);
return NULL;
}
q->next = copy->plugins;
copy->plugins = q;
}
}
return copy;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_copy_stream(struct soap *copy, struct soap *soap)
{ struct soap_attribute *tp = NULL, *tq;
if (copy == soap)
return;
copy->header = soap->header;
copy->mode = soap->mode;
copy->imode = soap->imode;
copy->omode = soap->omode;
copy->master = soap->master;
copy->socket = soap->socket;
copy->sendsk = soap->sendsk;
copy->recvsk = soap->recvsk;
copy->recv_timeout = soap->recv_timeout;
copy->send_timeout = soap->send_timeout;
#if defined(__cplusplus) && !defined(WITH_LEAN)
copy->os = soap->os;
copy->is = soap->is;
#endif
copy->sendfd = soap->sendfd;
copy->recvfd = soap->recvfd;
copy->bufidx = soap->bufidx;
copy->buflen = soap->buflen;
copy->ahead = soap->ahead;
copy->cdata = soap->cdata;
copy->chunksize = soap->chunksize;
copy->chunkbuflen = soap->chunkbuflen;
copy->keep_alive = soap->keep_alive;
copy->tcp_keep_alive = soap->tcp_keep_alive;
copy->tcp_keep_idle = soap->tcp_keep_idle;
copy->tcp_keep_intvl = soap->tcp_keep_intvl;
copy->tcp_keep_cnt = soap->tcp_keep_cnt;
copy->max_keep_alive = soap->max_keep_alive;
#ifndef WITH_NOIO
copy->peer = soap->peer;
copy->peerlen = soap->peerlen;
copy->ip = soap->ip;
copy->port = soap->port;
memcpy(copy->host, soap->host, sizeof(soap->host));
memcpy(copy->endpoint, soap->endpoint, sizeof(soap->endpoint));
#endif
#ifdef WITH_OPENSSL
copy->bio = soap->bio;
copy->ctx = soap->ctx;
copy->ssl = soap->ssl;
#endif
#ifdef WITH_GNUTLS
copy->session = soap->session;
#endif
#ifdef WITH_ZLIB
copy->zlib_state = soap->zlib_state;
copy->zlib_in = soap->zlib_in;
copy->zlib_out = soap->zlib_out;
if (!copy->d_stream)
copy->d_stream = (z_stream*)SOAP_MALLOC(copy, sizeof(z_stream));
if (copy->d_stream)
memcpy(copy->d_stream, soap->d_stream, sizeof(z_stream));
copy->z_crc = soap->z_crc;
copy->z_ratio_in = soap->z_ratio_in;
copy->z_ratio_out = soap->z_ratio_out;
copy->z_buf = NULL;
copy->z_buflen = soap->z_buflen;
copy->z_level = soap->z_level;
if (soap->z_buf && soap->zlib_state != SOAP_ZLIB_NONE)
{ copy->z_buf = (char*)SOAP_MALLOC(copy, SOAP_BUFLEN);
if (copy->z_buf)
memcpy(copy->z_buf, soap->z_buf, SOAP_BUFLEN);
}
copy->z_dict = soap->z_dict;
copy->z_dict_len = soap->z_dict_len;
#endif
memcpy(copy->buf, soap->buf, sizeof(soap->buf));
/* copy XML parser state */
soap_free_ns(copy);
soap_set_local_namespaces(copy);
copy->version = soap->version;
if (soap->nlist && soap->local_namespaces)
{ register struct soap_nlist *np = NULL, *nq;
/* copy reversed nlist */
for (nq = soap->nlist; nq; nq = nq->next)
{ register struct soap_nlist *nr = np;
size_t n = sizeof(struct soap_nlist) + strlen(nq->id);
np = (struct soap_nlist*)SOAP_MALLOC(copy, n);
if (!np)
break;
memcpy(np, nq, n);
np->next = nr;
}
while (np)
{ register const char *s = np->ns;
copy->level = np->level; /* preserve element nesting level */
if (!s && np->index >= 0)
{ s = soap->local_namespaces[np->index].out;
if (!s)
s = soap->local_namespaces[np->index].ns;
}
if (s && soap_push_namespace(copy, np->id, s) == NULL)
break;
nq = np;
np = np->next;
SOAP_FREE(copy, nq);
}
}
memcpy(copy->tag, soap->tag, sizeof(copy->tag));
memcpy(copy->id, soap->id, sizeof(copy->id));
memcpy(copy->href, soap->href, sizeof(copy->href));
memcpy(copy->type, soap->type, sizeof(copy->type));
copy->other = soap->other;
copy->root = soap->root;
copy->null = soap->null;
copy->body = soap->body;
copy->part = soap->part;
copy->mustUnderstand = soap->mustUnderstand;
copy->level = soap->level;
copy->peeked = soap->peeked;
/* copy attributes */
for (tq = soap->attributes; tq; tq = tq->next)
{ struct soap_attribute *tr = tp;
size_t n = sizeof(struct soap_attribute) + strlen(tq->name);
tp = (struct soap_attribute*)SOAP_MALLOC(copy, n);
memcpy(tp, tq, n);
if (tp->size)
{ tp->value = (char*)SOAP_MALLOC(copy, tp->size);
if (tp->value)
strcpy(tp->value, tq->value);
}
tp->ns = NULL;
tp->next = tr;
}
copy->attributes = tp;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_free_stream(struct soap *soap)
{ soap->socket = SOAP_INVALID_SOCKET;
soap->sendsk = SOAP_INVALID_SOCKET;
soap->recvsk = SOAP_INVALID_SOCKET;
#ifdef WITH_OPENSSL
soap->bio = NULL;
soap->ctx = NULL;
soap->ssl = NULL;
#endif
#ifdef WITH_GNUTLS
soap->xcred = NULL;
soap->acred = NULL;
soap->cache = NULL;
soap->session = NULL;
soap->dh_params = NULL;
soap->rsa_params = NULL;
#endif
#ifdef WITH_ZLIB
if (soap->z_buf)
SOAP_FREE(soap, soap->z_buf);
soap->z_buf = NULL;
#endif
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_initialize(struct soap *soap)
{ soap_versioning(soap_init)(soap, SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_versioning(soap_init)(struct soap *soap, soap_mode imode, soap_mode omode)
{ size_t i;
soap->state = SOAP_INIT;
#ifdef SOAP_MEM_DEBUG
soap_init_mht(soap);
#endif
#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
soap_init_logs(soap);
#endif
#ifdef SOAP_DEBUG
#ifdef TANDEM_NONSTOP
soap_set_test_logfile(soap, "TESTLOG");
soap_set_sent_logfile(soap, "SENTLOG");
soap_set_recv_logfile(soap, "RECVLOG");
#else
soap_set_test_logfile(soap, "TEST.log");
soap_set_sent_logfile(soap, "SENT.log");
soap_set_recv_logfile(soap, "RECV.log");
#endif
#endif
soap->version = 0;
soap_mode(soap, imode);
soap_imode(soap, imode);
soap_omode(soap, omode);
soap->plugins = NULL;
soap->user = NULL;
for (i = 0; i < sizeof(soap->data)/sizeof(*soap->data); i++)
soap->data[i] = NULL;
soap->userid = NULL;
soap->passwd = NULL;
soap->authrealm = NULL;
#ifdef WITH_NTLM
soap->ntlm_challenge = NULL;
#endif
#ifndef WITH_NOHTTP
soap->fpost = http_post;
soap->fget = http_get;
soap->fput = http_405;
soap->fdel = http_405;
soap->fopt = http_200;
soap->fhead = http_200;
soap->fform = NULL;
soap->fposthdr = http_post_header;
soap->fresponse = http_response;
soap->fparse = http_parse;
soap->fparsehdr = http_parse_header;
#endif
soap->fheader = NULL;
soap->fconnect = NULL;
soap->fdisconnect = NULL;
#ifndef WITH_NOIO
soap->ipv6_multicast_if = 0; /* in_addr_t value */
soap->ipv4_multicast_if = NULL; /* points to struct in_addr or in_addr_t */
soap->ipv4_multicast_ttl = 0; /* 0: use default */
#ifndef WITH_IPV6
soap->fresolve = tcp_gethost;
#else
soap->fresolve = NULL;
#endif
soap->faccept = tcp_accept;
soap->fopen = tcp_connect;
soap->fclose = tcp_disconnect;
soap->fclosesocket = tcp_closesocket;
soap->fshutdownsocket = tcp_shutdownsocket;
soap->fsend = fsend;
soap->frecv = frecv;
soap->fpoll = soap_poll;
#else
soap->fopen = NULL;
soap->fclose = NULL;
soap->fpoll = NULL;
#endif
soap->fseterror = NULL;
soap->fignore = NULL;
soap->fserveloop = NULL;
soap->fplugin = fplugin;
soap->fmalloc = NULL;
#ifndef WITH_LEANER
soap->feltbegin = NULL;
soap->feltendin = NULL;
soap->feltbegout = NULL;
soap->feltendout = NULL;
soap->fprepareinitsend = NULL;
soap->fprepareinitrecv = NULL;
soap->fpreparesend = NULL;
soap->fpreparerecv = NULL;
soap->fpreparefinalsend = NULL;
soap->fpreparefinalrecv = NULL;
soap->ffiltersend = NULL;
soap->ffilterrecv = NULL;
soap->fdimereadopen = NULL;
soap->fdimewriteopen = NULL;
soap->fdimereadclose = NULL;
soap->fdimewriteclose = NULL;
soap->fdimeread = NULL;
soap->fdimewrite = NULL;
soap->fmimereadopen = NULL;
soap->fmimewriteopen = NULL;
soap->fmimereadclose = NULL;
soap->fmimewriteclose = NULL;
soap->fmimeread = NULL;
soap->fmimewrite = NULL;
#endif
soap->float_format = "%.9G"; /* Alternative: use "%G" */
soap->double_format = "%.17lG"; /* Alternative: use "%lG" */
soap->dime_id_format = "cid:id%d"; /* default DIME id format */
soap->http_version = "1.1";
soap->proxy_http_version = "1.0";
soap->http_content = NULL;
soap->actor = NULL;
soap->lang = "en";
soap->keep_alive = 0;
soap->tcp_keep_alive = 0;
soap->tcp_keep_idle = 0;
soap->tcp_keep_intvl = 0;
soap->tcp_keep_cnt = 0;
soap->max_keep_alive = SOAP_MAXKEEPALIVE;
soap->recv_timeout = 0;
soap->send_timeout = 0;
soap->connect_timeout = 0;
soap->accept_timeout = 0;
soap->socket_flags = 0;
soap->connect_flags = 0;
soap->bind_flags = 0;
soap->accept_flags = 0;
soap->linger_time = 0;
soap->ip = 0;
soap->labbuf = NULL;
soap->lablen = 0;
soap->labidx = 0;
soap->encodingStyle = NULL;
#ifndef WITH_NONAMESPACES
soap->namespaces = namespaces;
#else
soap->namespaces = NULL;
#endif
soap->local_namespaces = NULL;
soap->nlist = NULL;
soap->blist = NULL;
soap->clist = NULL;
soap->alist = NULL;
soap->attributes = NULL;
soap->header = NULL;
soap->fault = NULL;
soap->master = SOAP_INVALID_SOCKET;
soap->socket = SOAP_INVALID_SOCKET;
soap->sendsk = SOAP_INVALID_SOCKET;
soap->recvsk = SOAP_INVALID_SOCKET;
soap->os = NULL;
soap->is = NULL;
#ifndef WITH_LEANER
soap->dom = NULL;
soap->dime.list = NULL;
soap->dime.first = NULL;
soap->dime.last = NULL;
soap->mime.list = NULL;
soap->mime.first = NULL;
soap->mime.last = NULL;
soap->mime.boundary = NULL;
soap->mime.start = NULL;
soap->xlist = NULL;
#endif
#ifndef UNDER_CE
soap->recvfd = 0;
soap->sendfd = 1;
#else
soap->recvfd = stdin;
soap->sendfd = stdout;
#endif
soap->host[0] = '\0';
soap->port = 0;
soap->action = NULL;
soap->proxy_host = NULL;
soap->proxy_port = 8080;
soap->proxy_userid = NULL;
soap->proxy_passwd = NULL;
soap->prolog = NULL;
#ifdef WITH_ZLIB
soap->zlib_state = SOAP_ZLIB_NONE;
soap->zlib_in = SOAP_ZLIB_NONE;
soap->zlib_out = SOAP_ZLIB_NONE;
soap->d_stream = (z_stream*)SOAP_MALLOC(soap, sizeof(z_stream));
soap->d_stream->zalloc = Z_NULL;
soap->d_stream->zfree = Z_NULL;
soap->d_stream->opaque = Z_NULL;
soap->z_buf = NULL;
soap->z_level = 6;
soap->z_dict = NULL;
soap->z_dict_len = 0;
#endif
#ifndef WITH_LEAN
soap->wsuid = NULL;
soap->c14nexclude = NULL;
soap->cookies = NULL;
soap->cookie_domain = NULL;
soap->cookie_path = NULL;
soap->cookie_max = 32;
#endif
#ifdef WMW_RPM_IO
soap->rpmreqid = NULL;
#endif
#ifdef PALM
palmNetLibOpen();
#endif
#ifndef WITH_NOIDREF
soap_init_iht(soap);
soap_init_pht(soap);
#endif
#ifdef WITH_OPENSSL
if (!soap_ssl_init_done)
soap_ssl_init();
soap->fsslauth = ssl_auth_init;
soap->fsslverify = ssl_verify_callback;
soap->bio = NULL;
soap->ssl = NULL;
soap->ctx = NULL;
soap->session = NULL;
soap->ssl_flags = SOAP_SSL_DEFAULT;
soap->keyfile = NULL;
soap->keyid = NULL;
soap->password = NULL;
soap->cafile = NULL;
soap->capath = NULL;
soap->crlfile = NULL;
soap->dhfile = NULL;
soap->randfile = NULL;
#endif
#ifdef WITH_GNUTLS
if (!soap_ssl_init_done)
soap_ssl_init();
soap->fsslauth = ssl_auth_init;
soap->fsslverify = NULL;
soap->xcred = NULL;
soap->acred = NULL;
soap->cache = NULL;
soap->session = NULL;
soap->ssl_flags = SOAP_SSL_DEFAULT;
soap->keyfile = NULL;
soap->keyid = NULL;
soap->password = NULL;
soap->cafile = NULL;
soap->capath = NULL;
soap->crlfile = NULL;
soap->dh_params = NULL;
soap->rsa_params = NULL;
#endif
#ifdef WITH_C_LOCALE
# ifdef WIN32
soap->c_locale = _create_locale(LC_ALL, "C");
# else
soap->c_locale = newlocale(LC_ALL_MASK, "C", NULL);
# endif
#else
soap->c_locale = NULL;
#endif
soap->buflen = 0;
soap->bufidx = 0;
#ifndef WITH_LEANER
soap->dime.chunksize = 0;
soap->dime.buflen = 0;
#endif
soap->null = 0;
soap->position = 0;
soap->encoding = 0;
soap->mustUnderstand = 0;
soap->ns = 0;
soap->part = SOAP_END;
soap->event = 0;
soap->evlev = 0;
soap->alloced = 0;
soap->count = 0;
soap->length = 0;
soap->cdata = 0;
soap->peeked = 0;
soap->ahead = 0;
soap->idnum = 0;
soap->level = 0;
soap->endpoint[0] = '\0';
soap->error = SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_begin(struct soap *soap)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reinitializing context\n"));
if (!soap->keep_alive)
{ soap->buflen = 0;
soap->bufidx = 0;
}
soap->null = 0;
soap->position = 0;
soap->encoding = 0;
soap->mustUnderstand = 0;
soap->mode = 0;
soap->ns = 0;
soap->part = SOAP_END;
soap->event = 0;
soap->evlev = 0;
soap->alloced = 0;
soap->count = 0;
soap->length = 0;
soap->cdata = 0;
soap->error = SOAP_OK;
soap->peeked = 0;
soap->ahead = 0;
soap->idnum = 0;
soap->level = 0;
soap->endpoint[0] = '\0';
soap->encodingStyle = SOAP_STR_EOS;
#ifndef WITH_LEANER
soap->dime.chunksize = 0;
soap->dime.buflen = 0;
#endif
soap_free_temp(soap);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_end(struct soap *soap)
{ if (soap_check_state(soap))
return;
soap_free_temp(soap);
soap_dealloc(soap, NULL);
while (soap->clist)
{ register struct soap_clist *cp = soap->clist->next;
SOAP_FREE(soap, soap->clist);
soap->clist = cp;
}
soap_closesock(soap);
#ifdef SOAP_DEBUG
soap_close_logfiles(soap);
#endif
#ifdef PALM
palmNetLibClose();
#endif
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_version(struct soap *soap, short version)
{ soap_set_local_namespaces(soap);
if (soap->version != version)
{ if (version == 1)
{ soap->local_namespaces[0].ns = soap_env1;
soap->local_namespaces[1].ns = soap_enc1;
}
else if (version == 2)
{ soap->local_namespaces[0].ns = soap_env2;
soap->local_namespaces[1].ns = soap_enc2;
}
soap->version = version;
}
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_namespaces(struct soap *soap, const struct Namespace *p)
{ register struct Namespace *ns = soap->local_namespaces;
register struct soap_nlist *np, *nq, *nr;
register unsigned int level = soap->level;
soap->namespaces = p;
soap->local_namespaces = NULL;
soap_set_local_namespaces(soap);
/* reverse the namespace list */
np = soap->nlist;
soap->nlist = NULL;
if (np)
{ nq = np->next;
np->next = NULL;
while (nq)
{ nr = nq->next;
nq->next = np;
np = nq;
nq = nr;
}
}
/* then push on new stack */
while (np)
{ register const char *s;
soap->level = np->level; /* preserve element nesting level */
s = np->ns;
if (!s && np->index >= 0 && ns)
{ s = ns[np->index].out;
if (!s)
s = ns[np->index].ns;
}
if (s && soap_push_namespace(soap, np->id, s) == NULL)
return soap->error;
nq = np;
np = np->next;
SOAP_FREE(soap, nq);
}
if (ns)
{ register int i;
for (i = 0; ns[i].id; i++)
{ if (ns[i].out)
{ SOAP_FREE(soap, ns[i].out);
ns[i].out = NULL;
}
}
SOAP_FREE(soap, ns);
}
soap->level = level; /* restore level */
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_local_namespaces(struct soap *soap)
{ if (soap->namespaces && !soap->local_namespaces)
{ register const struct Namespace *ns1;
register struct Namespace *ns2;
register size_t n = 1;
for (ns1 = soap->namespaces; ns1->id; ns1++)
n++;
n *= sizeof(struct Namespace);
ns2 = (struct Namespace*)SOAP_MALLOC(soap, n);
if (ns2)
{ memcpy(ns2, soap->namespaces, n);
if (ns2[0].ns)
{ if (!strcmp(ns2[0].ns, soap_env1))
soap->version = 1;
else if (!strcmp(ns2[0].ns, soap_env2))
soap->version = 2;
}
soap->local_namespaces = ns2;
for (; ns2->id; ns2++)
ns2->out = NULL;
}
}
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
#ifndef PALM_1
SOAP_FMAC1
const char *
SOAP_FMAC2
soap_tagsearch(const char *big, const char *little)
{ if (little)
{ register size_t n = strlen(little);
register const char *s = big;
while (s)
{ register const char *t = s;
register size_t i;
for (i = 0; i < n; i++, t++)
{ if (*t != little[i])
break;
}
if (*t == '\0' || *t == ' ')
{ if (i == n || (i && little[i-1] == ':'))
return s;
}
s = strchr(t, ' ');
if (s)
s++;
}
}
return NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEAN
#ifndef PALM_1
SOAP_FMAC1
struct soap_nlist *
SOAP_FMAC2
soap_lookup_ns(struct soap *soap, const char *tag, size_t n)
{ register struct soap_nlist *np;
for (np = soap->nlist; np; np = np->next)
{ if (!strncmp(np->id, tag, n) && !np->id[n])
return np;
}
return NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEAN
static struct soap_nlist *
soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized)
{ register struct soap_nlist *np;
size_t n, k;
if (soap_tagsearch(soap->c14nexclude, id))
return NULL;
if (!utilized)
{ for (np = soap->nlist; np; np = np->next)
{ if (!strcmp(np->id, id) && (!np->ns || !strcmp(np->ns, ns)))
break;
}
if (np)
{ if ((np->level < soap->level || !np->ns) && np->index == 1)
utilized = 1;
else
return NULL;
}
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Adding namespace binding (level=%u) '%s' '%s' utilized=%d\n", soap->level, id, ns ? ns : "(null)", utilized));
n = strlen(id);
if (ns)
k = strlen(ns);
else
k = 0;
np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k + 1);
if (!np)
{ soap->error = SOAP_EOM;
return NULL;
}
np->next = soap->nlist;
soap->nlist = np;
strcpy((char*)np->id, id);
if (ns)
np->ns = strcpy((char*)np->id + n + 1, ns);
else
np->ns = NULL;
np->level = soap->level;
np->index = utilized;
return np;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
static void
soap_utilize_ns(struct soap *soap, const char *tag)
{ register struct soap_nlist *np;
size_t n = 0;
const char *t = strchr(tag, ':');
if (t)
{ n = t - tag;
if (n >= sizeof(soap->tmpbuf))
n = sizeof(soap->tmpbuf) - 1;
}
np = soap_lookup_ns(soap, tag, n);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Utilizing namespace of '%s'\n", tag));
if (np)
{ if (np->index <= 0)
soap_push_ns(soap, np->id, np->ns, 1);
}
else if (strncmp(tag, "xml", 3))
{ strncpy(soap->tmpbuf, tag, n);
soap->tmpbuf[n] = '\0';
soap_push_ns(soap, soap->tmpbuf, NULL, 1);
}
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_element(struct soap *soap, const char *tag, int id, const char *type)
{
#ifndef WITH_LEAN
register const char *s;
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' level='%u' id='%d' type='%s'\n", tag, soap->level, id, type ? type : SOAP_STR_EOS));
soap->level++;
#ifdef WITH_DOM
#ifndef WITH_LEAN
if (soap->wsuid && soap_tagsearch(soap->wsuid, tag))
{ size_t i;
for (s = tag, i = 0; *s && i < sizeof(soap->tag) - 1; s++, i++)
soap->tag[i] = *s == ':' ? '-' : *s;
soap->tag[i] = '\0';
if (soap_set_attr(soap, "wsu:Id", soap->tag, 1))
return soap->error;
}
if ((soap->mode & SOAP_XML_CANONICAL) && !(soap->mode & SOAP_DOM_ASIS))
{ if (soap->evlev >= soap->level)
soap->evlev = 0;
if (soap->event == SOAP_SEC_BEGIN && !soap->evlev)
{ register struct soap_nlist *np;
/* non-nested wsu:Id found: clear xmlns, re-emit them for exc-c14n */
for (np = soap->nlist; np; np = np->next)
{ if (np->index == 2)
{ struct soap_nlist *np1 = soap_push_ns(soap, np->id, np->ns, 1);
if (np1)
np1->index = 0;
}
}
soap->evlev = soap->level;
}
}
#endif
if (soap->mode & SOAP_XML_DOM)
{ register struct soap_dom_element *elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element));
if (!elt)
return soap->error;
elt->soap = soap;
elt->next = NULL;
elt->prnt = soap->dom;
elt->name = soap_strdup(soap, tag);
elt->elts = NULL;
elt->atts = NULL;
elt->nstr = NULL;
elt->data = NULL;
elt->wide = NULL;
elt->node = NULL;
elt->type = 0;
elt->head = NULL;
elt->tail = NULL;
if (soap->dom)
{ struct soap_dom_element *p = soap->dom->elts;
if (p)
{ while (p->next)
p = p->next;
p->next = elt;
}
else
soap->dom->elts = elt;
}
soap->dom = elt;
}
else
{
#endif
#ifndef WITH_LEAN
if (!soap->ns)
{ if (!(soap->mode & SOAP_XML_CANONICAL)
&& soap_send(soap, soap->prolog ? soap->prolog : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"))
return soap->error;
}
else if (soap->mode & SOAP_XML_INDENT)
{ if (soap->ns == 1 && soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1))
return soap->error;
soap->body = 1;
}
if ((soap->mode & SOAP_XML_DEFAULTNS) && (s = strchr(tag, ':')))
{ struct Namespace *ns = soap->local_namespaces;
size_t n = s - tag;
if (soap_send_raw(soap, "<", 1)
|| soap_send(soap, s + 1))
return soap->error;
if (soap->nlist && !strncmp(soap->nlist->id, tag, n) && !soap->nlist->id[n])
ns = NULL;
for (; ns && ns->id; ns++)
{ if (*ns->id && (ns->out || ns->ns) && !strncmp(ns->id, tag, n) && !ns->id[n])
{ soap_push_ns(soap, ns->id, ns->out ? ns->out : ns->ns, 0);
if (soap_attribute(soap, "xmlns", ns->out ? ns->out : ns->ns))
return soap->error;
break;
}
}
}
else
#endif
if (soap_send_raw(soap, "<", 1)
|| soap_send(soap, tag))
return soap->error;
#ifdef WITH_DOM
}
#endif
if (!soap->ns)
{ struct Namespace *ns = soap->local_namespaces;
int k = -1;
if (ns)
{
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_DEFAULTNS))
{ if (soap->version)
k = 4; /* first four required entries */
else if (!(soap->mode & SOAP_XML_NOTYPE) || (soap->mode & SOAP_XML_NIL))
{ ns += 2;
k = 2; /* next two entries */
}
else
k = 0; /* no entries */
}
#endif
while (k-- && ns->id)
{ if (*ns->id && (ns->out || ns->ns))
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "xmlns:%s", ns->id);
#else
sprintf(soap->tmpbuf, "xmlns:%s", ns->id);
#endif
if (soap_attribute(soap, soap->tmpbuf, ns->out ? ns->out : ns->ns))
return soap->error;
}
ns++;
}
}
}
soap->ns = 1; /* namespace table control: ns = 0 or 2 to start, then 1 to stop dumping the table */
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
soap_utilize_ns(soap, tag);
#endif
if (id > 0)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "_%d", id);
#else
sprintf(soap->tmpbuf, "_%d", id);
#endif
if (soap->version == 2)
{ if (soap_attribute(soap, "SOAP-ENC:id", soap->tmpbuf))
return soap->error;
}
else if (soap_attribute(soap, "id", soap->tmpbuf))
return soap->error;
}
if (type && *type && !(soap->mode & SOAP_XML_NOTYPE) && soap->part != SOAP_IN_HEADER)
{ const char *t = type;
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_DEFAULTNS)
{ t = strchr(type, ':');
if (t)
t++;
else
t = type;
}
#endif
if (soap->attributes ? soap_set_attr(soap, "xsi:type", t, 1) : soap_attribute(soap, "xsi:type", t))
return soap->error;
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
soap_utilize_ns(soap, type);
#endif
}
if (soap->null && soap->position > 0)
{ register int i;
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf) - 1, "[%d", soap->positions[0]);
#else
sprintf(soap->tmpbuf, "[%d", soap->positions[0]);
#endif
for (i = 1; i < soap->position; i++)
{ register size_t l = strlen(soap->tmpbuf);
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf + l, sizeof(soap->tmpbuf)-l-1, ",%d", soap->positions[i]);
#else
if (l + 13 < sizeof(soap->tmpbuf))
sprintf(soap->tmpbuf + l, ",%d", soap->positions[i]);
#endif
}
strcat(soap->tmpbuf, "]");
if (soap_attribute(soap, "SOAP-ENC:position", soap->tmpbuf))
return soap->error;
}
if (soap->mustUnderstand)
{ if (soap->actor && *soap->actor)
{ if (soap_attribute(soap, soap->version == 2 ? "SOAP-ENV:role" : "SOAP-ENV:actor", soap->actor))
return soap->error;
}
if (soap_attribute(soap, "SOAP-ENV:mustUnderstand", soap->version == 2 ? "true" : "1"))
return soap->error;
soap->mustUnderstand = 0;
}
if (soap->encoding)
{ if (soap->encodingStyle && soap->local_namespaces && soap->local_namespaces[0].id && soap->local_namespaces[1].id)
{ if (!*soap->encodingStyle)
{ if (soap->local_namespaces[1].out)
soap->encodingStyle = soap->local_namespaces[1].out;
else
soap->encodingStyle = soap->local_namespaces[1].ns;
}
if (soap->encodingStyle && soap_attribute(soap, "SOAP-ENV:encodingStyle", soap->encodingStyle))
return soap->error;
}
else
soap->encodingStyle = NULL;
soap->encoding = 0;
}
soap->null = 0;
soap->position = 0;
if (soap->event == SOAP_SEC_BEGIN)
soap->event = 0;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_begin_out(struct soap *soap, const char *tag, int id, const char *type)
{ if (*tag == '-')
return SOAP_OK;
if (soap_element(soap, tag, id, type))
return soap->error;
#ifdef WITH_DOM
if (soap_element_start_end_out(soap, NULL))
return soap->error;
if (soap->feltbegout)
return soap->error = soap->feltbegout(soap, tag);
return SOAP_OK;
#else
return soap_element_start_end_out(soap, NULL);
#endif
}
#endif
/******************************************************************************/
#ifndef PALM_2
#ifndef HAVE_STRRCHR
SOAP_FMAC1
char*
SOAP_FMAC2
soap_strrchr(const char *s, int t)
{ register char *r = NULL;
while (*s)
if (*s++ == t)
r = (char*)s - 1;
return r;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
#ifndef HAVE_STRTOL
SOAP_FMAC1
long
SOAP_FMAC2
soap_strtol(const char *s, char **t, int b)
{ register long n = 0;
register int c;
while (*s > 0 && *s <= 32)
s++;
if (b == 10)
{ short neg = 0;
if (*s == '-')
{ s++;
neg = 1;
}
else if (*s == '+')
s++;
while ((c = *s) && c >= '0' && c <= '9')
{ if (n >= 214748364 && (n > 214748364 || c >= '8'))
break;
n *= 10;
n += c - '0';
s++;
}
if (neg)
n = -n;
}
else /* assume b == 16 and value is always positive */
{ while ((c = *s))
{ if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'A' && c <= 'F')
c -= 'A' - 10;
else if (c >= 'a' && c <= 'f')
c -= 'a' - 10;
if (n > 0x07FFFFFF)
break;
n <<= 4;
n += c;
s++;
}
}
if (t)
*t = (char*)s;
return n;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
#ifndef HAVE_STRTOUL
SOAP_FMAC1
unsigned long
SOAP_FMAC2
soap_strtoul(const char *s, char **t, int b)
{ unsigned long n = 0;
register int c;
while (*s > 0 && *s <= 32)
s++;
if (b == 10)
{ if (*s == '+')
s++;
while ((c = *s) && c >= '0' && c <= '9')
{ if (n >= 429496729 && (n > 429496729 || c >= '6'))
break;
n *= 10;
n += c - '0';
s++;
}
}
else /* b == 16 */
{ while ((c = *s))
{ if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'A' && c <= 'F')
c -= 'A' - 10;
else if (c >= 'a' && c <= 'f')
c -= 'a' - 10;
if (n > 0x0FFFFFFF)
break;
n <<= 4;
n += c;
s++;
}
}
if (t)
*t = (char*)s;
return n;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_array_begin_out(struct soap *soap, const char *tag, int id, const char *type, const char *offset)
{ if (!type || !*type)
return soap_element_begin_out(soap, tag, id, NULL);
if (soap_element(soap, tag, id, "SOAP-ENC:Array"))
return soap->error;
if (soap->version == 2)
{ const char *s;
s = soap_strrchr(type, '[');
if (s && (size_t)(s - type) < sizeof(soap->tmpbuf))
{ strncpy(soap->tmpbuf, type, s - type);
soap->tmpbuf[s - type] = '\0';
if (soap_attribute(soap, "SOAP-ENC:itemType", soap->tmpbuf))
return soap->error;
s++;
if (*s)
{ strncpy(soap->tmpbuf, s, sizeof(soap->tmpbuf));
soap->tmpbuf[sizeof(soap->tmpbuf) - 1] = '\0';
soap->tmpbuf[strlen(soap->tmpbuf) - 1] = '\0';
if (soap_attribute(soap, "SOAP-ENC:arraySize", soap->tmpbuf))
return soap->error;
}
}
}
else
{ if (offset && soap_attribute(soap, "SOAP-ENC:offset", offset))
return soap->error;
if (soap_attribute(soap, "SOAP-ENC:arrayType", type))
return soap->error;
}
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
soap_utilize_ns(soap, type);
#endif
return soap_element_start_end_out(soap, NULL);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_start_end_out(struct soap *soap, const char *tag)
{ register struct soap_attribute *tp;
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
{ struct soap_nlist *np;
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible && tp->name)
soap_utilize_ns(soap, tp->name);
}
for (np = soap->nlist; np; np = np->next)
{ if (np->index == 1 && np->ns)
{ if (*(np->id))
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "xmlns:%s", np->id);
#else
sprintf(soap->tmpbuf, "xmlns:%s", np->id);
#endif
}
else
strcpy(soap->tmpbuf, "xmlns");
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enabling utilized binding (level=%u) %s='%s'\n", np->level, soap->tmpbuf, np->ns));
soap_set_attr(soap, soap->tmpbuf, np->ns, 1);
np->index = 2;
}
}
}
#endif
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ register struct soap_dom_attribute **att;
att = &soap->dom->atts;
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible)
{ *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
if (!*att)
return soap->error;
(*att)->next = NULL;
(*att)->nstr = NULL;
(*att)->name = soap_strdup(soap, tp->name);
(*att)->data = soap_strdup(soap, tp->value);
(*att)->wide = NULL;
(*att)->soap = soap;
att = &(*att)->next;
tp->visible = 0;
}
}
return SOAP_OK;
}
#endif
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible)
{
#ifndef WITH_LEAN
const char *s;
if ((soap->mode & SOAP_XML_DEFAULTNS) && (s = strchr(tp->name, ':')))
{ size_t n = s - tp->name;
if (soap->nlist && !strncmp(soap->nlist->id, tp->name, n) && !soap->nlist->id[n])
s++;
else
s = tp->name;
if (soap_send(soap, " ") || soap_send(soap, s))
return soap->error;
}
else
#endif
if (soap_send(soap, " ") || soap_send(soap, tp->name))
return soap->error;
if (tp->visible == 2 && tp->value)
if (soap_send_raw(soap, "=\"", 2)
|| soap_string_out(soap, tp->value, tp->flag)
|| soap_send_raw(soap, "\"", 1))
return soap->error;
tp->visible = 0;
}
}
if (tag)
{
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
{ if (soap_send_raw(soap, ">", 1)
|| soap_element_end_out(soap, tag))
return soap->error;
return SOAP_OK;
}
#endif
soap->level--; /* decrement level just before /> */
return soap_send_raw(soap, "/>", 2);
}
return soap_send_raw(soap, ">", 1);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_end_out(struct soap *soap, const char *tag)
{
#ifndef WITH_LEAN
const char *s;
#endif
if (*tag == '-')
return SOAP_OK;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element ending tag='%s'\n", tag));
#ifdef WITH_DOM
if (soap->feltendout && (soap->error = soap->feltendout(soap, tag)))
return soap->error;
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ if (soap->dom->prnt)
soap->dom = soap->dom->prnt;
return SOAP_OK;
}
#endif
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
soap_pop_namespace(soap);
if (soap->mode & SOAP_XML_INDENT)
{ if (!soap->body)
{ if (soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1))
return soap->error;
}
soap->body = 0;
}
if ((soap->mode & SOAP_XML_DEFAULTNS) && (s = strchr(tag, ':')))
{ soap_pop_namespace(soap);
tag = s + 1;
}
#endif
if (soap_send_raw(soap, "</", 2)
|| soap_send(soap, tag))
return soap->error;
soap->level--; /* decrement level just before > */
return soap_send_raw(soap, ">", 1);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_ref(struct soap *soap, const char *tag, int id, int href)
{ register const char *s = "ref";
register int n = 1;
if (soap->version == 1)
{ s = "href";
n = 0;
}
else if (soap->version == 2)
s = "SOAP-ENC:ref";
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->href, sizeof(soap->href), "#_%d", href);
#else
sprintf(soap->href, "#_%d", href);
#endif
return soap_element_href(soap, tag, id, s, soap->href + n);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_href(struct soap *soap, const char *tag, int id, const char *ref, const char *val)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element '%s' reference %s='%s'\n", tag, ref, val));
if (soap_element(soap, tag, id, NULL)
|| soap_attribute(soap, ref, val)
|| soap_element_start_end_out(soap, tag))
return soap->error;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_null(struct soap *soap, const char *tag, int id, const char *type)
{ struct soap_attribute *tp = NULL;
for (tp = soap->attributes; tp; tp = tp->next)
if (tp->visible)
break;
if (tp || (soap->version == 2 && soap->position > 0) || id > 0 || (soap->mode & SOAP_XML_NIL))
{ if (soap_element(soap, tag, id, type)
|| (!tp && soap_attribute(soap, "xsi:nil", "true")))
return soap->error;
return soap_element_start_end_out(soap, tag);
}
soap->null = 1;
soap->position = 0;
soap->mustUnderstand = 0;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_nil(struct soap *soap, const char *tag)
{ if (soap_element(soap, tag, -1, NULL)
|| ((soap->mode & SOAP_XML_NIL) && soap_attribute(soap, "xsi:nil", "true")))
return soap->error;
return soap_element_start_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_id(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, int n, const char *type, int t)
{ if (!p)
{ soap->error = soap_element_null(soap, tag, id, type);
return -1;
}
#ifndef WITH_NOIDREF
if ((!soap->encodingStyle && !(soap->omode & SOAP_XML_GRAPH)) || (soap->omode & SOAP_XML_TREE))
return 0;
if (id < 0)
{ struct soap_plist *pp;
if (a)
id = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
else
id = soap_pointer_lookup(soap, p, t, &pp);
if (id)
{ if (soap_is_embedded(soap, pp))
{ soap_element_ref(soap, tag, 0, id);
return -1;
}
if (soap_is_single(soap, pp))
return 0;
soap_set_embedded(soap, pp);
}
}
return id;
#else
return 0;
#endif
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_result(struct soap *soap, const char *tag)
{ if (soap->version == 2 && soap->encodingStyle)
{ if (soap_element(soap, "SOAP-RPC:result", 0, NULL)
|| soap_attribute(soap, "xmlns:SOAP-RPC", soap_rpc)
|| soap_element_start_end_out(soap, NULL)
|| soap_string_out(soap, tag, 0)
|| soap_element_end_out(soap, "SOAP-RPC:result"))
return soap->error;
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_check_result(struct soap *soap, const char *tag)
{ if (soap->version == 2 && soap->encodingStyle)
{ soap_instring(soap, ":result", NULL, NULL, 0, 2, -1, -1);
/* just ignore content for compliance reasons, but should compare tag to element's QName value? */
}
(void)tag;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_attribute(struct soap *soap, const char *name, const char *value)
{
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Attribute '%s'='%s'\n", name, value));
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && !(soap->mode & SOAP_XML_CANONICAL) && soap->dom)
{ register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
if (!a)
return soap->error;
a->next = soap->dom->atts;
a->nstr = NULL;
a->name = soap_strdup(soap, name);
a->data = soap_strdup(soap, value);
a->wide = NULL;
a->soap = soap;
soap->dom->atts = a;
return SOAP_OK;
}
#endif
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
{ /* push namespace */
if (!strncmp(name, "xmlns", 5) && (name[5] == ':' || name[5] == '\0'))
soap_push_ns(soap, name + 5 + (name[5] == ':'), value, 0);
else if (soap_set_attr(soap, name, value, 1))
return soap->error;
}
else
#endif
{ if (soap_send(soap, " ") || soap_send(soap, name))
return soap->error;
if (value)
if (soap_send_raw(soap, "=\"", 2)
|| soap_string_out(soap, value, 1)
|| soap_send_raw(soap, "\"", 1))
return soap->error;
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_begin_in(struct soap *soap, const char *tag, int nillable, const char *type)
{ if (!soap_peek_element(soap))
{ if (soap->other)
return soap->error = SOAP_TAG_MISMATCH;
if (tag && *tag == '-')
return SOAP_OK;
if (!(soap->error = soap_match_tag(soap, soap->tag, tag)))
{ soap->peeked = 0;
if (type && *soap->type && soap_match_tag(soap, soap->type, type))
return soap->error = SOAP_TYPE;
if (!nillable && soap->null && (soap->mode & SOAP_XML_STRICT))
return soap->error = SOAP_NULL;
if (soap->body)
soap->level++;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag ? tag : SOAP_STR_EOS ));
soap->error = SOAP_OK;
}
}
else if (soap->error == SOAP_NO_TAG && tag && *tag == '-')
soap->error = SOAP_OK;
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_element_end_in(struct soap *soap, const char *tag)
{ register soap_wchar c;
register char *s;
register int n = 0;
if (tag && *tag == '-')
return SOAP_OK;
if (soap->error == SOAP_NO_TAG)
soap->error = SOAP_OK;
#ifdef WITH_DOM
/* this whitespace or mixed content is significant for DOM */
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ if (!soap->peeked && !soap_string_in(soap, 3, -1, -1))
return soap->error;
if (soap->dom->prnt)
soap->dom = soap->dom->prnt;
}
#endif
if (soap->peeked)
{ if (*soap->tag)
n++;
soap->peeked = 0;
}
do
{ while (((c = soap_get(soap)) != SOAP_TT))
{ if ((int)c == EOF)
return soap->error = SOAP_CHK_EOF;
if (c == SOAP_LT)
n++;
else if (c == '/')
{ c = soap_get(soap);
if (c == SOAP_GT)
n--;
else
soap_unget(soap, c);
}
}
} while (n--);
s = soap->tag;
n = sizeof(soap->tag);
while (soap_notblank(c = soap_get(soap)))
{ if (--n > 0)
*s++ = (char)c;
}
*s = '\0';
if ((int)c == EOF)
return soap->error = SOAP_CHK_EOF;
while (soap_blank(c))
c = soap_get(soap);
if (c != SOAP_GT)
return soap->error = SOAP_SYNTAX_ERROR;
#ifndef WITH_LEAN
#ifdef WITH_DOM
if (soap->feltendin)
{ soap->level--;
return soap->error = soap->feltendin(soap, soap->tag, tag);
}
#endif
if (tag && (soap->mode & SOAP_XML_STRICT))
{ soap_pop_namespace(soap);
if (soap_match_tag(soap, soap->tag, tag))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element tag '%s' does not match '%s'\n", soap->tag, tag ? tag : SOAP_STR_EOS));
return soap->error = SOAP_SYNTAX_ERROR;
}
}
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag ? tag : SOAP_STR_EOS));
soap->level--;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char *
SOAP_FMAC2
soap_attr_value(struct soap *soap, const char *name, int flag)
{ register struct soap_attribute *tp;
if (*name == '-')
return SOAP_STR_EOS;
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible && !soap_match_tag(soap, tp->name, name))
break;
}
if (tp)
{ if (flag == 2 && (soap->mode & SOAP_XML_STRICT))
soap->error = SOAP_PROHIBITED;
else
return tp->value;
}
else if (flag == 1 && (soap->mode & SOAP_XML_STRICT))
soap->error = SOAP_REQUIRED;
else
soap->error = SOAP_OK;
return NULL;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_attr(struct soap *soap, const char *name, const char *value, int flag)
{ register struct soap_attribute *tp;
if (*name == '-')
return SOAP_OK;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attribute %s='%s'\n", name, value ? value : SOAP_STR_EOS));
for (tp = soap->attributes; tp; tp = tp->next)
{ if (!strcmp(tp->name, name))
break;
}
if (!tp)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute %s\n", name));
if (!(tp = (struct soap_attribute*)SOAP_MALLOC(soap, sizeof(struct soap_attribute) + strlen(name))))
return soap->error = SOAP_EOM;
tp->ns = NULL;
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
{ struct soap_attribute **tpp = &soap->attributes;
const char *s = strchr(name, ':');
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inserting attribute %s for c14n\n", name));
if (!strncmp(name, "xmlns", 5))
{ for (; *tpp; tpp = &(*tpp)->next)
if (strncmp((*tpp)->name, "xmlns", 5) || strcmp((*tpp)->name + 5, name + 5) > 0)
break;
}
else if (!s)
{ for (; *tpp; tpp = &(*tpp)->next)
if (strncmp((*tpp)->name, "xmlns", 5) && ((*tpp)->ns || strcmp((*tpp)->name, name) > 0))
break;
}
else
{ struct soap_nlist *np = soap_lookup_ns(soap, name, s - name);
if (np)
tp->ns = np->ns;
else
{ struct soap_attribute *tq;
for (tq = soap->attributes; tq; tq = tq->next)
{ if (!strncmp(tq->name, "xmlns:", 6) && !strncmp(tq->name + 6, name, s - name) && !tq->name[6 + s - name])
{ tp->ns = tq->ns;
break;
}
}
}
for (; *tpp; tpp = &(*tpp)->next)
{ int k;
if (strncmp((*tpp)->name, "xmlns", 5) && (*tpp)->ns && tp->ns && ((k = strcmp((*tpp)->ns, tp->ns)) > 0 || (!k && strcmp((*tpp)->name, name) > 0)))
break;
}
}
tp->next = *tpp;
*tpp = tp;
}
else
#endif
{ tp->next = soap->attributes;
soap->attributes = tp;
}
strcpy((char*)tp->name, name);
tp->value = NULL;
}
else if (tp->visible)
{ return SOAP_OK;
}
else if (value && tp->value && tp->size <= strlen(value))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attribute value of %s (free %p)\n", name, tp->value));
SOAP_FREE(soap, tp->value);
tp->value = NULL;
tp->ns = NULL;
}
if (value)
{ if (!tp->value)
{ tp->size = strlen(value) + 1;
if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size)))
return soap->error = SOAP_EOM;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value for %s (%p)\n", tp->name, tp->value));
}
strcpy(tp->value, value);
if (!strncmp(tp->name, "xmlns:", 6))
tp->ns = tp->value;
tp->visible = 2;
tp->flag = (short)flag;
#ifndef WITH_LEAN
if (!strcmp(name, "wsu:Id"))
{ soap->event = SOAP_SEC_BEGIN;
strncpy(soap->id, value, sizeof(soap->id));
soap->id[sizeof(soap->id) - 1] = '\0';
}
#endif
}
else
tp->visible = 1;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_clr_attr(struct soap *soap)
{ register struct soap_attribute *tp;
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
{ while (soap->attributes)
{ tp = soap->attributes->next;
if (soap->attributes->value)
SOAP_FREE(soap, soap->attributes->value);
SOAP_FREE(soap, soap->attributes);
soap->attributes = tp;
}
}
else
#endif
{ for (tp = soap->attributes; tp; tp = tp->next)
tp->visible = 0;
}
}
#endif
/******************************************************************************/
#ifndef PALM_2
static int
soap_getattrval(struct soap *soap, char *s, size_t n, soap_wchar d)
{ register size_t i;
for (i = 0; i < n; i++)
{ register soap_wchar c = soap_get(soap);
switch (c)
{
case SOAP_TT:
*s++ = '<';
soap_unget(soap, '/');
break;
case SOAP_LT:
*s++ = '<';
break;
case SOAP_GT:
if (d == ' ')
{ soap_unget(soap, c);
*s = '\0';
return SOAP_OK;
}
*s++ = '>';
break;
case SOAP_QT:
if (c == d)
{ *s = '\0';
return SOAP_OK;
}
*s++ = '"';
break;
case SOAP_AP:
if (c == d)
{ *s = '\0';
return SOAP_OK;
}
*s++ = '\'';
break;
case '\t':
case '\n':
case '\r':
case ' ':
case '/':
if (d == ' ')
{ soap_unget(soap, c);
*s = '\0';
return SOAP_OK;
}
default:
if ((int)c == EOF)
{ *s = '\0';
return soap->error = SOAP_CHK_EOF;
}
*s++ = (char)c;
}
}
return soap->error = SOAP_EOM;
}
#endif
/******************************************************************************/
#ifdef WITH_FAST
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_store_lab(struct soap *soap, const char *s, size_t n)
{ soap->labidx = 0;
return soap_append_lab(soap, s, n);
}
#endif
#endif
/******************************************************************************/
#ifdef WITH_FAST
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_append_lab(struct soap *soap, const char *s, size_t n)
{ if (soap->labidx + n >= soap->lablen)
{ register char *t = soap->labbuf;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enlarging look-aside buffer to append data, size=%lu\n", (unsigned long)soap->lablen));
if (soap->lablen == 0)
soap->lablen = SOAP_LABLEN;
while (soap->labidx + n >= soap->lablen)
soap->lablen <<= 1;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New look-aside buffer size=%lu\n", (unsigned long)soap->lablen));
soap->labbuf = (char*)SOAP_MALLOC(soap, soap->lablen);
if (!soap->labbuf)
{ if (t)
SOAP_FREE(soap, t);
return soap->error = SOAP_EOM;
}
if (t)
{ memcpy(soap->labbuf, t, soap->labidx);
SOAP_FREE(soap, t);
}
}
if (s)
{ memcpy(soap->labbuf + soap->labidx, s, n);
soap->labidx += n;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_peek_element(struct soap *soap)
{
#ifdef WITH_DOM
register struct soap_dom_attribute **att = NULL;
register char *lead = NULL;
#endif
register struct soap_attribute *tp, *tq = NULL;
register const char *t;
register char *s;
register soap_wchar c;
register int i;
if (soap->peeked)
{ if (!*soap->tag)
return soap->error = SOAP_NO_TAG;
return SOAP_OK;
}
soap->peeked = 1;
soap->id[0] = '\0';
soap->href[0] = '\0';
soap->type[0] = '\0';
soap->arrayType[0] = '\0';
soap->arraySize[0] = '\0';
soap->arrayOffset[0] = '\0';
soap->other = 0;
soap->root = -1;
soap->position = 0;
soap->null = 0;
soap->mustUnderstand = 0;
/* UTF-8 BOM? */
c = soap_getchar(soap);
if (c == 0xEF && soap_get0(soap) == 0xBB)
{ c = soap_get1(soap);
if ((c = soap_get1(soap)) == 0xBF)
soap->mode &= ~SOAP_ENC_LATIN;
else
soap_unget(soap, (0x0F << 12) | (0xBB << 6) | (c & 0x3F)); /* UTF-8 */
}
else if ((c == 0xFE && soap_get0(soap) == 0xFF) /* UTF-16 BE */
|| (c == 0xFF && soap_get0(soap) == 0xFE)) /* UTF-16 LE */
return soap->error = SOAP_UTF_ERROR;
else
soap_unget(soap, c);
c = soap_get(soap);
#ifdef WITH_DOM
/* whitespace leading to tag is not insignificant for DOM */
if (soap_blank(c))
{ soap->labidx = 0;
do
{ if (soap_append_lab(soap, NULL, 0))
return soap->error;
s = soap->labbuf + soap->labidx;
i = soap->lablen - soap->labidx;
soap->labidx = soap->lablen;
while (soap_blank(c) && i--)
{ *s++ = c;
c = soap_get(soap);
}
}
while (soap_blank(c));
*s = '\0';
lead = soap->labbuf;
}
#else
/* skip space */
while (soap_blank(c))
c = soap_get(soap);
#endif
if (c != SOAP_LT)
{ *soap->tag = '\0';
if ((int)c == EOF)
return soap->error = SOAP_CHK_EOF;
soap_unget(soap, c);
#ifdef WITH_DOM
/* whitespace leading to end tag is significant for DOM */
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ if (lead && *lead)
soap->dom->tail = soap_strdup(soap, lead);
else
soap->dom->tail = (char*)SOAP_STR_EOS;
}
#endif
return soap->error = SOAP_NO_TAG;
}
do c = soap_get1(soap);
while (soap_blank(c));
s = soap->tag;
i = sizeof(soap->tag);
while (c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF)
{ if (--i > 0)
*s++ = (char)c;
c = soap_get1(soap);
}
*s = '\0';
while (soap_blank(c))
c = soap_get1(soap);
#ifdef WITH_DOM
if (soap->mode & SOAP_XML_DOM)
{ register struct soap_dom_element *elt;
elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element));
if (!elt)
return soap->error;
elt->next = NULL;
elt->nstr = NULL;
elt->name = soap_strdup(soap, soap->tag);
elt->prnt = soap->dom;
elt->elts = NULL;
elt->atts = NULL;
elt->data = NULL;
elt->wide = NULL;
elt->type = 0;
elt->node = NULL;
elt->head = soap_strdup(soap, lead);
elt->tail = NULL;
elt->soap = soap;
if (soap->dom)
{ struct soap_dom_element *p = soap->dom->elts;
if (p)
{ while (p->next)
p = p->next;
p->next = elt;
}
else
soap->dom->elts = elt;
}
soap->dom = elt;
att = &elt->atts;
}
#endif
soap_pop_namespace(soap);
for (tp = soap->attributes; tp; tp = tp->next)
tp->visible = 0;
while ((int)c != EOF && c != '>' && c != '/')
{ s = soap->tmpbuf;
i = sizeof(soap->tmpbuf);
while (c != '=' && c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF)
{ if (--i > 0)
*s++ = (char)c;
c = soap_get1(soap);
}
*s = '\0';
if (i == sizeof(soap->tmpbuf))
return soap->error = SOAP_SYNTAX_ERROR;
#ifdef WITH_DOM
/* add attribute name to dom */
if (att)
{ *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
if (!*att)
return soap->error;
(*att)->next = NULL;
(*att)->nstr = NULL;
(*att)->name = soap_strdup(soap, soap->tmpbuf);
(*att)->data = NULL;
(*att)->wide = NULL;
(*att)->soap = soap;
}
#endif
if (!strncmp(soap->tmpbuf, "xmlns", 5))
{ if (soap->tmpbuf[5] == ':')
t = soap->tmpbuf + 6;
else if (soap->tmpbuf[5])
t = NULL;
else
t = SOAP_STR_EOS;
}
else
t = NULL;
tq = NULL;
for (tp = soap->attributes; tp; tq = tp, tp = tp->next)
{ if (!SOAP_STRCMP(tp->name, soap->tmpbuf))
break;
}
if (!tp)
{ tp = (struct soap_attribute*)SOAP_MALLOC(soap, sizeof(struct soap_attribute) + strlen(soap->tmpbuf));
if (!tp)
return soap->error = SOAP_EOM;
strcpy((char*)tp->name, soap->tmpbuf);
tp->value = NULL;
tp->size = 0;
tp->ns = NULL;
/* if attribute name is qualified, append it to the end of the list */
if (tq && strchr(soap->tmpbuf, ':'))
{ tq->next = tp;
tp->next = NULL;
}
else
{ tp->next = soap->attributes;
soap->attributes = tp;
}
}
while (soap_blank(c))
c = soap_get1(soap);
if (c == '=')
{ do c = soap_getutf8(soap);
while (soap_blank(c));
if (c != SOAP_QT && c != SOAP_AP)
{ soap_unget(soap, c);
c = ' '; /* blank delimiter */
}
if (soap_getattrval(soap, tp->value, tp->size, c))
{
#ifdef WITH_FAST
if (soap->error != SOAP_EOM)
return soap->error;
soap->error = SOAP_OK;
if (soap_store_lab(soap, tp->value, tp->size))
return soap->error;
if (tp->value)
SOAP_FREE(soap, tp->value);
tp->value = NULL;
for (;;)
{ if (soap_getattrval(soap, soap->labbuf + soap->labidx, soap->lablen - soap->labidx, c))
{ if (soap->error != SOAP_EOM)
return soap->error;
soap->error = SOAP_OK;
soap->labidx = soap->lablen;
if (soap_append_lab(soap, NULL, 0))
return soap->error;
}
else
break;
}
if (soap->labidx)
tp->size = soap->lablen;
else
{ tp->size = strlen(soap->labbuf) + 1;
if (tp->size < SOAP_LABLEN)
tp->size = SOAP_LABLEN;
}
if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size)))
return soap->error = SOAP_EOM;
strcpy(tp->value, soap->labbuf);
#else
size_t n;
if (soap->error != SOAP_EOM)
return soap->error;
soap->error = SOAP_OK;
if (soap_new_block(soap) == NULL)
return soap->error;
for (;;)
{ if (!(s = (char*)soap_push_block(soap, NULL, SOAP_BLKLEN)))
return soap->error;
if (soap_getattrval(soap, s, SOAP_BLKLEN, c))
{ if (soap->error != SOAP_EOM)
return soap->error;
soap->error = SOAP_OK;
}
else
break;
}
n = tp->size + soap->blist->size;
if (!(s = (char*)SOAP_MALLOC(soap, n)))
return soap->error = SOAP_EOM;
if (tp->value)
{ memcpy(s, tp->value, tp->size);
SOAP_FREE(soap, tp->value);
}
soap_save_block(soap, NULL, s + tp->size, 0);
tp->value = s;
tp->size = n;
#endif
}
do c = soap_get1(soap);
while (soap_blank(c));
tp->visible = 2; /* seen this attribute w/ value */
#ifdef WITH_DOM
if (att)
(*att)->data = soap_strdup(soap, tp->value);
#endif
}
else
tp->visible = 1; /* seen this attribute w/o value */
#ifdef WITH_DOM
if (att)
att = &(*att)->next;
#endif
if (t && tp->value)
{ if (soap_push_namespace(soap, t, tp->value) == NULL)
return soap->error;
}
}
#ifdef WITH_DOM
if (att)
{ soap->dom->nstr = soap_current_namespace(soap, soap->tag);
for (att = &soap->dom->atts; *att; att = &(*att)->next)
(*att)->nstr = soap_current_namespace(soap, (*att)->name);
}
#endif
if ((int)c == EOF)
return soap->error = SOAP_CHK_EOF;
if (!(soap->body = (c != '/')))
do c = soap_get1(soap);
while (soap_blank(c));
#ifdef WITH_DOM
if (soap->mode & SOAP_XML_DOM)
{ if (!soap->body && soap->dom->prnt)
soap->dom = soap->dom->prnt;
}
#endif
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible && tp->value)
{
#ifndef WITH_NOIDREF
if (!strcmp(tp->name, "id"))
{ if ((soap->version > 0 && !(soap->imode & SOAP_XML_TREE))
|| (soap->mode & SOAP_XML_GRAPH))
{ *soap->id = '#';
strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2);
soap->id[sizeof(soap->id) - 1] = '\0';
}
}
else if (!strcmp(tp->name, "href"))
{ if ((soap->version == 1 && !(soap->imode & SOAP_XML_TREE))
|| (soap->mode & SOAP_XML_GRAPH)
|| (soap->mode & SOAP_ENC_MTOM)
|| (soap->mode & SOAP_ENC_DIME))
{ strncpy(soap->href, tp->value, sizeof(soap->href) - 1);
soap->href[sizeof(soap->href) - 1] = '\0';
}
}
else if (!strcmp(tp->name, "ref"))
{ if ((soap->version == 2 && !(soap->imode & SOAP_XML_TREE))
|| (soap->mode & SOAP_XML_GRAPH))
{ *soap->href = '#';
strncpy(soap->href + (*tp->value != '#'), tp->value, sizeof(soap->href) - 2);
soap->href[sizeof(soap->href) - 1] = '\0';
}
}
else
#endif
if (!soap_match_tag(soap, tp->name, "xsi:type"))
{ strncpy(soap->type, tp->value, sizeof(soap->type) - 1);
soap->type[sizeof(soap->type) - 1] = '\0';
}
else if ((!soap_match_tag(soap, tp->name, "xsi:null")
|| !soap_match_tag(soap, tp->name, "xsi:nil"))
&& (!strcmp(tp->value, "1")
|| !strcmp(tp->value, "true")))
{ soap->null = 1;
}
else if (soap->version == 1)
{ if (!soap_match_tag(soap, tp->name, "SOAP-ENC:arrayType"))
{ s = soap_strrchr(tp->value, '[');
if (s && (size_t)(s - tp->value) < sizeof(soap->arrayType))
{ strncpy(soap->arrayType, tp->value, s - tp->value);
soap->arrayType[s - tp->value] = '\0';
strncpy(soap->arraySize, s, sizeof(soap->arraySize));
}
else
strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType));
soap->arraySize[sizeof(soap->arraySize) - 1] = '\0';
soap->arrayType[sizeof(soap->arrayType) - 1] = '\0';
}
else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:offset"))
strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset));
else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:position"))
soap->position = soap_getposition(tp->value, soap->positions);
else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:root"))
soap->root = ((!strcmp(tp->value, "1") || !strcmp(tp->value, "true")));
else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:mustUnderstand")
&& (!strcmp(tp->value, "1") || !strcmp(tp->value, "true")))
soap->mustUnderstand = 1;
else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor"))
{ if ((!soap->actor || strcmp(soap->actor, tp->value))
&& strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next"))
soap->other = 1;
}
}
else if (soap->version == 2)
{
#ifndef WITH_NOIDREF
if (!soap_match_tag(soap, tp->name, "SOAP-ENC:id"))
{ *soap->id = '#';
strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2);
soap->id[sizeof(soap->id) - 1] = '\0';
}
else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:ref"))
{ *soap->href = '#';
strncpy(soap->href + (*tp->value != '#'), tp->value, sizeof(soap->href) - 2);
soap->href[sizeof(soap->href) - 1] = '\0';
}
else
#endif
if (!soap_match_tag(soap, tp->name, "SOAP-ENC:itemType"))
strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize"))
strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 1);
else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:mustUnderstand")
&& (!strcmp(tp->value, "1") || !strcmp(tp->value, "true")))
soap->mustUnderstand = 1;
else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:role"))
{ if ((!soap->actor || strcmp(soap->actor, tp->value))
&& strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next"))
soap->other = 1;
}
}
else
{ if (!soap_match_tag(soap, tp->name, "wsdl:required") && !strcmp(tp->value, "true"))
soap->mustUnderstand = 1;
}
}
}
#ifdef WITH_DOM
if (soap->feltbegin)
return soap->error = soap->feltbegin(soap, soap->tag);
#endif
return soap->error = SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_retry(struct soap *soap)
{ soap->error = SOAP_OK;
soap_revert(soap);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
SOAP_FMAC2
soap_revert(struct soap *soap)
{ if (!soap->peeked)
{ soap->peeked = 1;
if (soap->body)
soap->level--;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reverting to last element '%s' (level=%u)\n", soap->tag, soap->level));
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_string_out(struct soap *soap, const char *s, int flag)
{ register const char *t;
register soap_wchar c;
register soap_wchar mask = (soap_wchar)0xFFFFFF80UL;
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ soap->dom->data = soap_strdup(soap, s);
return SOAP_OK;
}
#endif
if (flag == 2 || soap->mode & SOAP_C_UTFSTRING)
mask = 0;
t = s;
while ((c = *t++))
{ switch (c)
{
case 0x09:
if (flag)
{ if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "	", 5))
return soap->error;
s = t;
}
break;
case 0x0A:
if (flag || !(soap->mode & SOAP_XML_CANONICAL))
{ if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
return soap->error;
s = t;
}
break;
case 0x0D:
if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
return soap->error;
s = t;
break;
case '&':
if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "&", 5))
return soap->error;
s = t;
break;
case '<':
if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "<", 4))
return soap->error;
s = t;
break;
case '>':
if (!flag)
{ if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, ">", 4))
return soap->error;
s = t;
}
break;
case '"':
if (flag)
{ if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, """, 6))
return soap->error;
s = t;
}
break;
default:
#ifndef WITH_LEANER
#ifdef HAVE_MBTOWC
if (soap->mode & SOAP_C_MBSTRING)
{ wchar_t wc;
register int m = mbtowc(&wc, t - 1, MB_CUR_MAX);
if (m > 0 && !((soap_wchar)wc == c && m == 1 && c < 0x80))
{ if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned long)wc))
return soap->error;
s = t += m - 1;
continue;
}
}
#endif
#endif
#ifndef WITH_NOSTRINGTOUTF8
if ((c & mask) || !(c & 0xFFFFFFE0UL))
{ if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned char)c))
return soap->error;
s = t;
}
#endif
}
}
return soap_send_raw(soap, s, t - s - 1);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char *
SOAP_FMAC2
soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
{ register char *s;
char *t = NULL;
register size_t i;
register long l = 0;
register int n = 0, f = 0, m = 0;
register soap_wchar c;
#if !defined(WITH_LEANER) && defined(HAVE_WCTOMB)
char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8];
#else
char buf[8];
#endif
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading string content, flag=%d\n", flag));
if (soap->peeked && *soap->tag)
{
#ifndef WITH_LEAN
struct soap_attribute *tp;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String content includes tag '%s' and attributes\n", soap->tag));
t = soap->tmpbuf;
*t = '<';
strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 2);
t[sizeof(soap->tmpbuf) - 1] = '\0';
t += strlen(t);
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible)
{ if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2)
break;
*t++ = ' ';
strcpy(t, tp->name);
t += strlen(t);
if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2)
break; /* too many or large attribute values */
if (tp->value)
{ *t++ = '=';
*t++ = '"';
strcpy(t, tp->value);
t += strlen(t);
*t++ = '"';
}
}
}
if (!soap->body)
*t++ = '/';
*t++ = '>';
*t = '\0';
t = soap->tmpbuf;
m = (int)strlen(soap->tmpbuf);
#endif
if (soap->body)
n = 1;
f = 1;
soap->peeked = 0;
}
#ifdef WITH_CDATA
if (!flag)
{ register int state = 0;
#ifdef WITH_FAST
soap->labidx = 0; /* use look-aside buffer */
#else
if (soap_new_block(soap) == NULL)
return NULL;
#endif
for (;;)
{
#ifdef WITH_FAST
register size_t k;
if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
return NULL;
s = soap->labbuf + soap->labidx; /* space to populate */
k = soap->lablen - soap->labidx; /* number of bytes available */
soap->labidx = soap->lablen; /* claim this space */
#else
register size_t k = SOAP_BLKLEN;
if (!(s = (char*)soap_push_block(soap, NULL, k)))
return NULL;
#endif
for (i = 0; i < k; i++)
{ if (m > 0)
{ *s++ = *t++; /* copy multibyte characters */
m--;
continue;
}
c = soap_getchar(soap);
if ((int)c == EOF)
goto end;
if ((c >= 0x80 || c < SOAP_AP) && state != 1 && !(soap->mode & SOAP_ENC_LATIN))
{ if ((c & 0x7FFFFFFF) >= 0x80)
{ soap_unget(soap, c);
c = soap_getutf8(soap);
}
if ((c & 0x7FFFFFFF) >= 0x80 && (!flag || (soap->mode & SOAP_C_UTFSTRING)))
{ c &= 0x7FFFFFFF;
t = buf;
if (c < 0x0800)
*t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
else
{ if (c < 0x010000)
*t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
else
{ if (c < 0x200000)
*t++ = (char)(0xF0 | ((c >> 18) & 0x07));
else
{ if (c < 0x04000000)
*t++ = (char)(0xF8 | ((c >> 24) & 0x03));
else
{ *t++ = (char)(0xFC | ((c >> 30) & 0x01));
*t++ = (char)(0x80 | ((c >> 24) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 18) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 12) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 6) & 0x3F));
}
*t++ = (char)(0x80 | (c & 0x3F));
m = (int)(t - buf) - 1;
t = buf;
*s++ = *t++;
continue;
}
}
switch (state)
{ case 1:
if (c == ']')
state = 4;
*s++ = (char)c;
continue;
case 2:
if (c == '-')
state = 6;
*s++ = (char)c;
continue;
case 3:
if (c == '?')
state = 8;
*s++ = (char)c;
continue;
/* CDATA */
case 4:
if (c == ']')
state = 5;
else
state = 1;
*s++ = (char)c;
continue;
case 5:
if (c == '>')
state = 0;
else if (c != ']')
state = 1;
*s++ = (char)c;
continue;
/* comment */
case 6:
if (c == '-')
state = 7;
else
state = 2;
*s++ = (char)c;
continue;
case 7:
if (c == '>')
state = 0;
else if (c != '-')
state = 2;
*s++ = (char)c;
continue;
/* PI */
case 8:
if (c == '>')
state = 0;
else if (c != '?')
state = 3;
*s++ = (char)c;
continue;
}
switch (c)
{
case SOAP_TT:
if (n == 0)
goto end;
n--;
*s++ = '<';
t = (char*)"/";
m = 1;
break;
case SOAP_LT:
if (f && n == 0)
goto end;
n++;
*s++ = '<';
break;
case SOAP_GT:
*s++ = '>';
break;
case SOAP_QT:
*s++ = '"';
break;
case SOAP_AP:
*s++ = '\'';
break;
case '/':
if (n > 0)
{ c = soap_getchar(soap);
if (c == '>')
n--;
soap_unget(soap, c);
}
*s++ = '/';
break;
case '<':
c = soap_getchar(soap);
if (c == '/')
{ if (n == 0)
{ c = SOAP_TT;
goto end;
}
n--;
}
else if (c == '!')
{ c = soap_getchar(soap);
if (c == '[')
{ do c = soap_getchar(soap);
while ((int)c != EOF && c != '[');
if ((int)c == EOF)
goto end;
t = (char*)"![CDATA[";
m = 8;
state = 1;
}
else if (c == '-')
{ if ((c = soap_getchar(soap)) == '-')
state = 2;
t = (char*)"!-";
m = 2;
soap_unget(soap, c);
}
else
{ t = (char*)"!";
m = 1;
soap_unget(soap, c);
}
*s++ = '<';
break;
}
else if (c == '?')
state = 3;
else if (f && n == 0)
{ soap_revget1(soap);
c = '<';
goto end;
}
else
n++;
soap_unget(soap, c);
*s++ = '<';
break;
case '>':
*s++ = '>';
break;
case '"':
*s++ = '"';
break;
default:
#ifndef WITH_LEANER
#ifdef HAVE_WCTOMB
if (soap->mode & SOAP_C_MBSTRING)
{ m = wctomb(buf, (wchar_t)(c & 0x7FFFFFFF));
if (m >= 1 && m <= (int)MB_CUR_MAX)
{ t = buf;
*s++ = *t++;
m--;
}
else
{ *s++ = SOAP_UNKNOWN_CHAR;
m = 0;
}
}
else
#endif
#endif
*s++ = (char)(c & 0xFF);
}
l++;
if (maxlen >= 0 && l > maxlen)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
soap->error = SOAP_LENGTH;
return NULL;
}
}
}
}
#endif
#ifdef WITH_FAST
soap->labidx = 0; /* use look-aside buffer */
#else
if (soap_new_block(soap) == NULL)
return NULL;
#endif
for (;;)
{
#ifdef WITH_FAST
register size_t k;
if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
return NULL;
s = soap->labbuf + soap->labidx; /* space to populate */
k = soap->lablen - soap->labidx; /* number of bytes available */
soap->labidx = soap->lablen; /* claim this space */
#else
register size_t k = SOAP_BLKLEN;
if (!(s = (char*)soap_push_block(soap, NULL, k)))
return NULL;
#endif
for (i = 0; i < k; i++)
{ if (m > 0)
{ *s++ = *t++; /* copy multibyte characters */
m--;
continue;
}
#ifndef WITH_CDATA
if (!flag)
c = soap_getchar(soap);
else
#endif
if ((soap->mode & SOAP_C_UTFSTRING))
{ if (((c = soap_get(soap)) & 0x80000000) && c >= -0x7FFFFF80 && c < SOAP_AP)
{ c &= 0x7FFFFFFF;
t = buf;
if (c < 0x0800)
*t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
else
{ if (c < 0x010000)
*t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
else
{ if (c < 0x200000)
*t++ = (char)(0xF0 | ((c >> 18) & 0x07));
else
{ if (c < 0x04000000)
*t++ = (char)(0xF8 | ((c >> 24) & 0x03));
else
{ *t++ = (char)(0xFC | ((c >> 30) & 0x01));
*t++ = (char)(0x80 | ((c >> 24) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 18) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 12) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 6) & 0x3F));
}
*t++ = (char)(0x80 | (c & 0x3F));
m = (int)(t - buf) - 1;
t = buf;
*s++ = *t++;
continue;
}
}
else
c = soap_getutf8(soap);
switch (c)
{
case SOAP_TT:
if (n == 0)
goto end;
n--;
*s++ = '<';
t = (char*)"/";
m = 1;
break;
case SOAP_LT:
if (f && n == 0)
goto end;
n++;
*s++ = '<';
break;
case SOAP_GT:
*s++ = '>';
break;
case SOAP_QT:
*s++ = '"';
break;
case SOAP_AP:
*s++ = '\'';
break;
case '/':
if (n > 0)
{ if (!flag)
{ c = soap_getchar(soap);
if (c == '>')
n--;
}
else
{ c = soap_get(soap);
if (c == SOAP_GT)
n--;
}
soap_unget(soap, c);
}
*s++ = '/';
break;
case (soap_wchar)('<' | 0x80000000):
if (flag)
*s++ = '<';
else
{ *s++ = '&';
t = (char*)"lt;";
m = 3;
}
break;
case (soap_wchar)('>' | 0x80000000):
if (flag)
*s++ = '>';
else
{ *s++ = '&';
t = (char*)"gt;";
m = 3;
}
break;
case (soap_wchar)('&' | 0x80000000):
if (flag)
*s++ = '&';
else
{ *s++ = '&';
t = (char*)"amp;";
m = 4;
}
break;
case (soap_wchar)('"' | 0x80000000):
if (flag)
*s++ = '"';
else
{ *s++ = '&';
t = (char*)"quot;";
m = 5;
}
break;
case (soap_wchar)('\'' | 0x80000000):
if (flag)
*s++ = '\'';
else
{ *s++ = '&';
t = (char*)"apos;";
m = 5;
}
break;
default:
if ((int)c == EOF)
goto end;
#ifndef WITH_CDATA
if (c == '<' && !flag)
{ if (f && n == 0)
goto end;
c = soap_getchar(soap);
soap_unget(soap, c);
if (c == '/')
{ c = SOAP_TT;
if (n == 0)
goto end;
n--;
}
else
n++;
*s++ = '<';
break;
}
else
#endif
#ifndef WITH_LEANER
#ifdef HAVE_WCTOMB
if (soap->mode & SOAP_C_MBSTRING)
{ m = wctomb(buf, (wchar_t)(c & 0x7FFFFFFF));
if (m >= 1 && m <= (int)MB_CUR_MAX)
{ t = buf;
*s++ = *t++;
m--;
}
else
{ *s++ = SOAP_UNKNOWN_CHAR;
m = 0;
}
}
else
#endif
#endif
*s++ = (char)(c & 0xFF);
}
l++;
if (maxlen >= 0 && l > maxlen)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
soap->error = SOAP_LENGTH;
return NULL;
}
}
}
end:
soap_unget(soap, c);
*s = '\0';
#ifdef WITH_FAST
t = soap_strdup(soap, soap->labbuf);
#else
soap_size_block(soap, NULL, i + 1);
t = soap_save_block(soap, NULL, 0);
#endif
if (l < minlen)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too short: %ld chars, minlen=%ld\n", l, minlen));
soap->error = SOAP_LENGTH;
return NULL;
}
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ if (flag == 3)
soap->dom->tail = t;
else
soap->dom->data = t;
}
#endif
if (flag == 2)
if (soap_s2QName(soap, t, &t, minlen, maxlen))
return NULL;
return t;
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_wstring_out(struct soap *soap, const wchar_t *s, int flag)
{ const char *t;
char tmp;
register soap_wchar c;
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ wchar_t *r = (wchar_t*)s;
int n = 1;
while (*r++)
n++;
soap->dom->wide = r = (wchar_t*)soap_malloc(soap, n * sizeof(wchar_t));
while (n--)
*r++ = *s++;
return SOAP_OK;
}
#endif
while ((c = *s++))
{ switch (c)
{
case 0x09:
if (flag)
t = "	";
else
t = "\t";
break;
case 0x0A:
if (flag || !(soap->mode & SOAP_XML_CANONICAL))
t = "
";
else
t = "\n";
break;
case 0x0D:
t = "
";
break;
case '&':
t = "&";
break;
case '<':
t = "<";
break;
case '>':
if (flag)
t = ">";
else
t = ">";
break;
case '"':
if (flag)
t = """;
else
t = "\"";
break;
default:
if (c >= 0x20 && c < 0x80)
{ tmp = (char)c;
if (soap_send_raw(soap, &tmp, 1))
return soap->error;
}
else
{ /* check for UTF16 encoding when wchar_t is too small to hold UCS */
if (sizeof(wchar_t) < 4 && (c & 0xFC00) == 0xD800)
{ register soap_wchar d = *s++;
if ((d & 0xFC00) == 0xDC00)
c = ((c - 0xD800) << 10) + (d - 0xDC00) + 0x10000;
else
c = 0xFFFD; /* Malformed */
}
if (soap_pututf8(soap, (unsigned long)c))
return soap->error;
}
continue;
}
if (soap_send(soap, t))
return soap->error;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_2
SOAP_FMAC1
wchar_t *
SOAP_FMAC2
soap_wstring_in(struct soap *soap, int flag, long minlen, long maxlen)
{ wchar_t *s;
register int i, n = 0, f = 0;
register long l = 0;
register soap_wchar c;
char *t = NULL;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading wide string content\n"));
if (soap->peeked)
{ if (*soap->tag)
{
#ifndef WITH_LEAN
struct soap_attribute *tp;
t = soap->tmpbuf;
*t = '<';
strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 2);
t[sizeof(soap->tmpbuf) - 1] = '\0';
t += strlen(t);
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible)
{ if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2)
break;
*t++ = ' ';
strcpy(t, tp->name);
t += strlen(t);
if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2)
break;
if (tp->value)
{ *t++ = '=';
*t++ = '"';
strcpy(t, tp->value);
t += strlen(t);
*t++ = '"';
}
}
}
if (!soap->body)
*t++ = '/';
*t++ = '>';
*t = '\0';
t = soap->tmpbuf;
#endif
if (soap->body)
n = 1;
f = 1;
soap->peeked = 0;
}
}
if (soap_new_block(soap) == NULL)
return NULL;
for (;;)
{ if (!(s = (wchar_t*)soap_push_block(soap, NULL, sizeof(wchar_t)*SOAP_BLKLEN)))
return NULL;
for (i = 0; i < SOAP_BLKLEN; i++)
{ if (t)
{ *s++ = (wchar_t)*t++;
if (!*t)
t = NULL;
continue;
}
c = soap_getutf8(soap);
switch (c)
{
case SOAP_TT:
if (n == 0)
goto end;
n--;
*s++ = '<';
soap_unget(soap, '/');
break;
case SOAP_LT:
if (f && n == 0)
goto end;
n++;
*s++ = '<';
break;
case SOAP_GT:
*s++ = '>';
break;
case SOAP_QT:
*s++ = '"';
break;
case SOAP_AP:
*s++ = '\'';
break;
case '/':
if (n > 0)
{ c = soap_getutf8(soap);
if (c == SOAP_GT)
n--;
soap_unget(soap, c);
}
*s++ = '/';
break;
case '<':
if (flag)
*s++ = (soap_wchar)'<';
else
{ *s++ = (soap_wchar)'&';
t = (char*)"lt;";
}
break;
case '>':
if (flag)
*s++ = (soap_wchar)'>';
else
{ *s++ = (soap_wchar)'&';
t = (char*)"gt;";
}
break;
case '"':
if (flag)
*s++ = (soap_wchar)'"';
else
{ *s++ = (soap_wchar)'&';
t = (char*)"quot;";
}
break;
default:
if ((int)c == EOF)
goto end;
/* use UTF16 encoding when wchar_t is too small to hold UCS */
if (sizeof(wchar_t) < 4 && c > 0xFFFF)
{ register soap_wchar c1, c2;
c1 = 0xD800 - (0x10000 >> 10) + (c >> 10);
c2 = 0xDC00 + (c & 0x3FF);
c = c1;
soap_unget(soap, c2);
}
*s++ = (wchar_t)c & 0x7FFFFFFF;
}
l++;
if (maxlen >= 0 && l > maxlen)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
soap->error = SOAP_LENGTH;
return NULL;
}
}
}
end:
soap_unget(soap, c);
*s = '\0';
soap_size_block(soap, NULL, sizeof(wchar_t) * (i + 1));
if (l < minlen)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too short: %ld chars, minlen=%ld\n", l, minlen));
soap->error = SOAP_LENGTH;
return NULL;
}
s = (wchar_t*)soap_save_block(soap, NULL, NULL, 0);
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
soap->dom->wide = s;
#endif
return s;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_int2s(struct soap *soap, int n)
{ return soap_long2s(soap, (long)n);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outint(struct soap *soap, const char *tag, int id, const int *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2int(struct soap *soap, const char *s, int *p)
{ if (s)
{ long n;
char *r;
#ifndef WITH_NOIO
#ifndef WITH_LEAN
soap_reset_errno;
#endif
#endif
n = soap_strtol(s, &r, 10);
if (s == r || *r
#ifndef WITH_LEAN
|| n != (int)n
#endif
#ifndef WITH_NOIO
#ifndef WITH_LEAN
|| soap_errno == SOAP_ERANGE
#endif
#endif
)
soap->error = SOAP_TYPE;
*p = (int)n;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int *
SOAP_FMAC2
soap_inint(struct soap *soap, const char *tag, int *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":int")
&& soap_match_tag(soap, soap->type, ":short")
&& soap_match_tag(soap, soap->type, ":byte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (int*)soap_id_enter(soap, soap->id, p, t, sizeof(int), 0, NULL, NULL, NULL);
if (*soap->href)
p = (int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(int), 0, NULL);
else if (p)
{ if (soap_s2int(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_long2s(struct soap *soap, long n)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%ld", n);
#else
sprintf(soap->tmpbuf, "%ld", n);
#endif
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outlong(struct soap *soap, const char *tag, int id, const long *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_long2s(soap, *p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2long(struct soap *soap, const char *s, long *p)
{ if (s)
{ char *r;
#ifndef WITH_NOIO
#ifndef WITH_LEAN
soap_reset_errno;
#endif
#endif
*p = soap_strtol(s, &r, 10);
if (s == r || *r
#ifndef WITH_NOIO
#ifndef WITH_LEAN
|| soap_errno == SOAP_ERANGE
#endif
#endif
)
soap->error = SOAP_TYPE;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
long *
SOAP_FMAC2
soap_inlong(struct soap *soap, const char *tag, long *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":int")
&& soap_match_tag(soap, soap->type, ":short")
&& soap_match_tag(soap, soap->type, ":byte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (long*)soap_id_enter(soap, soap->id, p, t, sizeof(long), 0, NULL, NULL, NULL);
if (*soap->href)
p = (long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(long), 0, NULL);
else if (p)
{ if (soap_s2long(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_LONG642s(struct soap *soap, LONG64 n)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), SOAP_LONG_FORMAT, n);
#else
sprintf(soap->tmpbuf, SOAP_LONG_FORMAT, n);
#endif
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
int
SOAP_FMAC2
soap_outLONG64(struct soap *soap, const char *tag, int id, const LONG64 *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_LONG642s(soap, *p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2LONG64(struct soap *soap, const char *s, LONG64 *p)
{ if (s)
{
#ifdef HAVE_STRTOLL
char *r;
#ifndef WITH_NOIO
#ifndef WITH_LEAN
soap_reset_errno;
#endif
#endif
*p = soap_strtoll(s, &r, 10);
if (s == r || *r
#ifndef WITH_NOIO
#ifndef WITH_LEAN
|| soap_errno == SOAP_ERANGE
#endif
#endif
)
#else
# ifdef HAVE_SSCANF
if (sscanf(s, SOAP_LONG_FORMAT, p) != 1)
# endif
#endif
soap->error = SOAP_TYPE;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
LONG64 *
SOAP_FMAC2
soap_inLONG64(struct soap *soap, const char *tag, LONG64 *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":integer")
&& soap_match_tag(soap, soap->type, ":positiveInteger")
&& soap_match_tag(soap, soap->type, ":negativeInteger")
&& soap_match_tag(soap, soap->type, ":nonPositiveInteger")
&& soap_match_tag(soap, soap->type, ":nonNegativeInteger")
&& soap_match_tag(soap, soap->type, ":long")
&& soap_match_tag(soap, soap->type, ":int")
&& soap_match_tag(soap, soap->type, ":short")
&& soap_match_tag(soap, soap->type, ":byte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (LONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(LONG64), 0, NULL, NULL, NULL);
if (*soap->href)
p = (LONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(LONG64), 0, NULL);
else if (p)
{ if (soap_s2LONG64(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_byte2s(struct soap *soap, char n)
{ return soap_long2s(soap, (long)n);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outbyte(struct soap *soap, const char *tag, int id, const char *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2byte(struct soap *soap, const char *s, char *p)
{ if (s)
{ long n;
char *r;
n = soap_strtol(s, &r, 10);
if (s == r || *r || n < -128 || n > 127)
soap->error = SOAP_TYPE;
*p = (char)n;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char *
SOAP_FMAC2
soap_inbyte(struct soap *soap, const char *tag, char *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":byte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (char*)soap_id_enter(soap, soap->id, p, t, sizeof(char), 0, NULL, NULL, NULL);
if (*soap->href)
p = (char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(char), 0, NULL);
else if (p)
{ if (soap_s2byte(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_short2s(struct soap *soap, short n)
{ return soap_long2s(soap, (long)n);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outshort(struct soap *soap, const char *tag, int id, const short *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2short(struct soap *soap, const char *s, short *p)
{ if (s)
{ long n;
char *r;
n = soap_strtol(s, &r, 10);
if (s == r || *r || n < -32768 || n > 32767)
soap->error = SOAP_TYPE;
*p = (short)n;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
short *
SOAP_FMAC2
soap_inshort(struct soap *soap, const char *tag, short *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":short")
&& soap_match_tag(soap, soap->type, ":byte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (short*)soap_id_enter(soap, soap->id, p, t, sizeof(short), 0, NULL, NULL, NULL);
if (*soap->href)
p = (short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(short), 0, NULL);
else if (p)
{ if (soap_s2short(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_float2s(struct soap *soap, float n)
{ char *s;
if (soap_isnan((double)n))
return "NaN";
if (soap_ispinff(n))
return "INF";
if (soap_isninff(n))
return "-INF";
#if defined(HAVE_SPRINTF_L)
# ifdef WIN32
_sprintf_s_l(soap->tmpbuf, _countof(soap->tmpbuf), soap->float_format, soap->c_locale, n);
# else
sprintf_l(soap->tmpbuf, soap->c_locale, soap->float_format, n);
# endif
#else
# ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), soap->float_format, n);
# else
sprintf(soap->tmpbuf, soap->float_format, n);
# endif
s = strchr(soap->tmpbuf, ','); /* convert decimal comma to DP */
if (s)
*s = '.';
#endif
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outfloat(struct soap *soap, const char *tag, int id, const float *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_float2s(soap, *p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2float(struct soap *soap, const char *s, float *p)
{ if (s)
{ if (!*s)
return soap->error = SOAP_TYPE;
if (!soap_tag_cmp(s, "INF"))
*p = FLT_PINFTY;
else if (!soap_tag_cmp(s, "+INF"))
*p = FLT_PINFTY;
else if (!soap_tag_cmp(s, "-INF"))
*p = FLT_NINFTY;
else if (!soap_tag_cmp(s, "NaN"))
*p = FLT_NAN;
else
{
/* On some systems strtof requires -std=c99 or does not even link: so we try to use strtod first */
#if defined(HAVE_STRTOD_L)
char *r;
# ifdef WIN32
*p = (float)_strtod_l(s, &r, soap->c_locale);
# else
*p = (float)strtod_l(s, &r, soap->c_locale);
# endif
if (*r)
#elif defined(HAVE_STRTOD)
char *r;
*p = (float)strtod(s, &r);
if (*r)
#elif defined(HAVE_STRTOF_L)
char *r;
*p = strtof_l((char*)s, &r, soap->c_locale);
if (*r)
#elif defined(HAVE_STRTOF)
char *r;
*p = strtof((char*)s, &r);
if (*r)
#endif
{
#if defined(HAVE_SSCANF_L) && !defined(HAVE_STRTOF_L) && !defined(HAVE_STRTOD_L)
if (sscanf_l(s, soap->c_locale, "%f", p) != 1)
soap->error = SOAP_TYPE;
#elif defined(HAVE_SSCANF)
if (sscanf(s, "%f", p) != 1)
soap->error = SOAP_TYPE;
#else
soap->error = SOAP_TYPE;
#endif
}
}
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
static int soap_isnumeric(struct soap *soap, const char *type)
{ if (soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":float")
&& soap_match_tag(soap, soap->type, ":double")
&& soap_match_tag(soap, soap->type, ":decimal")
&& soap_match_tag(soap, soap->type, ":integer")
&& soap_match_tag(soap, soap->type, ":positiveInteger")
&& soap_match_tag(soap, soap->type, ":negativeInteger")
&& soap_match_tag(soap, soap->type, ":nonPositiveInteger")
&& soap_match_tag(soap, soap->type, ":nonNegativeInteger")
&& soap_match_tag(soap, soap->type, ":long")
&& soap_match_tag(soap, soap->type, ":int")
&& soap_match_tag(soap, soap->type, ":short")
&& soap_match_tag(soap, soap->type, ":byte")
&& soap_match_tag(soap, soap->type, ":unsignedLong")
&& soap_match_tag(soap, soap->type, ":unsignedInt")
&& soap_match_tag(soap, soap->type, ":unsignedShort")
&& soap_match_tag(soap, soap->type, ":unsignedByte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return SOAP_ERR;
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
float *
SOAP_FMAC2
soap_infloat(struct soap *soap, const char *tag, float *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type != '\0' && soap_isnumeric(soap, type))
return NULL;
#endif
p = (float*)soap_id_enter(soap, soap->id, p, t, sizeof(float), 0, NULL, NULL, NULL);
if (*soap->href)
p = (float*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(float), 0, NULL);
else if (p)
{ if (soap_s2float(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_double2s(struct soap *soap, double n)
{ char *s;
if (soap_isnan(n))
return "NaN";
if (soap_ispinfd(n))
return "INF";
if (soap_isninfd(n))
return "-INF";
#if defined(HAVE_SPRINTF_L)
# ifdef WIN32
_sprintf_s_l(soap->tmpbuf, _countof(soap->tmpbuf), soap->double_format, soap->c_locale, n);
# else
sprintf_l(soap->tmpbuf, soap->c_locale, soap->double_format, n);
# endif
#else
# ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), soap->double_format, n);
#else
sprintf(soap->tmpbuf, soap->double_format, n);
#endif
s = strchr(soap->tmpbuf, ','); /* convert decimal comma to DP */
if (s)
*s = '.';
#endif
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outdouble(struct soap *soap, const char *tag, int id, const double *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_double2s(soap, *p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2double(struct soap *soap, const char *s, double *p)
{ if (s)
{ if (!*s)
return soap->error = SOAP_TYPE;
if (!soap_tag_cmp(s, "INF"))
*p = DBL_PINFTY;
else if (!soap_tag_cmp(s, "+INF"))
*p = DBL_PINFTY;
else if (!soap_tag_cmp(s, "-INF"))
*p = DBL_NINFTY;
else if (!soap_tag_cmp(s, "NaN"))
*p = DBL_NAN;
else
{
#if defined(HAVE_STRTOD_L)
char *r;
# ifdef WIN32
*p = _strtod_l(s, &r, soap->c_locale);
# else
*p = strtod_l(s, &r, soap->c_locale);
# endif
if (*r)
#elif defined(HAVE_STRTOD)
char *r;
*p = strtod(s, &r);
if (*r)
#endif
{
#if defined(HAVE_SSCANF_L) && !defined(HAVE_STRTOF_L) && !defined(HAVE_STRTOD_L)
if (sscanf_l(s, soap->c_locale, "%lf", p) != 1)
soap->error = SOAP_TYPE;
#elif defined(HAVE_SSCANF)
if (sscanf(s, "%lf", p) != 1)
soap->error = SOAP_TYPE;
#else
soap->error = SOAP_TYPE;
#endif
}
}
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
double *
SOAP_FMAC2
soap_indouble(struct soap *soap, const char *tag, double *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type != '\0' && soap_isnumeric(soap, type))
return NULL;
#endif
p = (double*)soap_id_enter(soap, soap->id, p, t, sizeof(double), 0, NULL, NULL, NULL);
if (*soap->href)
p = (double*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(double), 0, NULL);
else if (p)
{ if (soap_s2double(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_unsignedByte2s(struct soap *soap, unsigned char n)
{ return soap_unsignedLong2s(soap, (unsigned long)n);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outunsignedByte(struct soap *soap, const char *tag, int id, const unsigned char *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2unsignedByte(struct soap *soap, const char *s, unsigned char *p)
{ if (s)
{ unsigned long n;
char *r;
n = soap_strtoul(s, &r, 10);
if (s == r || *r || n > 255)
soap->error = SOAP_TYPE;
*p = (unsigned char)n;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
unsigned char *
SOAP_FMAC2
soap_inunsignedByte(struct soap *soap, const char *tag, unsigned char *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":unsignedByte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (unsigned char*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned char), 0, NULL, NULL, NULL);
if (*soap->href)
p = (unsigned char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned char), 0, NULL);
else if (p)
{ if (soap_s2unsignedByte(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_unsignedShort2s(struct soap *soap, unsigned short n)
{ return soap_unsignedLong2s(soap, (unsigned long)n);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outunsignedShort(struct soap *soap, const char *tag, int id, const unsigned short *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2unsignedShort(struct soap *soap, const char *s, unsigned short *p)
{ if (s)
{ unsigned long n;
char *r;
n = soap_strtoul(s, &r, 10);
if (s == r || *r || n > 65535)
soap->error = SOAP_TYPE;
*p = (unsigned short)n;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
unsigned short *
SOAP_FMAC2
soap_inunsignedShort(struct soap *soap, const char *tag, unsigned short *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":unsignedShort")
&& soap_match_tag(soap, soap->type, ":unsignedByte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (unsigned short*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned short), 0, NULL, NULL, NULL);
if (*soap->href)
p = (unsigned short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned short), 0, NULL);
else if (p)
{ if (soap_s2unsignedShort(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_unsignedInt2s(struct soap *soap, unsigned int n)
{ return soap_unsignedLong2s(soap, (unsigned long)n);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outunsignedInt(struct soap *soap, const char *tag, int id, const unsigned int *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2unsignedInt(struct soap *soap, const char *s, unsigned int *p)
{ if (s)
{ char *r;
#ifndef WITH_NOIO
#ifndef WITH_LEAN
soap_reset_errno;
#endif
#endif
*p = (unsigned int)soap_strtoul(s, &r, 10);
if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r
#ifndef WITH_NOIO
#ifndef WITH_LEAN
|| soap_errno == SOAP_ERANGE
#endif
#endif
)
soap->error = SOAP_TYPE;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
unsigned int *
SOAP_FMAC2
soap_inunsignedInt(struct soap *soap, const char *tag, unsigned int *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":unsignedInt")
&& soap_match_tag(soap, soap->type, ":unsignedShort")
&& soap_match_tag(soap, soap->type, ":unsignedByte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (unsigned int*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned int), 0, NULL, NULL, NULL);
if (*soap->href)
p = (unsigned int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned int), 0, NULL);
else if (p)
{ if (soap_s2unsignedInt(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_unsignedLong2s(struct soap *soap, unsigned long n)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%lu", n);
#else
sprintf(soap->tmpbuf, "%lu", n);
#endif
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outunsignedLong(struct soap *soap, const char *tag, int id, const unsigned long *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_unsignedLong2s(soap, *p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2unsignedLong(struct soap *soap, const char *s, unsigned long *p)
{ if (s)
{ char *r;
#ifndef WITH_NOIO
#ifndef WITH_LEAN
soap_reset_errno;
#endif
#endif
*p = soap_strtoul(s, &r, 10);
if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r
#ifndef WITH_NOIO
#ifndef WITH_LEAN
|| soap_errno == SOAP_ERANGE
#endif
#endif
)
soap->error = SOAP_TYPE;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
unsigned long *
SOAP_FMAC2
soap_inunsignedLong(struct soap *soap, const char *tag, unsigned long *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
#ifndef WITH_LEAN
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":unsignedInt")
&& soap_match_tag(soap, soap->type, ":unsignedShort")
&& soap_match_tag(soap, soap->type, ":unsignedByte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
#endif
p = (unsigned long*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned long), 0, NULL, NULL, NULL);
if (*soap->href)
p = (unsigned long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned long), 0, NULL);
else if (p)
{ if (soap_s2unsignedLong(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_ULONG642s(struct soap *soap, ULONG64 n)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), SOAP_ULONG_FORMAT, n);
#else
sprintf(soap->tmpbuf, SOAP_ULONG_FORMAT, n);
#endif
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
int
SOAP_FMAC2
soap_outULONG64(struct soap *soap, const char *tag, int id, const ULONG64 *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_ULONG642s(soap, *p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2ULONG64(struct soap *soap, const char *s, ULONG64 *p)
{ if (s)
{
#ifdef HAVE_STRTOULL
char *r;
#ifndef WITH_NOIO
#ifndef WITH_LEAN
soap_reset_errno;
#endif
#endif
*p = soap_strtoull(s, &r, 10);
if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r
#ifndef WITH_NOIO
#ifndef WITH_LEAN
|| soap_errno == SOAP_ERANGE
#endif
#endif
)
#else
#ifdef HAVE_SSCANF
if (sscanf(s, SOAP_ULONG_FORMAT, p) != 1)
#endif
#endif
soap->error = SOAP_TYPE;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
ULONG64 *
SOAP_FMAC2
soap_inULONG64(struct soap *soap, const char *tag, ULONG64 *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":positiveInteger")
&& soap_match_tag(soap, soap->type, ":nonNegativeInteger")
&& soap_match_tag(soap, soap->type, ":unsignedLong")
&& soap_match_tag(soap, soap->type, ":unsignedInt")
&& soap_match_tag(soap, soap->type, ":unsignedShort")
&& soap_match_tag(soap, soap->type, ":unsignedByte"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
p = (ULONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(ULONG64), 0, NULL, NULL, NULL);
if (*soap->href)
p = (ULONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(ULONG64), 0, NULL);
else if (p)
{ if (soap_s2ULONG64(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2string(struct soap *soap, const char *s, char **t, long minlen, long maxlen)
{ if (s)
{ long l = (long)strlen(s);
if ((maxlen >= 0 && l > maxlen) || l < minlen)
return soap->error = SOAP_LENGTH;
if (!(*t = soap_strdup(soap, s)))
return soap->error = SOAP_EOM;
if (!(soap->mode & (SOAP_ENC_LATIN | SOAP_C_UTFSTRING)))
{ char *r = *t;
/* remove non-ASCII chars */
for (s = *t; *s; s++)
if (!(*s & 0x80))
*r++ = *s;
*r = '\0';
}
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2QName(struct soap *soap, const char *s, char **t, long minlen, long maxlen)
{ if (s)
{ long l = (long)strlen(s);
if ((maxlen >= 0 && l > maxlen) || l < minlen)
return soap->error = SOAP_LENGTH;
soap->labidx = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Normalized namespace(s) of QNames '%s'", s));
/* convert (by prefix normalize prefix) all QNames in s */
for (;;)
{ size_t n;
struct soap_nlist *np;
register const char *p;
/* skip blanks */
while (*s && soap_blank((soap_wchar)*s))
s++;
if (!*s)
break;
/* find next QName */
n = 1;
while (s[n] && !soap_blank((soap_wchar)s[n]))
n++;
np = soap->nlist;
/* if there is no namespace stack, or prefix is "#" or "xml" then copy string */
if (!np || *s == '#' || !strncmp(s, "xml:", 4))
{ soap_append_lab(soap, s, n);
}
else /* we normalize the QName by replacing its prefix */
{ const char *q;
for (p = s; *p && p < s + n; p++)
if (*p == ':')
break;
if (*p == ':')
{ size_t k = p - s;
while (np && (strncmp(np->id, s, k) || np->id[k]))
np = np->next;
p++;
}
else
{ while (np && *np->id)
np = np->next;
p = s;
}
/* replace prefix */
if (np)
{ if (np->index >= 0 && soap->local_namespaces && (q = soap->local_namespaces[np->index].id))
{ size_t k = strlen(q);
if (q[k-1] != '_')
soap_append_lab(soap, q, k);
else
{ soap_append_lab(soap, "\"", 1);
soap_append_lab(soap, soap->local_namespaces[np->index].ns, strlen(soap->local_namespaces[np->index].ns));
soap_append_lab(soap, "\"", 1);
}
}
else if (np->ns)
{ soap_append_lab(soap, "\"", 1);
soap_append_lab(soap, np->ns, strlen(np->ns));
soap_append_lab(soap, "\"", 1);
}
else
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\nNamespace prefix of '%s' not defined (index=%d, URI='%s')\n", s, np->index, np->ns ? np->ns : SOAP_STR_EOS));
return soap->error = SOAP_NAMESPACE;
}
}
else if (s[n]) /* no namespace, part of string */
{ soap_append_lab(soap, s, n);
}
else /* no namespace: assume "" namespace */
{ soap_append_lab(soap, "\"\"", 2);
}
soap_append_lab(soap, ":", 1);
soap_append_lab(soap, p, n - (p-s));
}
/* advance to next and add spacing */
s += n;
if (*s)
soap_append_lab(soap, " ", 1);
}
soap_append_lab(soap, SOAP_STR_EOS, 1);
*t = soap_strdup(soap, soap->labbuf);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, " into '%s'\n", *t));
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_QName2s(struct soap *soap, const char *s)
{ const char *t = NULL;
if (s)
{ soap->labidx = 0;
for (;;)
{ size_t n;
/* skip blanks */
while (*s && soap_blank((soap_wchar)*s))
s++;
if (!*s)
break;
/* find next QName */
n = 1;
while (s[n] && !soap_blank((soap_wchar)s[n]))
n++;
/* normal prefix: pass string as is */
if (*s != '"')
{
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
soap_utilize_ns(soap, s);
if ((soap->mode & SOAP_XML_DEFAULTNS))
{ const char *r = strchr(s, ':');
if (r && soap->nlist && !strncmp(soap->nlist->id, s, r-s) && !soap->nlist->id[r-s])
{ n -= r-s + 1;
s = r + 1;
}
}
#endif
soap_append_lab(soap, s, n);
}
else /* URL-based string prefix */
{ const char *q;
s++;
q = strchr(s, '"');
if (q)
{ struct Namespace *p = soap->local_namespaces;
if (p)
{ for (; p->id; p++)
{ if (p->ns)
if (!soap_tag_cmp(s, p->ns))
break;
if (p->in)
if (!soap_tag_cmp(s, p->in))
break;
}
}
/* URL is in the namespace table? */
if (p && p->id)
{ const char *r = p->id;
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_DEFAULTNS) && soap->nlist && !strcmp(soap->nlist->id, r))
q++;
else
#endif
soap_append_lab(soap, r, strlen(r));
}
else /* not in namespace table: create xmlns binding */
{ char *r = soap_strdup(soap, s);
r[q-s] = '\0';
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "xmlns:_%d", soap->idnum++);
#else
sprintf(soap->tmpbuf, "xmlns:_%d", soap->idnum++);
#endif
soap_set_attr(soap, soap->tmpbuf, r, 1);
soap_append_lab(soap, soap->tmpbuf + 6, strlen(soap->tmpbuf + 6));
}
soap_append_lab(soap, q + 1, n - (q-s) - 1);
}
}
/* advance to next and add spacing */
s += n;
if (*s)
soap_append_lab(soap, " ", 1);
}
soap_append_lab(soap, SOAP_STR_EOS, 1);
t = soap_strdup(soap, soap->labbuf);
}
return t;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2wchar(struct soap *soap, const char *s, wchar_t **t, long minlen, long maxlen)
{ if (s)
{ long l;
wchar_t *r;
*t = r = (wchar_t*)soap_malloc(soap, sizeof(wchar_t) * (strlen(s) + 1));
if (!r)
return soap->error = SOAP_EOM;
if (soap->mode & SOAP_ENC_LATIN)
{ while (*s)
*r++ = (wchar_t)*s++;
}
else
{ /* Convert UTF8 to wchar */
while (*s)
{ register soap_wchar c, c1, c2, c3, c4;
c = (unsigned char)*s++;
if (c < 0x80)
*r++ = (wchar_t)c;
else
{ c1 = (soap_wchar)*s++ & 0x3F;
if (c < 0xE0)
*r++ = (wchar_t)(((soap_wchar)(c & 0x1F) << 6) | c1);
else
{ c2 = (soap_wchar)*s++ & 0x3F;
if (c < 0xF0)
*r++ = (wchar_t)(((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2);
else
{ c3 = (soap_wchar)*s++ & 0x3F;
if (c < 0xF8)
*r++ = (wchar_t)(((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3);
else
{ c4 = (soap_wchar)*s++ & 0x3F;
if (c < 0xFC)
*r++ = (wchar_t)(((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4);
else
*r++ = (wchar_t)(((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(*s++ & 0x3F));
}
}
}
}
}
}
*r = L'\0';
l = (long)(r - *t);
if ((maxlen >= 0 && l > maxlen) || l < minlen)
return soap->error = SOAP_LENGTH;
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_wchar2s(struct soap *soap, const wchar_t *s)
{ register soap_wchar c;
register char *r, *t;
const wchar_t *q = s;
size_t n = 0;
while ((c = *q++))
{ if (c > 0 && c < 0x80)
n++;
else
n += 6;
}
r = t = (char*)soap_malloc(soap, n + 1);
if (r)
{ /* Convert wchar to UTF8 */
while ((c = *s++))
{ if (c > 0 && c < 0x80)
*t++ = (char)c;
else
{ if (c < 0x0800)
*t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
else
{ if (c < 0x010000)
*t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
else
{ if (c < 0x200000)
*t++ = (char)(0xF0 | ((c >> 18) & 0x07));
else
{ if (c < 0x04000000)
*t++ = (char)(0xF8 | ((c >> 24) & 0x03));
else
{ *t++ = (char)(0xFC | ((c >> 30) & 0x01));
*t++ = (char)(0x80 | ((c >> 24) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 18) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 12) & 0x3F));
}
*t++ = (char)(0x80 | ((c >> 6) & 0x3F));
}
*t++ = (char)(0x80 | (c & 0x3F));
}
}
*t = '\0';
}
return r;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outstring(struct soap *soap, const char *tag, int id, char *const*p, const char *type, int n)
{ id = soap_element_id(soap, tag, id, *p, NULL, 0, type, n);
if (id < 0)
return soap->error;
if (!**p && (soap->mode & SOAP_C_NILSTRING))
return soap_element_null(soap, tag, id, type);
if (soap_element_begin_out(soap, tag, id, type)
|| soap_string_out(soap, *p, 0)
|| soap_element_end_out(soap, tag))
return soap->error;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char **
SOAP_FMAC2
soap_instring(struct soap *soap, const char *tag, char **p, const char *type, int t, int flag, long minlen, long maxlen)
{ (void)type;
if (soap_element_begin_in(soap, tag, 1, NULL))
{ if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG)
return NULL;
soap->error = SOAP_OK;
}
if (!p)
{ if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
return NULL;
}
if (soap->null)
*p = NULL;
else if (soap->body)
{ *p = soap_string_in(soap, flag, minlen, maxlen);
if (!*p || !(char*)soap_id_enter(soap, soap->id, *p, t, sizeof(char*), 0, NULL, NULL, NULL))
return NULL;
if (!**p && tag && *tag == '-')
{ soap->error = SOAP_NO_TAG;
return NULL;
}
}
else if (tag && *tag == '-')
{ soap->error = SOAP_NO_TAG;
return NULL;
}
else if (!*soap->href && minlen > 0)
{ soap->error = SOAP_LENGTH;
return NULL;
}
else
*p = soap_strdup(soap, SOAP_STR_EOS);
if (*soap->href)
p = (char**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(char**), 0);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outwstring(struct soap *soap, const char *tag, int id, wchar_t *const*p, const char *type, int n)
{ id = soap_element_id(soap, tag, id, *p, NULL, 0, type, n);
if (id < 0)
return soap->error;
if (!**p && (soap->mode & SOAP_C_NILSTRING))
return soap_element_null(soap, tag, id, type);
if (soap_element_begin_out(soap, tag, id, type)
|| soap_wstring_out(soap, *p, 0)
|| soap_element_end_out(soap, tag))
return soap->error;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_2
SOAP_FMAC1
wchar_t **
SOAP_FMAC2
soap_inwstring(struct soap *soap, const char *tag, wchar_t **p, const char *type, int t, long minlen, long maxlen)
{ (void)type;
if (soap_element_begin_in(soap, tag, 1, NULL))
{ if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG)
return NULL;
soap->error = SOAP_OK;
}
if (!p)
{ if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
return NULL;
}
if (soap->body)
{ *p = soap_wstring_in(soap, 1, minlen, maxlen);
if (!*p || !(wchar_t*)soap_id_enter(soap, soap->id, *p, t, sizeof(wchar_t*), 0, NULL, NULL, NULL))
return NULL;
if (!**p && tag && *tag == '-')
{ soap->error = SOAP_NO_TAG;
return NULL;
}
}
else if (tag && *tag == '-')
{ soap->error = SOAP_NO_TAG;
return NULL;
}
else if (soap->null)
*p = NULL;
else
*p = soap_wstrdup(soap, (wchar_t*)SOAP_STR_EOS);
if (*soap->href)
p = (wchar_t**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(wchar_t**), 0);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
time_t
SOAP_FMAC2
soap_timegm(struct tm *T)
{
#if defined(HAVE_TIMEGM)
return timegm(T);
#else
time_t t, g, z;
struct tm tm;
t = mktime(T);
if (t == (time_t)-1)
return (time_t)-1;
#ifdef HAVE_GMTIME_R
gmtime_r(&t, &tm);
#else
tm = *gmtime(&t);
#endif
tm.tm_isdst = 0;
g = mktime(&tm);
if (g == (time_t)-1)
return (time_t)-1;
z = g - t;
return t - z;
#endif
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_dateTime2s(struct soap *soap, time_t n)
{ struct tm T, *pT = &T;
#if defined(HAVE_GMTIME_R)
if (gmtime_r(&n, pT))
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
#elif defined(HAVE_GMTIME)
if ((pT = gmtime(&n)))
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
#elif defined(HAVE_TM_GMTOFF) || defined(HAVE_STRUCT_TM_TM_GMTOFF) || defined(HAVE_STRUCT_TM___TM_GMTOFF)
#if defined(HAVE_LOCALTIME_R)
if (localtime_r(&n, pT))
{ strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S%z", pT);
memmove(soap->tmpbuf + 23, soap->tmpbuf + 22, 3); /* 2000-03-01T02:00:00+0300 */
soap->tmpbuf[22] = ':'; /* 2000-03-01T02:00:00+03:00 */
}
#else
if ((pT = localtime(&n)))
{ strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S%z", pT);
memmove(soap->tmpbuf + 23, soap->tmpbuf + 22, 3); /* 2000-03-01T02:00:00+0300 */
soap->tmpbuf[22] = ':'; /* 2000-03-01T02:00:00+03:00 */
}
#endif
#elif defined(HAVE_GETTIMEOFDAY)
struct timezone tz;
memset((void*)&tz, 0, sizeof(tz));
#if defined(HAVE_LOCALTIME_R)
if (localtime_r(&n, pT))
{ struct timeval tv;
gettimeofday(&tv, &tz);
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60);
#else
sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60);
#endif
}
#else
if ((pT = localtime(&n)))
{ struct timeval tv;
gettimeofday(&tv, &tz);
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60);
#else
sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60);
#endif
}
#endif
#elif defined(HAVE_FTIME)
struct timeb t;
memset((void*)&t, 0, sizeof(t));
#if defined(HAVE_LOCALTIME_R)
if (localtime_r(&n, pT))
{
#ifdef __BORLANDC__
::ftime(&t);
#else
ftime(&t);
#endif
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60);
#else
sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60);
#endif
}
#else
if ((pT = localtime(&n)))
{
#ifdef __BORLANDC__
::ftime(&t);
#else
ftime(&t);
#endif
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60);
#else
sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60);
#endif
}
#endif
#elif defined(HAVE_LOCALTIME_R)
if (localtime_r(&n, pT))
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
#else
if ((pT = localtime(&n)))
strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
#endif
else
strcpy(soap->tmpbuf, "1969-12-31T23:59:59Z");
return soap->tmpbuf;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
int
SOAP_FMAC2
soap_outdateTime(struct soap *soap, const char *tag, int id, const time_t *p, const char *type, int n)
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|| soap_string_out(soap, soap_dateTime2s(soap, *p), 0))
return soap->error;
return soap_element_end_out(soap, tag);
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
int
SOAP_FMAC2
soap_s2dateTime(struct soap *soap, const char *s, time_t *p)
{ if (s)
{ char zone[32];
struct tm T;
const char *t;
*zone = '\0';
memset((void*)&T, 0, sizeof(T));
if (strchr(s, '-'))
t = "%d-%d-%dT%d:%d:%d%31s";
else if (strchr(s, ':'))
t = "%4d%2d%2dT%d:%d:%d%31s";
else /* parse non-XSD-standard alternative ISO 8601 format */
t = "%4d%2d%2dT%2d%2d%2d%31s";
if (sscanf(s, t, &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec, zone) < 6)
return soap->error = SOAP_TYPE;
if (T.tm_year == 1)
T.tm_year = 70;
else
T.tm_year -= 1900;
T.tm_mon--;
if (*zone == '.')
{ for (s = zone + 1; *s; s++)
if (*s < '0' || *s > '9')
break;
}
else
s = zone;
if (*s)
{
#ifndef WITH_NOZONE
if (*s == '+' || *s == '-')
{ int h = 0, m = 0;
if (s[3] == ':')
{ /* +hh:mm */
sscanf(s, "%d:%d", &h, &m);
if (h < 0)
m = -m;
}
else /* +hhmm */
{ m = (int)soap_strtol(s, NULL, 10);
h = m / 100;
m = m % 100;
}
T.tm_min -= m;
T.tm_hour -= h;
/* put hour and min in range */
T.tm_hour += T.tm_min / 60;
T.tm_min %= 60;
if (T.tm_min < 0)
{ T.tm_min += 60;
T.tm_hour--;
}
T.tm_mday += T.tm_hour / 24;
T.tm_hour %= 24;
if (T.tm_hour < 0)
{ T.tm_hour += 24;
T.tm_mday--;
}
/* note: day of the month may be out of range, timegm() handles it */
}
#endif
*p = soap_timegm(&T);
}
else /* no UTC or timezone, so assume we got a localtime */
{ T.tm_isdst = -1;
*p = mktime(&T);
}
}
return soap->error;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
time_t *
SOAP_FMAC2
soap_indateTime(struct soap *soap, const char *tag, time_t *p, const char *type, int t)
{ if (soap_element_begin_in(soap, tag, 0, NULL))
return NULL;
if (*soap->type
&& soap_match_tag(soap, soap->type, type)
&& soap_match_tag(soap, soap->type, ":dateTime"))
{ soap->error = SOAP_TYPE;
soap_revert(soap);
return NULL;
}
p = (time_t*)soap_id_enter(soap, soap->id, p, t, sizeof(time_t), 0, NULL, NULL, NULL);
if (*soap->href)
p = (time_t*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(time_t), 0, NULL);
else if (p)
{ if (soap_s2dateTime(soap, soap_value(soap), p))
return NULL;
}
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outliteral(struct soap *soap, const char *tag, char *const*p, const char *type)
{ int i;
const char *t = NULL;
if (tag && *tag != '-')
{ if (soap->local_namespaces && (t = strchr(tag, ':')))
{ size_t n = t - tag;
if (n >= sizeof(soap->tmpbuf))
n = sizeof(soap->tmpbuf) - 1;
strncpy(soap->tmpbuf, tag, n);
soap->tmpbuf[n] = '\0';
for (i = 0; soap->local_namespaces[i].id; i++)
if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
break;
t++;
if (soap_element(soap, t, 0, type)
|| soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS)
|| soap_element_start_end_out(soap, NULL))
return soap->error;
}
else
{ t = tag;
if (soap_element_begin_out(soap, t, 0, type))
return soap->error;
}
}
if (p && *p)
{ if (soap_send(soap, *p)) /* send as-is */
return soap->error;
}
if (t)
return soap_element_end_out(soap, t);
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
char **
SOAP_FMAC2
soap_inliteral(struct soap *soap, const char *tag, char **p)
{ if (soap_element_begin_in(soap, tag, 1, NULL))
{ if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT)
return NULL;
soap->error = SOAP_OK;
}
if (!p)
{ if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
return NULL;
}
if (soap->body || (tag && *tag == '-'))
{ *p = soap_string_in(soap, 0, -1, -1);
if (!*p)
return NULL;
if (!**p && tag && *tag == '-')
{ soap->error = SOAP_NO_TAG;
return NULL;
}
}
else if (soap->null)
*p = NULL;
else
*p = soap_strdup(soap, SOAP_STR_EOS);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p, const char *type)
{ int i;
const char *t = NULL;
if (tag && *tag != '-')
{ if (soap->local_namespaces && (t = strchr(tag, ':')))
{ size_t n = t - tag;
if (n >= sizeof(soap->tmpbuf))
n = sizeof(soap->tmpbuf) - 1;
strncpy(soap->tmpbuf, tag, n);
soap->tmpbuf[n] = '\0';
for (i = 0; soap->local_namespaces[i].id; i++)
if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
break;
t++;
if (soap_element(soap, t, 0, type)
|| soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS)
|| soap_element_start_end_out(soap, NULL))
return soap->error;
}
else
{ t = tag;
if (soap_element_begin_out(soap, t, 0, type))
return soap->error;
}
}
if (p)
{ wchar_t c;
const wchar_t *s = *p;
while ((c = *s++))
{ if (soap_pututf8(soap, (unsigned long)c)) /* send as-is in UTF8 */
return soap->error;
}
}
if (t)
return soap_element_end_out(soap, t);
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_2
SOAP_FMAC1
wchar_t **
SOAP_FMAC2
soap_inwliteral(struct soap *soap, const char *tag, wchar_t **p)
{ if (soap_element_begin_in(soap, tag, 1, NULL))
{ if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT)
return NULL;
soap->error = SOAP_OK;
}
if (!p)
{ if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
return NULL;
}
if (soap->body)
{ *p = soap_wstring_in(soap, 0, -1, -1);
if (!*p)
return NULL;
if (!**p && tag && *tag == '-')
{ soap->error = SOAP_NO_TAG;
return NULL;
}
}
else if (tag && *tag == '-')
{ soap->error = SOAP_NO_TAG;
return NULL;
}
else if (soap->null)
*p = NULL;
else
*p = soap_wstrdup(soap, (wchar_t*)SOAP_STR_EOS);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
return p;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
const char *
SOAP_FMAC2
soap_value(struct soap *soap)
{ register size_t i;
register soap_wchar c = 0;
register char *s = soap->tmpbuf;
if (!soap->body)
return SOAP_STR_EOS;
do c = soap_get(soap);
while (soap_blank(c));
for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++)
{ if (c == SOAP_TT || c == SOAP_LT || (int)c == EOF)
break;
*s++ = (char)c;
c = soap_get(soap);
}
for (s--; i > 0; i--, s--)
{ if (!soap_blank((soap_wchar)*s))
break;
}
s[1] = '\0';
soap->tmpbuf[sizeof(soap->tmpbuf) - 1] = '\0'; /* appease */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf));
if (c == SOAP_TT || c == SOAP_LT || (int)c == EOF)
soap_unget(soap, c);
else if (soap->mode & SOAP_XML_STRICT)
{ soap->error = SOAP_LENGTH;
return NULL;
}
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
soap->dom->data = soap_strdup(soap, soap->tmpbuf);
#endif
return soap->tmpbuf; /* return non-null pointer */
}
#endif
/******************************************************************************/
#if !defined(WITH_LEANER) || !defined(WITH_NOHTTP)
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_getline(struct soap *soap, char *s, int len)
{ int i = len;
soap_wchar c = 0;
for (;;)
{ while (--i > 0)
{ c = soap_getchar(soap);
if (c == '\r' || c == '\n')
break;
if ((int)c == EOF)
return soap->error = SOAP_CHK_EOF;
*s++ = (char)c;
}
*s = '\0';
if (c != '\n')
c = soap_getchar(soap); /* got \r or something else, now get \n */
if (c == '\n')
{ if (i + 1 == len) /* empty line: end of HTTP/MIME header */
break;
c = soap_get0(soap);
if (c != ' ' && c != '\t') /* HTTP line continuation? */
break;
}
else if ((int)c == EOF)
return soap->error = SOAP_CHK_EOF;
if (i <= 0)
return soap->error = SOAP_HDR;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
static size_t
soap_count_attachments(struct soap *soap)
{
#ifndef WITH_LEANER
register struct soap_multipart *content;
register size_t count = soap->count;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the message size with attachments, current count=%lu\n", (unsigned long)count));
if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the size of DIME attachments\n"));
for (content = soap->dime.first; content; content = content->next)
{ count += 12 + ((content->size+3)&(~3));
if (content->id)
count += ((strlen(content->id)+3)&(~3));
if (content->type)
count += ((strlen(content->type)+3)&(~3));
if (content->options)
count += ((((unsigned char)content->options[2] << 8) | ((unsigned char)content->options[3]))+7)&(~3);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of DIME attachment content is %lu bytes\n", (unsigned long)content->size));
}
}
if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary)
{ register size_t n = strlen(soap->mime.boundary);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the size of MIME attachments\n"));
for (content = soap->mime.first; content; content = content->next)
{ register const char *s;
/* count \r\n--boundary\r\n */
count += 6 + n;
/* count Content-Type: ...\r\n */
if (content->type)
count += 16 + strlen(content->type);
/* count Content-Transfer-Encoding: ...\r\n */
s = soap_code_str(mime_codes, content->encoding);
if (s)
count += 29 + strlen(s);
/* count Content-ID: ...\r\n */
if (content->id)
count += 14 + strlen(content->id);
/* count Content-Location: ...\r\n */
if (content->location)
count += 20 + strlen(content->location);
/* count Content-Description: ...\r\n */
if (content->description)
count += 23 + strlen(content->description);
/* count \r\n...content */
count += 2 + content->size;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of MIME attachment content is %lu bytes\n", (unsigned long)content->size));
}
/* count \r\n--boundary-- */
count += 6 + n;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count=%lu\n", (unsigned long)count));
return count;
#else
return soap->count;
#endif
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
static int
soap_putdimefield(struct soap *soap, const char *s, size_t n)
{ if (soap_send_raw(soap, s, n))
return soap->error;
return soap_send_raw(soap, SOAP_STR_PADDING, -(long)n&3);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
char *
SOAP_FMAC2
soap_dime_option(struct soap *soap, unsigned short optype, const char *option)
{ size_t n;
char *s = NULL;
if (option)
{ n = strlen(option);
s = (char*)soap_malloc(soap, n + 5);
if (s)
{ s[0] = (char)(optype >> 8);
s[1] = (char)(optype & 0xFF);
s[2] = (char)(n >> 8);
s[3] = (char)(n & 0xFF);
strcpy(s + 4, option);
}
}
return s;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_putdimehdr(struct soap *soap)
{ unsigned char tmp[12];
size_t optlen = 0, idlen = 0, typelen = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Put DIME header id='%s'\n", soap->dime.id ? soap->dime.id : SOAP_STR_EOS));
if (soap->dime.options)
optlen = (((unsigned char)soap->dime.options[2] << 8) | ((unsigned char)soap->dime.options[3])) + 4;
if (soap->dime.id)
{ idlen = strlen(soap->dime.id);
if (idlen > 0x0000FFFF)
idlen = 0x0000FFFF;
}
if (soap->dime.type)
{ typelen = strlen(soap->dime.type);
if (typelen > 0x0000FFFF)
typelen = 0x0000FFFF;
}
tmp[0] = SOAP_DIME_VERSION | (soap->dime.flags & 0x7);
tmp[1] = soap->dime.flags & 0xF0;
tmp[2] = (char)(optlen >> 8);
tmp[3] = (char)(optlen & 0xFF);
tmp[4] = (char)(idlen >> 8);
tmp[5] = (char)(idlen & 0xFF);
tmp[6] = (char)(typelen >> 8);
tmp[7] = (char)(typelen & 0xFF);
tmp[8] = (char)(soap->dime.size >> 24);
tmp[9] = (char)((soap->dime.size >> 16) & 0xFF);
tmp[10] = (char)((soap->dime.size >> 8) & 0xFF);
tmp[11] = (char)(soap->dime.size & 0xFF);
if (soap_send_raw(soap, (char*)tmp, 12)
|| soap_putdimefield(soap, soap->dime.options, optlen)
|| soap_putdimefield(soap, soap->dime.id, idlen)
|| soap_putdimefield(soap, soap->dime.type, typelen))
return soap->error;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_putdime(struct soap *soap)
{ struct soap_multipart *content;
if (!(soap->mode & SOAP_ENC_DIME))
return SOAP_OK;
for (content = soap->dime.first; content; content = content->next)
{ void *handle;
soap->dime.size = content->size;
soap->dime.id = content->id;
soap->dime.type = content->type;
soap->dime.options = content->options;
soap->dime.flags = SOAP_DIME_VERSION | SOAP_DIME_MEDIA;
if (soap->fdimereadopen && ((handle = soap->fdimereadopen(soap, (void*)content->ptr, content->id, content->type, content->options)) || soap->error))
{ size_t size = content->size;
if (!handle)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadopen failed\n"));
return soap->error;
}
if (!size && ((soap->mode & SOAP_ENC_XML) || (soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_IO) == SOAP_IO_STORE))
{ size_t chunksize = sizeof(soap->tmpbuf);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked streaming DIME\n"));
do
{ size = soap->fdimeread(soap, handle, soap->tmpbuf, chunksize);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread returned %lu bytes\n", (unsigned long)size));
if (size < chunksize)
{ soap->dime.flags &= ~SOAP_DIME_CF;
if (!content->next)
soap->dime.flags |= SOAP_DIME_ME;
}
else
soap->dime.flags |= SOAP_DIME_CF;
soap->dime.size = size;
if (soap_putdimehdr(soap)
|| soap_putdimefield(soap, soap->tmpbuf, size))
break;
if (soap->dime.id)
{ soap->dime.flags &= ~(SOAP_DIME_MB | SOAP_DIME_MEDIA);
soap->dime.id = NULL;
soap->dime.type = NULL;
soap->dime.options = NULL;
}
} while (size >= chunksize);
}
else
{ if (!content->next)
soap->dime.flags |= SOAP_DIME_ME;
if (soap_putdimehdr(soap))
return soap->error;
do
{ size_t bufsize;
if (size < sizeof(soap->tmpbuf))
bufsize = size;
else
bufsize = sizeof(soap->tmpbuf);
if (!(bufsize = soap->fdimeread(soap, handle, soap->tmpbuf, bufsize)))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)content->size));
soap->error = SOAP_CHK_EOF;
break;
}
if (soap_send_raw(soap, soap->tmpbuf, bufsize))
break;
size -= bufsize;
} while (size);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime.size&3);
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
if (soap->fdimereadclose)
soap->fdimereadclose(soap, handle);
}
else
{ if (!content->next)
soap->dime.flags |= SOAP_DIME_ME;
if (soap_putdimehdr(soap)
|| soap_putdimefield(soap, (char*)content->ptr, content->size))
return soap->error;
}
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
static char *
soap_getdimefield(struct soap *soap, size_t n)
{ register soap_wchar c;
register size_t i;
register char *s;
register char *p = NULL;
if (n)
{ p = (char*)soap_malloc(soap, n + 1);
if (p)
{ s = p;
for (i = n; i > 0; i--)
{ if ((int)(c = soap_get1(soap)) == EOF)
{ soap->error = SOAP_CHK_EOF;
return NULL;
}
*s++ = (char)c;
}
*s = '\0';
if ((soap->error = soap_move(soap, (size_t)(-(long)n&3))))
return NULL;
}
else
soap->error = SOAP_EOM;
}
return p;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_getdimehdr(struct soap *soap)
{ register soap_wchar c;
register char *s;
register int i;
unsigned char tmp[12];
size_t optlen, idlen, typelen;
if (!(soap->mode & SOAP_ENC_DIME))
return soap->error = SOAP_DIME_END;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME header\n"));
if (soap->dime.buflen || soap->dime.chunksize)
{ if (soap_move(soap, soap->dime.size - soap_tell(soap)))
return soap->error = SOAP_CHK_EOF;
soap_unget(soap, soap_getchar(soap)); /* skip padding and get hdr */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... From chunked\n"));
return SOAP_OK;
}
s = (char*)tmp;
for (i = 12; i > 0; i--)
{ if ((int)(c = soap_getchar(soap)) == EOF)
return soap->error = SOAP_CHK_EOF;
*s++ = (char)c;
}
if ((tmp[0] & 0xF8) != SOAP_DIME_VERSION)
return soap->error = SOAP_DIME_MISMATCH;
soap->dime.flags = (tmp[0] & 0x7) | (tmp[1] & 0xF0);
optlen = (tmp[2] << 8) | tmp[3];
idlen = (tmp[4] << 8) | tmp[5];
typelen = (tmp[6] << 8) | tmp[7];
soap->dime.size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%lu flags=0x%X\n", (unsigned long)soap->dime.size, soap->dime.flags));
if (!(soap->dime.options = soap_getdimefield(soap, optlen)) && soap->error)
return soap->error;
if (!(soap->dime.id = soap_getdimefield(soap, idlen)) && soap->error)
return soap->error;
if (!(soap->dime.type = soap_getdimefield(soap, typelen)) && soap->error)
return soap->error;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id='%s', type='%s', options='%s'\n", soap->dime.id ? soap->dime.id : SOAP_STR_EOS, soap->dime.type ? soap->dime.type : "", soap->dime.options ? soap->dime.options+4 : SOAP_STR_EOS));
if (soap->dime.flags & SOAP_DIME_ME)
soap->mode &= ~SOAP_ENC_DIME;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_getdime(struct soap *soap)
{ while (soap->dime.flags & SOAP_DIME_CF)
{ if (soap_getdimehdr(soap))
return soap->error;
if (soap_move(soap, soap->dime.size))
return soap->error = SOAP_EOF;
}
if (soap_move(soap, (size_t)(((soap->dime.size+3)&(~3)) - soap_tell(soap))))
return soap->error = SOAP_EOF;
for (;;)
{ register struct soap_multipart *content;
if (soap_getdimehdr(soap))
break;
if (soap->fdimewriteopen && ((soap->dime.ptr = (char*)soap->fdimewriteopen(soap, soap->dime.id, soap->dime.type, soap->dime.options)) || soap->error))
{ const char *id, *type, *options;
size_t size, n;
if (!soap->dime.ptr)
return soap->error;
id = soap->dime.id;
type = soap->dime.type;
options = soap->dime.options;
for (;;)
{ size = soap->dime.size;
for (;;)
{ n = soap->buflen - soap->bufidx;
if (size < n)
n = size;
if ((soap->error = soap->fdimewrite(soap, (void*)soap->dime.ptr, soap->buf + soap->bufidx, n)))
break;
size -= n;
if (!size)
{ soap->bufidx += n;
break;
}
if (soap_recv(soap))
{ soap->error = SOAP_EOF;
goto end;
}
}
if (soap_move(soap, (size_t)(-(long)soap->dime.size&3)))
{ soap->error = SOAP_EOF;
break;
}
if (!(soap->dime.flags & SOAP_DIME_CF))
break;
if (soap_getdimehdr(soap))
break;
}
end:
if (soap->fdimewriteclose)
soap->fdimewriteclose(soap, (void*)soap->dime.ptr);
soap->dime.size = 0;
soap->dime.id = id;
soap->dime.type = type;
soap->dime.options = options;
}
else if (soap->dime.flags & SOAP_DIME_CF)
{ const char *id, *type, *options;
id = soap->dime.id;
type = soap->dime.type;
options = soap->dime.options;
if (soap_new_block(soap) == NULL)
return SOAP_EOM;
for (;;)
{ register soap_wchar c;
register size_t i;
register char *s;
if (soap->dime.size > SOAP_MAXDIMESIZE)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%lu exceeds SOAP_MAXDIMESIZE=%lu\n", (unsigned long)soap->dime.size, (unsigned long)SOAP_MAXDIMESIZE));
return soap->error = SOAP_DIME_ERROR;
}
s = (char*)soap_push_block(soap, NULL, soap->dime.size);
if (!s)
return soap->error = SOAP_EOM;
for (i = soap->dime.size; i > 0; i--)
{ if ((int)(c = soap_get1(soap)) == EOF)
return soap->error = SOAP_EOF;
*s++ = (char)c;
}
if (soap_move(soap, (size_t)(-(long)soap->dime.size&3)))
return soap->error = SOAP_EOF;
if (!(soap->dime.flags & SOAP_DIME_CF))
break;
if (soap_getdimehdr(soap))
return soap->error;
}
soap->dime.size = soap->blist->size++; /* allocate one more byte in blist for the terminating '\0' */
if (!(soap->dime.ptr = soap_save_block(soap, NULL, NULL, 0)))
return soap->error;
soap->dime.ptr[soap->dime.size] = '\0'; /* make 0-terminated */
soap->dime.id = id;
soap->dime.type = type;
soap->dime.options = options;
}
else
soap->dime.ptr = soap_getdimefield(soap, soap->dime.size);
content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, soap->dime.ptr, soap->dime.size);
if (!content)
return soap->error = SOAP_EOM;
content->id = soap->dime.id;
content->type = soap->dime.type;
content->options = soap->dime.options;
if (soap->error)
return soap->error;
soap_resolve_attachment(soap, content);
}
if (soap->error != SOAP_DIME_END)
return soap->error;
return soap->error = SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_getmimehdr(struct soap *soap)
{ struct soap_multipart *content;
do
{ if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
return soap->error;
}
while (!*soap->msgbuf);
if (soap->msgbuf[0] == '-' && soap->msgbuf[1] == '-')
{ char *s = soap->msgbuf + strlen(soap->msgbuf) - 1;
/* remove white space */
while (soap_blank((soap_wchar)*s))
s--;
s[1] = '\0';
if (soap->mime.boundary)
{ if (strcmp(soap->msgbuf + 2, soap->mime.boundary))
return soap->error = SOAP_MIME_ERROR;
}
else
soap->mime.boundary = soap_strdup(soap, soap->msgbuf + 2);
if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
return soap->error;
}
if (soap_set_mime_attachment(soap, NULL, 0, SOAP_MIME_NONE, NULL, NULL, NULL, NULL))
return soap->error = SOAP_EOM;
content = soap->mime.last;
for (;;)
{ register char *key = soap->msgbuf;
register char *val;
if (!*key)
break;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "MIME header: %s\n", key));
val = strchr(soap->msgbuf, ':');
if (val)
{ *val = '\0';
do val++;
while (*val && *val <= 32);
if (!soap_tag_cmp(key, "Content-ID"))
content->id = soap_strdup(soap, val);
else if (!soap_tag_cmp(key, "Content-Location"))
content->location = soap_strdup(soap, val);
else if (!soap_tag_cmp(key, "Content-Disposition"))
content->id = soap_strdup(soap, soap_get_header_attribute(soap, val, "name"));
else if (!soap_tag_cmp(key, "Content-Type"))
content->type = soap_strdup(soap, val);
else if (!soap_tag_cmp(key, "Content-Description"))
content->description = soap_strdup(soap, val);
else if (!soap_tag_cmp(key, "Content-Transfer-Encoding"))
content->encoding = (enum soap_mime_encoding)soap_code_int(mime_codes, val, (long)SOAP_MIME_NONE);
}
if (soap_getline(soap, key, sizeof(soap->msgbuf)))
return soap->error;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_getmime(struct soap *soap)
{ while (soap_get_mime_attachment(soap, NULL))
;
return soap->error;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_post_check_mime_attachments(struct soap *soap)
{ soap->imode |= SOAP_MIME_POSTCHECK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_check_mime_attachments(struct soap *soap)
{ if (soap->mode & SOAP_MIME_POSTCHECK)
return soap_get_mime_attachment(soap, NULL) != NULL;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
struct soap_multipart *
SOAP_FMAC2
soap_get_mime_attachment(struct soap *soap, void *handle)
{ register soap_wchar c = 0;
register size_t i, m = 0;
register char *s, *t = NULL;
register struct soap_multipart *content;
register short flag = 0;
if (!(soap->mode & SOAP_ENC_MIME))
return NULL;
content = soap->mime.last;
if (!content)
{ if (soap_getmimehdr(soap))
return NULL;
content = soap->mime.last;
}
else if (content != soap->mime.first)
{ if (soap->fmimewriteopen && ((content->ptr = (char*)soap->fmimewriteopen(soap, (void*)handle, content->id, content->type, content->description, content->encoding)) || soap->error))
{ if (!content->ptr)
return NULL;
}
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id='%s' type='%s'\n", content->id ? content->id : SOAP_STR_EOS, content->type ? content->type : SOAP_STR_EOS));
if (!content->ptr && soap_new_block(soap) == NULL)
{ soap->error = SOAP_EOM;
return NULL;
}
for (;;)
{ if (content->ptr)
s = soap->tmpbuf;
else if (!(s = (char*)soap_push_block(soap, NULL, sizeof(soap->tmpbuf))))
{ soap->error = SOAP_EOM;
return NULL;
}
for (i = 0; i < sizeof(soap->tmpbuf); i++)
{ if (m > 0)
{ *s++ = *t++;
m--;
}
else
{ if (!flag)
{ c = soap_get1(soap);
if ((int)c == EOF)
{ if (content->ptr && soap->fmimewriteclose)
soap->fmimewriteclose(soap, (void*)content->ptr);
soap->error = SOAP_CHK_EOF;
return NULL;
}
}
if (flag || c == '\r')
{ t = soap->msgbuf;
memset(t, 0, sizeof(soap->msgbuf));
strcpy(t, "\n--");
if (soap->mime.boundary)
strncat(t, soap->mime.boundary, sizeof(soap->msgbuf)-4);
do c = soap_getchar(soap);
while (c == *t++);
if ((int)c == EOF)
{ if (content->ptr && soap->fmimewriteclose)
soap->fmimewriteclose(soap, (void*)content->ptr);
soap->error = SOAP_CHK_EOF;
return NULL;
}
if (!*--t)
goto end;
*t = (char)c;
flag = (c == '\r');
m = t - soap->msgbuf + 1 - flag;
t = soap->msgbuf;
c = '\r';
}
*s++ = (char)c;
}
}
if (content->ptr && soap->fmimewrite)
{ if ((soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i)))
break;
}
}
end:
*s = '\0'; /* make 0-terminated */
if (content->ptr)
{ if (!soap->error && soap->fmimewrite)
soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i);
if (soap->fmimewriteclose)
soap->fmimewriteclose(soap, (void*)content->ptr);
if (soap->error)
return NULL;
}
else
{ content->size = soap_size_block(soap, NULL, i+1) - 1; /* last block with '\0' */
content->ptr = soap_save_block(soap, NULL, NULL, 0);
}
soap_resolve_attachment(soap, content);
if (c == '-' && soap_getchar(soap) == '-')
{ soap->mode &= ~SOAP_ENC_MIME;
if ((soap->mode & SOAP_MIME_POSTCHECK) && soap_end_recv(soap))
{ if (soap->keep_alive < 0)
soap->keep_alive = 0;
soap_closesock(soap);
return NULL;
}
}
else
{ while (c != '\r' && (int)c != EOF && soap_blank(c))
c = soap_getchar(soap);
if (c != '\r' || soap_getchar(soap) != '\n')
{ soap->error = SOAP_MIME_ERROR;
return NULL;
}
if (soap_getmimehdr(soap))
return NULL;
}
return content;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_match_cid(struct soap *soap, const char *s, const char *t)
{ register size_t n;
if (!s)
return 1;
if (!strcmp(s, t))
return 0;
if (!strncmp(s, "cid:", 4))
s += 4;
n = strlen(t);
if (*t == '<')
{ t++;
n -= 2;
}
if (!strncmp(s, t, n) && !s[n])
return 0;
soap_decode(soap->tmpbuf, sizeof(soap->tmpbuf), s, SOAP_STR_EOS);
if (!strncmp(soap->tmpbuf, t, n) && !soap->tmpbuf[n])
return 0;
return 1;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
static void
soap_resolve_attachment(struct soap *soap, struct soap_multipart *content)
{ if (content->id)
{ register struct soap_xlist **xp = &soap->xlist;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id='%s'\n", content->id));
while (*xp)
{ register struct soap_xlist *xq = *xp;
if (!soap_match_cid(soap, xq->id, content->id))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment id='%s' for content id='%s'\n", xq->id, content->id));
*xp = xq->next;
*xq->ptr = (unsigned char*)content->ptr;
*xq->size = (int)content->size;
*xq->type = (char*)content->type;
if (content->options)
*xq->options = (char*)content->options;
else
*xq->options = (char*)content->description;
SOAP_FREE(soap, xq);
}
else
xp = &(*xp)->next;
}
}
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_putmimehdr(struct soap *soap, struct soap_multipart *content)
{ const char *s;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MIME attachment type='%s'\n", content->type ? content->type : SOAP_STR_EOS));
if (soap_send3(soap, "\r\n--", soap->mime.boundary, "\r\n"))
return soap->error;
if (content->type && soap_send3(soap, "Content-Type: ", content->type, "\r\n"))
return soap->error;
s = soap_code_str(mime_codes, content->encoding);
if (s && soap_send3(soap, "Content-Transfer-Encoding: ", s, "\r\n"))
return soap->error;
if (content->id && soap_send3(soap, "Content-ID: ", content->id, "\r\n"))
return soap->error;
if (content->location && soap_send3(soap, "Content-Location: ", content->location, "\r\n"))
return soap->error;
if (content->description && soap_send3(soap, "Content-Description: ", content->description, "\r\n"))
return soap->error;
return soap_send_raw(soap, "\r\n", 2);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_putmime(struct soap *soap)
{ struct soap_multipart *content;
if (!(soap->mode & SOAP_ENC_MIME) || !soap->mime.boundary)
return SOAP_OK;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending MIME attachments\n"));
for (content = soap->mime.first; content; content = content->next)
{ void *handle;
if (soap->fmimereadopen && ((handle = soap->fmimereadopen(soap, (void*)content->ptr, content->id, content->type, content->description)) || soap->error))
{ size_t size = content->size;
if (!handle)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimereadopen failed\n"));
return soap->error;
}
if (soap_putmimehdr(soap, content))
return soap->error;
if (!size)
{ if ((soap->mode & SOAP_ENC_XML) || (soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_IO) == SOAP_IO_STORE)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked streaming MIME\n"));
do
{ size = soap->fmimeread(soap, handle, soap->tmpbuf, sizeof(soap->tmpbuf));
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread returned %lu bytes\n", (unsigned long)size));
if (soap_send_raw(soap, soap->tmpbuf, size))
break;
} while (size);
}
else
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error: cannot chunk streaming MIME (no HTTP chunking)\n"));
}
}
else
{ do
{ size_t bufsize;
if (size < sizeof(soap->tmpbuf))
bufsize = size;
else
bufsize = sizeof(soap->tmpbuf);
if (!(bufsize = soap->fmimeread(soap, handle, soap->tmpbuf, bufsize)))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)content->size));
soap->error = SOAP_EOF;
break;
}
if (soap_send_raw(soap, soap->tmpbuf, bufsize))
break;
size -= bufsize;
} while (size);
}
if (soap->fmimereadclose)
soap->fmimereadclose(soap, handle);
}
else
{ if (soap_putmimehdr(soap, content)
|| soap_send_raw(soap, content->ptr, content->size))
return soap->error;
}
}
return soap_send3(soap, "\r\n--", soap->mime.boundary, "--");
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_dime(struct soap *soap)
{ soap->omode |= SOAP_ENC_DIME;
soap->dime.first = NULL;
soap->dime.last = NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_mime(struct soap *soap, const char *boundary, const char *start)
{ soap->omode |= SOAP_ENC_MIME;
soap->mime.first = NULL;
soap->mime.last = NULL;
soap->mime.boundary = soap_strdup(soap, boundary);
soap->mime.start = soap_strdup(soap, start);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_clr_dime(struct soap *soap)
{ soap->omode &= ~SOAP_ENC_DIME;
soap->dime.first = NULL;
soap->dime.last = NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_clr_mime(struct soap *soap)
{ soap->omode &= ~SOAP_ENC_MIME;
soap->mime.first = NULL;
soap->mime.last = NULL;
soap->mime.boundary = NULL;
soap->mime.start = NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
static struct soap_multipart*
soap_new_multipart(struct soap *soap, struct soap_multipart **first, struct soap_multipart **last, char *ptr, size_t size)
{ struct soap_multipart *content;
content = (struct soap_multipart*)soap_malloc(soap, sizeof(struct soap_multipart));
if (content)
{ content->next = NULL;
content->ptr = ptr;
content->size = size;
content->id = NULL;
content->type = NULL;
content->options = NULL;
content->encoding = SOAP_MIME_NONE;
content->location = NULL;
content->description = NULL;
if (!*first)
*first = content;
if (*last)
(*last)->next = content;
*last = content;
}
return content;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_dime_attachment(struct soap *soap, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option)
{ struct soap_multipart *content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, ptr, size);
if (!content)
return SOAP_EOM;
content->id = soap_strdup(soap, id);
content->type = soap_strdup(soap, type);
content->options = soap_dime_option(soap, optype, option);
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_mime_attachment(struct soap *soap, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description)
{ struct soap_multipart *content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, ptr, size);
if (!content)
return SOAP_EOM;
content->id = soap_strdup(soap, id);
content->type = soap_strdup(soap, type);
content->encoding = encoding;
content->location = soap_strdup(soap, location);
content->description = soap_strdup(soap, description);
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
struct soap_multipart*
SOAP_FMAC2
soap_next_multipart(struct soap_multipart *content)
{ if (content)
return content->next;
return NULL;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
static void
soap_select_mime_boundary(struct soap *soap)
{ while (!soap->mime.boundary || soap_valid_mime_boundary(soap))
{ register char *s = soap->mime.boundary;
register size_t n = 0;
if (s)
n = strlen(s);
if (n < 16)
{ n = 64;
s = soap->mime.boundary = (char*)soap_malloc(soap, n + 1);
if (!s)
return;
}
strcpy(s, "==");
s += 2;
n -= 4;
while (n)
{ *s++ = soap_base64o[soap_random & 0x3F];
n--;
}
strcpy(s, "==");
}
if (!soap->mime.start)
soap->mime.start = "<SOAP-ENV:Envelope>";
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
static int
soap_valid_mime_boundary(struct soap *soap)
{ register struct soap_multipart *content;
register size_t k;
if (soap->fmimeread)
return SOAP_OK;
k = strlen(soap->mime.boundary);
for (content = soap->mime.first; content; content = content->next)
{ if (content->ptr && content->size >= k)
{ register const char *p = (const char*)content->ptr;
register size_t i;
for (i = 0; i < content->size - k; i++, p++)
{ if (!strncmp(p, soap->mime.boundary, k))
return SOAP_ERR;
}
}
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifdef WITH_GZIP
#ifndef PALM_1
static int
soap_getgziphdr(struct soap *soap)
{ int i;
soap_wchar c = 0, f = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get gzip header\n"));
for (i = 0; i < 9; i++)
{ if ((int)(c = soap_get1(soap) == EOF))
return soap->error = SOAP_ZLIB_ERROR;
if (i == 1 && c == 8)
soap->z_dict = 0;
if (i == 2)
f = c;
}
if (f & 0x04) /* FEXTRA */
{ for (i = soap_get1(soap) | (soap_get1(soap) << 8); i; i--)
{ if ((int)soap_get1(soap) == EOF)
return soap->error = SOAP_ZLIB_ERROR;
}
}
if (f & 0x08) /* skip FNAME */
{ do
c = soap_get1(soap);
while (c && (int)c != EOF);
}
if ((int)c != EOF && (f & 0x10)) /* skip FCOMMENT */
{ do
c = soap_get1(soap);
while (c && (int)c != EOF);
}
if ((int)c != EOF && (f & 0x02)) /* skip FHCRC (CRC32 is used) */
{ if ((int)(c = soap_get1(soap)) != EOF)
c = soap_get1(soap);
}
if ((int)c == EOF)
return soap->error = SOAP_ZLIB_ERROR;
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_begin_serve(struct soap *soap)
{
#ifdef WITH_FASTCGI
if (FCGI_Accept() < 0)
{ soap->error = SOAP_EOF;
return soap_send_fault(soap);
}
#endif
soap_begin(soap);
if (soap_begin_recv(soap)
|| soap_envelope_begin_in(soap)
|| soap_recv_header(soap)
|| soap_body_begin_in(soap))
{ if (soap->error < SOAP_STOP)
{
#ifdef WITH_FASTCGI
soap_send_fault(soap);
#else
return soap_send_fault(soap);
#endif
}
return soap_closesock(soap);
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_begin_recv(struct soap *soap)
{ register soap_wchar c;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for input from socket=%d/fd=%d\n", soap->socket, soap->recvfd));
soap->error = SOAP_OK;
soap->filterstop = SOAP_OK;
soap_free_temp(soap);
soap_set_local_namespaces(soap);
soap->version = 0; /* don't assume we're parsing SOAP content by default */
#ifndef WITH_NOIDREF
soap_free_iht(soap);
#endif
if ((soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
soap->omode |= SOAP_IO_CHUNK;
soap->imode &= ~(SOAP_IO | SOAP_ENC_MIME);
soap->mode = soap->imode;
if (!soap->keep_alive)
{ soap->buflen = 0;
soap->bufidx = 0;
}
if (!(soap->mode & SOAP_IO_KEEPALIVE))
soap->keep_alive = 0;
soap->ahead = 0;
soap->peeked = 0;
soap->level = 0;
soap->part = SOAP_BEGIN;
soap->alloced = 0;
soap->body = 1;
soap->count = 0;
soap->length = 0;
soap->cdata = 0;
*soap->endpoint = '\0';
soap->action = NULL;
soap->header = NULL;
soap->fault = NULL;
soap->status = 0;
soap->fform = NULL;
#ifndef WITH_LEANER
soap->dom = NULL;
soap->dime.chunksize = 0;
soap->dime.buflen = 0;
soap->dime.list = NULL;
soap->dime.first = NULL;
soap->dime.last = NULL;
soap->mime.list = NULL;
soap->mime.first = NULL;
soap->mime.last = NULL;
soap->mime.boundary = NULL;
soap->mime.start = NULL;
#endif
#ifdef WIN32
#ifndef UNDER_CE
#ifndef WITH_FASTCGI
if (!soap_valid_socket(soap->socket) && !soap->is) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
#ifdef __BORLANDC__
setmode(soap->recvfd, _O_BINARY);
#else
_setmode(soap->recvfd, _O_BINARY);
#endif
#endif
#endif
#endif
#ifdef WITH_ZLIB
soap->mode &= ~SOAP_ENC_ZLIB;
soap->zlib_in = SOAP_ZLIB_NONE;
soap->zlib_out = SOAP_ZLIB_NONE;
soap->d_stream->next_in = Z_NULL;
soap->d_stream->avail_in = 0;
soap->d_stream->next_out = (Byte*)soap->buf;
soap->d_stream->avail_out = SOAP_BUFLEN;
soap->z_ratio_in = 1.0;
#endif
#ifdef WITH_OPENSSL
if (soap->ssl)
ERR_clear_error();
#endif
#ifndef WITH_LEANER
if (soap->fprepareinitrecv && (soap->error = soap->fprepareinitrecv(soap)))
return soap->error;
#endif
c = soap_getchar(soap);
#ifdef WITH_GZIP
if (c == 0x1F)
{ if (soap_getgziphdr(soap))
return soap->error;
if (inflateInit2(soap->d_stream, -MAX_WBITS) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
if (soap->z_dict)
{ if (inflateSetDictionary(soap->d_stream, (const Bytef*)soap->z_dict, soap->z_dict_len) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
}
soap->zlib_state = SOAP_ZLIB_INFLATE;
soap->mode |= SOAP_ENC_ZLIB;
soap->zlib_in = SOAP_ZLIB_GZIP;
soap->z_crc = crc32(0L, NULL, 0);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
if (!soap->z_buf)
soap->z_buf = (char*)SOAP_MALLOC(soap, SOAP_BUFLEN);
memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
/* should not chunk over plain transport, so why bother to check? */
/* if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) */
/* soap->z_buflen = soap->bufidx; */
/* else */
soap->d_stream->next_in = (Byte*)(soap->z_buf + soap->bufidx);
soap->d_stream->avail_in = (unsigned int)(soap->buflen - soap->bufidx);
soap->z_buflen = soap->buflen;
soap->buflen = soap->bufidx;
c = ' ';
}
#endif
while (soap_blank(c))
c = soap_getchar(soap);
#ifndef WITH_LEANER
if (c == '-' && soap_get0(soap) == '-')
soap->mode |= SOAP_ENC_MIME;
else if ((c & 0xFFFC) == (SOAP_DIME_VERSION | SOAP_DIME_MB) && (soap_get0(soap) & 0xFFF0) == 0x20)
soap->mode |= SOAP_ENC_DIME;
else
#endif
{ /* skip BOM */
if (c == 0xEF && soap_get0(soap) == 0xBB)
{ c = soap_get1(soap);
if ((c = soap_get1(soap)) == 0xBF)
{ soap->mode &= ~SOAP_ENC_LATIN;
c = soap_getchar(soap);
}
else
c = (0x0F << 12) | (0xBB << 6) | (c & 0x3F); /* UTF-8 */
}
else if ((c == 0xFE && soap_get0(soap) == 0xFF) /* UTF-16 BE */
|| (c == 0xFF && soap_get0(soap) == 0xFE)) /* UTF-16 LE */
return soap->error = SOAP_UTF_ERROR;
/* skip space */
while (soap_blank(c))
c = soap_getchar(soap);
}
if ((int)c == EOF)
return soap->error = SOAP_CHK_EOF;
soap_unget(soap, c);
#ifndef WITH_NOHTTP
/* if not XML/MIME/DIME/ZLIB, assume HTTP method or status line */
if (((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB | SOAP_ENC_XML)))
{ soap_mode m = soap->imode;
soap->mode &= ~SOAP_IO;
soap->error = soap->fparse(soap);
if (soap->error && soap->error < SOAP_STOP)
{ soap->keep_alive = 0; /* force close later */
return soap->error;
}
if (soap->error == SOAP_STOP)
{ if (soap->fform)
{ soap->error = soap->fform(soap);
if (soap->error == SOAP_OK)
soap->error = SOAP_STOP; /* prevents further processing */
}
return soap->error;
}
soap->mode = soap->imode; /* if imode is changed, effectuate */
soap->imode = m; /* restore imode */
#ifdef WITH_ZLIB
soap->mode &= ~SOAP_ENC_ZLIB;
#endif
if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
{ soap->chunkbuflen = soap->buflen;
soap->buflen = soap->bufidx;
soap->chunksize = 0;
}
/* Note: fparse should not use soap_unget to push back last char */
#if 0
if (soap->status > 200 && soap->length == 0 && !(soap->http_content && (!soap->keep_alive || soap->recv_timeout)) && (soap->imode & SOAP_IO) != SOAP_IO_CHUNK)
#endif
if (soap->status && !soap->body)
return soap->error = soap->status;
#ifdef WITH_ZLIB
if (soap->zlib_in != SOAP_ZLIB_NONE)
{
#ifdef WITH_GZIP
if (soap->zlib_in != SOAP_ZLIB_DEFLATE)
{ c = soap_get1(soap);
if (c == (int)EOF)
return soap->error = SOAP_EOF;
if (c == 0x1F)
{ if (soap_getgziphdr(soap))
return soap->error;
if (inflateInit2(soap->d_stream, -MAX_WBITS) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
soap->z_crc = crc32(0L, NULL, 0);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
}
else
{ soap_revget1(soap);
if (inflateInit(soap->d_stream) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
soap->zlib_in = SOAP_ZLIB_DEFLATE;
}
}
else
#endif
if (inflateInit(soap->d_stream) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
if (soap->z_dict)
{ if (inflateSetDictionary(soap->d_stream, (const Bytef*)soap->z_dict, soap->z_dict_len) != Z_OK)
return soap->error = SOAP_ZLIB_ERROR;
}
soap->zlib_state = SOAP_ZLIB_INFLATE;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate initialized\n"));
soap->mode |= SOAP_ENC_ZLIB;
if (!soap->z_buf)
soap->z_buf = (char*)SOAP_MALLOC(soap, SOAP_BUFLEN);
memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
soap->d_stream->next_in = (Byte*)(soap->z_buf + soap->bufidx);
soap->d_stream->avail_in = (unsigned int)(soap->buflen - soap->bufidx);
soap->z_buflen = soap->buflen;
soap->buflen = soap->bufidx;
}
#endif
#ifndef WITH_LEANER
if (soap->fpreparerecv && (soap->mode & SOAP_IO) != SOAP_IO_CHUNK && soap->buflen > soap->bufidx)
{ int r;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Invoking fpreparerecv\n"));
if ((r = soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx)))
return soap->error = r;
}
#endif
if (soap_get0(soap) == (int)EOF)
{ if (soap->status == 0 || soap->status == 200)
return soap->error = SOAP_NO_DATA; /* HTTP OK: always expect data */
return soap->error = soap->status;
}
if (soap->error)
{ if (soap->error == SOAP_FORM && soap->fform)
{ soap->error = soap->fform(soap);
if (soap->error == SOAP_OK)
soap->error = SOAP_STOP; /* prevents further processing */
}
return soap->error;
}
}
#endif
#ifndef WITH_LEANER
if (soap->mode & SOAP_ENC_MIME)
{ do /* skip preamble */
{ if ((int)(c = soap_getchar(soap)) == EOF)
return soap->error = SOAP_CHK_EOF;
} while (c != '-' || soap_get0(soap) != '-');
soap_unget(soap, c);
if (soap_getmimehdr(soap))
return soap->error;
if (soap->mime.start)
{ do
{ if (!soap->mime.last->id)
break;
if (!soap_match_cid(soap, soap->mime.start, soap->mime.last->id))
break;
} while (soap_get_mime_attachment(soap, NULL));
}
if (soap_get_header_attribute(soap, soap->mime.first->type, "application/dime"))
soap->mode |= SOAP_ENC_DIME;
}
if (soap->mode & SOAP_ENC_DIME)
{ if (soap_getdimehdr(soap))
return soap->error;
if (soap->dime.flags & SOAP_DIME_CF)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked DIME SOAP message\n"));
soap->dime.chunksize = soap->dime.size;
if (soap->buflen - soap->bufidx >= soap->dime.chunksize)
{ soap->dime.buflen = soap->buflen;
soap->buflen = soap->bufidx + soap->dime.chunksize;
}
else
soap->dime.chunksize -= soap->buflen - soap->bufidx;
}
soap->count = soap->buflen - soap->bufidx;
}
#endif
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_envelope_begin_out(struct soap *soap)
{
#ifndef WITH_LEANER
size_t n = 0;
if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->mime.start && strlen(soap->mime.boundary) + strlen(soap->mime.start) < sizeof(soap->tmpbuf) - 80 )
{ const char *s;
if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM))
s = "application/dime";
else if (soap->version == 2)
{ if (soap->mode & SOAP_ENC_MTOM)
s = "application/xop+xml; charset=utf-8; type=\"application/soap+xml\"";
else
s = "application/soap+xml; charset=utf-8";
}
else if (soap->mode & SOAP_ENC_MTOM)
s = "application/xop+xml; charset=utf-8; type=\"text/xml\"";
else
s = "text/xml; charset=utf-8";
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "--%s\r\nContent-Type: %s\r\nContent-Transfer-Encoding: binary\r\nContent-ID: %s\r\n\r\n", soap->mime.boundary, s, soap->mime.start);
#else
sprintf(soap->tmpbuf, "--%s\r\nContent-Type: %s\r\nContent-Transfer-Encoding: binary\r\nContent-ID: %s\r\n\r\n", soap->mime.boundary, s, soap->mime.start);
#endif
n = strlen(soap->tmpbuf);
if (soap_send_raw(soap, soap->tmpbuf, n))
return soap->error;
}
if (soap->mode & SOAP_IO_LENGTH)
soap->dime.size = soap->count; /* DIME in MIME correction */
if (!(soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME))
{ if (soap_putdimehdr(soap))
return soap->error;
}
#endif
if (soap->version == 0)
return SOAP_OK;
soap->part = SOAP_IN_ENVELOPE;
return soap_element_begin_out(soap, "SOAP-ENV:Envelope", 0, NULL);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_envelope_end_out(struct soap *soap)
{ if (soap->version == 0)
return SOAP_OK;
if (soap_element_end_out(soap, "SOAP-ENV:Envelope")
|| soap_send_raw(soap, "\r\n", 2)) /* 2.8: always emit \r\n */
return soap->error;
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM))
{ soap->dime.size = soap->count - soap->dime.size; /* DIME in MIME correction */
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->id, sizeof(soap->id), soap->dime_id_format, 0);
#else
sprintf(soap->id, soap->dime_id_format, 0);
#endif
soap->dime.id = soap->id;
if (soap->local_namespaces)
{ if (soap->local_namespaces[0].out)
soap->dime.type = (char*)soap->local_namespaces[0].out;
else
soap->dime.type = (char*)soap->local_namespaces[0].ns;
}
soap->dime.options = NULL;
soap->dime.flags = SOAP_DIME_MB | SOAP_DIME_ABSURI;
if (!soap->dime.first)
soap->dime.flags |= SOAP_DIME_ME;
soap->count += 12 + ((strlen(soap->dime.id)+3)&(~3)) + (soap->dime.type ? ((strlen(soap->dime.type)+3)&(~3)) : 0);
}
if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM))
return soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime.size&3);
#endif
soap->part = SOAP_END_ENVELOPE;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
#ifndef PALM_1
SOAP_FMAC1
char*
SOAP_FMAC2
soap_get_http_body(struct soap *soap, size_t *len)
{ if (len)
*len = 0;
#ifndef WITH_LEAN
register size_t l = 0, n = 0;
register char *s;
/* get HTTP body length */
if (!(soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) != SOAP_IO_CHUNK)
{ n = soap->length;
if (!n)
return NULL;
}
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Parsing HTTP body (mode=0x%x,len=%lu)\n", soap->mode, (unsigned long)n));
#ifdef WITH_FAST
soap->labidx = 0; /* use look-aside buffer */
#else
if (soap_new_block(soap) == NULL)
return NULL;
#endif
for (;;)
{
#ifdef WITH_FAST
register size_t i, k;
if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
return NULL;
s = soap->labbuf + soap->labidx; /* space to populate */
k = soap->lablen - soap->labidx; /* number of bytes available */
soap->labidx = soap->lablen; /* claim this space */
#else
register size_t i, k = SOAP_BLKLEN;
if (!(s = (char*)soap_push_block(soap, NULL, k)))
return NULL;
#endif
for (i = 0; i < k; i++)
{ register soap_wchar c;
l++;
if (n > 0 && l > n)
goto end;
c = soap_get1(soap);
if ((int)c == EOF)
goto end;
*s++ = (char)(c & 0xFF);
}
}
end:
*s = '\0';
if (len)
*len = l - 1; /* len excludes terminating \0 */
#ifdef WITH_FAST
if ((s = (char*)soap_malloc(soap, l)))
memcpy(s, soap->labbuf, l);
#else
soap_size_block(soap, NULL, i+1);
s = soap_save_block(soap, NULL, 0);
#endif
return s;
#else
return NULL;
#endif
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_envelope_begin_in(struct soap *soap)
{ register struct Namespace *p;
soap->part = SOAP_IN_ENVELOPE;
if (soap_element_begin_in(soap, "SOAP-ENV:Envelope", 0, NULL))
{ if (soap->error == SOAP_TAG_MISMATCH)
{ if (!soap_element_begin_in(soap, "Envelope", 0, NULL))
soap->error = SOAP_VERSIONMISMATCH;
else if (soap->status == 0 || (soap->status >= 200 && soap->status <= 299))
return SOAP_OK; /* allow non-SOAP XML content to be captured */
soap->error = soap->status;
}
else if (soap->status)
soap->error = soap->status;
return soap->error;
}
p = soap->local_namespaces;
if (p)
{ const char *ns = p[0].out;
if (!ns)
ns = p[0].ns;
if (!strcmp(ns, soap_env1))
{ soap->version = 1; /* make sure we use SOAP 1.1 */
if (p[1].out)
SOAP_FREE(soap, p[1].out);
if ((p[1].out = (char*)SOAP_MALLOC(soap, sizeof(soap_enc1))))
strcpy(p[1].out, soap_enc1);
}
else if (!strcmp(ns, soap_env2))
{ soap->version = 2; /* make sure we use SOAP 1.2 */
if (p[1].out)
SOAP_FREE(soap, p[1].out);
if ((p[1].out = (char*)SOAP_MALLOC(soap, sizeof(soap_enc2))))
strcpy(p[1].out, soap_enc2);
}
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_envelope_end_in(struct soap *soap)
{ if (soap->version == 0)
return SOAP_OK;
soap->part = SOAP_END_ENVELOPE;
return soap_element_end_in(soap, "SOAP-ENV:Envelope");
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_body_begin_out(struct soap *soap)
{ if (soap->version == 1)
soap->encoding = 1;
#ifndef WITH_LEAN
if ((soap->mode & SOAP_SEC_WSUID) && soap_set_attr(soap, "wsu:Id", "Body", 1))
return soap->error;
#endif
if (soap->version == 0)
return SOAP_OK;
soap->part = SOAP_IN_BODY;
return soap_element_begin_out(soap, "SOAP-ENV:Body", 0, NULL);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_body_end_out(struct soap *soap)
{ if (soap->version == 0)
return SOAP_OK;
if (soap_element_end_out(soap, "SOAP-ENV:Body"))
return soap->error;
soap->part = SOAP_END_BODY;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_body_begin_in(struct soap *soap)
{ if (soap->version == 0)
return SOAP_OK;
soap->part = SOAP_IN_BODY;
if (soap_element_begin_in(soap, "SOAP-ENV:Body", 0, NULL))
return soap->error;
if (!soap->body)
soap->part = SOAP_NO_BODY;
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_body_end_in(struct soap *soap)
{ if (soap->version == 0)
return SOAP_OK;
if (soap->part == SOAP_NO_BODY)
return soap->error = SOAP_OK;
soap->part = SOAP_END_BODY;
return soap_element_end_in(soap, "SOAP-ENV:Body");
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_recv_header(struct soap *soap)
{ if (soap_getheader(soap) && soap->error == SOAP_TAG_MISMATCH)
soap->error = SOAP_OK;
if (soap->error == SOAP_OK && soap->fheader)
soap->error = soap->fheader(soap);
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_endpoint(struct soap *soap, const char *endpoint)
{ register const char *s;
register size_t i, n;
soap->endpoint[0] = '\0';
soap->host[0] = '\0';
soap->path[0] = '/';
soap->path[1] = '\0';
soap->port = 80;
if (!endpoint || !*endpoint)
return;
#ifdef WITH_OPENSSL
if (!soap_tag_cmp(endpoint, "https:*"))
soap->port = 443;
#endif
strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint));
soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
s = strchr(endpoint, ':');
if (s && s[1] == '/' && s[2] == '/')
s += 3;
else
s = endpoint;
n = strlen(s);
if (n >= sizeof(soap->host))
n = sizeof(soap->host) - 1;
#ifdef WITH_IPV6
if (s[0] == '[')
{ s++;
for (i = 0; i < n; i++)
{ if (s[i] == ']')
{ s++;
--n;
break;
}
soap->host[i] = s[i];
}
}
else
{ for (i = 0; i < n; i++)
{ soap->host[i] = s[i];
if (s[i] == '/' || s[i] == ':')
break;
}
}
#else
for (i = 0; i < n; i++)
{ soap->host[i] = s[i];
if (s[i] == '/' || s[i] == ':')
break;
}
#endif
soap->host[i] = '\0';
if (s[i] == ':')
{ soap->port = (int)soap_strtol(s + i + 1, NULL, 10);
for (i++; i < n; i++)
if (s[i] == '/')
break;
}
if (i < n && s[i])
{ strncpy(soap->path, s + i, sizeof(soap->path));
soap->path[sizeof(soap->path) - 1] = '\0';
}
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_connect(struct soap *soap, const char *endpoint, const char *action)
{ return soap_connect_command(soap, SOAP_POST, endpoint, action);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_connect_command(struct soap *soap, int http_command, const char *endpoints, const char *action)
{ char *endpoint;
const char *s;
if (endpoints && (s = strchr(endpoints, ' ')))
{ endpoint = (char*)SOAP_MALLOC(soap, strlen(endpoints) + 1);
for (;;)
{ strncpy(endpoint, endpoints, s - endpoints);
endpoint[s - endpoints] = '\0';
if (soap_try_connect_command(soap, http_command, endpoint, action) != SOAP_TCP_ERROR)
break;
if (!*s)
break;
soap->error = SOAP_OK;
while (*s == ' ')
s++;
endpoints = s;
s = strchr(endpoints, ' ');
if (!s)
s = endpoints + strlen(endpoints);
}
SOAP_FREE(soap, endpoint);
}
else
soap_try_connect_command(soap, http_command, endpoints, action);
return soap->error;
}
#endif
/******************************************************************************/
#ifndef PALM_1
static int
soap_try_connect_command(struct soap *soap, int http_command, const char *endpoint, const char *action)
{ char host[sizeof(soap->host)];
int port;
size_t count;
soap->error = SOAP_OK;
strcpy(host, soap->host); /* save previous host name: if != then reconnect */
port = soap->port; /* save previous port to compare */
soap->status = http_command;
soap_set_endpoint(soap, endpoint);
#ifndef WITH_LEANER
if (soap->fconnect)
{ if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port)))
return soap->error;
}
else
#endif
soap->action = soap_strdup(soap, action);
if (soap->fopen && *soap->host)
{ if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap))
{ soap->error = SOAP_OK;
#ifndef WITH_LEAN
if (!strncmp(endpoint, "soap.udp:", 9))
soap->omode |= SOAP_IO_UDP;
else
#endif
{ soap->keep_alive = 0; /* to force close */
soap->omode &= ~SOAP_IO_UDP; /* to force close */
}
soap_closesock(soap);
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to '%s' host='%s' path='%s' port=%d\n", endpoint?endpoint:"(null)", soap->host, soap->path, soap->port));
if (!soap->keep_alive || !soap_valid_socket(soap->socket))
{ soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
if (soap->error)
return soap->error;
soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0);
}
}
}
#ifdef WITH_NTLM
if (soap_ntlm_handshake(soap, SOAP_GET, endpoint, soap->host, soap->port))
return soap->error;
#endif
count = soap_count_attachments(soap);
if (soap_begin_send(soap))
return soap->error;
if (http_command == SOAP_GET)
{ soap->mode &= ~SOAP_IO;
soap->mode |= SOAP_IO_BUFFER;
}
#ifndef WITH_NOHTTP
if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML) && endpoint)
{ unsigned int k = soap->mode;
soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
if ((k & SOAP_IO) != SOAP_IO_FLUSH)
soap->mode |= SOAP_IO_BUFFER;
if ((soap->error = soap->fpost(soap, endpoint, soap->host, soap->port, soap->path, action, count)))
return soap->error;
#ifndef WITH_LEANER
if ((k & SOAP_IO) == SOAP_IO_CHUNK)
{ if (soap_flush(soap))
return soap->error;
}
#endif
soap->mode = k;
}
if (http_command == SOAP_GET || http_command == SOAP_DEL)
return soap_end_send_flush(soap);
#endif
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifdef WITH_NTLM
#ifndef PALM_1
static int
soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const char *host, int port)
{ /* requires libntlm from http://www.nongnu.org/libntlm/ */
const char *userid = (soap->proxy_userid ? soap->proxy_userid : soap->userid);
const char *passwd = (soap->proxy_passwd ? soap->proxy_passwd : soap->passwd);
struct SOAP_ENV__Header *oldheader;
if (soap->ntlm_challenge && userid && passwd && soap->authrealm)
{ tSmbNtlmAuthRequest req;
tSmbNtlmAuthResponse res;
tSmbNtlmAuthChallenge ch;
short k = soap->keep_alive;
size_t l = soap->length;
size_t c = soap->count;
soap_mode m = soap->mode, o = soap->omode;
int s = soap->status;
char *a = soap->action;
short v = soap->version;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM '%s'\n", soap->ntlm_challenge));
if (!*soap->ntlm_challenge)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM S->C Type 1: received NTLM authentication challenge from server\n"));
/* S -> C 401 Unauthorized
WWW-Authenticate: NTLM
*/
buildSmbNtlmAuthRequest(&req, userid, soap->authrealm);
soap->ntlm_challenge = soap_s2base64(soap, (unsigned char*)&req, NULL, SmbLength(&req));
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM C->S Type 2: sending NTLM authorization to server\nAuthorization: NTLM %s\n", soap->ntlm_challenge));
/* C -> S GET ...
Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S
*/
soap->omode = SOAP_IO_BUFFER;
if (soap_begin_send(soap))
return soap->error;
soap->keep_alive = 1;
soap->status = command;
if (soap->fpost(soap, endpoint, host, port, soap->path, soap->action, 0)
|| soap_end_send_flush(soap))
return soap->error;
soap->mode = m;
soap->keep_alive = k;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM S->C Type 2: waiting on server NTLM response\n"));
oldheader = soap->header;
if (soap_begin_recv(soap))
if (soap->error == SOAP_EOF)
return soap->error;
soap_end_recv(soap);
soap->header = oldheader;
soap->length = l;
if (soap->status != 401 && soap->status != 407)
return soap->error = SOAP_NTLM_ERROR;
soap->error = SOAP_OK;
}
/* S -> C 401 Unauthorized
WWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABggAAU3J2Tm9uY2UAAAAAAAAAAA==
*/
soap_base642s(soap, soap->ntlm_challenge, (char*)&ch, sizeof(tSmbNtlmAuthChallenge), NULL);
buildSmbNtlmAuthResponse(&ch, &res, userid, passwd);
soap->ntlm_challenge = soap_s2base64(soap, (unsigned char*)&res, NULL, SmbLength(&res));
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM C->S Type 3: sending NTLM authorization to server\nAuthorization: NTLM %s\n", soap->ntlm_challenge));
/* C -> S GET ...
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHIAAAAYABgAigAAABQAFABAAAAADAAMAFQAAAASABIAYAAAAAAAAACiAAAAAYIAAFUAUgBTAEEALQBNAEkATgBPAFIAWgBhAHAAaABvAGQATABJAEcASABUAEMASQBUAFkArYfKbe/jRoW5xDxHeoxC1gBmfWiS5+iX4OAN4xBKG/IFPwfH3agtPEia6YnhsADT
*/
soap->userid = NULL;
soap->passwd = NULL;
soap->proxy_userid = NULL;
soap->proxy_passwd = NULL;
soap->keep_alive = k;
soap->length = l;
soap->count = c;
soap->mode = m;
soap->omode = o;
soap->status = s;
soap->action = a;
soap->version = v;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
char*
SOAP_FMAC2
soap_s2base64(struct soap *soap, const unsigned char *s, char *t, int n)
{ register int i;
register unsigned long m;
register char *p;
if (!t)
t = (char*)soap_malloc(soap, (n + 2) / 3 * 4 + 1);
if (!t)
return NULL;
p = t;
t[0] = '\0';
if (!s)
return p;
for (; n > 2; n -= 3, s += 3)
{ m = s[0];
m = (m << 8) | s[1];
m = (m << 8) | s[2];
for (i = 4; i > 0; m >>= 6)
t[--i] = soap_base64o[m & 0x3F];
t += 4;
}
t[0] = '\0';
if (n > 0) /* 0 < n <= 2 implies that t[0..4] is allocated (base64 scaling formula) */
{ m = 0;
for (i = 0; i < n; i++)
m = (m << 8) | *s++;
for (; i < 3; i++)
m <<= 8;
for (i = 4; i > 0; m >>= 6)
t[--i] = soap_base64o[m & 0x3F];
for (i = 3; i > n; i--)
t[i] = '=';
t[4] = '\0';
}
return p;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_base642s(struct soap *soap, const char *s, char *t, size_t l, int *n)
{ register size_t i, j;
register soap_wchar c;
register unsigned long m;
register const char *p;
if (!s || !*s)
{ if (n)
*n = 0;
if (soap->error)
return NULL;
return SOAP_NON_NULL;
}
if (!t)
{ l = (strlen(s) + 3) / 4 * 3 + 1; /* make sure enough space for \0 */
t = (char*)soap_malloc(soap, l);
}
if (!t)
return NULL;
p = t;
if (n)
*n = 0;
for (i = 0; ; i += 3, l -= 3)
{ m = 0;
j = 0;
while (j < 4)
{ c = *s++;
if (c == '=' || !c)
{ if (l >= j - 1)
{ switch (j)
{ case 2:
*t++ = (char)((m >> 4) & 0xFF);
i++;
l--;
break;
case 3:
*t++ = (char)((m >> 10) & 0xFF);
*t++ = (char)((m >> 2) & 0xFF);
i += 2;
l -= 2;
}
}
if (n)
*n = (int)i;
if (l)
*t = '\0';
return p;
}
c -= '+';
if (c >= 0 && c <= 79)
{ int b = soap_base64i[c];
if (b >= 64)
{ soap->error = SOAP_TYPE;
return NULL;
}
m = (m << 6) + b;
j++;
}
else if (!soap_blank(c + '+'))
{ soap->error = SOAP_TYPE;
return NULL;
}
}
if (l < 3)
{ if (n)
*n = (int)i;
if (l)
*t = '\0';
return p;
}
*t++ = (char)((m >> 16) & 0xFF);
*t++ = (char)((m >> 8) & 0xFF);
*t++ = (char)(m & 0xFF);
}
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
char*
SOAP_FMAC2
soap_s2hex(struct soap *soap, const unsigned char *s, char *t, int n)
{ register char *p;
if (!t)
t = (char*)soap_malloc(soap, 2 * n + 1);
if (!t)
return NULL;
p = t;
t[0] = '\0';
if (s)
{ for (; n > 0; n--)
{ register int m = *s++;
*t++ = (char)((m >> 4) + (m > 159 ? 'a' - 10 : '0'));
m &= 0x0F;
*t++ = (char)(m + (m > 9 ? 'a' - 10 : '0'));
}
}
*t++ = '\0';
return p;
}
#endif
/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n)
{ register const char *p;
if (!s || !*s)
{ if (n)
*n = 0;
if (soap->error)
return NULL;
return SOAP_NON_NULL;
}
if (!t)
{ l = strlen(s) / 2 + 1; /* make sure enough space for \0 */
t = (char*)soap_malloc(soap, l);
}
if (!t)
return NULL;
p = t;
while (l)
{ register int d1, d2;
d1 = *s++;
if (!d1)
break;
d2 = *s++;
if (!d2)
break;
*t++ = (char)(((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'));
l--;
}
if (n)
*n = (int)(t - p);
if (l)
*t = '\0';
return p;
}
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_puthttphdr(struct soap *soap, int status, size_t count)
{ if (soap->status != SOAP_GET && soap->status != SOAP_DEL && soap->status != SOAP_CONNECT)
{ register const char *s = "text/xml; charset=utf-8";
register int err = SOAP_OK;
#ifndef WITH_LEANER
register const char *r = NULL;
#endif
if ((status == SOAP_FILE || soap->status == SOAP_PUT || soap->status == SOAP_POST_FILE) && soap->http_content && !strchr(s, 10) && !strchr(s, 13))
s = soap->http_content;
else if (status == SOAP_HTML)
s = "text/html; charset=utf-8";
else if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK))
{ if (soap->version == 2)
s = "application/soap+xml; charset=utf-8";
}
#ifndef WITH_LEANER
if (soap->mode & (SOAP_ENC_DIME | SOAP_ENC_MTOM))
{ if (soap->mode & SOAP_ENC_MTOM)
{ if (soap->version == 2)
r = "application/soap+xml";
else
r = "text/xml";
s = "application/xop+xml";
}
else
s = "application/dime";
}
if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && strlen(soap->mime.boundary) + strlen(soap->mime.start ? soap->mime.start : SOAP_STR_EOS) < sizeof(soap->tmpbuf) - 80)
{ register const char *t;
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "multipart/related; charset=utf-8; boundary=\"%s\"; type=\"", soap->mime.boundary);
#else
sprintf(soap->tmpbuf, "multipart/related; charset=utf-8; boundary=\"%s\"; type=\"", soap->mime.boundary);
#endif
t = strchr(s, ';');
if (t)
strncat(soap->tmpbuf, s, t - s);
else
strcat(soap->tmpbuf, s);
if (soap->mime.start && strlen(soap->tmpbuf) + strlen(soap->mime.start) + 11 < sizeof(soap->tmpbuf))
{ strcat(soap->tmpbuf, "\"; start=\"");
strcat(soap->tmpbuf, soap->mime.start);
}
strcat(soap->tmpbuf, "\"");
if (r && strlen(soap->tmpbuf) + strlen(r) + 15 < sizeof(soap->tmpbuf))
{ strcat(soap->tmpbuf, "; start-info=\"");
strcat(soap->tmpbuf, r);
strcat(soap->tmpbuf, "\"");
}
}
else
strncpy(soap->tmpbuf, s, sizeof(soap->tmpbuf));
soap->tmpbuf[sizeof(soap->tmpbuf) - 1] = '\0';
s = soap->tmpbuf;
if (status == SOAP_OK && soap->version == 2 && soap->action && strlen(soap->action) + strlen(s) < sizeof(soap->tmpbuf) - 80)
{
#ifdef HAVE_SNPRINTF
size_t l = strlen(s);
soap_snprintf(soap->tmpbuf + l, sizeof(soap->tmpbuf) - l, "; action=\"%s\"", soap->action);
#else
sprintf(soap->tmpbuf + strlen(s), "; action=\"%s\"", soap->action);
#endif
}
#endif
if ((err = soap->fposthdr(soap, "Content-Type", s)))
return err;
#ifdef WITH_ZLIB
if ((soap->omode & SOAP_ENC_ZLIB))
{
#ifdef WITH_GZIP
err = soap->fposthdr(soap, "Content-Encoding", soap->zlib_out == SOAP_ZLIB_DEFLATE ? "deflate" : "gzip");
#else
err = soap->fposthdr(soap, "Content-Encoding", "deflate");
#endif
if (err)
return err;
}
#endif
#ifndef WITH_LEANER
if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)
err = soap->fposthdr(soap, "Transfer-Encoding", "chunked");
else
#endif
if (s)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%lu", (unsigned long)count);
#else
sprintf(soap->tmpbuf, "%lu", (unsigned long)count);
#endif
err = soap->fposthdr(soap, "Content-Length", soap->tmpbuf);
}
if (err)
return err;
}
return soap->fposthdr(soap, "Connection", soap->keep_alive ? "keep-alive" : "close");
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEAN
static const char*
soap_set_validation_fault(struct soap *soap, const char *s, const char *t)
{ if (!t)
t = SOAP_STR_EOS;
if (*soap->tag)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Validation constraint violation: %s%s in element '%s'", s, t ? t : SOAP_STR_EOS, soap->tag);
#else
if (strlen(soap->tag) + strlen(t) < sizeof(soap->msgbuf) - 100)
sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element '%s'", s, t, soap->tag);
else
sprintf(soap->msgbuf, "Validation constraint violation: %s", s);
#endif
}
else
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Validation constraint violation: %s%s", s, t ? t : SOAP_STR_EOS);
#else
if (strlen(soap->tag) + strlen(t) < sizeof(soap->msgbuf) - 100)
sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t);
else
sprintf(soap->msgbuf, "Validation constraint violation: %s", s);
#endif
}
return soap->msgbuf;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
void
SOAP_FMAC2
soap_set_fault(struct soap *soap)
{ const char **c = soap_faultcode(soap);
const char **s = soap_faultstring(soap);
if (soap->fseterror)
soap->fseterror(soap, c, s);
if (!*c)
{ if (soap->version == 2)
*c = "SOAP-ENV:Sender";
else
*c = "SOAP-ENV:Client";
}
if (*s)
return;
switch (soap->error)
{
#ifndef WITH_LEAN
case SOAP_CLI_FAULT:
*s = "Client fault";
break;
case SOAP_SVR_FAULT:
*s = "Server fault";
break;
case SOAP_TAG_MISMATCH:
*s = soap_set_validation_fault(soap, "tag name or namespace mismatch", NULL);
break;
case SOAP_TYPE:
*s = soap_set_validation_fault(soap, "data type mismatch ", soap->type);
break;
case SOAP_SYNTAX_ERROR:
*s = "Well-formedness violation";
break;
case SOAP_NO_TAG:
*s = "No tag: no XML root element or missing SOAP message body element";
break;
case SOAP_MUSTUNDERSTAND:
*c = "SOAP-ENV:MustUnderstand";
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "The data in element '%s' must be understood but cannot be handled", soap->tag);
#else
strncpy(soap->msgbuf, soap->tag, sizeof(soap->msgbuf));
soap->msgbuf[sizeof(soap->msgbuf) - 1] = '\0';
#endif
*s = soap->msgbuf;
break;
case SOAP_VERSIONMISMATCH:
*c = "SOAP-ENV:VersionMismatch";
*s = "Invalid SOAP message or SOAP version mismatch";
break;
case SOAP_DATAENCODINGUNKNOWN:
*c = "SOAP-ENV:DataEncodingUnknown";
*s = "Unsupported SOAP data encoding";
break;
case SOAP_NAMESPACE:
*s = soap_set_validation_fault(soap, "namespace error", NULL);
break;
case SOAP_USER_ERROR:
*s = "User data error";
break;
case SOAP_FATAL_ERROR:
*s = "Fatal error";
break;
case SOAP_NO_METHOD:
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Method '%s' not implemented: method name or namespace not recognized", soap->tag);
#else
sprintf(soap->msgbuf, "Method '%s' not implemented: method name or namespace not recognized", soap->tag);
#endif
*s = soap->msgbuf;
break;
case SOAP_NO_DATA:
*s = "Data required for operation";
break;
case SOAP_GET_METHOD:
*s = "HTTP GET method not implemented";
break;
case SOAP_PUT_METHOD:
*s = "HTTP PUT method not implemented";
break;
case SOAP_HTTP_METHOD:
*s = "HTTP method not implemented";
break;
case SOAP_EOM:
*s = "Out of memory";
break;
case SOAP_MOE:
*s = "Memory overflow or memory corruption error";
break;
case SOAP_HDR:
*s = "Header line too long";
break;
case SOAP_IOB:
*s = "Array index out of bounds";
break;
case SOAP_NULL:
*s = soap_set_validation_fault(soap, "nil not allowed", NULL);
break;
case SOAP_DUPLICATE_ID:
*s = soap_set_validation_fault(soap, "multiple elements (use the SOAP_XML_TREE flag) with duplicate id ", soap->id);
if (soap->version == 2)
*soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID";
break;
case SOAP_MISSING_ID:
*s = soap_set_validation_fault(soap, "missing id for ref ", soap->id);
if (soap->version == 2)
*soap_faultsubcode(soap) = "SOAP-ENC:MissingID";
break;
case SOAP_HREF:
*s = soap_set_validation_fault(soap, "incompatible object type id-ref ", soap->id);
break;
case SOAP_FAULT:
break;
#ifndef WITH_NOIO
case SOAP_UDP_ERROR:
*s = "Message too large for UDP packet";
break;
case SOAP_TCP_ERROR:
*s = tcp_error(soap);
break;
#endif
case SOAP_HTTP_ERROR:
*s = "An HTTP processing error occurred";
break;
case SOAP_NTLM_ERROR:
*s = "An HTTP NTLM authentication error occurred";
break;
case SOAP_SSL_ERROR:
#ifdef WITH_OPENSSL
*s = "SSL/TLS error";
#else
*s = "OpenSSL not installed: recompile with -DWITH_OPENSSL";
#endif
break;
case SOAP_PLUGIN_ERROR:
*s = "Plugin registry error";
break;
case SOAP_DIME_ERROR:
*s = "DIME format error or max DIME size exceeds SOAP_MAXDIMESIZE";
break;
case SOAP_DIME_HREF:
*s = "DIME href to missing attachment";
break;
case SOAP_DIME_MISMATCH:
*s = "DIME version/transmission error";
break;
case SOAP_DIME_END:
*s = "End of DIME error";
break;
case SOAP_MIME_ERROR:
*s = "MIME format error";
break;
case SOAP_MIME_HREF:
*s = "MIME href to missing attachment";
break;
case SOAP_MIME_END:
*s = "End of MIME error";
break;
case SOAP_ZLIB_ERROR:
#ifdef WITH_ZLIB
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Zlib/gzip error: '%s'", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS);
#else
sprintf(soap->msgbuf, "Zlib/gzip error: '%s'", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS);
#endif
*s = soap->msgbuf;
#else
*s = "Zlib/gzip not installed for (de)compression: recompile with -DWITH_GZIP";
#endif
break;
case SOAP_REQUIRED:
*s = soap_set_validation_fault(soap, "missing required attribute", NULL);
break;
case SOAP_PROHIBITED:
*s = soap_set_validation_fault(soap, "prohibited attribute present", NULL);
break;
case SOAP_OCCURS:
*s = soap_set_validation_fault(soap, "occurrence violation", NULL);
break;
case SOAP_LENGTH:
*s = soap_set_validation_fault(soap, "content range or length violation", NULL);
break;
case SOAP_FD_EXCEEDED:
*s = "Maximum number of open connections was reached (no define HAVE_POLL): increase FD_SETSIZE";
break;
case SOAP_UTF_ERROR:
*s = "UTF content encoding error";
break;
case SOAP_STOP:
*s = "Stopped: no response sent or received (informative)";
break;
#endif
case SOAP_EOF:
#ifndef WITH_NOIO
*s = soap_strerror(soap); /* *s = soap->msgbuf */
#ifndef WITH_LEAN
if (strlen(soap->msgbuf) + 25 < sizeof(soap->msgbuf))
{ memmove(soap->msgbuf + 25, soap->msgbuf, strlen(soap->msgbuf) + 1);
memcpy(soap->msgbuf, "End of file or no input: ", 25);
}
#endif
break;
#else
*s = "End of file or no input";
break;
#endif
default:
#ifndef WITH_NOHTTP
#ifndef WITH_LEAN
if (soap->error > 200 && soap->error < 600)
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "HTTP Error: %d %s", soap->error, http_error(soap, soap->error));
#else
sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error));
#endif
*s = soap->msgbuf;
}
else
#endif
#endif
{
#ifdef HAVE_SNPRINTF
soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Error %d", soap->error);
#else
sprintf(soap->msgbuf, "Error %d", soap->error);
#endif
*s = soap->msgbuf;
}
}
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send_fault(struct soap *soap)
{ register int status = soap->error;
if (status == SOAP_OK || status == SOAP_STOP)
return soap_closesock(soap);
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Sending back fault struct for error code %d\n", soap->error));
soap->keep_alive = 0; /* to terminate connection */
soap_set_fault(soap);
if (soap->error < 200 && soap->error != SOAP_FAULT)
soap->header = NULL;
if (status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout))
{ register int r = 1;
#ifndef WITH_NOIO
if (soap->fpoll && soap->fpoll(soap))
r = 0;
#ifndef WITH_LEAN
else if (soap_valid_socket(soap->socket))
{ r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_SND, 0);
if (r > 0)
{ int t;
if (!(r & SOAP_TCP_SELECT_SND)
|| ((r & SOAP_TCP_SELECT_RCV)
&& recv(soap->socket, (char*)&t, 1, MSG_PEEK) < 0))
r = 0;
}
}
#endif
#endif
if (r > 0)
{ soap->error = SOAP_OK;
soap->encodingStyle = NULL; /* no encodingStyle in Faults */
soap_serializeheader(soap);
soap_serializefault(soap);
soap_begin_count(soap);
if (soap->mode & SOAP_IO_LENGTH)
{ soap_envelope_begin_out(soap);
soap_putheader(soap);
soap_body_begin_out(soap);
soap_putfault(soap);
soap_body_end_out(soap);
soap_envelope_end_out(soap);
}
soap_end_count(soap);
if (soap_response(soap, status)
|| soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_putfault(soap)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap_closesock(soap);
soap_end_send(soap);
}
}
soap->error = status;
return soap_closesock(soap);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_recv_fault(struct soap *soap, int check)
{ register int status = soap->error;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Check if receiving SOAP Fault\n"));
if (!check)
{ /* try getfault when no tag or tag mismatched at level 2, otherwise ret */
if (soap->error != SOAP_NO_TAG
&& (soap->error != SOAP_TAG_MISMATCH || soap->level != 2))
return soap->error;
}
else if (soap->version == 0) /* check == 1 but no SOAP: do not parse SOAP Fault */
return SOAP_OK;
soap->error = SOAP_OK;
if (soap_getfault(soap))
{ /* check flag set: check if SOAP Fault is present, if not just return */
if (check && soap->error == SOAP_TAG_MISMATCH && soap->level == 2)
return soap->error = SOAP_OK;
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Error: soap_get_soapfault() failed at level %u tag '%s'\n", soap->level, soap->tag));
*soap_faultcode(soap) = (soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client");
soap->error = status;
soap_set_fault(soap);
}
else
{ register const char *s = *soap_faultcode(soap);
if (!soap_match_tag(soap, s, "SOAP-ENV:Server") || !soap_match_tag(soap, s, "SOAP-ENV:Receiver"))
status = SOAP_SVR_FAULT;
else if (!soap_match_tag(soap, s, "SOAP-ENV:Client") || !soap_match_tag(soap, s, "SOAP-ENV:Sender"))
status = SOAP_CLI_FAULT;
else if (!soap_match_tag(soap, s, "SOAP-ENV:MustUnderstand"))
status = SOAP_MUSTUNDERSTAND;
else if (!soap_match_tag(soap, s, "SOAP-ENV:VersionMismatch"))
status = SOAP_VERSIONMISMATCH;
else
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Received SOAP Fault code %s\n", s));
status = SOAP_FAULT;
}
if (!soap_body_end_in(soap))
soap_envelope_end_in(soap);
}
soap_end_recv(soap);
soap->error = status;
return soap_closesock(soap);
}
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send_empty_response(struct soap *soap, int httpstatuscode)
{ register soap_mode m = soap->omode;
if (!(m & SOAP_IO_UDP))
{ soap->count = 0;
if ((m & SOAP_IO) == SOAP_IO_CHUNK)
soap->omode = (m & ~SOAP_IO) | SOAP_IO_BUFFER;
soap_response(soap, httpstatuscode);
soap_end_send(soap); /* force end of sends */
soap->error = SOAP_STOP; /* stops the server (from returning a response) */
soap->omode = m;
}
return soap_closesock(soap);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_recv_empty_response(struct soap *soap)
{ if (!(soap->omode & SOAP_IO_UDP))
{ if (!soap_begin_recv(soap))
{
#ifndef WITH_LEAN
if (soap->body)
soap_get_http_body(soap, NULL); /* read (empty?) HTTP body and discard */
#endif
soap_end_recv(soap);
}
else if (soap->error == SOAP_NO_DATA || soap->error == 202)
soap->error = SOAP_OK;
}
return soap_closesock(soap);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static const char*
soap_strerror(struct soap *soap)
{ register int err = soap->errnum;
*soap->msgbuf = '\0';
if (err)
{
#ifndef WIN32
# ifdef HAVE_STRERROR_R
# ifdef _GNU_SOURCE
return strerror_r(err, soap->msgbuf, sizeof(soap->msgbuf)); /* GNU-specific */
# else
strerror_r(err, soap->msgbuf, sizeof(soap->msgbuf)); /* XSI-compliant */
# endif
# else
return strerror(err);
# endif
#else
#ifndef UNDER_CE
DWORD len;
*soap->msgbuf = '\0';
len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)soap->msgbuf, (DWORD)sizeof(soap->msgbuf), NULL);
#else
DWORD i, len;
*soap->msgbuf = '\0';
len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)soap->msgbuf, (DWORD)(sizeof(soap->msgbuf)/sizeof(TCHAR)), NULL);
for (i = 0; i <= len; i++)
{ if (((TCHAR*)soap->msgbuf)[i] < 0x80)
soap->msgbuf[i] = (char)((TCHAR*)soap->msgbuf)[i];
else
soap->msgbuf[i] = '?';
}
#endif
#endif
}
else
{ char *s = soap->msgbuf;
#ifndef WITH_LEAN
int rt = soap->recv_timeout, st = soap->send_timeout;
int ru = ' ', su = ' ';
#endif
strcpy(s, "Operation interrupted or timed out");
#ifndef WITH_LEAN
if (rt < 0)
{ rt = -rt;
ru = 'u';
}
if (st < 0)
{ st = -st;
su = 'u';
}
if (rt)
{
#ifdef HAVE_SNPRINTF
size_t l = strlen(s);
soap_snprintf(s + l, sizeof(soap->msgbuf) - l, " (%d%cs recv delay)", rt, ru);
#else
sprintf(s + strlen(s), " (%d%cs recv delay)", rt, ru);
#endif
}
if (st)
{
#ifdef HAVE_SNPRINTF
size_t l = strlen(s);
soap_snprintf(s + l, sizeof(soap->msgbuf) - l, " (%d%cs send delay)", st, su);
#else
sprintf(s + strlen(s), " (%d%cs send delay)", st, su);
#endif
}
#endif
}
return soap->msgbuf;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_2
static int
soap_set_error(struct soap *soap, const char *faultcode, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML, int soaperror)
{ *soap_faultcode(soap) = faultcode;
if (faultsubcodeQName)
*soap_faultsubcode(soap) = faultsubcodeQName;
*soap_faultstring(soap) = faultstring;
if (faultdetailXML && *faultdetailXML)
{ register const char **s = soap_faultdetail(soap);
if (s)
*s = faultdetailXML;
}
return soap->error = soaperror;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_sender_error(struct soap *soap, const char *faultstring, const char *faultdetailXML, int soaperror)
{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", NULL, faultstring, faultdetailXML, soaperror);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_set_receiver_error(struct soap *soap, const char *faultstring, const char *faultdetailXML, int soaperror)
{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", NULL, faultstring, faultdetailXML, soaperror);
}
#endif
/******************************************************************************/
#ifndef PALM_2
static int
soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML)
{ char *r = NULL, *s = NULL, *t = NULL;
if (faultsubcodeQName)
r = soap_strdup(soap, faultsubcodeQName);
if (faultstring)
s = soap_strdup(soap, faultstring);
if (faultdetailXML)
t = soap_strdup(soap, faultdetailXML);
return soap_set_error(soap, faultcode, r, s, t, SOAP_FAULT);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetailXML)
{ return soap_sender_fault_subcode(soap, NULL, faultstring, faultdetailXML);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_sender_fault_subcode(struct soap *soap, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML)
{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultsubcodeQName, faultstring, faultdetailXML);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetailXML)
{ return soap_receiver_fault_subcode(soap, NULL, faultstring, faultdetailXML);
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_receiver_fault_subcode(struct soap *soap, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML)
{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultsubcodeQName, faultstring, faultdetailXML);
}
#endif
/******************************************************************************/
#ifndef PALM_2
#ifndef WITH_NOSTDLIB
SOAP_FMAC1
void
SOAP_FMAC2
soap_print_fault(struct soap *soap, FILE *fd)
{ if (soap_check_state(soap))
fprintf(fd, "Error: soap struct state not initialized\n");
else if (soap->error)
{ const char **c, *v = NULL, *s, *d;
c = soap_faultcode(soap);
if (!*c)
soap_set_fault(soap);
if (soap->version == 2)
v = soap_check_faultsubcode(soap);
s = *soap_faultstring(soap);
d = soap_check_faultdetail(soap);
fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c, v ? v : "no subcode", s ? s : "[no reason]", d ? d : "[no detail]");
}
}
#endif
#endif
/******************************************************************************/
#ifdef __cplusplus
#ifndef WITH_LEAN
#ifndef WITH_NOSTDLIB
#ifndef WITH_COMPAT
SOAP_FMAC1
void
SOAP_FMAC2
soap_stream_fault(struct soap *soap, std::ostream& os)
{ if (soap_check_state(soap))
os << "Error: soap struct state not initialized\n";
else if (soap->error)
{ const char **c, *v = NULL, *s, *d;
c = soap_faultcode(soap);
if (!*c)
soap_set_fault(soap);
if (soap->version == 2)
v = soap_check_faultsubcode(soap);
s = *soap_faultstring(soap);
d = soap_check_faultdetail(soap);
os << (soap->version ? "SOAP 1." : "Error ")
<< (soap->version ? (int)soap->version : soap->error)
<< " fault: " << *c
<< "[" << (v ? v : "no subcode") << "]"
<< std::endl
<< "\"" << (s ? s : "[no reason]") << "\""
<< std::endl
<< "Detail: " << (d ? d : "[no detail]")
<< std::endl;
}
}
#endif
#endif
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEAN
#ifndef WITH_NOSTDLIB
SOAP_FMAC1
char*
SOAP_FMAC2
soap_sprint_fault(struct soap *soap, char *buf, size_t len)
{ if (soap_check_state(soap))
{ strncpy(buf, "Error: soap struct not initialized", len);
buf[len - 1] = '\0';
}
else if (soap->error)
{ const char **c, *v = NULL, *s, *d;
c = soap_faultcode(soap);
if (!*c)
soap_set_fault(soap);
if (soap->version == 2)
v = *soap_faultsubcode(soap);
s = *soap_faultstring(soap);
d = soap_check_faultdetail(soap);
#ifdef HAVE_SNPRINTF
soap_snprintf(buf, len, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c, v ? v : "no subcode", s ? s : "[no reason]", d ? d : "[no detail]");
#else
if (len > 40 + (v ? strlen(v) : 0) + (s ? strlen(s) : 0) + (d ? strlen(d) : 0))
sprintf(buf, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c, v ? v : "no subcode", s ? s : "[no reason]", d ? d : "[no detail]");
else if (len > 40)
sprintf(buf, "%s%d fault: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c);
else
buf[0] = '\0';
#endif
}
return buf;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
#ifndef WITH_NOSTDLIB
SOAP_FMAC1
void
SOAP_FMAC2
soap_print_fault_location(struct soap *soap, FILE *fd)
{
#ifndef WITH_LEAN
int i, j, c1, c2;
if (soap->error && soap->error != SOAP_STOP && soap->bufidx <= soap->buflen && soap->buflen > 0 && soap->buflen <= SOAP_BUFLEN)
{ i = (int)soap->bufidx - 1;
if (i <= 0)
i = 0;
c1 = soap->buf[i];
soap->buf[i] = '\0';
if ((int)soap->buflen >= i + 1024)
j = i + 1023;
else
j = (int)soap->buflen - 1;
c2 = soap->buf[j];
soap->buf[j] = '\0';
fprintf(fd, "%s%c\n<!-- ** HERE ** -->\n", soap->buf, c1);
if (soap->bufidx < soap->buflen)
fprintf(fd, "%s\n", soap->buf + soap->bufidx);
soap->buf[i] = (char)c1;
soap->buf[j] = (char)c2;
}
#endif
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_register_plugin_arg(struct soap *soap, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void *arg)
{ register struct soap_plugin *p;
register int r;
if (!(p = (struct soap_plugin*)SOAP_MALLOC(soap, sizeof(struct soap_plugin))))
return soap->error = SOAP_EOM;
p->id = NULL;
p->data = NULL;
p->fcopy = NULL;
p->fdelete = NULL;
r = fcreate(soap, p, arg);
if (!r && p->fdelete)
{ p->next = soap->plugins;
soap->plugins = p;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Registered '%s' plugin\n", p->id));
return SOAP_OK;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not register plugin '%s': plugin returned error %d (or fdelete callback not set)\n", p->id ? p->id : "?", r));
SOAP_FREE(soap, p);
return r;
}
#endif
/******************************************************************************/
#ifndef PALM_1
static void *
fplugin(struct soap *soap, const char *id)
{ register struct soap_plugin *p;
for (p = soap->plugins; p; p = p->next)
if (p->id == id || !strcmp(p->id, id))
return p->data;
return NULL;
}
#endif
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void *
SOAP_FMAC2
soap_lookup_plugin(struct soap *soap, const char *id)
{ return soap->fplugin(soap, id);
}
#endif
/******************************************************************************/
#ifdef __cplusplus
}
#endif
/******************************************************************************\
*
* C++ soap struct methods
*
\******************************************************************************/
#ifdef __cplusplus
soap::soap()
{ soap_init(this);
}
#endif
/******************************************************************************/
#ifdef __cplusplus
soap::soap(soap_mode m)
{ soap_init1(this, m);
}
#endif
/******************************************************************************/
#ifdef __cplusplus
soap::soap(soap_mode im, soap_mode om)
{ soap_init2(this, im, om);
}
#endif
/******************************************************************************/
#ifdef __cplusplus
soap::soap(const struct soap& soap)
{ soap_copy_context(this, &soap);
}
#endif
/******************************************************************************/
#ifdef __cplusplus
soap::~soap()
{ soap_destroy(this);
soap_end(this);
soap_done(this);
}
#endif
/******************************************************************************/
| [
"dukezuo@eyecloud.tech"
] | dukezuo@eyecloud.tech |
4a95e9be7279d4f31f8c119cd582281bf55e7bcd | e52e306e00e4c8e355d8e32364e4aff860162e8f | /darknet_detection/src/conv_lstm_layer.c | cb7e3fe176a6cc93e5e9ac581d8f487234b1f21b | [
"BSD-3-Clause"
] | permissive | Hack-n-Chill/ShittyBots | 3696473575c3a30570b1c13b33345a99d6bd23ca | 0833053cd24b63495864c1dc9a9ee4b0141df73a | refs/heads/main | 2023-01-05T00:26:08.854768 | 2020-10-19T06:49:27 | 2020-10-19T06:49:27 | 303,737,526 | 1 | 3 | BSD-3-Clause | 2020-10-18T00:03:57 | 2020-10-13T14:53:27 | C | UTF-8 | C | false | false | 48,545 | c | // Page 4: https://arxiv.org/abs/1506.04214v2
// Page 3: https://arxiv.org/pdf/1705.06368v3.pdf
// https://wikimedia.org/api/rest_v1/media/math/render/svg/1edbece2559479959fe829e9c6657efb380debe7
#include "conv_lstm_layer.h"
#include "connected_layer.h"
#include "convolutional_layer.h"
#include "utils.h"
#include "dark_cuda.h"
#include "blas.h"
#include "gemm.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void increment_layer(layer *l, int steps)
{
int num = l->outputs*l->batch*steps;
l->output += num;
l->delta += num;
l->x += num;
l->x_norm += num;
#ifdef GPU
l->output_gpu += num;
l->delta_gpu += num;
l->x_gpu += num;
l->x_norm_gpu += num;
#endif
}
layer make_conv_lstm_layer(int batch, int h, int w, int c, int output_filters, int groups, int steps, int size, int stride, int dilation, int pad, ACTIVATION activation, int batch_normalize, int peephole, int xnor, int train)
{
fprintf(stderr, "CONV_LSTM Layer: %d x %d x %d image, %d filters\n", h, w, c, output_filters);
/*
batch = batch / steps;
layer l = { (LAYER_TYPE)0 };
l.batch = batch;
l.type = LSTM;
l.steps = steps;
l.inputs = inputs;
l.out_w = 1;
l.out_h = 1;
l.out_c = outputs;
*/
batch = batch / steps;
layer l = { (LAYER_TYPE)0 };
l.train = train;
l.batch = batch;
l.type = CONV_LSTM;
l.steps = steps;
l.size = size;
l.stride = stride;
l.dilation = dilation;
l.pad = pad;
l.h = h;
l.w = w;
l.c = c;
l.groups = groups;
l.out_c = output_filters;
l.inputs = h * w * c;
l.xnor = xnor;
l.peephole = peephole;
// U
l.uf = (layer*)xcalloc(1, sizeof(layer));
*(l.uf) = make_convolutional_layer(batch, steps, h, w, c, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.uf->batch = batch;
if (l.workspace_size < l.uf->workspace_size) l.workspace_size = l.uf->workspace_size;
l.ui = (layer*)xcalloc(1, sizeof(layer));
*(l.ui) = make_convolutional_layer(batch, steps, h, w, c, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.ui->batch = batch;
if (l.workspace_size < l.ui->workspace_size) l.workspace_size = l.ui->workspace_size;
l.ug = (layer*)xcalloc(1, sizeof(layer));
*(l.ug) = make_convolutional_layer(batch, steps, h, w, c, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.ug->batch = batch;
if (l.workspace_size < l.ug->workspace_size) l.workspace_size = l.ug->workspace_size;
l.uo = (layer*)xcalloc(1, sizeof(layer));
*(l.uo) = make_convolutional_layer(batch, steps, h, w, c, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.uo->batch = batch;
if (l.workspace_size < l.uo->workspace_size) l.workspace_size = l.uo->workspace_size;
// W
l.wf = (layer*)xcalloc(1, sizeof(layer));
*(l.wf) = make_convolutional_layer(batch, steps, h, w, output_filters, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.wf->batch = batch;
if (l.workspace_size < l.wf->workspace_size) l.workspace_size = l.wf->workspace_size;
l.wi = (layer*)xcalloc(1, sizeof(layer));
*(l.wi) = make_convolutional_layer(batch, steps, h, w, output_filters, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.wi->batch = batch;
if (l.workspace_size < l.wi->workspace_size) l.workspace_size = l.wi->workspace_size;
l.wg = (layer*)xcalloc(1, sizeof(layer));
*(l.wg) = make_convolutional_layer(batch, steps, h, w, output_filters, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.wg->batch = batch;
if (l.workspace_size < l.wg->workspace_size) l.workspace_size = l.wg->workspace_size;
l.wo = (layer*)xcalloc(1, sizeof(layer));
*(l.wo) = make_convolutional_layer(batch, steps, h, w, output_filters, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.wo->batch = batch;
if (l.workspace_size < l.wo->workspace_size) l.workspace_size = l.wo->workspace_size;
// V
l.vf = (layer*)xcalloc(1, sizeof(layer));
if (l.peephole) {
*(l.vf) = make_convolutional_layer(batch, steps, h, w, output_filters, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.vf->batch = batch;
if (l.workspace_size < l.vf->workspace_size) l.workspace_size = l.vf->workspace_size;
}
l.vi = (layer*)xcalloc(1, sizeof(layer));
if (l.peephole) {
*(l.vi) = make_convolutional_layer(batch, steps, h, w, output_filters, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.vi->batch = batch;
if (l.workspace_size < l.vi->workspace_size) l.workspace_size = l.vi->workspace_size;
}
l.vo = (layer*)xcalloc(1, sizeof(layer));
if (l.peephole) {
*(l.vo) = make_convolutional_layer(batch, steps, h, w, output_filters, output_filters, groups, size, stride, stride, dilation, pad, activation, batch_normalize, 0, xnor, 0, 0, 0, 0, NULL, 0, 0, train);
l.vo->batch = batch;
if (l.workspace_size < l.vo->workspace_size) l.workspace_size = l.vo->workspace_size;
}
l.batch_normalize = batch_normalize;
l.out_h = l.wo->out_h;
l.out_w = l.wo->out_w;
l.outputs = l.wo->outputs;
int outputs = l.outputs;
l.inputs = w*h*c;
assert(l.wo->outputs == l.uo->outputs);
l.output = (float*)xcalloc(outputs * batch * steps, sizeof(float));
//l.state = (float*)xcalloc(outputs * batch, sizeof(float));
l.forward = forward_conv_lstm_layer;
l.update = update_conv_lstm_layer;
l.backward = backward_conv_lstm_layer;
l.prev_state_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.prev_cell_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.cell_cpu = (float*)xcalloc(batch*outputs*steps, sizeof(float));
l.f_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.i_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.g_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.o_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.c_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.stored_c_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.h_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.stored_h_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.temp_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.temp2_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.temp3_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.dc_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
l.dh_cpu = (float*)xcalloc(batch*outputs, sizeof(float));
#ifdef GPU
l.forward_gpu = forward_conv_lstm_layer_gpu;
l.backward_gpu = backward_conv_lstm_layer_gpu;
l.update_gpu = update_conv_lstm_layer_gpu;
//l.state_gpu = cuda_make_array(l.state, batch*l.outputs);
l.output_gpu = cuda_make_array(0, batch*outputs*steps);
l.delta_gpu = cuda_make_array(0, batch*l.outputs*steps);
l.prev_state_gpu = cuda_make_array(0, batch*outputs);
l.prev_cell_gpu = cuda_make_array(0, batch*outputs);
l.cell_gpu = cuda_make_array(0, batch*outputs*steps);
l.f_gpu = cuda_make_array(0, batch*outputs);
l.i_gpu = cuda_make_array(0, batch*outputs);
l.g_gpu = cuda_make_array(0, batch*outputs);
l.o_gpu = cuda_make_array(0, batch*outputs);
l.c_gpu = cuda_make_array(0, batch*outputs);
l.h_gpu = cuda_make_array(0, batch*outputs);
l.stored_c_gpu = cuda_make_array(0, batch*outputs);
l.stored_h_gpu = cuda_make_array(0, batch*outputs);
l.temp_gpu = cuda_make_array(0, batch*outputs);
l.temp2_gpu = cuda_make_array(0, batch*outputs);
l.temp3_gpu = cuda_make_array(0, batch*outputs);
l.dc_gpu = cuda_make_array(0, batch*outputs);
l.dh_gpu = cuda_make_array(0, batch*outputs);
l.last_prev_state_gpu = cuda_make_array(0, l.batch*l.outputs);
l.last_prev_cell_gpu = cuda_make_array(0, l.batch*l.outputs);
#endif
l.bflops = l.uf->bflops + l.ui->bflops + l.ug->bflops + l.uo->bflops +
l.wf->bflops + l.wi->bflops + l.wg->bflops + l.wo->bflops +
l.vf->bflops + l.vi->bflops + l.vo->bflops;
if(l.peephole) l.bflops += 12 * l.outputs*l.batch / 1000000000.;
else l.bflops += 9 * l.outputs*l.batch / 1000000000.;
return l;
}
void update_conv_lstm_layer(layer l, int batch, float learning_rate, float momentum, float decay)
{
if (l.peephole) {
update_convolutional_layer(*(l.vf), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.vi), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.vo), batch, learning_rate, momentum, decay);
}
update_convolutional_layer(*(l.wf), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.wi), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.wg), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.wo), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.uf), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.ui), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.ug), batch, learning_rate, momentum, decay);
update_convolutional_layer(*(l.uo), batch, learning_rate, momentum, decay);
}
void resize_conv_lstm_layer(layer *l, int w, int h)
{
if (l->peephole) {
resize_convolutional_layer(l->vf, w, h);
if (l->workspace_size < l->vf->workspace_size) l->workspace_size = l->vf->workspace_size;
resize_convolutional_layer(l->vi, w, h);
if (l->workspace_size < l->vi->workspace_size) l->workspace_size = l->vi->workspace_size;
resize_convolutional_layer(l->vo, w, h);
if (l->workspace_size < l->vo->workspace_size) l->workspace_size = l->vo->workspace_size;
}
resize_convolutional_layer(l->wf, w, h);
if (l->workspace_size < l->wf->workspace_size) l->workspace_size = l->wf->workspace_size;
resize_convolutional_layer(l->wi, w, h);
if (l->workspace_size < l->wi->workspace_size) l->workspace_size = l->wi->workspace_size;
resize_convolutional_layer(l->wg, w, h);
if (l->workspace_size < l->wg->workspace_size) l->workspace_size = l->wg->workspace_size;
resize_convolutional_layer(l->wo, w, h);
if (l->workspace_size < l->wo->workspace_size) l->workspace_size = l->wo->workspace_size;
resize_convolutional_layer(l->uf, w, h);
if (l->workspace_size < l->uf->workspace_size) l->workspace_size = l->uf->workspace_size;
resize_convolutional_layer(l->ui, w, h);
if (l->workspace_size < l->ui->workspace_size) l->workspace_size = l->ui->workspace_size;
resize_convolutional_layer(l->ug, w, h);
if (l->workspace_size < l->ug->workspace_size) l->workspace_size = l->ug->workspace_size;
resize_convolutional_layer(l->uo, w, h);
if (l->workspace_size < l->uo->workspace_size) l->workspace_size = l->uo->workspace_size;
l->w = w;
l->h = h;
l->out_h = l->wo->out_h;
l->out_w = l->wo->out_w;
l->outputs = l->wo->outputs;
int outputs = l->outputs;
l->inputs = w*h*l->c;
int steps = l->steps;
int batch = l->batch;
assert(l->wo->outputs == l->uo->outputs);
l->output = (float*)xrealloc(l->output, outputs * batch * steps * sizeof(float));
//l->state = (float*)xrealloc(l->state, outputs * batch * sizeof(float));
l->prev_state_cpu = (float*)xrealloc(l->prev_state_cpu, batch*outputs * sizeof(float));
l->prev_cell_cpu = (float*)xrealloc(l->prev_cell_cpu, batch*outputs * sizeof(float));
l->cell_cpu = (float*)xrealloc(l->cell_cpu, batch*outputs*steps * sizeof(float));
l->f_cpu = (float*)xrealloc(l->f_cpu, batch*outputs * sizeof(float));
l->i_cpu = (float*)xrealloc(l->i_cpu, batch*outputs * sizeof(float));
l->g_cpu = (float*)xrealloc(l->g_cpu, batch*outputs * sizeof(float));
l->o_cpu = (float*)xrealloc(l->o_cpu, batch*outputs * sizeof(float));
l->c_cpu = (float*)xrealloc(l->c_cpu, batch*outputs * sizeof(float));
l->h_cpu = (float*)xrealloc(l->h_cpu, batch*outputs * sizeof(float));
l->temp_cpu = (float*)xrealloc(l->temp_cpu, batch*outputs * sizeof(float));
l->temp2_cpu = (float*)xrealloc(l->temp2_cpu, batch*outputs * sizeof(float));
l->temp3_cpu = (float*)xrealloc(l->temp3_cpu, batch*outputs * sizeof(float));
l->dc_cpu = (float*)xrealloc(l->dc_cpu, batch*outputs * sizeof(float));
l->dh_cpu = (float*)xrealloc(l->dh_cpu, batch*outputs * sizeof(float));
l->stored_c_cpu = (float*)xrealloc(l->stored_c_cpu, batch*outputs * sizeof(float));
l->stored_h_cpu = (float*)xrealloc(l->stored_h_cpu, batch*outputs * sizeof(float));
#ifdef GPU
//if (l->state_gpu) cudaFree(l->state_gpu);
//l->state_gpu = cuda_make_array(l->state, batch*l->outputs);
if (l->output_gpu) cudaFree(l->output_gpu);
l->output_gpu = cuda_make_array(0, batch*outputs*steps);
if (l->delta_gpu) cudaFree(l->delta_gpu);
l->delta_gpu = cuda_make_array(0, batch*outputs*steps);
if (l->prev_state_gpu) cudaFree(l->prev_state_gpu);
l->prev_state_gpu = cuda_make_array(0, batch*outputs);
if (l->prev_cell_gpu) cudaFree(l->prev_cell_gpu);
l->prev_cell_gpu = cuda_make_array(0, batch*outputs);
if (l->cell_gpu) cudaFree(l->cell_gpu);
l->cell_gpu = cuda_make_array(0, batch*outputs*steps);
if (l->f_gpu) cudaFree(l->f_gpu);
l->f_gpu = cuda_make_array(0, batch*outputs);
if (l->i_gpu) cudaFree(l->i_gpu);
l->i_gpu = cuda_make_array(0, batch*outputs);
if (l->g_gpu) cudaFree(l->g_gpu);
l->g_gpu = cuda_make_array(0, batch*outputs);
if (l->o_gpu) cudaFree(l->o_gpu);
l->o_gpu = cuda_make_array(0, batch*outputs);
if (l->c_gpu) cudaFree(l->c_gpu);
l->c_gpu = cuda_make_array(0, batch*outputs);
if (l->h_gpu) cudaFree(l->h_gpu);
l->h_gpu = cuda_make_array(0, batch*outputs);
if (l->temp_gpu) cudaFree(l->temp_gpu);
l->temp_gpu = cuda_make_array(0, batch*outputs);
if (l->temp2_gpu) cudaFree(l->temp2_gpu);
l->temp2_gpu = cuda_make_array(0, batch*outputs);
if (l->temp3_gpu) cudaFree(l->temp3_gpu);
l->temp3_gpu = cuda_make_array(0, batch*outputs);
if (l->dc_gpu) cudaFree(l->dc_gpu);
l->dc_gpu = cuda_make_array(0, batch*outputs);
if (l->dh_gpu) cudaFree(l->dh_gpu);
l->dh_gpu = cuda_make_array(0, batch*outputs);
if (l->stored_c_gpu) cudaFree(l->stored_c_gpu);
l->stored_c_gpu = cuda_make_array(0, batch*outputs);
if (l->stored_h_gpu) cudaFree(l->stored_h_gpu);
l->stored_h_gpu = cuda_make_array(0, batch*outputs);
if (l->last_prev_state_gpu) cudaFree(l->last_prev_state_gpu);
l->last_prev_state_gpu = cuda_make_array(0, batch*outputs);
if (l->last_prev_cell_gpu) cudaFree(l->last_prev_cell_gpu);
l->last_prev_cell_gpu = cuda_make_array(0, batch*outputs);
#endif
}
void free_state_conv_lstm(layer l)
{
int i;
for (i = 0; i < l.outputs * l.batch; ++i) l.h_cpu[i] = 0;
for (i = 0; i < l.outputs * l.batch; ++i) l.c_cpu[i] = 0;
#ifdef GPU
cuda_push_array(l.h_gpu, l.h_cpu, l.outputs * l.batch);
cuda_push_array(l.c_gpu, l.c_cpu, l.outputs * l.batch);
//fill_ongpu(l.outputs * l.batch, 0, l.dc_gpu, 1); // dont use
//fill_ongpu(l.outputs * l.batch, 0, l.dh_gpu, 1); // dont use
#endif // GPU
}
void randomize_state_conv_lstm(layer l)
{
int i;
for (i = 0; i < l.outputs * l.batch; ++i) l.h_cpu[i] = rand_uniform(-1, 1);
for (i = 0; i < l.outputs * l.batch; ++i) l.c_cpu[i] = rand_uniform(-1, 1);
#ifdef GPU
cuda_push_array(l.h_gpu, l.h_cpu, l.outputs * l.batch);
cuda_push_array(l.c_gpu, l.c_cpu, l.outputs * l.batch);
#endif // GPU
}
void remember_state_conv_lstm(layer l)
{
memcpy(l.stored_c_cpu, l.c_cpu, l.outputs * l.batch * sizeof(float));
memcpy(l.stored_h_cpu, l.h_cpu, l.outputs * l.batch * sizeof(float));
#ifdef GPU
copy_ongpu(l.outputs*l.batch, l.c_gpu, 1, l.stored_c_gpu, 1);
copy_ongpu(l.outputs*l.batch, l.h_gpu, 1, l.stored_h_gpu, 1);
#endif // GPU
}
void restore_state_conv_lstm(layer l)
{
memcpy(l.c_cpu, l.stored_c_cpu, l.outputs * l.batch * sizeof(float));
memcpy(l.h_cpu, l.stored_h_cpu, l.outputs * l.batch * sizeof(float));
#ifdef GPU
copy_ongpu(l.outputs*l.batch, l.stored_c_gpu, 1, l.c_gpu, 1);
copy_ongpu(l.outputs*l.batch, l.stored_h_gpu, 1, l.h_gpu, 1);
#endif // GPU
}
void forward_conv_lstm_layer(layer l, network_state state)
{
network_state s = { 0 };
s.train = state.train;
s.workspace = state.workspace;
s.net = state.net;
int i;
layer vf = *(l.vf);
layer vi = *(l.vi);
layer vo = *(l.vo);
layer wf = *(l.wf);
layer wi = *(l.wi);
layer wg = *(l.wg);
layer wo = *(l.wo);
layer uf = *(l.uf);
layer ui = *(l.ui);
layer ug = *(l.ug);
layer uo = *(l.uo);
if (state.train) {
if (l.peephole) {
fill_cpu(l.outputs * l.batch * l.steps, 0, vf.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, vi.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, vo.delta, 1);
}
fill_cpu(l.outputs * l.batch * l.steps, 0, wf.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, wi.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, wg.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, wo.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, uf.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, ui.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, ug.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, uo.delta, 1);
fill_cpu(l.outputs * l.batch * l.steps, 0, l.delta, 1);
}
for (i = 0; i < l.steps; ++i)
{
if (l.peephole) {
assert(l.outputs == vf.out_w * vf.out_h * vf.out_c);
s.input = l.c_cpu;
forward_convolutional_layer(vf, s);
forward_convolutional_layer(vi, s);
// vo below
}
assert(l.outputs == wf.out_w * wf.out_h * wf.out_c);
assert(wf.c == l.out_c && wi.c == l.out_c && wg.c == l.out_c && wo.c == l.out_c);
s.input = l.h_cpu;
forward_convolutional_layer(wf, s);
forward_convolutional_layer(wi, s);
forward_convolutional_layer(wg, s);
forward_convolutional_layer(wo, s);
assert(l.inputs == uf.w * uf.h * uf.c);
assert(uf.c == l.c && ui.c == l.c && ug.c == l.c && uo.c == l.c);
s.input = state.input;
forward_convolutional_layer(uf, s);
forward_convolutional_layer(ui, s);
forward_convolutional_layer(ug, s);
forward_convolutional_layer(uo, s);
// f = wf + uf + vf
copy_cpu(l.outputs*l.batch, wf.output, 1, l.f_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, uf.output, 1, l.f_cpu, 1);
if (l.peephole) axpy_cpu(l.outputs*l.batch, 1, vf.output, 1, l.f_cpu, 1);
// i = wi + ui + vi
copy_cpu(l.outputs*l.batch, wi.output, 1, l.i_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, ui.output, 1, l.i_cpu, 1);
if (l.peephole) axpy_cpu(l.outputs*l.batch, 1, vi.output, 1, l.i_cpu, 1);
// g = wg + ug
copy_cpu(l.outputs*l.batch, wg.output, 1, l.g_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, ug.output, 1, l.g_cpu, 1);
activate_array(l.f_cpu, l.outputs*l.batch, LOGISTIC);
activate_array(l.i_cpu, l.outputs*l.batch, LOGISTIC);
activate_array(l.g_cpu, l.outputs*l.batch, TANH);
// c = f*c + i*g
copy_cpu(l.outputs*l.batch, l.i_cpu, 1, l.temp_cpu, 1);
mul_cpu(l.outputs*l.batch, l.g_cpu, 1, l.temp_cpu, 1);
mul_cpu(l.outputs*l.batch, l.f_cpu, 1, l.c_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, l.temp_cpu, 1, l.c_cpu, 1);
// o = wo + uo + vo(c_new)
if (l.peephole) {
s.input = l.c_cpu;
forward_convolutional_layer(vo, s);
}
copy_cpu(l.outputs*l.batch, wo.output, 1, l.o_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, uo.output, 1, l.o_cpu, 1);
if (l.peephole) axpy_cpu(l.outputs*l.batch, 1, vo.output, 1, l.o_cpu, 1);
activate_array(l.o_cpu, l.outputs*l.batch, LOGISTIC);
// h = o * tanh(c)
copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.h_cpu, 1);
activate_array(l.h_cpu, l.outputs*l.batch, TANH);
mul_cpu(l.outputs*l.batch, l.o_cpu, 1, l.h_cpu, 1);
if (l.state_constrain) constrain_cpu(l.outputs*l.batch, l.state_constrain, l.c_cpu);
fix_nan_and_inf_cpu(l.c_cpu, l.outputs*l.batch);
fix_nan_and_inf_cpu(l.h_cpu, l.outputs*l.batch);
copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.cell_cpu, 1);
copy_cpu(l.outputs*l.batch, l.h_cpu, 1, l.output, 1);
state.input += l.inputs*l.batch;
l.output += l.outputs*l.batch;
l.cell_cpu += l.outputs*l.batch;
if (l.peephole) {
increment_layer(&vf, 1);
increment_layer(&vi, 1);
increment_layer(&vo, 1);
}
increment_layer(&wf, 1);
increment_layer(&wi, 1);
increment_layer(&wg, 1);
increment_layer(&wo, 1);
increment_layer(&uf, 1);
increment_layer(&ui, 1);
increment_layer(&ug, 1);
increment_layer(&uo, 1);
}
}
void backward_conv_lstm_layer(layer l, network_state state)
{
network_state s = { 0 };
s.train = state.train;
s.workspace = state.workspace;
int i;
layer vf = *(l.vf);
layer vi = *(l.vi);
layer vo = *(l.vo);
layer wf = *(l.wf);
layer wi = *(l.wi);
layer wg = *(l.wg);
layer wo = *(l.wo);
layer uf = *(l.uf);
layer ui = *(l.ui);
layer ug = *(l.ug);
layer uo = *(l.uo);
if (l.peephole) {
increment_layer(&vf, l.steps - 1);
increment_layer(&vi, l.steps - 1);
increment_layer(&vo, l.steps - 1);
}
increment_layer(&wf, l.steps - 1);
increment_layer(&wi, l.steps - 1);
increment_layer(&wg, l.steps - 1);
increment_layer(&wo, l.steps - 1);
increment_layer(&uf, l.steps - 1);
increment_layer(&ui, l.steps - 1);
increment_layer(&ug, l.steps - 1);
increment_layer(&uo, l.steps - 1);
state.input += l.inputs*l.batch*(l.steps - 1);
if (state.delta) state.delta += l.inputs*l.batch*(l.steps - 1);
l.output += l.outputs*l.batch*(l.steps - 1);
l.cell_cpu += l.outputs*l.batch*(l.steps - 1);
l.delta += l.outputs*l.batch*(l.steps - 1);
for (i = l.steps - 1; i >= 0; --i) {
if (i != 0) copy_cpu(l.outputs*l.batch, l.cell_cpu - l.outputs*l.batch, 1, l.prev_cell_cpu, 1);
copy_cpu(l.outputs*l.batch, l.cell_cpu, 1, l.c_cpu, 1);
if (i != 0) copy_cpu(l.outputs*l.batch, l.output - l.outputs*l.batch, 1, l.prev_state_cpu, 1);
copy_cpu(l.outputs*l.batch, l.output, 1, l.h_cpu, 1);
l.dh_cpu = (i == 0) ? 0 : l.delta - l.outputs*l.batch;
// f = wf + uf + vf
copy_cpu(l.outputs*l.batch, wf.output, 1, l.f_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, uf.output, 1, l.f_cpu, 1);
if (l.peephole) axpy_cpu(l.outputs*l.batch, 1, vf.output, 1, l.f_cpu, 1);
// i = wi + ui + vi
copy_cpu(l.outputs*l.batch, wi.output, 1, l.i_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, ui.output, 1, l.i_cpu, 1);
if (l.peephole) axpy_cpu(l.outputs*l.batch, 1, vi.output, 1, l.i_cpu, 1);
// g = wg + ug
copy_cpu(l.outputs*l.batch, wg.output, 1, l.g_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, ug.output, 1, l.g_cpu, 1);
// o = wo + uo + vo
copy_cpu(l.outputs*l.batch, wo.output, 1, l.o_cpu, 1);
axpy_cpu(l.outputs*l.batch, 1, uo.output, 1, l.o_cpu, 1);
if (l.peephole) axpy_cpu(l.outputs*l.batch, 1, vo.output, 1, l.o_cpu, 1);
activate_array(l.f_cpu, l.outputs*l.batch, LOGISTIC);
activate_array(l.i_cpu, l.outputs*l.batch, LOGISTIC);
activate_array(l.g_cpu, l.outputs*l.batch, TANH);
activate_array(l.o_cpu, l.outputs*l.batch, LOGISTIC);
copy_cpu(l.outputs*l.batch, l.delta, 1, l.temp3_cpu, 1);
copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.temp_cpu, 1);
activate_array(l.temp_cpu, l.outputs*l.batch, TANH);
copy_cpu(l.outputs*l.batch, l.temp3_cpu, 1, l.temp2_cpu, 1);
mul_cpu(l.outputs*l.batch, l.o_cpu, 1, l.temp2_cpu, 1);
gradient_array(l.temp_cpu, l.outputs*l.batch, TANH, l.temp2_cpu);
axpy_cpu(l.outputs*l.batch, 1, l.dc_cpu, 1, l.temp2_cpu, 1);
// temp = tanh(c)
// temp2 = delta * o * grad_tanh(tanh(c))
// temp3 = delta
copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.temp_cpu, 1);
activate_array(l.temp_cpu, l.outputs*l.batch, TANH);
mul_cpu(l.outputs*l.batch, l.temp3_cpu, 1, l.temp_cpu, 1);
gradient_array(l.o_cpu, l.outputs*l.batch, LOGISTIC, l.temp_cpu);
// delta for o(w,u,v): temp = delta * tanh(c) * grad_logistic(o)
// delta for c,f,i,g(w,u,v): temp2 = delta * o * grad_tanh(tanh(c)) + delta_c(???)
// delta for output: temp3 = delta
// o
// delta for O(w,u,v): temp = delta * tanh(c) * grad_logistic(o)
if (l.peephole) {
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, vo.delta, 1);
s.input = l.cell_cpu;
//s.delta = l.dc_cpu;
backward_convolutional_layer(vo, s);
}
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wo.delta, 1);
s.input = l.prev_state_cpu;
//s.delta = l.dh_cpu;
backward_convolutional_layer(wo, s);
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, uo.delta, 1);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer(uo, s);
// g
copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1);
mul_cpu(l.outputs*l.batch, l.i_cpu, 1, l.temp_cpu, 1);
gradient_array(l.g_cpu, l.outputs*l.batch, TANH, l.temp_cpu);
// delta for c,f,i,g(w,u,v): temp2 = (delta * o * grad_tanh(tanh(c)) + delta_c(???)) * g * grad_logistic(i)
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wg.delta, 1);
s.input = l.prev_state_cpu;
//s.delta = l.dh_cpu;
backward_convolutional_layer(wg, s);
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, ug.delta, 1);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer(ug, s);
// i
copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1);
mul_cpu(l.outputs*l.batch, l.g_cpu, 1, l.temp_cpu, 1);
gradient_array(l.i_cpu, l.outputs*l.batch, LOGISTIC, l.temp_cpu);
// delta for c,f,i,g(w,u,v): temp2 = (delta * o * grad_tanh(tanh(c)) + delta_c(???)) * g * grad_logistic(i)
if (l.peephole) {
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, vi.delta, 1);
s.input = l.prev_cell_cpu;
//s.delta = l.dc_cpu;
backward_convolutional_layer(vi, s);
}
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wi.delta, 1);
s.input = l.prev_state_cpu;
//s.delta = l.dh_cpu;
backward_convolutional_layer(wi, s);
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, ui.delta, 1);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer(ui, s);
// f
copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1);
mul_cpu(l.outputs*l.batch, l.prev_cell_cpu, 1, l.temp_cpu, 1);
gradient_array(l.f_cpu, l.outputs*l.batch, LOGISTIC, l.temp_cpu);
// delta for c,f,i,g(w,u,v): temp2 = (delta * o * grad_tanh(tanh(c)) + delta_c(???)) * c * grad_logistic(f)
if (l.peephole) {
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, vf.delta, 1);
s.input = l.prev_cell_cpu;
//s.delta = l.dc_cpu;
backward_convolutional_layer(vf, s);
}
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wf.delta, 1);
s.input = l.prev_state_cpu;
//s.delta = l.dh_cpu;
backward_convolutional_layer(wf, s);
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, uf.delta, 1);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer(uf, s);
copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1);
mul_cpu(l.outputs*l.batch, l.f_cpu, 1, l.temp_cpu, 1);
copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, l.dc_cpu, 1);
state.input -= l.inputs*l.batch;
if (state.delta) state.delta -= l.inputs*l.batch;
l.output -= l.outputs*l.batch;
l.cell_cpu -= l.outputs*l.batch;
l.delta -= l.outputs*l.batch;
if (l.peephole) {
increment_layer(&vf, -1);
increment_layer(&vi, -1);
increment_layer(&vo, -1);
}
increment_layer(&wf, -1);
increment_layer(&wi, -1);
increment_layer(&wg, -1);
increment_layer(&wo, -1);
increment_layer(&uf, -1);
increment_layer(&ui, -1);
increment_layer(&ug, -1);
increment_layer(&uo, -1);
}
}
#ifdef GPU
void pull_conv_lstm_layer(layer l)
{
if (l.peephole) {
pull_convolutional_layer(*(l.vf));
pull_convolutional_layer(*(l.vi));
pull_convolutional_layer(*(l.vo));
}
pull_convolutional_layer(*(l.wf));
pull_convolutional_layer(*(l.wi));
pull_convolutional_layer(*(l.wg));
pull_convolutional_layer(*(l.wo));
pull_convolutional_layer(*(l.uf));
pull_convolutional_layer(*(l.ui));
pull_convolutional_layer(*(l.ug));
pull_convolutional_layer(*(l.uo));
}
void push_conv_lstm_layer(layer l)
{
if (l.peephole) {
push_convolutional_layer(*(l.vf));
push_convolutional_layer(*(l.vi));
push_convolutional_layer(*(l.vo));
}
push_convolutional_layer(*(l.wf));
push_convolutional_layer(*(l.wi));
push_convolutional_layer(*(l.wg));
push_convolutional_layer(*(l.wo));
push_convolutional_layer(*(l.uf));
push_convolutional_layer(*(l.ui));
push_convolutional_layer(*(l.ug));
push_convolutional_layer(*(l.uo));
}
void update_conv_lstm_layer_gpu(layer l, int batch, float learning_rate, float momentum, float decay, float loss_scale)
{
if (l.peephole) {
update_convolutional_layer_gpu(*(l.vf), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.vi), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.vo), batch, learning_rate, momentum, decay, loss_scale);
}
update_convolutional_layer_gpu(*(l.wf), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.wi), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.wg), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.wo), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.uf), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.ui), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.ug), batch, learning_rate, momentum, decay, loss_scale);
update_convolutional_layer_gpu(*(l.uo), batch, learning_rate, momentum, decay, loss_scale);
}
void forward_conv_lstm_layer_gpu(layer l, network_state state)
{
network_state s = { 0 };
s.train = state.train;
s.workspace = state.workspace;
s.net = state.net;
if (!state.train) s.index = state.index; // don't use TC for training (especially without cuda_convert_f32_to_f16() )
int i;
layer vf = *(l.vf);
layer vi = *(l.vi);
layer vo = *(l.vo);
layer wf = *(l.wf);
layer wi = *(l.wi);
layer wg = *(l.wg);
layer wo = *(l.wo);
layer uf = *(l.uf);
layer ui = *(l.ui);
layer ug = *(l.ug);
layer uo = *(l.uo);
if (state.train) {
if (l.peephole) {
fill_ongpu(l.outputs * l.batch * l.steps, 0, vf.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, vi.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, vo.delta_gpu, 1);
}
fill_ongpu(l.outputs * l.batch * l.steps, 0, wf.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, wi.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, wg.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, wo.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, uf.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, ui.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, ug.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, uo.delta_gpu, 1);
fill_ongpu(l.outputs * l.batch * l.steps, 0, l.delta_gpu, 1);
}
for (i = 0; i < l.steps; ++i)
{
if (l.peephole) {
assert(l.outputs == vf.out_w * vf.out_h * vf.out_c);
s.input = l.c_gpu;
forward_convolutional_layer_gpu(vf, s);
forward_convolutional_layer_gpu(vi, s);
// vo below
}
assert(l.outputs == wf.out_w * wf.out_h * wf.out_c);
assert(wf.c == l.out_c && wi.c == l.out_c && wg.c == l.out_c && wo.c == l.out_c);
s.input = l.h_gpu;
forward_convolutional_layer_gpu(wf, s);
forward_convolutional_layer_gpu(wi, s);
forward_convolutional_layer_gpu(wg, s);
forward_convolutional_layer_gpu(wo, s);
assert(l.inputs == uf.w * uf.h * uf.c);
assert(uf.c == l.c && ui.c == l.c && ug.c == l.c && uo.c == l.c);
s.input = state.input;
forward_convolutional_layer_gpu(uf, s);
forward_convolutional_layer_gpu(ui, s);
forward_convolutional_layer_gpu(ug, s);
forward_convolutional_layer_gpu(uo, s);
// f = wf + uf + vf
add_3_arrays_activate(wf.output_gpu, uf.output_gpu, (l.peephole)?vf.output_gpu:NULL, l.outputs*l.batch, LOGISTIC, l.f_gpu);
//copy_ongpu(l.outputs*l.batch, wf.output_gpu, 1, l.f_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, uf.output_gpu, 1, l.f_gpu, 1);
//if (l.peephole) axpy_ongpu(l.outputs*l.batch, 1, vf.output_gpu, 1, l.f_gpu, 1);
//activate_array_ongpu(l.f_gpu, l.outputs*l.batch, LOGISTIC);
// i = wi + ui + vi
add_3_arrays_activate(wi.output_gpu, ui.output_gpu, (l.peephole) ? vi.output_gpu : NULL, l.outputs*l.batch, LOGISTIC, l.i_gpu);
//copy_ongpu(l.outputs*l.batch, wi.output_gpu, 1, l.i_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, ui.output_gpu, 1, l.i_gpu, 1);
//if (l.peephole) axpy_ongpu(l.outputs*l.batch, 1, vi.output_gpu, 1, l.i_gpu, 1);
//activate_array_ongpu(l.i_gpu, l.outputs*l.batch, LOGISTIC);
// g = wg + ug
add_3_arrays_activate(wg.output_gpu, ug.output_gpu, NULL, l.outputs*l.batch, TANH, l.g_gpu);
//copy_ongpu(l.outputs*l.batch, wg.output_gpu, 1, l.g_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, ug.output_gpu, 1, l.g_gpu, 1);
//activate_array_ongpu(l.g_gpu, l.outputs*l.batch, TANH);
// c = f*c + i*g
sum_of_mults(l.f_gpu, l.c_gpu, l.i_gpu, l.g_gpu, l.outputs*l.batch, l.c_gpu); // decreases mAP???
//copy_ongpu(l.outputs*l.batch, l.i_gpu, 1, l.temp_gpu, 1);
//mul_ongpu(l.outputs*l.batch, l.g_gpu, 1, l.temp_gpu, 1);
//mul_ongpu(l.outputs*l.batch, l.f_gpu, 1, l.c_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, l.temp_gpu, 1, l.c_gpu, 1);
// o = wo + uo + vo(c_new)
if (l.peephole) {
s.input = l.c_gpu;
forward_convolutional_layer_gpu(vo, s);
}
add_3_arrays_activate(wo.output_gpu, uo.output_gpu, (l.peephole) ? vo.output_gpu : NULL, l.outputs*l.batch, LOGISTIC, l.o_gpu);
//copy_ongpu(l.outputs*l.batch, wo.output_gpu, 1, l.o_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, uo.output_gpu, 1, l.o_gpu, 1);
//if (l.peephole) axpy_ongpu(l.outputs*l.batch, 1, vo.output_gpu, 1, l.o_gpu, 1);
//activate_array_ongpu(l.o_gpu, l.outputs*l.batch, LOGISTIC);
// h = o * tanh(c)
activate_and_mult(l.c_gpu, l.o_gpu, l.outputs*l.batch, TANH, l.h_gpu);
//simple_copy_ongpu(l.outputs*l.batch, l.c_gpu, l.h_gpu);
//activate_array_ongpu(l.h_gpu, l.outputs*l.batch, TANH);
//mul_ongpu(l.outputs*l.batch, l.o_gpu, 1, l.h_gpu, 1);
fix_nan_and_inf(l.c_gpu, l.outputs*l.batch);
fix_nan_and_inf(l.h_gpu, l.outputs*l.batch);
if (l.state_constrain) constrain_ongpu(l.outputs*l.batch, l.state_constrain, l.c_gpu, 1);
if(state.train) simple_copy_ongpu(l.outputs*l.batch, l.c_gpu, l.cell_gpu);
simple_copy_ongpu(l.outputs*l.batch, l.h_gpu, l.output_gpu); // is required for both Detection and Training
state.input += l.inputs*l.batch;
l.output_gpu += l.outputs*l.batch;
l.cell_gpu += l.outputs*l.batch;
if (l.peephole) {
increment_layer(&vf, 1);
increment_layer(&vi, 1);
increment_layer(&vo, 1);
}
increment_layer(&wf, 1);
increment_layer(&wi, 1);
increment_layer(&wg, 1);
increment_layer(&wo, 1);
increment_layer(&uf, 1);
increment_layer(&ui, 1);
increment_layer(&ug, 1);
increment_layer(&uo, 1);
}
}
void backward_conv_lstm_layer_gpu(layer l, network_state state)
{
float *last_output = l.output_gpu + l.outputs*l.batch*(l.steps - 1);
float *last_cell = l.cell_gpu + l.outputs*l.batch*(l.steps - 1);
network_state s = { 0 };
s.train = state.train;
s.workspace = state.workspace;
s.net = state.net;
int i;
layer vf = *(l.vf);
layer vi = *(l.vi);
layer vo = *(l.vo);
layer wf = *(l.wf);
layer wi = *(l.wi);
layer wg = *(l.wg);
layer wo = *(l.wo);
layer uf = *(l.uf);
layer ui = *(l.ui);
layer ug = *(l.ug);
layer uo = *(l.uo);
if (l.peephole) {
increment_layer(&vf, l.steps - 1);
increment_layer(&vi, l.steps - 1);
increment_layer(&vo, l.steps - 1);
}
increment_layer(&wf, l.steps - 1);
increment_layer(&wi, l.steps - 1);
increment_layer(&wg, l.steps - 1);
increment_layer(&wo, l.steps - 1);
increment_layer(&uf, l.steps - 1);
increment_layer(&ui, l.steps - 1);
increment_layer(&ug, l.steps - 1);
increment_layer(&uo, l.steps - 1);
state.input += l.inputs*l.batch*(l.steps - 1);
if (state.delta) state.delta += l.inputs*l.batch*(l.steps - 1);
l.output_gpu += l.outputs*l.batch*(l.steps - 1);
l.cell_gpu += l.outputs*l.batch*(l.steps - 1);
l.delta_gpu += l.outputs*l.batch*(l.steps - 1);
//fill_ongpu(l.outputs * l.batch, 0, l.dc_gpu, 1); // dont use
const int sequence = get_sequence_value(state.net);
for (i = l.steps - 1; i >= 0; --i) {
if (i != 0) simple_copy_ongpu(l.outputs*l.batch, l.cell_gpu - l.outputs*l.batch, l.prev_cell_gpu);
//else fill_ongpu(l.outputs * l.batch, 0, l.prev_cell_gpu, 1); // dont use
else if (state.net.current_subdivision % sequence != 0) simple_copy_ongpu(l.outputs*l.batch, l.last_prev_cell_gpu, l.prev_cell_gpu);
simple_copy_ongpu(l.outputs*l.batch, l.cell_gpu, l.c_gpu);
if (i != 0) simple_copy_ongpu(l.outputs*l.batch, l.output_gpu - l.outputs*l.batch, l.prev_state_gpu);
//else fill_ongpu(l.outputs * l.batch, 0, l.prev_state_gpu, 1); // dont use
else if(state.net.current_subdivision % sequence != 0) simple_copy_ongpu(l.outputs*l.batch, l.last_prev_state_gpu, l.prev_state_gpu);
simple_copy_ongpu(l.outputs*l.batch, l.output_gpu, l.h_gpu);
l.dh_gpu = (i == 0) ? 0 : l.delta_gpu - l.outputs*l.batch;
// f = wf + uf + vf
add_3_arrays_activate(wf.output_gpu, uf.output_gpu, (l.peephole) ? vf.output_gpu : NULL, l.outputs*l.batch, LOGISTIC, l.f_gpu);
//copy_ongpu(l.outputs*l.batch, wf.output_gpu, 1, l.f_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, uf.output_gpu, 1, l.f_gpu, 1);
//if (l.peephole) axpy_ongpu(l.outputs*l.batch, 1, vf.output_gpu, 1, l.f_gpu, 1);
//activate_array_ongpu(l.f_gpu, l.outputs*l.batch, LOGISTIC);
// i = wi + ui + vi
add_3_arrays_activate(wi.output_gpu, ui.output_gpu, (l.peephole) ? vi.output_gpu : NULL, l.outputs*l.batch, LOGISTIC, l.i_gpu);
//copy_ongpu(l.outputs*l.batch, wi.output_gpu, 1, l.i_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, ui.output_gpu, 1, l.i_gpu, 1);
//if (l.peephole) axpy_ongpu(l.outputs*l.batch, 1, vi.output_gpu, 1, l.i_gpu, 1);
//activate_array_ongpu(l.i_gpu, l.outputs*l.batch, LOGISTIC);
// g = wg + ug
add_3_arrays_activate(wg.output_gpu, ug.output_gpu, NULL, l.outputs*l.batch, TANH, l.g_gpu);
//copy_ongpu(l.outputs*l.batch, wg.output_gpu, 1, l.g_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, ug.output_gpu, 1, l.g_gpu, 1);
//activate_array_ongpu(l.g_gpu, l.outputs*l.batch, TANH);
// o = wo + uo + vo
add_3_arrays_activate(wo.output_gpu, uo.output_gpu, (l.peephole) ? vo.output_gpu : NULL, l.outputs*l.batch, LOGISTIC, l.o_gpu);
//copy_ongpu(l.outputs*l.batch, wo.output_gpu, 1, l.o_gpu, 1);
//axpy_ongpu(l.outputs*l.batch, 1, uo.output_gpu, 1, l.o_gpu, 1);
//if (l.peephole) axpy_ongpu(l.outputs*l.batch, 1, vo.output_gpu, 1, l.o_gpu, 1);
//activate_array_ongpu(l.o_gpu, l.outputs*l.batch, LOGISTIC);
simple_copy_ongpu(l.outputs*l.batch, l.delta_gpu, l.temp3_gpu); // temp3 = delta
simple_copy_ongpu(l.outputs*l.batch, l.c_gpu, l.temp_gpu);
activate_array_ongpu(l.temp_gpu, l.outputs*l.batch, TANH); // temp = tanh(c)
simple_copy_ongpu(l.outputs*l.batch, l.temp3_gpu, l.temp2_gpu);
mul_ongpu(l.outputs*l.batch, l.o_gpu, 1, l.temp2_gpu, 1); // temp2 = delta * o
gradient_array_ongpu(l.temp_gpu, l.outputs*l.batch, TANH, l.temp2_gpu); // temp2 = delta * o * grad_tanh(tanh(c))
//???
axpy_ongpu(l.outputs*l.batch, 1, l.dc_gpu, 1, l.temp2_gpu, 1); // temp2 = delta * o * grad_tanh(tanh(c)) + delta_c(???)
// temp = tanh(c)
// temp2 = delta * o * grad_tanh(tanh(c)) + delta_c(???)
// temp3 = delta
simple_copy_ongpu(l.outputs*l.batch, l.c_gpu, l.temp_gpu);
activate_array_ongpu(l.temp_gpu, l.outputs*l.batch, TANH); // temp = tanh(c)
mul_ongpu(l.outputs*l.batch, l.temp3_gpu, 1, l.temp_gpu, 1); // temp = delta * tanh(c)
gradient_array_ongpu(l.o_gpu, l.outputs*l.batch, LOGISTIC, l.temp_gpu); // temp = delta * tanh(c) * grad_logistic(o)
// delta for o(w,u,v): temp = delta * tanh(c) * grad_logistic(o)
// delta for c,f,i,g(w,u,v): temp2 = delta * o * grad_tanh(tanh(c)) + delta_c(???)
// delta for output: temp3 = delta
// o
// delta for O(w,u,v): temp = delta * tanh(c) * grad_logistic(o)
if (l.peephole) {
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, vo.delta_gpu);
s.input = l.cell_gpu;
//s.delta = l.dc_gpu;
backward_convolutional_layer_gpu(vo, s);
}
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, wo.delta_gpu);
s.input = l.prev_state_gpu;
//s.delta = l.dh_gpu;
backward_convolutional_layer_gpu(wo, s);
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, uo.delta_gpu);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer_gpu(uo, s);
// g
simple_copy_ongpu(l.outputs*l.batch, l.temp2_gpu, l.temp_gpu);
mul_ongpu(l.outputs*l.batch, l.i_gpu, 1, l.temp_gpu, 1);
gradient_array_ongpu(l.g_gpu, l.outputs*l.batch, TANH, l.temp_gpu);
// delta for c,f,i,g(w,u,v): temp = (delta * o * grad_tanh(tanh(c)) + delta_c(???)) * i * grad_tanh(g)
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, wg.delta_gpu);
s.input = l.prev_state_gpu;
//s.delta = l.dh_gpu;
backward_convolutional_layer_gpu(wg, s);
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, ug.delta_gpu);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer_gpu(ug, s);
// i
simple_copy_ongpu(l.outputs*l.batch, l.temp2_gpu, l.temp_gpu);
mul_ongpu(l.outputs*l.batch, l.g_gpu, 1, l.temp_gpu, 1);
gradient_array_ongpu(l.i_gpu, l.outputs*l.batch, LOGISTIC, l.temp_gpu);
// delta for c,f,i,g(w,u,v): temp = (delta * o * grad_tanh(tanh(c)) + delta_c(???)) * g * grad_logistic(i)
if (l.peephole) {
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, vi.delta_gpu);
s.input = l.prev_cell_gpu;
//s.delta = l.dc_gpu;
backward_convolutional_layer_gpu(vi, s);
}
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, wi.delta_gpu);
s.input = l.prev_state_gpu;
//s.delta = l.dh_gpu;
backward_convolutional_layer_gpu(wi, s);
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, ui.delta_gpu);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer_gpu(ui, s);
// f
simple_copy_ongpu(l.outputs*l.batch, l.temp2_gpu, l.temp_gpu);
mul_ongpu(l.outputs*l.batch, l.prev_cell_gpu, 1, l.temp_gpu, 1);
gradient_array_ongpu(l.f_gpu, l.outputs*l.batch, LOGISTIC, l.temp_gpu);
// delta for c,f,i,g(w,u,v): temp = (delta * o * grad_tanh(tanh(c)) + delta_c(???)) * c * grad_logistic(f)
if (l.peephole) {
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, vf.delta_gpu);
s.input = l.prev_cell_gpu;
//s.delta = l.dc_gpu;
backward_convolutional_layer_gpu(vf, s);
}
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, wf.delta_gpu);
s.input = l.prev_state_gpu;
//s.delta = l.dh_gpu;
backward_convolutional_layer_gpu(wf, s);
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, uf.delta_gpu);
s.input = state.input;
s.delta = state.delta;
backward_convolutional_layer_gpu(uf, s);
// c
simple_copy_ongpu(l.outputs*l.batch, l.temp2_gpu, l.temp_gpu);
mul_ongpu(l.outputs*l.batch, l.f_gpu, 1, l.temp_gpu, 1);
simple_copy_ongpu(l.outputs*l.batch, l.temp_gpu, l.dc_gpu);
fix_nan_and_inf(l.dc_gpu, l.outputs*l.batch);
// delta for c,f,i,g(w,u,v): delta_c = temp = (delta * o * grad_tanh(tanh(c)) + delta_c(???)) * f // (grad_linear(c)==1)
state.input -= l.inputs*l.batch;
if (state.delta) state.delta -= l.inputs*l.batch; // new delta: state.delta = prev_layer.delta_gpu;
l.output_gpu -= l.outputs*l.batch;
l.cell_gpu -= l.outputs*l.batch;
l.delta_gpu -= l.outputs*l.batch;
if (l.peephole) {
increment_layer(&vf, -1);
increment_layer(&vi, -1);
increment_layer(&vo, -1);
}
increment_layer(&wf, -1);
increment_layer(&wi, -1);
increment_layer(&wg, -1);
increment_layer(&wo, -1);
increment_layer(&uf, -1);
increment_layer(&ui, -1);
increment_layer(&ug, -1);
increment_layer(&uo, -1);
}
simple_copy_ongpu(l.outputs*l.batch, last_output, l.last_prev_state_gpu);
simple_copy_ongpu(l.outputs*l.batch, last_cell, l.last_prev_cell_gpu);
// free state after each 100 iterations
//if (get_current_batch(state.net) % 100) free_state_conv_lstm(l); // dont use
}
#endif
| [
"roybiparnak@gmail.com"
] | roybiparnak@gmail.com |
6d85be3ffeef74233af1585118f2ca76755d57d9 | 0b4883c9a1d4da6daf9874887d4ed81d010c97b7 | /pmanager/pmanager.c | 20168269d32e8c031fc9785eb0ecde9dc01dbbc9 | [
"MIT"
] | permissive | tomxmm0/pmanager | eaab8781668bc26f89f8a40c47355499b57e8f28 | 8eb181e4f2969e53f3c0d4472e4f97ad7ec0a809 | refs/heads/master | 2022-11-05T14:21:28.069924 | 2020-06-25T15:42:14 | 2020-06-25T15:42:14 | 274,948,944 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 4,224 | c | #include "stdinc.h"
#include "pmanager_helper.h"
#include "pmanager.h"
struct pmanager
{
symmetric_key skey;
sqlite3* db;
unsigned char password_hash[32];
};
int pmanager_list_callback(struct pmanager* pm, const int argc, const char** argv, const char** column)
{
if (!pmanager_rijndael_setup(&pm->skey, pm->password_hash, sizeof(pm->password_hash)))
{
return SQLITE_ABORT;
}
for (int i = 0; i < argc; i++)
{
if (!strcmp(column[i], "name"))
{
printf("%s: ", argv[i]);
}
else
{
const unsigned char* encrypted_password = (const unsigned char*)argv[i];
const unsigned char decrypted_password[32] = { 0 };
if (!pmanager_decrypt(&pm->skey, encrypted_password, decrypted_password) || !pmanager_decrypt(&pm->skey, &encrypted_password[16], &decrypted_password[16]))
{
return SQLITE_ABORT;
}
printf("%s\n", (const char*)decrypted_password);
}
}
pmanager_rijndael_done(&pm->skey);
return SQLITE_OK;
}
bool pmanager_new(const char* name, const char* password)
{
struct pmanager pm = { 0 };
if (!pmanager_hash(password, strlen(password), pm.password_hash))
{
return false;
}
unsigned char generated_password[32] = { 0 };
pmanager_generate_password((char*)generated_password, sizeof(generated_password));
unsigned char encrypted_password[sizeof(generated_password)] = { 0 };
if (!pmanager_rijndael_setup(&pm.skey, pm.password_hash, sizeof(pm.password_hash)))
{
return false;
}
if (!pmanager_encrypt(&pm.skey, generated_password, encrypted_password) || !pmanager_encrypt(&pm.skey, &generated_password[16], &encrypted_password[16]))
{
pmanager_rijndael_done(&pm.skey);
return false;
}
pmanager_rijndael_done(&pm.skey);
if (!pmanager_connect_db(&pm.db))
{
return false;
}
sqlite3_stmt* stmt = NULL;
if (sqlite3_prepare_v2(pm.db, "INSERT INTO passwords (name, encrypted_password) VALUES (?, ?)", -1, &stmt, NULL) != SQLITE_OK)
{
printf("sqlite3_prepare_v2 failed: %s\n", sqlite3_errmsg(pm.db));
goto db_error;
}
if (sqlite3_bind_text(stmt, 1, name, -1, NULL) != SQLITE_OK)
{
printf("sqlite3_bind_text failed: %s\n", sqlite3_errmsg(pm.db));
goto db_error;
}
if (sqlite3_bind_blob(stmt, 2, encrypted_password, sizeof(encrypted_password), NULL) != SQLITE_OK)
{
printf("sqlite3_bind_blob failed: %s\n", sqlite3_errmsg(pm.db));
goto db_error;
}
if (sqlite3_step(stmt) != SQLITE_DONE)
{
printf("sqlite3_step failed: %s\n", sqlite3_errmsg(pm.db));
goto db_error;
}
printf("Generated passowrd for \"%s\": %s\n", name, generated_password);
pmanager_close_db(pm.db);
return true;
db_error:
if (pm.db)
{
pmanager_close_db(pm.db);
}
return false;
}
bool pmanager_list(const char* password)
{
struct pmanager pm = { 0 };
if (!pmanager_hash(password, strlen(password), pm.password_hash))
{
return false;
}
if (!pmanager_connect_db(&pm.db))
{
return false;
}
char* err = NULL;
sqlite3_exec(pm.db, "SELECT name, encrypted_password FROM passwords", &pmanager_list_callback, &pm, &err);
if (err)
{
printf("sqlite3_exec failed: %s\n", err);
sqlite3_free(err);
pmanager_close_db(pm.db);
return false;
}
pmanager_close_db(pm.db);
return true;
}
bool pmanager_delete(const char* name)
{
sqlite3* db = NULL;
if (!pmanager_connect_db(&db))
{
return false;
}
sqlite3_stmt* stmt = NULL;
if (sqlite3_prepare_v2(db, "DELETE FROM passwords WHERE name = ?", -1, &stmt, 0) != SQLITE_OK)
{
printf("sqlite3_prepare_v2 failed: %s\n", sqlite3_errmsg(db));
goto db_error;
}
if (sqlite3_bind_text(stmt, 1, name, -1, NULL) != SQLITE_OK)
{
printf("sqlite3_bind_text failed: %s\n", sqlite3_errmsg(db));
goto db_error;
}
if (sqlite3_step(stmt) != SQLITE_DONE)
{
printf("sqlite3_step failed: %s\n", sqlite3_errmsg(db));
goto db_error;
}
pmanager_close_db(db);
return true;
db_error:
pmanager_close_db(db);
return false;
}
bool pmanager_delete_all()
{
sqlite3* db;
if (!pmanager_connect_db(&db))
{
return false;
}
char* err = NULL;
sqlite3_exec(db, "DELETE FROM passwords", NULL, NULL, &err);
if (err)
{
printf("sqlite3_exec failed: %s\n", err);
sqlite3_free(err);
pmanager_close_db(&db);
return false;
}
pmanager_close_db(db);
return true;
}
| [
"tomking1902@gmail.com"
] | tomking1902@gmail.com |
7f72f0a1a902276d8c4e3af4426b4b5455c3c000 | 6cb0442545ca25b996539b919671b59a4d16e61f | /MenuSampler/Pods/Headers/Private/MenuKit/BRMenuModelPropertyEditor.h | b3ab5fe8e7b260f7d1596993343f57758ce4eeb4 | [
"Apache-2.0"
] | permissive | Blue-Rocket/BRMenu | 1262744859367404a0e99380e14ba27dd056d45c | 879159a0ede45627e87c5d24435afc0791f9ebf8 | refs/heads/master | 2021-01-22T05:05:25.871183 | 2016-03-02T18:29:37 | 2016-03-02T18:29:37 | 39,219,896 | 0 | 1 | null | null | null | null | UTF-8 | C | false | false | 57 | h | ../../../../../Menu/Code/Core/BRMenuModelPropertyEditor.h | [
"git+matt@msqr.us"
] | git+matt@msqr.us |
bc9d59c41993744c057056105d319f7245b3f48a | b52fcc295c73b353d9976b1d657de337a6f7e620 | /samd21/samples/quick_start/src/ASF/sam0/utils/cmsis/samd21/include/samd21e18a.h | 623605e1a8f9292aa7a10eacc55c5b754bb7a81a | [] | no_license | mksong-atmel/parse-embedded-sdks | 148ece8f01e0734fd7d20c4ec897f1c4860948a3 | 7bf8140f2de40513506c58f2dafc30cddb93304d | refs/heads/master | 2021-01-18T08:22:29.238490 | 2015-09-04T02:06:07 | 2015-09-04T02:06:07 | 41,890,531 | 2 | 3 | null | 2015-09-04T00:32:24 | 2015-09-04T00:32:24 | null | UTF-8 | C | false | false | 29,547 | h | /**
* \file
*
* \brief Header file for SAMD21E18A
*
* Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* \page License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/
#ifndef _SAMD21E18A_
#define _SAMD21E18A_
/**
* \ingroup SAMD21_definitions
* \addtogroup SAMD21E18A_definitions SAMD21E18A definitions
* This file defines all structures and symbols for SAMD21E18A:
* - registers and bitfields
* - peripheral base address
* - peripheral ID
* - PIO definitions
*/
/*@{*/
#ifdef __cplusplus
extern "C" {
#endif
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
#include <stdint.h>
#ifndef __cplusplus
typedef volatile const uint32_t RoReg; /**< Read only 32-bit register (volatile const unsigned int) */
typedef volatile const uint16_t RoReg16; /**< Read only 16-bit register (volatile const unsigned int) */
typedef volatile const uint8_t RoReg8; /**< Read only 8-bit register (volatile const unsigned int) */
#else
typedef volatile uint32_t RoReg; /**< Read only 32-bit register (volatile const unsigned int) */
typedef volatile uint16_t RoReg16; /**< Read only 16-bit register (volatile const unsigned int) */
typedef volatile uint8_t RoReg8; /**< Read only 8-bit register (volatile const unsigned int) */
#endif
typedef volatile uint32_t WoReg; /**< Write only 32-bit register (volatile unsigned int) */
typedef volatile uint16_t WoReg16; /**< Write only 16-bit register (volatile unsigned int) */
typedef volatile uint32_t WoReg8; /**< Write only 8-bit register (volatile unsigned int) */
typedef volatile uint32_t RwReg; /**< Read-Write 32-bit register (volatile unsigned int) */
typedef volatile uint16_t RwReg16; /**< Read-Write 16-bit register (volatile unsigned int) */
typedef volatile uint8_t RwReg8; /**< Read-Write 8-bit register (volatile unsigned int) */
#define CAST(type, value) ((type *)(value))
#define REG_ACCESS(type, address) (*(type*)(address)) /**< C code: Register value */
#else
#define CAST(type, value) (value)
#define REG_ACCESS(type, address) (address) /**< Assembly code: Register address */
#endif
/* ************************************************************************** */
/** CMSIS DEFINITIONS FOR SAMD21E18A */
/* ************************************************************************** */
/** \defgroup SAMD21E18A_cmsis CMSIS Definitions */
/*@{*/
/** Interrupt Number Definition */
typedef enum IRQn
{
/****** Cortex-M0+ Processor Exceptions Numbers ******************************/
NonMaskableInt_IRQn = -14,/**< 2 Non Maskable Interrupt */
HardFault_IRQn = -13,/**< 3 Cortex-M0+ Hard Fault Interrupt */
SVCall_IRQn = -5, /**< 11 Cortex-M0+ SV Call Interrupt */
PendSV_IRQn = -2, /**< 14 Cortex-M0+ Pend SV Interrupt */
SysTick_IRQn = -1, /**< 15 Cortex-M0+ System Tick Interrupt */
/****** SAMD21E18A-specific Interrupt Numbers ***********************/
PM_IRQn = 0, /**< 0 SAMD21E18A Power Manager (PM) */
SYSCTRL_IRQn = 1, /**< 1 SAMD21E18A System Control (SYSCTRL) */
WDT_IRQn = 2, /**< 2 SAMD21E18A Watchdog Timer (WDT) */
RTC_IRQn = 3, /**< 3 SAMD21E18A Real-Time Counter (RTC) */
EIC_IRQn = 4, /**< 4 SAMD21E18A External Interrupt Controller (EIC) */
NVMCTRL_IRQn = 5, /**< 5 SAMD21E18A Non-Volatile Memory Controller (NVMCTRL) */
DMAC_IRQn = 6, /**< 6 SAMD21E18A Direct Memory Access Controller (DMAC) */
USB_IRQn = 7, /**< 7 SAMD21E18A Universal Serial Bus (USB) */
EVSYS_IRQn = 8, /**< 8 SAMD21E18A Event System Interface (EVSYS) */
SERCOM0_IRQn = 9, /**< 9 SAMD21E18A Serial Communication Interface 0 (SERCOM0) */
SERCOM1_IRQn = 10, /**< 10 SAMD21E18A Serial Communication Interface 1 (SERCOM1) */
SERCOM2_IRQn = 11, /**< 11 SAMD21E18A Serial Communication Interface 2 (SERCOM2) */
SERCOM3_IRQn = 12, /**< 12 SAMD21E18A Serial Communication Interface 3 (SERCOM3) */
TCC0_IRQn = 15, /**< 15 SAMD21E18A Timer Counter Control 0 (TCC0) */
TCC1_IRQn = 16, /**< 16 SAMD21E18A Timer Counter Control 1 (TCC1) */
TCC2_IRQn = 17, /**< 17 SAMD21E18A Timer Counter Control 2 (TCC2) */
TC3_IRQn = 18, /**< 18 SAMD21E18A Basic Timer Counter 3 (TC3) */
TC4_IRQn = 19, /**< 19 SAMD21E18A Basic Timer Counter 4 (TC4) */
TC5_IRQn = 20, /**< 20 SAMD21E18A Basic Timer Counter 5 (TC5) */
ADC_IRQn = 23, /**< 23 SAMD21E18A Analog Digital Converter (ADC) */
AC_IRQn = 24, /**< 24 SAMD21E18A Analog Comparators (AC) */
DAC_IRQn = 25, /**< 25 SAMD21E18A Digital Analog Converter (DAC) */
PTC_IRQn = 26, /**< 26 SAMD21E18A Peripheral Touch Controller (PTC) */
I2S_IRQn = 27, /**< 27 SAMD21E18A Inter-IC Sound Interface (I2S) */
PERIPH_COUNT_IRQn = 28 /**< Number of peripheral IDs */
} IRQn_Type;
typedef struct _DeviceVectors
{
/* Stack pointer */
void* pvStack;
/* Cortex-M handlers */
void* pfnReset_Handler;
void* pfnNMI_Handler;
void* pfnHardFault_Handler;
void* pfnReservedM12;
void* pfnReservedM11;
void* pfnReservedM10;
void* pfnReservedM9;
void* pfnReservedM8;
void* pfnReservedM7;
void* pfnReservedM6;
void* pfnSVC_Handler;
void* pfnReservedM4;
void* pfnReservedM3;
void* pfnPendSV_Handler;
void* pfnSysTick_Handler;
/* Peripheral handlers */
void* pfnPM_Handler; /* 0 Power Manager */
void* pfnSYSCTRL_Handler; /* 1 System Control */
void* pfnWDT_Handler; /* 2 Watchdog Timer */
void* pfnRTC_Handler; /* 3 Real-Time Counter */
void* pfnEIC_Handler; /* 4 External Interrupt Controller */
void* pfnNVMCTRL_Handler; /* 5 Non-Volatile Memory Controller */
void* pfnDMAC_Handler; /* 6 Direct Memory Access Controller */
void* pfnUSB_Handler; /* 7 Universal Serial Bus */
void* pfnEVSYS_Handler; /* 8 Event System Interface */
void* pfnSERCOM0_Handler; /* 9 Serial Communication Interface 0 */
void* pfnSERCOM1_Handler; /* 10 Serial Communication Interface 1 */
void* pfnSERCOM2_Handler; /* 11 Serial Communication Interface 2 */
void* pfnSERCOM3_Handler; /* 12 Serial Communication Interface 3 */
void* pfnReserved13;
void* pfnReserved14;
void* pfnTCC0_Handler; /* 15 Timer Counter Control 0 */
void* pfnTCC1_Handler; /* 16 Timer Counter Control 1 */
void* pfnTCC2_Handler; /* 17 Timer Counter Control 2 */
void* pfnTC3_Handler; /* 18 Basic Timer Counter 3 */
void* pfnTC4_Handler; /* 19 Basic Timer Counter 4 */
void* pfnTC5_Handler; /* 20 Basic Timer Counter 5 */
void* pfnReserved21;
void* pfnReserved22;
void* pfnADC_Handler; /* 23 Analog Digital Converter */
void* pfnAC_Handler; /* 24 Analog Comparators */
void* pfnDAC_Handler; /* 25 Digital Analog Converter */
void* pfnPTC_Handler; /* 26 Peripheral Touch Controller */
void* pfnI2S_Handler; /* 27 Inter-IC Sound Interface */
} DeviceVectors;
/* Cortex-M0+ processor handlers */
void Reset_Handler ( void );
void NMI_Handler ( void );
void HardFault_Handler ( void );
void SVC_Handler ( void );
void PendSV_Handler ( void );
void SysTick_Handler ( void );
/* Peripherals handlers */
void PM_Handler ( void );
void SYSCTRL_Handler ( void );
void WDT_Handler ( void );
void RTC_Handler ( void );
void EIC_Handler ( void );
void NVMCTRL_Handler ( void );
void DMAC_Handler ( void );
void USB_Handler ( void );
void EVSYS_Handler ( void );
void SERCOM0_Handler ( void );
void SERCOM1_Handler ( void );
void SERCOM2_Handler ( void );
void SERCOM3_Handler ( void );
void TCC0_Handler ( void );
void TCC1_Handler ( void );
void TCC2_Handler ( void );
void TC3_Handler ( void );
void TC4_Handler ( void );
void TC5_Handler ( void );
void ADC_Handler ( void );
void AC_Handler ( void );
void DAC_Handler ( void );
void PTC_Handler ( void );
void I2S_Handler ( void );
/*
* \brief Configuration of the Cortex-M0+ Processor and Core Peripherals
*/
#define LITTLE_ENDIAN 1
#define __CM0PLUS_REV 1 /*!< Core revision r0p1 */
#define __MPU_PRESENT 0 /*!< MPU present or not */
#define __NVIC_PRIO_BITS 2 /*!< Number of bits used for Priority Levels */
#define __VTOR_PRESENT 1 /*!< VTOR present or not */
#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
/**
* \brief CMSIS includes
*/
#include <core_cm0plus.h>
#if !defined DONT_USE_CMSIS_INIT
#include "system_samd21.h"
#endif /* DONT_USE_CMSIS_INIT */
/*@}*/
/* ************************************************************************** */
/** SOFTWARE PERIPHERAL API DEFINITION FOR SAMD21E18A */
/* ************************************************************************** */
/** \defgroup SAMD21E18A_api Peripheral Software API */
/*@{*/
#include "component/ac.h"
#include "component/adc.h"
#include "component/dac.h"
#include "component/dmac.h"
#include "component/dsu.h"
#include "component/eic.h"
#include "component/evsys.h"
#include "component/gclk.h"
#include "component/hmatrixb.h"
#include "component/i2s.h"
#include "component/mtb.h"
#include "component/nvmctrl.h"
#include "component/pac.h"
#include "component/pm.h"
#include "component/port.h"
#include "component/rtc.h"
#include "component/sercom.h"
#include "component/sysctrl.h"
#include "component/tc.h"
#include "component/tcc.h"
#include "component/usb.h"
#include "component/wdt.h"
/*@}*/
/* ************************************************************************** */
/** REGISTERS ACCESS DEFINITIONS FOR SAMD21E18A */
/* ************************************************************************** */
/** \defgroup SAMD21E18A_reg Registers Access Definitions */
/*@{*/
#include "instance/ac.h"
#include "instance/adc.h"
#include "instance/dac.h"
#include "instance/dmac.h"
#include "instance/dsu.h"
#include "instance/eic.h"
#include "instance/evsys.h"
#include "instance/gclk.h"
#include "instance/sbmatrix.h"
#include "instance/i2s.h"
#include "instance/mtb.h"
#include "instance/nvmctrl.h"
#include "instance/pac0.h"
#include "instance/pac1.h"
#include "instance/pac2.h"
#include "instance/pm.h"
#include "instance/port.h"
#include "instance/rtc.h"
#include "instance/sercom0.h"
#include "instance/sercom1.h"
#include "instance/sercom2.h"
#include "instance/sercom3.h"
#include "instance/sysctrl.h"
#include "instance/tc3.h"
#include "instance/tc4.h"
#include "instance/tc5.h"
#include "instance/tcc0.h"
#include "instance/tcc1.h"
#include "instance/tcc2.h"
#include "instance/usb.h"
#include "instance/wdt.h"
/*@}*/
/* ************************************************************************** */
/** PERIPHERAL ID DEFINITIONS FOR SAMD21E18A */
/* ************************************************************************** */
/** \defgroup SAMD21E18A_id Peripheral Ids Definitions */
/*@{*/
// Peripheral instances on HPB0 bridge
#define ID_PAC0 0 /**< \brief Peripheral Access Controller 0 (PAC0) */
#define ID_PM 1 /**< \brief Power Manager (PM) */
#define ID_SYSCTRL 2 /**< \brief System Control (SYSCTRL) */
#define ID_GCLK 3 /**< \brief Generic Clock Generator (GCLK) */
#define ID_WDT 4 /**< \brief Watchdog Timer (WDT) */
#define ID_RTC 5 /**< \brief Real-Time Counter (RTC) */
#define ID_EIC 6 /**< \brief External Interrupt Controller (EIC) */
// Peripheral instances on HPB1 bridge
#define ID_PAC1 32 /**< \brief Peripheral Access Controller 1 (PAC1) */
#define ID_DSU 33 /**< \brief Device Service Unit (DSU) */
#define ID_NVMCTRL 34 /**< \brief Non-Volatile Memory Controller (NVMCTRL) */
#define ID_PORT 35 /**< \brief Port Module (PORT) */
#define ID_DMAC 36 /**< \brief Direct Memory Access Controller (DMAC) */
#define ID_USB 37 /**< \brief Universal Serial Bus (USB) */
#define ID_MTB 38 /**< \brief Cortex-M0+ Micro-Trace Buffer (MTB) */
#define ID_SBMATRIX 39 /**< \brief HSB Matrix (SBMATRIX) */
// Peripheral instances on HPB2 bridge
#define ID_PAC2 64 /**< \brief Peripheral Access Controller 2 (PAC2) */
#define ID_EVSYS 65 /**< \brief Event System Interface (EVSYS) */
#define ID_SERCOM0 66 /**< \brief Serial Communication Interface 0 (SERCOM0) */
#define ID_SERCOM1 67 /**< \brief Serial Communication Interface 1 (SERCOM1) */
#define ID_SERCOM2 68 /**< \brief Serial Communication Interface 2 (SERCOM2) */
#define ID_SERCOM3 69 /**< \brief Serial Communication Interface 3 (SERCOM3) */
#define ID_TCC0 72 /**< \brief Timer Counter Control 0 (TCC0) */
#define ID_TCC1 73 /**< \brief Timer Counter Control 1 (TCC1) */
#define ID_TCC2 74 /**< \brief Timer Counter Control 2 (TCC2) */
#define ID_TC3 75 /**< \brief Basic Timer Counter 3 (TC3) */
#define ID_TC4 76 /**< \brief Basic Timer Counter 4 (TC4) */
#define ID_TC5 77 /**< \brief Basic Timer Counter 5 (TC5) */
#define ID_ADC 80 /**< \brief Analog Digital Converter (ADC) */
#define ID_AC 81 /**< \brief Analog Comparators (AC) */
#define ID_DAC 82 /**< \brief Digital Analog Converter (DAC) */
#define ID_PTC 83 /**< \brief Peripheral Touch Controller (PTC) */
#define ID_I2S 84 /**< \brief Inter-IC Sound Interface (I2S) */
#define ID_PERIPH_COUNT 85 /**< \brief Number of peripheral IDs */
/*@}*/
/* ************************************************************************** */
/** BASE ADDRESS DEFINITIONS FOR SAMD21E18A */
/* ************************************************************************** */
/** \defgroup SAMD21E18A_base Peripheral Base Address Definitions */
/*@{*/
#if defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)
#define AC (0x42004400UL) /**< \brief (AC) APB Base Address */
#define ADC (0x42004000UL) /**< \brief (ADC) APB Base Address */
#define DAC (0x42004800UL) /**< \brief (DAC) APB Base Address */
#define DMAC (0x41004800UL) /**< \brief (DMAC) APB Base Address */
#define DSU (0x41002000UL) /**< \brief (DSU) APB Base Address */
#define EIC (0x40001800UL) /**< \brief (EIC) APB Base Address */
#define EVSYS (0x42000400UL) /**< \brief (EVSYS) APB Base Address */
#define GCLK (0x40000C00UL) /**< \brief (GCLK) APB Base Address */
#define SBMATRIX (0x41007000UL) /**< \brief (SBMATRIX) APB Base Address */
#define I2S (0x42005000UL) /**< \brief (I2S) APB Base Address */
#define MTB (0x41006000UL) /**< \brief (MTB) APB Base Address */
#define NVMCTRL (0x41004000UL) /**< \brief (NVMCTRL) APB Base Address */
#define NVMCTRL_CAL (0x00800000UL) /**< \brief (NVMCTRL) CAL Base Address */
#define NVMCTRL_LOCKBIT (0x00802000UL) /**< \brief (NVMCTRL) LOCKBIT Base Address */
#define NVMCTRL_OTP1 (0x00806000UL) /**< \brief (NVMCTRL) OTP1 Base Address */
#define NVMCTRL_OTP2 (0x00806008UL) /**< \brief (NVMCTRL) OTP2 Base Address */
#define NVMCTRL_OTP4 (0x00806020UL) /**< \brief (NVMCTRL) OTP4 Base Address */
#define NVMCTRL_TEMP_LOG (0x00806030UL) /**< \brief (NVMCTRL) TEMP_LOG Base Address */
#define NVMCTRL_USER (0x00804000UL) /**< \brief (NVMCTRL) USER Base Address */
#define PAC0 (0x40000000UL) /**< \brief (PAC0) APB Base Address */
#define PAC1 (0x41000000UL) /**< \brief (PAC1) APB Base Address */
#define PAC2 (0x42000000UL) /**< \brief (PAC2) APB Base Address */
#define PM (0x40000400UL) /**< \brief (PM) APB Base Address */
#define PORT (0x41004400UL) /**< \brief (PORT) APB Base Address */
#define PORT_IOBUS (0x60000000UL) /**< \brief (PORT) IOBUS Base Address */
#define RTC (0x40001400UL) /**< \brief (RTC) APB Base Address */
#define SERCOM0 (0x42000800UL) /**< \brief (SERCOM0) APB Base Address */
#define SERCOM1 (0x42000C00UL) /**< \brief (SERCOM1) APB Base Address */
#define SERCOM2 (0x42001000UL) /**< \brief (SERCOM2) APB Base Address */
#define SERCOM3 (0x42001400UL) /**< \brief (SERCOM3) APB Base Address */
#define SYSCTRL (0x40000800UL) /**< \brief (SYSCTRL) APB Base Address */
#define TC3 (0x42002C00UL) /**< \brief (TC3) APB Base Address */
#define TC4 (0x42003000UL) /**< \brief (TC4) APB Base Address */
#define TC5 (0x42003400UL) /**< \brief (TC5) APB Base Address */
#define TCC0 (0x42002000UL) /**< \brief (TCC0) APB Base Address */
#define TCC1 (0x42002400UL) /**< \brief (TCC1) APB Base Address */
#define TCC2 (0x42002800UL) /**< \brief (TCC2) APB Base Address */
#define USB (0x41005000UL) /**< \brief (USB) APB Base Address */
#define WDT (0x40001000UL) /**< \brief (WDT) APB Base Address */
#else
#define AC ((Ac *)0x42004400UL) /**< \brief (AC) APB Base Address */
#define AC_INST_NUM 1 /**< \brief (AC) Number of instances */
#define AC_INSTS { AC } /**< \brief (AC) Instances List */
#define ADC ((Adc *)0x42004000UL) /**< \brief (ADC) APB Base Address */
#define ADC_INST_NUM 1 /**< \brief (ADC) Number of instances */
#define ADC_INSTS { ADC } /**< \brief (ADC) Instances List */
#define DAC ((Dac *)0x42004800UL) /**< \brief (DAC) APB Base Address */
#define DAC_INST_NUM 1 /**< \brief (DAC) Number of instances */
#define DAC_INSTS { DAC } /**< \brief (DAC) Instances List */
#define DMAC ((Dmac *)0x41004800UL) /**< \brief (DMAC) APB Base Address */
#define DMAC_INST_NUM 1 /**< \brief (DMAC) Number of instances */
#define DMAC_INSTS { DMAC } /**< \brief (DMAC) Instances List */
#define DSU ((Dsu *)0x41002000UL) /**< \brief (DSU) APB Base Address */
#define DSU_INST_NUM 1 /**< \brief (DSU) Number of instances */
#define DSU_INSTS { DSU } /**< \brief (DSU) Instances List */
#define EIC ((Eic *)0x40001800UL) /**< \brief (EIC) APB Base Address */
#define EIC_INST_NUM 1 /**< \brief (EIC) Number of instances */
#define EIC_INSTS { EIC } /**< \brief (EIC) Instances List */
#define EVSYS ((Evsys *)0x42000400UL) /**< \brief (EVSYS) APB Base Address */
#define EVSYS_INST_NUM 1 /**< \brief (EVSYS) Number of instances */
#define EVSYS_INSTS { EVSYS } /**< \brief (EVSYS) Instances List */
#define GCLK ((Gclk *)0x40000C00UL) /**< \brief (GCLK) APB Base Address */
#define GCLK_INST_NUM 1 /**< \brief (GCLK) Number of instances */
#define GCLK_INSTS { GCLK } /**< \brief (GCLK) Instances List */
#define SBMATRIX ((Hmatrixb *)0x41007000UL) /**< \brief (SBMATRIX) APB Base Address */
#define HMATRIXB_INST_NUM 1 /**< \brief (HMATRIXB) Number of instances */
#define HMATRIXB_INSTS { SBMATRIX } /**< \brief (HMATRIXB) Instances List */
#define I2S ((I2s *)0x42005000UL) /**< \brief (I2S) APB Base Address */
#define I2S_INST_NUM 1 /**< \brief (I2S) Number of instances */
#define I2S_INSTS { I2S } /**< \brief (I2S) Instances List */
#define MTB ((Mtb *)0x41006000UL) /**< \brief (MTB) APB Base Address */
#define MTB_INST_NUM 1 /**< \brief (MTB) Number of instances */
#define MTB_INSTS { MTB } /**< \brief (MTB) Instances List */
#define NVMCTRL ((Nvmctrl *)0x41004000UL) /**< \brief (NVMCTRL) APB Base Address */
#define NVMCTRL_CAL (0x00800000UL) /**< \brief (NVMCTRL) CAL Base Address */
#define NVMCTRL_LOCKBIT (0x00802000UL) /**< \brief (NVMCTRL) LOCKBIT Base Address */
#define NVMCTRL_OTP1 (0x00806000UL) /**< \brief (NVMCTRL) OTP1 Base Address */
#define NVMCTRL_OTP2 (0x00806008UL) /**< \brief (NVMCTRL) OTP2 Base Address */
#define NVMCTRL_OTP4 (0x00806020UL) /**< \brief (NVMCTRL) OTP4 Base Address */
#define NVMCTRL_TEMP_LOG (0x00806030UL) /**< \brief (NVMCTRL) TEMP_LOG Base Address */
#define NVMCTRL_USER (0x00804000UL) /**< \brief (NVMCTRL) USER Base Address */
#define NVMCTRL_INST_NUM 1 /**< \brief (NVMCTRL) Number of instances */
#define NVMCTRL_INSTS { NVMCTRL } /**< \brief (NVMCTRL) Instances List */
#define PAC0 ((Pac *)0x40000000UL) /**< \brief (PAC0) APB Base Address */
#define PAC1 ((Pac *)0x41000000UL) /**< \brief (PAC1) APB Base Address */
#define PAC2 ((Pac *)0x42000000UL) /**< \brief (PAC2) APB Base Address */
#define PAC_INST_NUM 3 /**< \brief (PAC) Number of instances */
#define PAC_INSTS { PAC0, PAC1, PAC2 } /**< \brief (PAC) Instances List */
#define PM ((Pm *)0x40000400UL) /**< \brief (PM) APB Base Address */
#define PM_INST_NUM 1 /**< \brief (PM) Number of instances */
#define PM_INSTS { PM } /**< \brief (PM) Instances List */
#define PORT ((Port *)0x41004400UL) /**< \brief (PORT) APB Base Address */
#define PORT_IOBUS ((Port *)0x60000000UL) /**< \brief (PORT) IOBUS Base Address */
#define PORT_INST_NUM 1 /**< \brief (PORT) Number of instances */
#define PORT_INSTS { PORT } /**< \brief (PORT) Instances List */
#define PTC_GCLK_ID 34
#define PTC_INST_NUM 1 /**< \brief (PTC) Number of instances */
#define PTC_INSTS { PTC } /**< \brief (PTC) Instances List */
#define RTC ((Rtc *)0x40001400UL) /**< \brief (RTC) APB Base Address */
#define RTC_INST_NUM 1 /**< \brief (RTC) Number of instances */
#define RTC_INSTS { RTC } /**< \brief (RTC) Instances List */
#define SERCOM0 ((Sercom *)0x42000800UL) /**< \brief (SERCOM0) APB Base Address */
#define SERCOM1 ((Sercom *)0x42000C00UL) /**< \brief (SERCOM1) APB Base Address */
#define SERCOM2 ((Sercom *)0x42001000UL) /**< \brief (SERCOM2) APB Base Address */
#define SERCOM3 ((Sercom *)0x42001400UL) /**< \brief (SERCOM3) APB Base Address */
#define SERCOM_INST_NUM 4 /**< \brief (SERCOM) Number of instances */
#define SERCOM_INSTS { SERCOM0, SERCOM1, SERCOM2, SERCOM3 } /**< \brief (SERCOM) Instances List */
#define SYSCTRL ((Sysctrl *)0x40000800UL) /**< \brief (SYSCTRL) APB Base Address */
#define SYSCTRL_INST_NUM 1 /**< \brief (SYSCTRL) Number of instances */
#define SYSCTRL_INSTS { SYSCTRL } /**< \brief (SYSCTRL) Instances List */
#define TC3 ((Tc *)0x42002C00UL) /**< \brief (TC3) APB Base Address */
#define TC4 ((Tc *)0x42003000UL) /**< \brief (TC4) APB Base Address */
#define TC5 ((Tc *)0x42003400UL) /**< \brief (TC5) APB Base Address */
#define TC_INST_NUM 3 /**< \brief (TC) Number of instances */
#define TC_INSTS { TC3, TC4, TC5 } /**< \brief (TC) Instances List */
#define TCC0 ((Tcc *)0x42002000UL) /**< \brief (TCC0) APB Base Address */
#define TCC1 ((Tcc *)0x42002400UL) /**< \brief (TCC1) APB Base Address */
#define TCC2 ((Tcc *)0x42002800UL) /**< \brief (TCC2) APB Base Address */
#define TCC_INST_NUM 3 /**< \brief (TCC) Number of instances */
#define TCC_INSTS { TCC0, TCC1, TCC2 } /**< \brief (TCC) Instances List */
#define USB ((Usb *)0x41005000UL) /**< \brief (USB) APB Base Address */
#define USB_INST_NUM 1 /**< \brief (USB) Number of instances */
#define USB_INSTS { USB } /**< \brief (USB) Instances List */
#define WDT ((Wdt *)0x40001000UL) /**< \brief (WDT) APB Base Address */
#define WDT_INST_NUM 1 /**< \brief (WDT) Number of instances */
#define WDT_INSTS { WDT } /**< \brief (WDT) Instances List */
#endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/*@}*/
/* ************************************************************************** */
/** PORT DEFINITIONS FOR SAMD21E18A */
/* ************************************************************************** */
/** \defgroup SAMD21E18A_port PORT Definitions */
/*@{*/
#include "pio/samd21e18a.h"
/*@}*/
/* ************************************************************************** */
/** MEMORY MAPPING DEFINITIONS FOR SAMD21E18A */
/* ************************************************************************** */
#define FLASH_SIZE 0x40000UL /* 256 kB */
#define FLASH_PAGE_SIZE 64
#define FLASH_NB_OF_PAGES 4096
#define FLASH_USER_PAGE_SIZE 64
#define HMCRAMC0_SIZE 0x8000UL /* 32 kB */
#define FLASH_ADDR (0x00000000UL) /**< FLASH base address */
#define FLASH_USER_PAGE_ADDR (0x00800000UL) /**< FLASH_USER_PAGE base address */
#define HMCRAMC0_ADDR (0x20000000UL) /**< HMCRAMC0 base address */
#define DSU_DID_RESETVALUE 0x1001000AUL
#define EIC_EXTINT_NUM 16
#define PORT_GROUPS 1
/* ************************************************************************** */
/** ELECTRICAL DEFINITIONS FOR SAMD21E18A */
/* ************************************************************************** */
#ifdef __cplusplus
}
#endif
/*@}*/
#endif /* SAMD21E18A_H */
| [
"mk.song@atmel.com"
] | mk.song@atmel.com |
def5160e4669b465283eabafe5a3ca4db7c409b4 | 87eb2cd82ea5b617f359989a95589db76fd1d812 | /archive/master/v0.0.4-545-gcd662e5/arty/net/mor1kx.linux/software/include/generated/csr.h | 837dd70686dae820faf890862cb944a2d4b98e71 | [
"MIT",
"BSD-2-Clause"
] | permissive | timvideos/HDMI2USB-firmware-prebuilt | d6872785c7b97d5a1a2fe3418458824d944c3f37 | bf8ee7bf8ec3569980b02ab39c9700bf4b9ce5a9 | refs/heads/master | 2023-05-04T14:30:57.741336 | 2020-01-30T16:52:41 | 2020-01-30T16:52:41 | 11,761,544 | 9 | 14 | null | 2018-04-27T21:25:04 | 2013-07-30T09:33:09 | Verilog | UTF-8 | C | false | false | 33,964 | h | //--------------------------------------------------------------------------------
// Auto-generated by Migen (562c046) & LiteX (113f7f40) on 2019-07-09 10:30:55
//--------------------------------------------------------------------------------
#ifndef __GENERATED_CSR_H
#define __GENERATED_CSR_H
#include <stdint.h>
#ifdef CSR_ACCESSORS_DEFINED
extern void csr_writeb(uint8_t value, unsigned long addr);
extern uint8_t csr_readb(unsigned long addr);
extern void csr_writew(uint16_t value, unsigned long addr);
extern uint16_t csr_readw(unsigned long addr);
extern void csr_writel(uint32_t value, unsigned long addr);
extern uint32_t csr_readl(unsigned long addr);
#else /* ! CSR_ACCESSORS_DEFINED */
#include <hw/common.h>
#endif /* ! CSR_ACCESSORS_DEFINED */
/* cas */
#define CSR_CAS_BASE 0xe0006800L
#define CSR_CAS_LEDS_OUT_ADDR 0xe0006800L
#define CSR_CAS_LEDS_OUT_SIZE 1
static inline unsigned char cas_leds_out_read(void) {
unsigned char r = csr_readl(0xe0006800L);
return r;
}
static inline void cas_leds_out_write(unsigned char value) {
csr_writel(value, 0xe0006800L);
}
#define CSR_CAS_SWITCHES_IN_ADDR 0xe0006804L
#define CSR_CAS_SWITCHES_IN_SIZE 1
static inline unsigned char cas_switches_in_read(void) {
unsigned char r = csr_readl(0xe0006804L);
return r;
}
#define CSR_CAS_BUTTONS_EV_STATUS_ADDR 0xe0006808L
#define CSR_CAS_BUTTONS_EV_STATUS_SIZE 1
static inline unsigned char cas_buttons_ev_status_read(void) {
unsigned char r = csr_readl(0xe0006808L);
return r;
}
static inline void cas_buttons_ev_status_write(unsigned char value) {
csr_writel(value, 0xe0006808L);
}
#define CSR_CAS_BUTTONS_EV_PENDING_ADDR 0xe000680cL
#define CSR_CAS_BUTTONS_EV_PENDING_SIZE 1
static inline unsigned char cas_buttons_ev_pending_read(void) {
unsigned char r = csr_readl(0xe000680cL);
return r;
}
static inline void cas_buttons_ev_pending_write(unsigned char value) {
csr_writel(value, 0xe000680cL);
}
#define CSR_CAS_BUTTONS_EV_ENABLE_ADDR 0xe0006810L
#define CSR_CAS_BUTTONS_EV_ENABLE_SIZE 1
static inline unsigned char cas_buttons_ev_enable_read(void) {
unsigned char r = csr_readl(0xe0006810L);
return r;
}
static inline void cas_buttons_ev_enable_write(unsigned char value) {
csr_writel(value, 0xe0006810L);
}
/* ctrl */
#define CSR_CTRL_BASE 0xe0000000L
#define CSR_CTRL_RESET_ADDR 0xe0000000L
#define CSR_CTRL_RESET_SIZE 1
static inline unsigned char ctrl_reset_read(void) {
unsigned char r = csr_readl(0xe0000000L);
return r;
}
static inline void ctrl_reset_write(unsigned char value) {
csr_writel(value, 0xe0000000L);
}
#define CSR_CTRL_SCRATCH_ADDR 0xe0000004L
#define CSR_CTRL_SCRATCH_SIZE 4
static inline unsigned int ctrl_scratch_read(void) {
unsigned int r = csr_readl(0xe0000004L);
r <<= 8;
r |= csr_readl(0xe0000008L);
r <<= 8;
r |= csr_readl(0xe000000cL);
r <<= 8;
r |= csr_readl(0xe0000010L);
return r;
}
static inline void ctrl_scratch_write(unsigned int value) {
csr_writel(value >> 24, 0xe0000004L);
csr_writel(value >> 16, 0xe0000008L);
csr_writel(value >> 8, 0xe000000cL);
csr_writel(value, 0xe0000010L);
}
#define CSR_CTRL_BUS_ERRORS_ADDR 0xe0000014L
#define CSR_CTRL_BUS_ERRORS_SIZE 4
static inline unsigned int ctrl_bus_errors_read(void) {
unsigned int r = csr_readl(0xe0000014L);
r <<= 8;
r |= csr_readl(0xe0000018L);
r <<= 8;
r |= csr_readl(0xe000001cL);
r <<= 8;
r |= csr_readl(0xe0000020L);
return r;
}
/* ddrphy */
#define CSR_DDRPHY_BASE 0xe0005800L
#define CSR_DDRPHY_HALF_SYS8X_TAPS_ADDR 0xe0005800L
#define CSR_DDRPHY_HALF_SYS8X_TAPS_SIZE 1
static inline unsigned char ddrphy_half_sys8x_taps_read(void) {
unsigned char r = csr_readl(0xe0005800L);
return r;
}
static inline void ddrphy_half_sys8x_taps_write(unsigned char value) {
csr_writel(value, 0xe0005800L);
}
#define CSR_DDRPHY_CDLY_RST_ADDR 0xe0005804L
#define CSR_DDRPHY_CDLY_RST_SIZE 1
static inline unsigned char ddrphy_cdly_rst_read(void) {
unsigned char r = csr_readl(0xe0005804L);
return r;
}
static inline void ddrphy_cdly_rst_write(unsigned char value) {
csr_writel(value, 0xe0005804L);
}
#define CSR_DDRPHY_CDLY_INC_ADDR 0xe0005808L
#define CSR_DDRPHY_CDLY_INC_SIZE 1
static inline unsigned char ddrphy_cdly_inc_read(void) {
unsigned char r = csr_readl(0xe0005808L);
return r;
}
static inline void ddrphy_cdly_inc_write(unsigned char value) {
csr_writel(value, 0xe0005808L);
}
#define CSR_DDRPHY_DLY_SEL_ADDR 0xe000580cL
#define CSR_DDRPHY_DLY_SEL_SIZE 1
static inline unsigned char ddrphy_dly_sel_read(void) {
unsigned char r = csr_readl(0xe000580cL);
return r;
}
static inline void ddrphy_dly_sel_write(unsigned char value) {
csr_writel(value, 0xe000580cL);
}
#define CSR_DDRPHY_RDLY_DQ_RST_ADDR 0xe0005810L
#define CSR_DDRPHY_RDLY_DQ_RST_SIZE 1
static inline unsigned char ddrphy_rdly_dq_rst_read(void) {
unsigned char r = csr_readl(0xe0005810L);
return r;
}
static inline void ddrphy_rdly_dq_rst_write(unsigned char value) {
csr_writel(value, 0xe0005810L);
}
#define CSR_DDRPHY_RDLY_DQ_INC_ADDR 0xe0005814L
#define CSR_DDRPHY_RDLY_DQ_INC_SIZE 1
static inline unsigned char ddrphy_rdly_dq_inc_read(void) {
unsigned char r = csr_readl(0xe0005814L);
return r;
}
static inline void ddrphy_rdly_dq_inc_write(unsigned char value) {
csr_writel(value, 0xe0005814L);
}
#define CSR_DDRPHY_RDLY_DQ_BITSLIP_RST_ADDR 0xe0005818L
#define CSR_DDRPHY_RDLY_DQ_BITSLIP_RST_SIZE 1
static inline unsigned char ddrphy_rdly_dq_bitslip_rst_read(void) {
unsigned char r = csr_readl(0xe0005818L);
return r;
}
static inline void ddrphy_rdly_dq_bitslip_rst_write(unsigned char value) {
csr_writel(value, 0xe0005818L);
}
#define CSR_DDRPHY_RDLY_DQ_BITSLIP_ADDR 0xe000581cL
#define CSR_DDRPHY_RDLY_DQ_BITSLIP_SIZE 1
static inline unsigned char ddrphy_rdly_dq_bitslip_read(void) {
unsigned char r = csr_readl(0xe000581cL);
return r;
}
static inline void ddrphy_rdly_dq_bitslip_write(unsigned char value) {
csr_writel(value, 0xe000581cL);
}
/* ethmac */
#define CSR_ETHMAC_BASE 0xe0007800L
#define CSR_ETHMAC_SRAM_WRITER_SLOT_ADDR 0xe0007800L
#define CSR_ETHMAC_SRAM_WRITER_SLOT_SIZE 1
static inline unsigned char ethmac_sram_writer_slot_read(void) {
unsigned char r = csr_readl(0xe0007800L);
return r;
}
#define CSR_ETHMAC_SRAM_WRITER_LENGTH_ADDR 0xe0007804L
#define CSR_ETHMAC_SRAM_WRITER_LENGTH_SIZE 4
static inline unsigned int ethmac_sram_writer_length_read(void) {
unsigned int r = csr_readl(0xe0007804L);
r <<= 8;
r |= csr_readl(0xe0007808L);
r <<= 8;
r |= csr_readl(0xe000780cL);
r <<= 8;
r |= csr_readl(0xe0007810L);
return r;
}
#define CSR_ETHMAC_SRAM_WRITER_ERRORS_ADDR 0xe0007814L
#define CSR_ETHMAC_SRAM_WRITER_ERRORS_SIZE 4
static inline unsigned int ethmac_sram_writer_errors_read(void) {
unsigned int r = csr_readl(0xe0007814L);
r <<= 8;
r |= csr_readl(0xe0007818L);
r <<= 8;
r |= csr_readl(0xe000781cL);
r <<= 8;
r |= csr_readl(0xe0007820L);
return r;
}
#define CSR_ETHMAC_SRAM_WRITER_EV_STATUS_ADDR 0xe0007824L
#define CSR_ETHMAC_SRAM_WRITER_EV_STATUS_SIZE 1
static inline unsigned char ethmac_sram_writer_ev_status_read(void) {
unsigned char r = csr_readl(0xe0007824L);
return r;
}
static inline void ethmac_sram_writer_ev_status_write(unsigned char value) {
csr_writel(value, 0xe0007824L);
}
#define CSR_ETHMAC_SRAM_WRITER_EV_PENDING_ADDR 0xe0007828L
#define CSR_ETHMAC_SRAM_WRITER_EV_PENDING_SIZE 1
static inline unsigned char ethmac_sram_writer_ev_pending_read(void) {
unsigned char r = csr_readl(0xe0007828L);
return r;
}
static inline void ethmac_sram_writer_ev_pending_write(unsigned char value) {
csr_writel(value, 0xe0007828L);
}
#define CSR_ETHMAC_SRAM_WRITER_EV_ENABLE_ADDR 0xe000782cL
#define CSR_ETHMAC_SRAM_WRITER_EV_ENABLE_SIZE 1
static inline unsigned char ethmac_sram_writer_ev_enable_read(void) {
unsigned char r = csr_readl(0xe000782cL);
return r;
}
static inline void ethmac_sram_writer_ev_enable_write(unsigned char value) {
csr_writel(value, 0xe000782cL);
}
#define CSR_ETHMAC_SRAM_READER_START_ADDR 0xe0007830L
#define CSR_ETHMAC_SRAM_READER_START_SIZE 1
static inline unsigned char ethmac_sram_reader_start_read(void) {
unsigned char r = csr_readl(0xe0007830L);
return r;
}
static inline void ethmac_sram_reader_start_write(unsigned char value) {
csr_writel(value, 0xe0007830L);
}
#define CSR_ETHMAC_SRAM_READER_READY_ADDR 0xe0007834L
#define CSR_ETHMAC_SRAM_READER_READY_SIZE 1
static inline unsigned char ethmac_sram_reader_ready_read(void) {
unsigned char r = csr_readl(0xe0007834L);
return r;
}
#define CSR_ETHMAC_SRAM_READER_LEVEL_ADDR 0xe0007838L
#define CSR_ETHMAC_SRAM_READER_LEVEL_SIZE 1
static inline unsigned char ethmac_sram_reader_level_read(void) {
unsigned char r = csr_readl(0xe0007838L);
return r;
}
#define CSR_ETHMAC_SRAM_READER_SLOT_ADDR 0xe000783cL
#define CSR_ETHMAC_SRAM_READER_SLOT_SIZE 1
static inline unsigned char ethmac_sram_reader_slot_read(void) {
unsigned char r = csr_readl(0xe000783cL);
return r;
}
static inline void ethmac_sram_reader_slot_write(unsigned char value) {
csr_writel(value, 0xe000783cL);
}
#define CSR_ETHMAC_SRAM_READER_LENGTH_ADDR 0xe0007840L
#define CSR_ETHMAC_SRAM_READER_LENGTH_SIZE 2
static inline unsigned short int ethmac_sram_reader_length_read(void) {
unsigned short int r = csr_readl(0xe0007840L);
r <<= 8;
r |= csr_readl(0xe0007844L);
return r;
}
static inline void ethmac_sram_reader_length_write(unsigned short int value) {
csr_writel(value >> 8, 0xe0007840L);
csr_writel(value, 0xe0007844L);
}
#define CSR_ETHMAC_SRAM_READER_EV_STATUS_ADDR 0xe0007848L
#define CSR_ETHMAC_SRAM_READER_EV_STATUS_SIZE 1
static inline unsigned char ethmac_sram_reader_ev_status_read(void) {
unsigned char r = csr_readl(0xe0007848L);
return r;
}
static inline void ethmac_sram_reader_ev_status_write(unsigned char value) {
csr_writel(value, 0xe0007848L);
}
#define CSR_ETHMAC_SRAM_READER_EV_PENDING_ADDR 0xe000784cL
#define CSR_ETHMAC_SRAM_READER_EV_PENDING_SIZE 1
static inline unsigned char ethmac_sram_reader_ev_pending_read(void) {
unsigned char r = csr_readl(0xe000784cL);
return r;
}
static inline void ethmac_sram_reader_ev_pending_write(unsigned char value) {
csr_writel(value, 0xe000784cL);
}
#define CSR_ETHMAC_SRAM_READER_EV_ENABLE_ADDR 0xe0007850L
#define CSR_ETHMAC_SRAM_READER_EV_ENABLE_SIZE 1
static inline unsigned char ethmac_sram_reader_ev_enable_read(void) {
unsigned char r = csr_readl(0xe0007850L);
return r;
}
static inline void ethmac_sram_reader_ev_enable_write(unsigned char value) {
csr_writel(value, 0xe0007850L);
}
#define CSR_ETHMAC_PREAMBLE_CRC_ADDR 0xe0007854L
#define CSR_ETHMAC_PREAMBLE_CRC_SIZE 1
static inline unsigned char ethmac_preamble_crc_read(void) {
unsigned char r = csr_readl(0xe0007854L);
return r;
}
#define CSR_ETHMAC_PREAMBLE_ERRORS_ADDR 0xe0007858L
#define CSR_ETHMAC_PREAMBLE_ERRORS_SIZE 4
static inline unsigned int ethmac_preamble_errors_read(void) {
unsigned int r = csr_readl(0xe0007858L);
r <<= 8;
r |= csr_readl(0xe000785cL);
r <<= 8;
r |= csr_readl(0xe0007860L);
r <<= 8;
r |= csr_readl(0xe0007864L);
return r;
}
#define CSR_ETHMAC_CRC_ERRORS_ADDR 0xe0007868L
#define CSR_ETHMAC_CRC_ERRORS_SIZE 4
static inline unsigned int ethmac_crc_errors_read(void) {
unsigned int r = csr_readl(0xe0007868L);
r <<= 8;
r |= csr_readl(0xe000786cL);
r <<= 8;
r |= csr_readl(0xe0007870L);
r <<= 8;
r |= csr_readl(0xe0007874L);
return r;
}
/* ethphy */
#define CSR_ETHPHY_BASE 0xe0007000L
#define CSR_ETHPHY_CRG_RESET_ADDR 0xe0007000L
#define CSR_ETHPHY_CRG_RESET_SIZE 1
static inline unsigned char ethphy_crg_reset_read(void) {
unsigned char r = csr_readl(0xe0007000L);
return r;
}
static inline void ethphy_crg_reset_write(unsigned char value) {
csr_writel(value, 0xe0007000L);
}
#define CSR_ETHPHY_MDIO_W_ADDR 0xe0007004L
#define CSR_ETHPHY_MDIO_W_SIZE 1
static inline unsigned char ethphy_mdio_w_read(void) {
unsigned char r = csr_readl(0xe0007004L);
return r;
}
static inline void ethphy_mdio_w_write(unsigned char value) {
csr_writel(value, 0xe0007004L);
}
#define CSR_ETHPHY_MDIO_R_ADDR 0xe0007008L
#define CSR_ETHPHY_MDIO_R_SIZE 1
static inline unsigned char ethphy_mdio_r_read(void) {
unsigned char r = csr_readl(0xe0007008L);
return r;
}
/* info */
#define CSR_INFO_BASE 0xe0006000L
#define CSR_INFO_DNA_ID_ADDR 0xe0006000L
#define CSR_INFO_DNA_ID_SIZE 8
static inline unsigned long long int info_dna_id_read(void) {
unsigned long long int r = csr_readl(0xe0006000L);
r <<= 8;
r |= csr_readl(0xe0006004L);
r <<= 8;
r |= csr_readl(0xe0006008L);
r <<= 8;
r |= csr_readl(0xe000600cL);
r <<= 8;
r |= csr_readl(0xe0006010L);
r <<= 8;
r |= csr_readl(0xe0006014L);
r <<= 8;
r |= csr_readl(0xe0006018L);
r <<= 8;
r |= csr_readl(0xe000601cL);
return r;
}
#define CSR_INFO_GIT_COMMIT_ADDR 0xe0006020L
#define CSR_INFO_GIT_COMMIT_SIZE 20
#define CSR_INFO_PLATFORM_PLATFORM_ADDR 0xe0006070L
#define CSR_INFO_PLATFORM_PLATFORM_SIZE 8
static inline unsigned long long int info_platform_platform_read(void) {
unsigned long long int r = csr_readl(0xe0006070L);
r <<= 8;
r |= csr_readl(0xe0006074L);
r <<= 8;
r |= csr_readl(0xe0006078L);
r <<= 8;
r |= csr_readl(0xe000607cL);
r <<= 8;
r |= csr_readl(0xe0006080L);
r <<= 8;
r |= csr_readl(0xe0006084L);
r <<= 8;
r |= csr_readl(0xe0006088L);
r <<= 8;
r |= csr_readl(0xe000608cL);
return r;
}
#define CSR_INFO_PLATFORM_TARGET_ADDR 0xe0006090L
#define CSR_INFO_PLATFORM_TARGET_SIZE 8
static inline unsigned long long int info_platform_target_read(void) {
unsigned long long int r = csr_readl(0xe0006090L);
r <<= 8;
r |= csr_readl(0xe0006094L);
r <<= 8;
r |= csr_readl(0xe0006098L);
r <<= 8;
r |= csr_readl(0xe000609cL);
r <<= 8;
r |= csr_readl(0xe00060a0L);
r <<= 8;
r |= csr_readl(0xe00060a4L);
r <<= 8;
r |= csr_readl(0xe00060a8L);
r <<= 8;
r |= csr_readl(0xe00060acL);
return r;
}
#define CSR_INFO_XADC_TEMPERATURE_ADDR 0xe00060b0L
#define CSR_INFO_XADC_TEMPERATURE_SIZE 2
static inline unsigned short int info_xadc_temperature_read(void) {
unsigned short int r = csr_readl(0xe00060b0L);
r <<= 8;
r |= csr_readl(0xe00060b4L);
return r;
}
#define CSR_INFO_XADC_VCCINT_ADDR 0xe00060b8L
#define CSR_INFO_XADC_VCCINT_SIZE 2
static inline unsigned short int info_xadc_vccint_read(void) {
unsigned short int r = csr_readl(0xe00060b8L);
r <<= 8;
r |= csr_readl(0xe00060bcL);
return r;
}
#define CSR_INFO_XADC_VCCAUX_ADDR 0xe00060c0L
#define CSR_INFO_XADC_VCCAUX_SIZE 2
static inline unsigned short int info_xadc_vccaux_read(void) {
unsigned short int r = csr_readl(0xe00060c0L);
r <<= 8;
r |= csr_readl(0xe00060c4L);
return r;
}
#define CSR_INFO_XADC_VCCBRAM_ADDR 0xe00060c8L
#define CSR_INFO_XADC_VCCBRAM_SIZE 2
static inline unsigned short int info_xadc_vccbram_read(void) {
unsigned short int r = csr_readl(0xe00060c8L);
r <<= 8;
r |= csr_readl(0xe00060ccL);
return r;
}
/* sdram */
#define CSR_SDRAM_BASE 0xe0004000L
#define CSR_SDRAM_DFII_CONTROL_ADDR 0xe0004000L
#define CSR_SDRAM_DFII_CONTROL_SIZE 1
static inline unsigned char sdram_dfii_control_read(void) {
unsigned char r = csr_readl(0xe0004000L);
return r;
}
static inline void sdram_dfii_control_write(unsigned char value) {
csr_writel(value, 0xe0004000L);
}
#define CSR_SDRAM_DFII_PI0_COMMAND_ADDR 0xe0004004L
#define CSR_SDRAM_DFII_PI0_COMMAND_SIZE 1
static inline unsigned char sdram_dfii_pi0_command_read(void) {
unsigned char r = csr_readl(0xe0004004L);
return r;
}
static inline void sdram_dfii_pi0_command_write(unsigned char value) {
csr_writel(value, 0xe0004004L);
}
#define CSR_SDRAM_DFII_PI0_COMMAND_ISSUE_ADDR 0xe0004008L
#define CSR_SDRAM_DFII_PI0_COMMAND_ISSUE_SIZE 1
static inline unsigned char sdram_dfii_pi0_command_issue_read(void) {
unsigned char r = csr_readl(0xe0004008L);
return r;
}
static inline void sdram_dfii_pi0_command_issue_write(unsigned char value) {
csr_writel(value, 0xe0004008L);
}
#define CSR_SDRAM_DFII_PI0_ADDRESS_ADDR 0xe000400cL
#define CSR_SDRAM_DFII_PI0_ADDRESS_SIZE 2
static inline unsigned short int sdram_dfii_pi0_address_read(void) {
unsigned short int r = csr_readl(0xe000400cL);
r <<= 8;
r |= csr_readl(0xe0004010L);
return r;
}
static inline void sdram_dfii_pi0_address_write(unsigned short int value) {
csr_writel(value >> 8, 0xe000400cL);
csr_writel(value, 0xe0004010L);
}
#define CSR_SDRAM_DFII_PI0_BADDRESS_ADDR 0xe0004014L
#define CSR_SDRAM_DFII_PI0_BADDRESS_SIZE 1
static inline unsigned char sdram_dfii_pi0_baddress_read(void) {
unsigned char r = csr_readl(0xe0004014L);
return r;
}
static inline void sdram_dfii_pi0_baddress_write(unsigned char value) {
csr_writel(value, 0xe0004014L);
}
#define CSR_SDRAM_DFII_PI0_WRDATA_ADDR 0xe0004018L
#define CSR_SDRAM_DFII_PI0_WRDATA_SIZE 4
static inline unsigned int sdram_dfii_pi0_wrdata_read(void) {
unsigned int r = csr_readl(0xe0004018L);
r <<= 8;
r |= csr_readl(0xe000401cL);
r <<= 8;
r |= csr_readl(0xe0004020L);
r <<= 8;
r |= csr_readl(0xe0004024L);
return r;
}
static inline void sdram_dfii_pi0_wrdata_write(unsigned int value) {
csr_writel(value >> 24, 0xe0004018L);
csr_writel(value >> 16, 0xe000401cL);
csr_writel(value >> 8, 0xe0004020L);
csr_writel(value, 0xe0004024L);
}
#define CSR_SDRAM_DFII_PI0_RDDATA_ADDR 0xe0004028L
#define CSR_SDRAM_DFII_PI0_RDDATA_SIZE 4
static inline unsigned int sdram_dfii_pi0_rddata_read(void) {
unsigned int r = csr_readl(0xe0004028L);
r <<= 8;
r |= csr_readl(0xe000402cL);
r <<= 8;
r |= csr_readl(0xe0004030L);
r <<= 8;
r |= csr_readl(0xe0004034L);
return r;
}
#define CSR_SDRAM_DFII_PI1_COMMAND_ADDR 0xe0004038L
#define CSR_SDRAM_DFII_PI1_COMMAND_SIZE 1
static inline unsigned char sdram_dfii_pi1_command_read(void) {
unsigned char r = csr_readl(0xe0004038L);
return r;
}
static inline void sdram_dfii_pi1_command_write(unsigned char value) {
csr_writel(value, 0xe0004038L);
}
#define CSR_SDRAM_DFII_PI1_COMMAND_ISSUE_ADDR 0xe000403cL
#define CSR_SDRAM_DFII_PI1_COMMAND_ISSUE_SIZE 1
static inline unsigned char sdram_dfii_pi1_command_issue_read(void) {
unsigned char r = csr_readl(0xe000403cL);
return r;
}
static inline void sdram_dfii_pi1_command_issue_write(unsigned char value) {
csr_writel(value, 0xe000403cL);
}
#define CSR_SDRAM_DFII_PI1_ADDRESS_ADDR 0xe0004040L
#define CSR_SDRAM_DFII_PI1_ADDRESS_SIZE 2
static inline unsigned short int sdram_dfii_pi1_address_read(void) {
unsigned short int r = csr_readl(0xe0004040L);
r <<= 8;
r |= csr_readl(0xe0004044L);
return r;
}
static inline void sdram_dfii_pi1_address_write(unsigned short int value) {
csr_writel(value >> 8, 0xe0004040L);
csr_writel(value, 0xe0004044L);
}
#define CSR_SDRAM_DFII_PI1_BADDRESS_ADDR 0xe0004048L
#define CSR_SDRAM_DFII_PI1_BADDRESS_SIZE 1
static inline unsigned char sdram_dfii_pi1_baddress_read(void) {
unsigned char r = csr_readl(0xe0004048L);
return r;
}
static inline void sdram_dfii_pi1_baddress_write(unsigned char value) {
csr_writel(value, 0xe0004048L);
}
#define CSR_SDRAM_DFII_PI1_WRDATA_ADDR 0xe000404cL
#define CSR_SDRAM_DFII_PI1_WRDATA_SIZE 4
static inline unsigned int sdram_dfii_pi1_wrdata_read(void) {
unsigned int r = csr_readl(0xe000404cL);
r <<= 8;
r |= csr_readl(0xe0004050L);
r <<= 8;
r |= csr_readl(0xe0004054L);
r <<= 8;
r |= csr_readl(0xe0004058L);
return r;
}
static inline void sdram_dfii_pi1_wrdata_write(unsigned int value) {
csr_writel(value >> 24, 0xe000404cL);
csr_writel(value >> 16, 0xe0004050L);
csr_writel(value >> 8, 0xe0004054L);
csr_writel(value, 0xe0004058L);
}
#define CSR_SDRAM_DFII_PI1_RDDATA_ADDR 0xe000405cL
#define CSR_SDRAM_DFII_PI1_RDDATA_SIZE 4
static inline unsigned int sdram_dfii_pi1_rddata_read(void) {
unsigned int r = csr_readl(0xe000405cL);
r <<= 8;
r |= csr_readl(0xe0004060L);
r <<= 8;
r |= csr_readl(0xe0004064L);
r <<= 8;
r |= csr_readl(0xe0004068L);
return r;
}
#define CSR_SDRAM_DFII_PI2_COMMAND_ADDR 0xe000406cL
#define CSR_SDRAM_DFII_PI2_COMMAND_SIZE 1
static inline unsigned char sdram_dfii_pi2_command_read(void) {
unsigned char r = csr_readl(0xe000406cL);
return r;
}
static inline void sdram_dfii_pi2_command_write(unsigned char value) {
csr_writel(value, 0xe000406cL);
}
#define CSR_SDRAM_DFII_PI2_COMMAND_ISSUE_ADDR 0xe0004070L
#define CSR_SDRAM_DFII_PI2_COMMAND_ISSUE_SIZE 1
static inline unsigned char sdram_dfii_pi2_command_issue_read(void) {
unsigned char r = csr_readl(0xe0004070L);
return r;
}
static inline void sdram_dfii_pi2_command_issue_write(unsigned char value) {
csr_writel(value, 0xe0004070L);
}
#define CSR_SDRAM_DFII_PI2_ADDRESS_ADDR 0xe0004074L
#define CSR_SDRAM_DFII_PI2_ADDRESS_SIZE 2
static inline unsigned short int sdram_dfii_pi2_address_read(void) {
unsigned short int r = csr_readl(0xe0004074L);
r <<= 8;
r |= csr_readl(0xe0004078L);
return r;
}
static inline void sdram_dfii_pi2_address_write(unsigned short int value) {
csr_writel(value >> 8, 0xe0004074L);
csr_writel(value, 0xe0004078L);
}
#define CSR_SDRAM_DFII_PI2_BADDRESS_ADDR 0xe000407cL
#define CSR_SDRAM_DFII_PI2_BADDRESS_SIZE 1
static inline unsigned char sdram_dfii_pi2_baddress_read(void) {
unsigned char r = csr_readl(0xe000407cL);
return r;
}
static inline void sdram_dfii_pi2_baddress_write(unsigned char value) {
csr_writel(value, 0xe000407cL);
}
#define CSR_SDRAM_DFII_PI2_WRDATA_ADDR 0xe0004080L
#define CSR_SDRAM_DFII_PI2_WRDATA_SIZE 4
static inline unsigned int sdram_dfii_pi2_wrdata_read(void) {
unsigned int r = csr_readl(0xe0004080L);
r <<= 8;
r |= csr_readl(0xe0004084L);
r <<= 8;
r |= csr_readl(0xe0004088L);
r <<= 8;
r |= csr_readl(0xe000408cL);
return r;
}
static inline void sdram_dfii_pi2_wrdata_write(unsigned int value) {
csr_writel(value >> 24, 0xe0004080L);
csr_writel(value >> 16, 0xe0004084L);
csr_writel(value >> 8, 0xe0004088L);
csr_writel(value, 0xe000408cL);
}
#define CSR_SDRAM_DFII_PI2_RDDATA_ADDR 0xe0004090L
#define CSR_SDRAM_DFII_PI2_RDDATA_SIZE 4
static inline unsigned int sdram_dfii_pi2_rddata_read(void) {
unsigned int r = csr_readl(0xe0004090L);
r <<= 8;
r |= csr_readl(0xe0004094L);
r <<= 8;
r |= csr_readl(0xe0004098L);
r <<= 8;
r |= csr_readl(0xe000409cL);
return r;
}
#define CSR_SDRAM_DFII_PI3_COMMAND_ADDR 0xe00040a0L
#define CSR_SDRAM_DFII_PI3_COMMAND_SIZE 1
static inline unsigned char sdram_dfii_pi3_command_read(void) {
unsigned char r = csr_readl(0xe00040a0L);
return r;
}
static inline void sdram_dfii_pi3_command_write(unsigned char value) {
csr_writel(value, 0xe00040a0L);
}
#define CSR_SDRAM_DFII_PI3_COMMAND_ISSUE_ADDR 0xe00040a4L
#define CSR_SDRAM_DFII_PI3_COMMAND_ISSUE_SIZE 1
static inline unsigned char sdram_dfii_pi3_command_issue_read(void) {
unsigned char r = csr_readl(0xe00040a4L);
return r;
}
static inline void sdram_dfii_pi3_command_issue_write(unsigned char value) {
csr_writel(value, 0xe00040a4L);
}
#define CSR_SDRAM_DFII_PI3_ADDRESS_ADDR 0xe00040a8L
#define CSR_SDRAM_DFII_PI3_ADDRESS_SIZE 2
static inline unsigned short int sdram_dfii_pi3_address_read(void) {
unsigned short int r = csr_readl(0xe00040a8L);
r <<= 8;
r |= csr_readl(0xe00040acL);
return r;
}
static inline void sdram_dfii_pi3_address_write(unsigned short int value) {
csr_writel(value >> 8, 0xe00040a8L);
csr_writel(value, 0xe00040acL);
}
#define CSR_SDRAM_DFII_PI3_BADDRESS_ADDR 0xe00040b0L
#define CSR_SDRAM_DFII_PI3_BADDRESS_SIZE 1
static inline unsigned char sdram_dfii_pi3_baddress_read(void) {
unsigned char r = csr_readl(0xe00040b0L);
return r;
}
static inline void sdram_dfii_pi3_baddress_write(unsigned char value) {
csr_writel(value, 0xe00040b0L);
}
#define CSR_SDRAM_DFII_PI3_WRDATA_ADDR 0xe00040b4L
#define CSR_SDRAM_DFII_PI3_WRDATA_SIZE 4
static inline unsigned int sdram_dfii_pi3_wrdata_read(void) {
unsigned int r = csr_readl(0xe00040b4L);
r <<= 8;
r |= csr_readl(0xe00040b8L);
r <<= 8;
r |= csr_readl(0xe00040bcL);
r <<= 8;
r |= csr_readl(0xe00040c0L);
return r;
}
static inline void sdram_dfii_pi3_wrdata_write(unsigned int value) {
csr_writel(value >> 24, 0xe00040b4L);
csr_writel(value >> 16, 0xe00040b8L);
csr_writel(value >> 8, 0xe00040bcL);
csr_writel(value, 0xe00040c0L);
}
#define CSR_SDRAM_DFII_PI3_RDDATA_ADDR 0xe00040c4L
#define CSR_SDRAM_DFII_PI3_RDDATA_SIZE 4
static inline unsigned int sdram_dfii_pi3_rddata_read(void) {
unsigned int r = csr_readl(0xe00040c4L);
r <<= 8;
r |= csr_readl(0xe00040c8L);
r <<= 8;
r |= csr_readl(0xe00040ccL);
r <<= 8;
r |= csr_readl(0xe00040d0L);
return r;
}
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_UPDATE_ADDR 0xe00040d4L
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_UPDATE_SIZE 1
static inline unsigned char sdram_controller_bandwidth_update_read(void) {
unsigned char r = csr_readl(0xe00040d4L);
return r;
}
static inline void sdram_controller_bandwidth_update_write(unsigned char value) {
csr_writel(value, 0xe00040d4L);
}
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_NREADS_ADDR 0xe00040d8L
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_NREADS_SIZE 3
static inline unsigned int sdram_controller_bandwidth_nreads_read(void) {
unsigned int r = csr_readl(0xe00040d8L);
r <<= 8;
r |= csr_readl(0xe00040dcL);
r <<= 8;
r |= csr_readl(0xe00040e0L);
return r;
}
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_NWRITES_ADDR 0xe00040e4L
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_NWRITES_SIZE 3
static inline unsigned int sdram_controller_bandwidth_nwrites_read(void) {
unsigned int r = csr_readl(0xe00040e4L);
r <<= 8;
r |= csr_readl(0xe00040e8L);
r <<= 8;
r |= csr_readl(0xe00040ecL);
return r;
}
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_DATA_WIDTH_ADDR 0xe00040f0L
#define CSR_SDRAM_CONTROLLER_BANDWIDTH_DATA_WIDTH_SIZE 1
static inline unsigned char sdram_controller_bandwidth_data_width_read(void) {
unsigned char r = csr_readl(0xe00040f0L);
return r;
}
/* spiflash */
#define CSR_SPIFLASH_BASE 0xe0005000L
#define CSR_SPIFLASH_BITBANG_ADDR 0xe0005000L
#define CSR_SPIFLASH_BITBANG_SIZE 1
static inline unsigned char spiflash_bitbang_read(void) {
unsigned char r = csr_readl(0xe0005000L);
return r;
}
static inline void spiflash_bitbang_write(unsigned char value) {
csr_writel(value, 0xe0005000L);
}
#define CSR_SPIFLASH_MISO_ADDR 0xe0005004L
#define CSR_SPIFLASH_MISO_SIZE 1
static inline unsigned char spiflash_miso_read(void) {
unsigned char r = csr_readl(0xe0005004L);
return r;
}
#define CSR_SPIFLASH_BITBANG_EN_ADDR 0xe0005008L
#define CSR_SPIFLASH_BITBANG_EN_SIZE 1
static inline unsigned char spiflash_bitbang_en_read(void) {
unsigned char r = csr_readl(0xe0005008L);
return r;
}
static inline void spiflash_bitbang_en_write(unsigned char value) {
csr_writel(value, 0xe0005008L);
}
/* timer0 */
#define CSR_TIMER0_BASE 0xe0002800L
#define CSR_TIMER0_LOAD_ADDR 0xe0002800L
#define CSR_TIMER0_LOAD_SIZE 4
static inline unsigned int timer0_load_read(void) {
unsigned int r = csr_readl(0xe0002800L);
r <<= 8;
r |= csr_readl(0xe0002804L);
r <<= 8;
r |= csr_readl(0xe0002808L);
r <<= 8;
r |= csr_readl(0xe000280cL);
return r;
}
static inline void timer0_load_write(unsigned int value) {
csr_writel(value >> 24, 0xe0002800L);
csr_writel(value >> 16, 0xe0002804L);
csr_writel(value >> 8, 0xe0002808L);
csr_writel(value, 0xe000280cL);
}
#define CSR_TIMER0_RELOAD_ADDR 0xe0002810L
#define CSR_TIMER0_RELOAD_SIZE 4
static inline unsigned int timer0_reload_read(void) {
unsigned int r = csr_readl(0xe0002810L);
r <<= 8;
r |= csr_readl(0xe0002814L);
r <<= 8;
r |= csr_readl(0xe0002818L);
r <<= 8;
r |= csr_readl(0xe000281cL);
return r;
}
static inline void timer0_reload_write(unsigned int value) {
csr_writel(value >> 24, 0xe0002810L);
csr_writel(value >> 16, 0xe0002814L);
csr_writel(value >> 8, 0xe0002818L);
csr_writel(value, 0xe000281cL);
}
#define CSR_TIMER0_EN_ADDR 0xe0002820L
#define CSR_TIMER0_EN_SIZE 1
static inline unsigned char timer0_en_read(void) {
unsigned char r = csr_readl(0xe0002820L);
return r;
}
static inline void timer0_en_write(unsigned char value) {
csr_writel(value, 0xe0002820L);
}
#define CSR_TIMER0_UPDATE_VALUE_ADDR 0xe0002824L
#define CSR_TIMER0_UPDATE_VALUE_SIZE 1
static inline unsigned char timer0_update_value_read(void) {
unsigned char r = csr_readl(0xe0002824L);
return r;
}
static inline void timer0_update_value_write(unsigned char value) {
csr_writel(value, 0xe0002824L);
}
#define CSR_TIMER0_VALUE_ADDR 0xe0002828L
#define CSR_TIMER0_VALUE_SIZE 4
static inline unsigned int timer0_value_read(void) {
unsigned int r = csr_readl(0xe0002828L);
r <<= 8;
r |= csr_readl(0xe000282cL);
r <<= 8;
r |= csr_readl(0xe0002830L);
r <<= 8;
r |= csr_readl(0xe0002834L);
return r;
}
#define CSR_TIMER0_EV_STATUS_ADDR 0xe0002838L
#define CSR_TIMER0_EV_STATUS_SIZE 1
static inline unsigned char timer0_ev_status_read(void) {
unsigned char r = csr_readl(0xe0002838L);
return r;
}
static inline void timer0_ev_status_write(unsigned char value) {
csr_writel(value, 0xe0002838L);
}
#define CSR_TIMER0_EV_PENDING_ADDR 0xe000283cL
#define CSR_TIMER0_EV_PENDING_SIZE 1
static inline unsigned char timer0_ev_pending_read(void) {
unsigned char r = csr_readl(0xe000283cL);
return r;
}
static inline void timer0_ev_pending_write(unsigned char value) {
csr_writel(value, 0xe000283cL);
}
#define CSR_TIMER0_EV_ENABLE_ADDR 0xe0002840L
#define CSR_TIMER0_EV_ENABLE_SIZE 1
static inline unsigned char timer0_ev_enable_read(void) {
unsigned char r = csr_readl(0xe0002840L);
return r;
}
static inline void timer0_ev_enable_write(unsigned char value) {
csr_writel(value, 0xe0002840L);
}
/* uart */
#define CSR_UART_BASE 0xe0001800L
#define CSR_UART_RXTX_ADDR 0xe0001800L
#define CSR_UART_RXTX_SIZE 1
static inline unsigned char uart_rxtx_read(void) {
unsigned char r = csr_readl(0xe0001800L);
return r;
}
static inline void uart_rxtx_write(unsigned char value) {
csr_writel(value, 0xe0001800L);
}
#define CSR_UART_TXFULL_ADDR 0xe0001804L
#define CSR_UART_TXFULL_SIZE 1
static inline unsigned char uart_txfull_read(void) {
unsigned char r = csr_readl(0xe0001804L);
return r;
}
#define CSR_UART_RXEMPTY_ADDR 0xe0001808L
#define CSR_UART_RXEMPTY_SIZE 1
static inline unsigned char uart_rxempty_read(void) {
unsigned char r = csr_readl(0xe0001808L);
return r;
}
#define CSR_UART_EV_STATUS_ADDR 0xe000180cL
#define CSR_UART_EV_STATUS_SIZE 1
static inline unsigned char uart_ev_status_read(void) {
unsigned char r = csr_readl(0xe000180cL);
return r;
}
static inline void uart_ev_status_write(unsigned char value) {
csr_writel(value, 0xe000180cL);
}
#define CSR_UART_EV_PENDING_ADDR 0xe0001810L
#define CSR_UART_EV_PENDING_SIZE 1
static inline unsigned char uart_ev_pending_read(void) {
unsigned char r = csr_readl(0xe0001810L);
return r;
}
static inline void uart_ev_pending_write(unsigned char value) {
csr_writel(value, 0xe0001810L);
}
#define CSR_UART_EV_ENABLE_ADDR 0xe0001814L
#define CSR_UART_EV_ENABLE_SIZE 1
static inline unsigned char uart_ev_enable_read(void) {
unsigned char r = csr_readl(0xe0001814L);
return r;
}
static inline void uart_ev_enable_write(unsigned char value) {
csr_writel(value, 0xe0001814L);
}
/* uart_phy */
#define CSR_UART_PHY_BASE 0xe0001000L
#define CSR_UART_PHY_TUNING_WORD_ADDR 0xe0001000L
#define CSR_UART_PHY_TUNING_WORD_SIZE 4
static inline unsigned int uart_phy_tuning_word_read(void) {
unsigned int r = csr_readl(0xe0001000L);
r <<= 8;
r |= csr_readl(0xe0001004L);
r <<= 8;
r |= csr_readl(0xe0001008L);
r <<= 8;
r |= csr_readl(0xe000100cL);
return r;
}
static inline void uart_phy_tuning_word_write(unsigned int value) {
csr_writel(value >> 24, 0xe0001000L);
csr_writel(value >> 16, 0xe0001004L);
csr_writel(value >> 8, 0xe0001008L);
csr_writel(value, 0xe000100cL);
}
/* identifier_mem */
#define CSR_IDENTIFIER_MEM_BASE 0xe0002000L
/* constants */
#define ETHMAC_INTERRUPT 3
static inline int ethmac_interrupt_read(void) {
return 3;
}
#define NMI_INTERRUPT 0
static inline int nmi_interrupt_read(void) {
return 0;
}
#define TIMER0_INTERRUPT 2
static inline int timer0_interrupt_read(void) {
return 2;
}
#define UART_INTERRUPT 1
static inline int uart_interrupt_read(void) {
return 1;
}
#define CSR_DATA_WIDTH 8
static inline int csr_data_width_read(void) {
return 8;
}
#define SYSTEM_CLOCK_FREQUENCY 100000000
static inline int system_clock_frequency_read(void) {
return 100000000;
}
#define SPIFLASH_PAGE_SIZE 256
static inline int spiflash_page_size_read(void) {
return 256;
}
#define SPIFLASH_SECTOR_SIZE 65536
static inline int spiflash_sector_size_read(void) {
return 65536;
}
#define READ_LEVELING_BITSLIP 3
static inline int read_leveling_bitslip_read(void) {
return 3;
}
#define READ_LEVELING_DELAY 14
static inline int read_leveling_delay_read(void) {
return 14;
}
#define L2_SIZE 8192
static inline int l2_size_read(void) {
return 8192;
}
#define LOCALIP1 192
static inline int localip1_read(void) {
return 192;
}
#define LOCALIP2 168
static inline int localip2_read(void) {
return 168;
}
#define LOCALIP3 100
static inline int localip3_read(void) {
return 100;
}
#define LOCALIP4 50
static inline int localip4_read(void) {
return 50;
}
#define REMOTEIP1 192
static inline int remoteip1_read(void) {
return 192;
}
#define REMOTEIP2 168
static inline int remoteip2_read(void) {
return 168;
}
#define REMOTEIP3 100
static inline int remoteip3_read(void) {
return 100;
}
#define REMOTEIP4 100
static inline int remoteip4_read(void) {
return 100;
}
#define CAS_LEDS_COUNT 4
static inline int cas_leds_count_read(void) {
return 4;
}
#define CAS_SWITCHES_COUNT 4
static inline int cas_switches_count_read(void) {
return 4;
}
#define CAS_BUTTONS_COUNT 4
static inline int cas_buttons_count_read(void) {
return 4;
}
#define ETHMAC_RX_SLOTS 2
static inline int ethmac_rx_slots_read(void) {
return 2;
}
#define ETHMAC_TX_SLOTS 2
static inline int ethmac_tx_slots_read(void) {
return 2;
}
#define ETHMAC_SLOT_SIZE 2048
static inline int ethmac_slot_size_read(void) {
return 2048;
}
#define CONFIG_CLOCK_FREQUENCY 100000000
static inline int config_clock_frequency_read(void) {
return 100000000;
}
#define CONFIG_CPU_RESET_ADDR 0
static inline int config_cpu_reset_addr_read(void) {
return 0;
}
#define CONFIG_CPU_TYPE "MOR1KX"
static inline const char * config_cpu_type_read(void) {
return "MOR1KX";
}
#define CONFIG_CSR_DATA_WIDTH 8
static inline int config_csr_data_width_read(void) {
return 8;
}
#endif
| [
"robot@timvideos.us"
] | robot@timvideos.us |
dc072f1479bcc4a132e3a205b5f5e296be0668bd | e59481ddff8673ac04c0cb0a0afdffb8a2cab599 | /libnvcore/src/tcp.c | a2e2ff584808e3e9e7c7c3f87229722d30351715 | [] | no_license | u125300/netvirt | 5f8d967f59fd08e8766a8a7d495d96e05cee3f8a | fc16fbe5e7ef98bd9a6f50625b2e29d1de8d7091 | refs/heads/master | 2020-03-09T23:19:33.297681 | 2017-12-22T02:20:28 | 2017-12-22T02:20:28 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 10,204 | c | /*
* NetVirt - Network Virtualization Platform
* Copyright (C) 2009-2014
* Nicolas J. Bouliane <admin@netvirt.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; version 3 of the license.
*
* 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 Affero General Public License for more details
*/
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "logger.h"
#include "netbus.h"
#include "tcp.h"
#define CONN_BACKLOG 512
#define TCPBUS_SERVER 0x1
#define TCPBUS_CLIENT 0x2
#define NUM_EVENTS 64
#define BACKING_STORE 512
#define ION_READ 1
#define ION_WRTE 2
#define ION_EROR 3
static int tcpbus_queue = -1;
static struct epoll_event ep_ev[NUM_EVENTS];
static int setnonblocking(int socket)
{
int ret;
ret = fcntl(socket, F_GETFL);
if (ret >= 0) {
ret = fcntl(socket, F_SETFL, ret | O_NONBLOCK);
}
return ret;
}
static int setreuse(int socket)
{
int ret, on = 1;
ret = setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(int));
return ret;
}
int tcpbus_ion_add(int fd, void *data)
{
struct epoll_event nevent;
int ret;
memset(&nevent, 1, sizeof(struct epoll_event));
nevent.events = EPOLLIN | EPOLLRDHUP | EPOLLERR;
nevent.data.ptr = data;
ret = epoll_ctl(tcpbus_queue, EPOLL_CTL_ADD, fd, &nevent);
if (ret < 0)
jlog(L_NOTICE, "epoll_ctl failed: %s", strerror(errno));
return ret;
}
int tcpbus_ion_new()
{
int epoll_fd;
epoll_fd = epoll_create(BACKING_STORE);
if (epoll_fd < 0)
jlog(L_NOTICE, "epoll_create failed: %s", strerror(errno));
return epoll_fd;
}
static void tcpbus_disconnect(peer_t *peer)
{
int ret;
//close() will cause the socket to be automatically removed from the queue
ret = close(peer->socket);
if (ret < 0) {
jlog(L_NOTICE, "close failed: %u %u %s",
peer->socket, ret, strerror(errno));
return;
}
jlog(L_DEBUG, "client close: %u", peer->socket);
free(peer->buffer);
free(peer);
}
static int tcpbus_send(peer_t *peer, void *data, int len)
{
int ret = 0;
int total = 0;
int byteleft = len;
errno = 0;
while (total < len) {
ret = send(peer->socket, (uint8_t*)data + total, byteleft, 0);
if (errno != 0) {
//jlog(L_ERROR, "tcpbus_send failed: %s", strerror(errno));
}
if (ret == -1 && errno != 11)
return -1;
if (ret != -1) {
total += ret;
byteleft -= ret;
}
}
return ret;
}
static int tcpbus_recv(peer_t *peer)
{
// TODO use dynamic buffer
#define PEER_BUF_SZ 5000
fd_set rfds;
struct timeval tv;
int ret = 0;
FD_ZERO(&rfds);
FD_SET(peer->socket, &rfds);
/* Wait up to one second */
tv.tv_sec = 1;
tv.tv_usec = 0;
ret = select(peer->socket + 1, &rfds, NULL, NULL, &tv);
if (ret == 0) { /* TIMEOUT !*/
jlog(L_NOTICE, "tcpbus_recv TIMEOUT peer->socket(%i)",
peer->socket);
return -1;
}
if (peer->buffer == NULL) {
peer->buffer = calloc(1, PEER_BUF_SZ);
if (peer->buffer == NULL) {
jlog(L_ERROR, "tcpbus_recv calloc failed");
return -1;
}
}
else {
memset(peer->buffer, 0, PEER_BUF_SZ);
}
/*
* XXX It may happen that the buffer is too short,
* in that case we should then re-alloc and move
* the bytes.
*/
ret = recv(peer->socket, peer->buffer, PEER_BUF_SZ, 0);
if (ret < 0)
return -1;
return ret;
}
static void tcpbus_on_input(peer_t *peer)
{
if (peer->on_input)
peer->on_input(peer);
}
static void tcpbus_on_disconnect(peer_t *peer)
{
// inform upper layer
if (peer->on_disconnect)
peer->on_disconnect(peer);
tcpbus_disconnect(peer);
}
static void tcpbus_on_connect(peer_t *peer)
{
int ret, addrlen;
struct sockaddr_in addr;
peer_t *npeer; /* new peer connected */
npeer = calloc(sizeof(peer_t), 1);
addrlen = sizeof(struct sockaddr_in);
npeer->socket = accept(peer->socket, (struct sockaddr *)&addr, (socklen_t *)&addrlen);
if (npeer->socket < 0) {
jlog(L_ERROR, "accept failed: %s", strerror(errno));
free(npeer);
return;
}
ret = setnonblocking(npeer->socket);
if (ret < 0) {
jlog(L_ERROR, "setnonblocking failed: %s", strerror(errno));
free(npeer);
return;
}
npeer->type = TCPBUS_CLIENT;
npeer->on_connect = peer->on_connect;
npeer->on_disconnect = peer->on_disconnect;
npeer->on_input = peer->on_input;
npeer->recv = peer->recv;
npeer->send = peer->send;
npeer->disconnect = peer->disconnect;
npeer->ext_ptr = peer->ext_ptr;
npeer->buffer = NULL;
ret = tcpbus_ion_add(npeer->socket, npeer);
if (ret < 0) {
jlog(L_ERROR, "tcpbus_ion_add failed: %s", strerror(errno));
free(npeer);
return;
}
if (peer->on_connect)
peer->on_connect(npeer);
jlog(L_DEBUG, "successfully added TCP client {%i} on server {%i}", npeer->socket, peer->socket);
}
peer_t *tcpbus_server(const char *in_addr,
const char *port,
void (*on_connect)(peer_t*),
void (*on_disconnect)(peer_t*),
void (*on_input)(peer_t*),
void *ext_ptr)
{
int ret;
struct sockaddr_in addr;
peer_t *peer;
jlog(L_NOTICE, "server ready: %s:%s", in_addr, port);
peer = calloc(sizeof(peer_t), 1);
peer->type = TCPBUS_SERVER;
peer->on_connect = on_connect;
peer->on_disconnect = on_disconnect;
peer->on_input = on_input;
peer->recv = tcpbus_recv;
peer->send = tcpbus_send;
peer->disconnect = tcpbus_disconnect;
peer->buffer = NULL;
peer->ext_ptr = ext_ptr;
peer->socket = socket(PF_INET, SOCK_STREAM, 0);
if (peer->socket < 0) {
jlog(L_NOTICE, "socket failed: %s", strerror(errno));
free(peer);
return NULL;
}
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_port = htons(atoi(port));
addr.sin_addr.s_addr = inet_addr(in_addr);
ret = setreuse(peer->socket);
if (ret < 0) {
jlog(L_NOTICE, "setreuse: %s", strerror(errno));
close(peer->socket);
free(peer);
return NULL;
}
ret = bind(peer->socket, (const struct sockaddr *)&addr, sizeof(const struct sockaddr));
if (ret < 0) {
jlog(L_NOTICE, "bind failed: %s %s", strerror(errno), in_addr);
close(peer->socket);
free(peer);
return NULL;
}
/* The backlog parameter defines the maximum length the
* queue of pending connection may grow to. LISTEN(2)
*/
ret = listen(peer->socket, CONN_BACKLOG);
if (ret < 0) {
jlog(L_NOTICE, "set_nonblocking failed: %s", strerror(errno));
close(peer->socket);
free(peer);
return NULL;
}
ret = tcpbus_ion_add(peer->socket, peer);
if (ret < 0) {
jlog(L_NOTICE, "tcpbus_ion_add failed: %s", strerror(errno));
close(peer->socket);
free(peer);
return NULL;
}
return peer;
}
peer_t *tcpbus_client(const char *addr,
const char *port,
void (*on_disconnect)(peer_t*),
void (*on_input)(peer_t*))
{
fd_set wfds;
struct timeval tv;
int ret = 0;
int optval = 0;
socklen_t optlen = 0;
struct sockaddr_in addr_in;
peer_t *peer = NULL;
FD_ZERO(&wfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
peer = calloc(sizeof(peer_t), 1);
peer->socket = socket(PF_INET, SOCK_STREAM, 0);
if (peer->socket == -1) {
jlog(L_ERROR, "socket failed: %s", strerror(errno));
free(peer);
return NULL;
}
ret = setnonblocking(peer->socket);
if (ret < 0) {
jlog(L_ERROR, "setnonblocking failed: %s", strerror(errno));
close(peer->socket);
free(peer);
return NULL;
}
memset(&addr_in, 0, sizeof(struct sockaddr_in));
addr_in.sin_family = AF_INET;
addr_in.sin_port = htons(atoi(port));
addr_in.sin_addr.s_addr = inet_addr(addr);
FD_SET(peer->socket, &wfds);
errno = 0;
ret = connect(peer->socket, (const struct sockaddr *)&addr_in, sizeof(const struct sockaddr));
if (ret == -1) {
if (errno == EINPROGRESS) {
/* The socket is non-blocking and the
* connection cannot be completed immediately.
*/
ret = select(peer->socket + 1, NULL, &wfds, NULL, &tv);
if (ret == 0) { /* TIMEOUT */
jlog(L_DEBUG, "connect timed out");
close(peer->socket);
free(peer);
return NULL;
}
else {
optlen = (socklen_t)sizeof(optval);
/* use getsockopt(2) with SO_ERROR to check for error conditions */
ret = getsockopt(peer->socket, SOL_SOCKET, SO_ERROR, &optval, &optlen);
if (ret == -1) {
jlog(L_DEBUG, "getsockopt failed: %s");
close(peer->socket);
free(peer);
return NULL;
}
if (optval != 0) { /* NOT CONNECTED ! TIMEOUT... */
jlog(L_DEBUG, "connect timed out");
close(peer->socket);
free(peer);
return NULL;
}
else {
/* ... connected, we continue ! */
}
}
}
else {
jlog(L_DEBUG, "connect faield: %s", strerror(errno));
close(peer->socket);
free(peer);
return NULL;
}
}
peer->type = TCPBUS_CLIENT;
peer->on_disconnect = on_disconnect;
peer->on_input = on_input;
peer->send = tcpbus_send;
peer->recv = tcpbus_recv;
peer->disconnect = tcpbus_disconnect;
peer->buffer = NULL;
ret = tcpbus_ion_add(peer->socket, peer);
if (ret < 0) {
jlog(L_NOTICE, "ion_add failed: %s", strerror(errno));
close(peer->socket);
free(peer);
return NULL;
}
return peer;
}
void tcpbus_fini()
{
if (tcpbus_queue != -1) {
close(tcpbus_queue);
}
}
void tcpbus_init()
{
jlog(L_NOTICE, "init tcp bus");
tcpbus_queue = tcpbus_ion_new();
}
int tcpbus_ion_poke()
{
int nfd, i;
peer_t *peer = NULL;
nfd = epoll_wait(tcpbus_queue, ep_ev, NUM_EVENTS, 1);
if (nfd < 0) {
jlog(L_NOTICE, "epoll_wait failed: %s", strerror(errno));
return -1;
}
for (i = 0; i < nfd; i++) {
peer = ep_ev[i].data.ptr;
if (peer == NULL) {
continue;
}
if (ep_ev[i].events & EPOLLRDHUP) {
tcpbus_on_disconnect(peer);
} else if (ep_ev[i].events & EPOLLERR) {
tcpbus_on_disconnect(peer);
} else if (ep_ev[i].events & EPOLLIN) {
if (peer->type == TCPBUS_SERVER) {
tcpbus_on_connect(peer);
} else if (peer->type == TCPBUS_CLIENT) {
tcpbus_on_input(peer);
}
}
}
return nfd;
}
| [
"nicboul@gmail.com"
] | nicboul@gmail.com |
dcb0658c95f02fc43a88e00c3d2fa7583389fe68 | a80406f1e85578d3a7f060a022cc3eaa067ca1fa | /ADC_without_DMA_example/src/main.c | 78abe37ce72954f15b8910e6fe60ad81f208b384 | [] | no_license | bmaxfie/Cerulean-Hardware | c13ffa8f9189c875257bfbd5a8e92fa35a745876 | cd9c01953d2f09cfc32970e9381c2d01791d7f36 | refs/heads/master | 2021-01-20T23:09:53.655000 | 2015-08-07T01:57:42 | 2015-08-07T01:57:42 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 3,407 | c | #include "stm32f4_discovery.h"
#include "stm32f4xx_conf.h"
#include <misc.h> // I recommend you have a look at these in the ST firmware folder
#include <stm32f4xx_usart.h> // under Libraries/STM32F4xx_StdPeriph_Driver/inc and src
#include <stm32f4xx_dma.h>
#include <stm32f4xx_adc.h>
void Delay(__IO uint32_t nCount) {
while(nCount--) {
}
}
void init_DMA_ADC3(uint16_t *array, uint16_t size)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
ADC_StructInit(&ADC_InitStructure);
/**
Set up the clocks are needed for the ADC
*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);
/* Analog channel configuration : PF3, 4, 5, 10*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF, &GPIO_InitStructure);
/**
Config the ADC3
*/
ADC_DeInit();
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //continuous conversion
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_NbrOfConversion = size;
ADC_InitStructure.ADC_ScanConvMode = DISABLE; // 1=scan more that one channel in group
ADC_Init(ADC3,&ADC_InitStructure);
ADC_RegularChannelConfig(ADC3, ADC_Channel_3, 1, ADC_SampleTime_144Cycles);//PF3
ADC_RegularChannelConfig(ADC3, ADC_Channel_4, 2, ADC_SampleTime_144Cycles);//PF4
ADC_RegularChannelConfig(ADC3, ADC_Channel_5, 3, ADC_SampleTime_144Cycles);//PF5
ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 4, ADC_SampleTime_144Cycles);//PF10
/* Now do the setup */
ADC_Init(ADC1, &ADC_InitStructure);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
}
void main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOD Periph clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/* Configures the leds and the read/write pin on D1 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12| GPIO_Pin_13 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
uint8_t adc_value = 0;
while(1)
{
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
GPIO_ResetBits(GPIOD, GPIO_Pin_12);
GPIO_ResetBits(GPIOD, GPIO_Pin_13);
Delay(0xffffff);
GPIO_SetBits(GPIOD, GPIO_Pin_10);
GPIO_SetBits(GPIOD, GPIO_Pin_11);
GPIO_SetBits(GPIOD, GPIO_Pin_12);
GPIO_SetBits(GPIOD, GPIO_Pin_13);
Delay(0xffffff);
}
} | [
"rmcbee@purdue.edu"
] | rmcbee@purdue.edu |
facce1fa1160a1984c6a534b2bbe99b28dd3921d | 7270fa8a47187d7675d5ebec2b00615ea8a42a83 | /Primeiros Passos/Resumo_De_Conteudo/estruturasDeRepeticao.c | 02e714f6a53d5a2e059276d1df85e12fb13bfe92 | [] | no_license | JavelFreitas/Estrutura-de-Dados-2019.1 | 1fc5fecb74e7008cfdd5dfec84da0ca2bcc1d2e4 | 6a8327499605af2f7e8fbe0b0422b7877d63785b | refs/heads/master | 2020-04-29T05:46:45.102429 | 2019-06-18T21:41:46 | 2019-06-18T21:41:46 | 175,893,980 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 930 | c | #include <stdio.h>
// Estruturas de Repetição for, while, do while;
int main(){
int x = 0, soma = 0;
printf("\n");
for(int i = 0;i<=10; i++){ //mais usado quando se sabe o numero de repeticoes Ex: Vetores e Matrizes
printf("Digite o %d numero\n", i);
scanf("%d", &x);
soma += x;
}
printf("O valor de x eh %d\n", x);
printf("A soma de todos os valores eh %d\n\n", soma);
x = 0;
while(x != 10){ //mais usado quando o numero de repeticoes eh incerto
x++;
printf("O valor atual de x eh %d\n", x);
}
printf("\n");
x = 0;
int tentativas = 0;
do{
printf("Adivinhe o numero entre 1 e 10!\n");
scanf("%d", &x);
tentativas++;
if(x == 5){
printf("5! Voce achou o numero :]\n");
printf("seu numero de tentativas foi %d\n", tentativas);
}
}while(x != 5);
return 0;
} | [
"javelqueiroz@outlook.com"
] | javelqueiroz@outlook.com |
251ea430501509ed86384fe2f970ff087c13fafe | 075ed80a041ae98a7ae9bb20a9551b4be6493a86 | /d/Empire/islands/ruins.h | d01dc56ff8531004970ff65aa55b5d4cf58ce167 | [] | no_license | simonthoresen/viking | 959c53f97c5dcb6c242d22464e3d7e2c42f65c66 | c3b0de23a8cfa89862000d2c8bc01aaf8bf824ea | refs/heads/master | 2021-03-12T21:54:46.636466 | 2014-10-10T07:28:55 | 2014-10-10T07:28:55 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 3,902 | h | #ifndef RUINS_H
#define RUINS_H
#include "/d/Empire/empire.h"
#define RUN_DIR (EMP_DIR_ISLANDS + "ruins/")
#define RUN_DIR_DAEMONS (RUN_DIR + "daemons/")
#define RUN_DIR_ETC (RUN_DIR + "etc/")
#define RUN_DIR_OBJ (RUN_DIR + "obj/")
#define RUN_DIR_ROOMS (RUN_DIR + "rooms/")
#define RUN_DIR_STD (RUN_DIR + "std/")
#define RUN_ISLAND (RUN_DIR + "island")
#define RUN_MAP (RUN_DIR + "map")
#define RUN_MAP_AEGIR ('A')
#define RUN_MAP_FORNJOT ('F')
#define RUN_MAP_KARI ('K')
#define RUN_MAP_LOGI ('L')
#define RUN_MAP_RUIN ('r')
#define RUN_MAP_RUNESTONE ('T')
#define RUN_MAP_RUBBLE ('u')
#define RUN_MAP_WALL ('w')
#define RUN_C_AEGIR (RUN_DIR_OBJ + "aegir")
#define RUN_C_AEGIR_DAUGHTER (RUN_DIR_OBJ + "aegir_daughter")
#define RUN_C_AEGIR_WIFE (RUN_DIR_OBJ + "aegir_wife")
#define RUN_C_FORNJOT (RUN_DIR_OBJ + "fornjot")
#define RUN_C_FORNJOT_GUARD (RUN_DIR_OBJ + "fornjot_guard")
#define RUN_C_FORNJOT_RUNESTONE (RUN_DIR_OBJ + "fornjot_runestone")
#define RUN_C_FORNJOT_SHADE (RUN_DIR_OBJ + "fornjot_shade")
#define RUN_C_KARI (RUN_DIR_OBJ + "kari")
#define RUN_C_KARI_ACOLYTE (RUN_DIR_OBJ + "kari_acolyte")
#define RUN_C_KARI_TORNADO (RUN_DIR_OBJ + "kari_tornado")
#define RUN_C_LOGI (RUN_DIR_OBJ + "logi")
#define RUN_C_LOGI_DAUGHTER1 (RUN_DIR_OBJ + "logi_daughter1")
#define RUN_C_LOGI_DAUGHTER2 (RUN_DIR_OBJ + "logi_daughter2")
#define RUN_C_LOGI_FIRE (RUN_DIR_OBJ + "logi_fire")
#define RUN_C_LOGI_WIFE (RUN_DIR_OBJ + "logi_wife")
#define RUN_D_RUINS (RUN_DIR_DAEMONS + "ruinsd")
#define RUN_I_LOGI_DAUGHTER (RUN_DIR_STD + "logi_daughter")
#define RUN_I_MONSTER (RUN_DIR_STD + "monster")
#define RUN_I_ROOM (RUN_DIR_STD + "room")
#define RUN_I_STATUE (RUN_DIR_STD + "statue")
/* balancing constants */
#define AEGIR_DAUGHTER_HEAL (2500)
#define AEGIR_DAUGHTER_SPAWN_INTERVAL (30)
#define AEGIR_DAUGHTER_STUN_DAMAGE (50 + random(25))
#define AEGIR_DAUGHTER_STUN_DURATION (2)
#define AEGIR_THROW_COUNTDOWN_BEATS (5)
#define AEGIR_THROW_DAMAGE1 (50 + random(50))
#define AEGIR_THROW_DAMAGE2 (25 + random(25))
#define AEGIR_THROW_FORCE (10)
#define AEGIR_WIFE_TICK_HEAL (250)
#define AEGIR_WIFE_TICK_SECS (1)
#define FORNJOT_RUNESTONE_NUM_GUARDS (2)
#define FORNJOT_RUNESTONE_RESPAWN_DELAY (450)
#define FORNJOT_RUNESTONE_SPAWN_DELAY (2)
#define FORNJOT_SHADE_INVULN_SECS (3)
#define FORNJOT_SHADE_SPAWN_DELAY (2)
#define FORNJOT_SHADE_TICK_HEAL (10)
#define FORNJOT_SHADE_TICK_SECS (2)
#define FORNJOT_STUN_COUNTDOWN_BEATS (30)
#define FORNJOT_STUN_DURATION_SECS (30)
#define FORNJOT_VULNERABILITY_SECS (30)
#define KARI_ACOLYTE_SPAWN_INTERVAL (45)
#define KARI_TORNADO_DAMAGE (25 + random(25))
#define KARI_TORNADO_DURATION_SECS (120)
#define KARI_TORNADO_SPAWN_INTERVAL (30)
#define LOGI_DAUGHTER_THROW_DAMAGE (50 + random(50))
#define LOGI_DAUGHTER_THROW_FORCE (1)
#define LOGI_FIRE_INC_PER_BEAT (25)
#define LOGI_FIRE_DURATION_SECS (10)
#define LOGI_RAIN_INTERVAL (3)
#define LOGI_RAIN_DAMAGE (50 + random(50))
#define LOGI_SPAWN_DAUGHTERS_AT (75)
#define LOGI_SPAWN_WIFE_AT (10)
#define LOGI_THROW_CHANCE (5)
#define LOGI_THROW_DAMAGE (15 + random(15))
#define LOGI_THROW_FORCE (2)
#define LOGI_WIFE_AOE_DAMAGE (25)
#endif
| [
"simon@hult-thoresen.com"
] | simon@hult-thoresen.com |
06bb553043e5017e321d05fe82bf2d80068b7df6 | 37683f8abb4d01de29ebee70b201b18d2710da6e | /ft_putnbr.c | 6d9a885a1656cbca40f9684fc20d13dbf137d72a | [] | no_license | sumaseko/libft | 15c96c346d3b16a4ccb61218528750c67aedfda9 | cc373c187ed371aff95a1ef1023c0e8762d5909e | refs/heads/master | 2020-05-23T22:40:40.277937 | 2019-06-20T06:37:01 | 2019-06-20T06:37:01 | 186,978,784 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,151 | c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sumaseko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/12 14:13:05 by sumaseko #+# #+# */
/* Updated: 2019/06/14 15:37:44 by sumaseko ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr(int n)
{
if (n == -2147483648)
ft_putstr("-2147483648");
else if (n < 0)
{
ft_putchar('-');
ft_putnbr(-n);
}
else if (n >= 10)
{
ft_putnbr(n / 10);
ft_putchar(n % 10 + '0');
}
else
ft_putchar(n + '0');
}
| [
"sumaseko@c4r9s8.wethinkcode.co.za"
] | sumaseko@c4r9s8.wethinkcode.co.za |
cb67316c31f52aa2d5c9bb78508f887254be02b4 | 86a35f1d288b74e40df09fbe6824cdaf9ac4cd09 | /cPractice/2019-3-9.c | 48cf88cfe23adb5569806b8ec65faac2b3f3fec7 | [] | no_license | South-Walker/ACM | d94d2660dd1f644606cc4273a17f96ad89129db0 | 69719343d4f424b3060ddc1c247577b213daf6a6 | refs/heads/master | 2020-04-06T06:28:06.663486 | 2019-03-21T12:43:51 | 2019-03-21T12:43:51 | 82,779,207 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 4,175 | c | #include <stdio.h>
int howmany(char*x,int xcount,char*guo,int guocount)
{
int i,j=0;
int r=0;
for(i=0;i<guocount;i++)
{
if(x[j]==guo[i])
{
r++;
}
j++;
if(j>=xcount)
{
j=0;
}
}
return r;
}
int q1()
{
char*a="ABC";
char*b="BABC";
char*c="CCAABB";
int n;
int ia,ib,ic;
int max;
char guo[200];
scanf("%d",&n);
scanf("%s",guo);
ia=howmany(a,3,guo,n);
ib=howmany(b,4,guo,n);
ic=howmany(c,6,guo,n);
max=(ia>ib)?ia:ib;
max=(max>ic)?max:ic;
printf("%d\n",max);
if(max==ia)
{
printf("Adrian\n");
}
if(max==ib)
{
printf("Bruno\n");
}
if(max==ic)
{
printf("Goran\n");
}
return 0;
}
typedef struct
{
int havetime;
int no;
}guest;
int cmp(const void*a,const void*b)
{
return ((guest*)a)->havetime-((guest*)b)->havetime;
}
int q2()
{
int guestnum;
int i,j;
int a,b;
guest guests[10000];
scanf("%d",&guestnum);
for(i=0;i<guestnum;i++)
{
scanf("%d%d",&a,&b);
guests[i].no=i+1;
guests[i].havetime=a+b;
}
qsort(guests,guestnum,sizeof(guests[0]),&cmp);
for(i=0;i<guestnum;i++)
{
printf("%d ",guests[i].no);
}
return 0;
}
typedef struct node
{
int ai;
int time;
struct node*left;
struct node*right;
}tree;
tree* create(int now)
{
tree*r=(tree*)malloc(sizeof(tree));
r->ai=now;
r->time=1;
r->left=NULL;
r->right=NULL;
return r;
}
void add(tree*root,int now)
{
if(root->ai==now)
{
root->time++;
return;
}
if(root->ai<now)
{
if(root->right!=NULL)
{
add(root->right,now);
return;
}
else
{
root->right=create(now);
return;
}
}
else
{
if(root->left!=NULL)
{
add(root->left,now);
return;
}
else
{
root->left=create(now);
return;
}
}
}
int allxian=0;
void searchall(tree*root)
{
if(root==NULL)
return;
searchall(root->left);
searchall(root->right);
if(root->time%2!=0)
{
allxian++;
}
}
int q3()
{
int alla[100001];
int allcount=0;
int i,j;
int now;
tree*root;
scanf("%d",&allcount);
scanf("%d",&now);
root=create(now);
for(i=0;i<allcount-1;i++)
{
scanf("%d",&now);
add(root,now);
}
searchall(root);
printf("%d",allxian);
return 0;
}
typedef struct
{
int time;
int value;
}xiancao;
xiancao all[20];
int check[20];
int max=0;
int count;
void search(int timenow,int value)
{
int i;
for(i=0;i<count;i++)
{
if(check[i]==0)
{
if(timenow>=all[i].time)
{
check[i]=1;
search(timenow-all[i].time,value+all[i].value);
check[i]=0;
}
}
}
max=(value>max)?value:max;
}
int q4()
{
int alltime;
int i,j;
int a,b;
scanf("%d%d",&alltime,&count);
for(i=0;i<count;i++)
{
scanf("%d%d",&a,&b);
all[i].time=a;
all[i].value=b;
check[i]=0;
}
search(alltime,0);
printf("%d",max);
return 0;
}
long long all[30000];
long long max=999999999;
int allcount=0;
int check(long long num)
{
int have3=0;
int have5=0;
int have7=0;
long long now=num;
while(now!=0)
{
if(now%10==3)
{
have3=1;
}
else if(now%10==5)
{
have5=1;
}
else
{
have7=1;
}
now/=10;
}
if(have3==1&&have5==1&&have7==1)
{
return 1;
}
return 0;
}
void getall(long long now)
{
if(now>max)
return;
if(check(now)==1)
{
all[allcount]=now;
allcount++;
}
getall(now*10+3);
getall(now*10+5);
getall(now*10+7);
}
int cmp(const void*a,const void*b)
{
long long la=*(long long*)a;
long long lb=*(long long*)b;
if(la>=lb)
return 1;
else
return -1;
}
int q5()
{
int i,j;
long long time;
getall(3);
getall(5);
getall(7);
qsort(all,allcount,sizeof(all[0]),&cmp);
scanf("%lld",&time);
for(i=0;i<allcount;i++)
{
if(all[i]<=time)
{
continue;
}
else
{
break;
}
}
printf("%d",i);
return 0;
}
long long booknum[51];
int aorb(long long n,long long k)
{
long long ppn,pn;
if(n==0||n==1)
{
return n;
}
ppn=booknum[n-2];
pn=booknum[n-1];
if(k<=ppn)
{
return aorb(n-2,k);
}
else
{
return aorb(n-1,k-ppn);
}
}
int q6()
{
long long a1=1,a2=1,now;
long long n,k;
int i,j;
int num;
booknum[0]=1;
booknum[1]=1;
for(i=2;i<51;i++)
{
now=a1+a2;
booknum[i]=now;
a1=a2;a2=now;
}
scanf("%d",&num);
while(num)
{
num--;
scanf("%lld %lld",&n,&k);
if(aorb(n,k)==0)
{
printf("a\n");
}
else
{
printf("b\n");
}
}
return 0;
}
| [
"506830915@qq.com"
] | 506830915@qq.com |
719af10cb7e2beaf47f5ddf4bf0ca31f0f9ae6d6 | 1da17c4632bedb3afb80a7d6cd85e9427d8566b4 | /usbDataTransferDll/Hpp/Resource.h | 601c00e6759faa02d501b462617d075013a23c7e | [] | no_license | luoshutu/usbApplication | 1293c214c84acf92d3af45b50de8f06398747d9b | 17ca7ee9ba247b519eebea9cb64bf04813786252 | refs/heads/master | 2023-04-08T19:51:41.113209 | 2021-04-26T06:32:56 | 2021-04-26T06:32:56 | 350,678,566 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,474 | h | //{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by BulkLoop.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_BULKLOOP_DIALOG 102
#define IDR_MAINFRAME 128
#define IDI_CYICON 132
#define IDC_XFERSIZE_EDIT 1005
#define IDC_SEED_EDIT 1006
#define IDC_OUT_COMBOX 1011
#define IDC_IN_COMBOX 1012
#define IDC_STOP_ON_ERROR_CHKBOX 1013
#define IDC_SUCCESS_LABEL 1014
#define IDC_FAILURE_LABEL 1015
#define IDC_START_BTN 1016
#define IDC_RESET_BTN 1022
#define IDC_FILLPATTERN_COMBOX 1023
#define IDC_STATUS_LABEL 1024
#define IDC_LOOPBACK 1033
#define IDC_INONLY 1034
#define IDC_OUTONLY 1035
#define IDC_DEVICELIST_COMBOX 1036
#define IDC_REFRESH_BTN 1037
#define IDC_TEST_BTN 1038
#define IDC_DISABLE_TIMEOUT 1039
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 134
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1040
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
| [
"luoshutu@qq.com"
] | luoshutu@qq.com |
fb4558fbc0b222dca9dcba996d89e1ad665ab2cc | 976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f | /source/linux/drivers/spi/extr_spi-uniphier.c_uniphier_spi_set_cs.c | 458bc9b8f45325a13fb4044598087ddddbafad96 | [] | no_license | isabella232/AnghaBench | 7ba90823cf8c0dd25a803d1688500eec91d1cf4e | 9a5f60cdc907a0475090eef45e5be43392c25132 | refs/heads/master | 2023-04-20T09:05:33.024569 | 2021-05-07T18:36:26 | 2021-05-07T18:36:26 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,085 | c | #define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
/* Type definitions */
typedef int /*<<< orphan*/ u32 ;
struct uniphier_spi_priv {scalar_t__ base; } ;
struct spi_device {int /*<<< orphan*/ master; } ;
/* Variables and functions */
scalar_t__ SSI_FPS ;
int /*<<< orphan*/ SSI_FPS_FSPOL ;
int /*<<< orphan*/ readl (scalar_t__) ;
struct uniphier_spi_priv* spi_master_get_devdata (int /*<<< orphan*/ ) ;
int /*<<< orphan*/ writel (int /*<<< orphan*/ ,scalar_t__) ;
__attribute__((used)) static void uniphier_spi_set_cs(struct spi_device *spi, bool enable)
{
struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master);
u32 val;
val = readl(priv->base + SSI_FPS);
if (enable)
val |= SSI_FPS_FSPOL;
else
val &= ~SSI_FPS_FSPOL;
writel(val, priv->base + SSI_FPS);
} | [
"brenocfg@gmail.com"
] | brenocfg@gmail.com |
3288da4ec86599bf493a66e7bc98c5ccfb2fc32a | f8e6f6c6fa9495561653ca41777d754e431ad543 | /demos/pc/windows/common/application_code/aws_entropy_hardware_poll.c | bc0661b587b5f29129c0b87ea8c254b139a32df4 | [
"MIT"
] | permissive | roedan/amazon-freertos | b3750673f345a6985bf1a988babf1b5c1c326a19 | 52edb7c79ee1691088208ad5fdd6e062bbe8151b | refs/heads/master | 2021-08-24T06:32:46.955449 | 2017-12-07T17:47:06 | 2017-12-07T17:47:06 | 113,350,623 | 1 | 2 | null | 2017-12-06T18:05:40 | 2017-12-06T18:05:39 | null | UTF-8 | C | false | false | 2,217 | c | /*
* Amazon FreeRTOS V1.0.0
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. If you wish to use our Amazon
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#include <Windows.h>
#include <wincrypt.h>
#include "mbedtls/entropy.h"
/*-----------------------------------------------------------*/
int mbedtls_hardware_poll( void * data,
unsigned char * output,
size_t len,
size_t * olen )
{
int lStatus = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
HCRYPTPROV hProv = 0;
/* Unferenced parameter. */
( void ) data;
/*
* This is port-specific for the Windows simulator, so just use Crypto API.
*/
if( TRUE == CryptAcquireContextA(
&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) )
{
if( TRUE == CryptGenRandom( hProv, len, output ) )
{
lStatus = 0;
*olen = len;
}
CryptReleaseContext( hProv, 0 );
}
return lStatus;
}
| [
"aggarg@amazon.com"
] | aggarg@amazon.com |
8f7a4f718cacb61bf79567f999ca390b442e267a | 70f63f6b356c665842e359469a89287106a5a754 | /src/mudlib/d/limbo/comun/habitacion/limbo/newbie/mina/cruce01.c | 83db9c75621396fa9731e91ffd0d8eb7401f3da3 | [] | no_license | DPrenC/endor-mud | 2aebc7af384db692c7dbc6c0a0dbb3c600e93ecc | 3ca7605715ce2c02734c68766470f5d581b9fc98 | refs/heads/master | 2021-01-21T18:53:26.493953 | 2017-05-21T23:04:36 | 2017-05-21T23:04:36 | null | 0 | 0 | null | null | null | null | ISO-8859-1 | C | false | false | 1,462 | c | /*
DESCRIPCION : cruce entre galerias
FICHERO : /d/limbo/comun/habitacion/limbo/newbie/mina/cruce01.c
MODIFICACION : 05-08-98 [Angor@Simauria] Creacion
--------------------------------------------------------------------------------
*/
#include "./path.h"
inherit ROOM;
create()
{
::create();
SetIntShort("un cruce entre galerías");
SetIntLong("Has llegado a un cruce. En este punto coinciden varias de las galerías de este nivel de la mina. Además, "
"sobre tu cabeza se alza un agujero oscuro cuya altura no adivinas y que parece ser uno de los pozos de esta mina. "
"Una escalera fijada en la pared del pozo y que baja hasta el suelo de la galería permite ascender por él.\n");
AddDetail(({"cruce"}), QueryIntLong());
AddDetail(({"escalera"}),"Una larga escalera de madera está fijada firmemente a la pared del pozo. Permite subir por "
"él.\n");
AddDetail(({"pozo"}),"Sobre este cruce de galerías no hay techo, sino un agujero oscuro en la roca. Es uno de los "
"pozos excavados en esta mina para llegar de unos niveles a otros.\n");
SetIntNoise("Oyes el eco de tus pasos y el goteo del agua.\n");
SetIntSmell("Huele a tierra mojada.\n");
SetLocate("mina de isla Limbo");
SetIndoors(1);
SetIntBright(0);
AddExit("este",MINA("cruce00"));
AddExit("sur",MINA("cruce02"));
AddExit("arriba",MINA("pozo18"));
AddItem(PNJ("osezno"), REFRESH_DESTRUCT, 1);
}
| [
"ea5gna@gmail.com"
] | ea5gna@gmail.com |
7cd20c868663d48a74d8b8d27b3991d400f448a1 | fad392b7b1533103a0ddcc18e059fcd2e85c0fda | /install/px4_msgs/include/px4_msgs/msg/log_message__functions.h | 245de04503400d7c12f7eaa72d72494f16b71158 | [] | no_license | adamdai/px4_ros_com_ros2 | bee6ef27559a3a157d10c250a45818a5c75f2eff | bcd7a1bd13c318d69994a64215f256b9ec7ae2bb | refs/heads/master | 2023-07-24T18:09:24.817561 | 2021-08-23T21:47:18 | 2021-08-23T21:47:18 | 399,255,215 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 107 | h | /home/navlab-tx2-4/px4_ros_com_ros2/build/px4_msgs/rosidl_generator_c/px4_msgs/msg/log_message__functions.h | [
"adamdai97@gmail.com"
] | adamdai97@gmail.com |
b092bce7099982554849a2c8e670a2a0e043a05d | 0282ff3f0f1094a1795181f5a242e2ece073f480 | /Templates/C.c | 75b30dc05cec53fa92eb4b60a66bd595ce6bf1b6 | [] | no_license | Zerva5/dotfiles | 14b0bce3a24852874c6ef10dc9538dc9e9178f95 | b0947f425e6de93d026d2a2af42e2dcc402b6f1b | refs/heads/master | 2023-08-07T03:51:41.322584 | 2023-07-25T18:41:55 | 2023-07-25T18:41:55 | 191,096,996 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 86 | c | #include <stdio.h>
int main(int argc, char** argv) {
printf("hello world!\n");
}
| [
"lucasmmayall@gmail.com"
] | lucasmmayall@gmail.com |
4568c938a6b922186789c8e8cc0bff973b55bc6e | bb108c3ea7d235e6fee0575181b5988e6b6a64ef | /mame/src/emu/cpu/sh4/sh4comn.c | 72730abeca28e841c9cdc3b34a54f07b94aed926 | [
"MIT"
] | permissive | clobber/MAME-OS-X | 3c5e6058b2814754176f3c6dcf1b2963ca804fc3 | ca11d0e946636bda042b6db55c82113e5722fc08 | refs/heads/master | 2021-01-20T05:31:15.086981 | 2013-04-17T18:42:40 | 2013-04-17T18:42:40 | 3,805,274 | 15 | 8 | null | 2013-04-17T18:42:41 | 2012-03-23T04:23:01 | C | UTF-8 | C | false | false | 37,252 | c | /*****************************************************************************
*
* sh4comn.c
*
* SH-4 non-specific components
*
*****************************************************************************/
#include "emu.h"
#include "debugger.h"
#include "sh4.h"
#include "sh4regs.h"
#include "sh4comn.h"
static const int tcnt_div[8] = { 4, 16, 64, 256, 1024, 1, 1, 1 };
static const int rtcnt_div[8] = { 0, 4, 16, 64, 256, 1024, 2048, 4096 };
static const int daysmonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static const int dmasize[8] = { 8, 1, 2, 4, 32, 0, 0, 0 };
static const UINT32 exception_priority_default[] = { EXPPRI(1,1,0,0), EXPPRI(1,2,0,1), EXPPRI(1,1,0,2), EXPPRI(1,3,0,3), EXPPRI(1,4,0,4),
EXPPRI(2,0,0,5), EXPPRI(2,1,0,6), EXPPRI(2,2,0,7), EXPPRI(2,3,0,8), EXPPRI(2,4,0,9), EXPPRI(2,4,0,10), EXPPRI(2,4,0,11), EXPPRI(2,4,0,12),
EXPPRI(2,5,0,13), EXPPRI(2,5,0,14), EXPPRI(2,6,0,15), EXPPRI(2,6,0,16), EXPPRI(2,7,0,17), EXPPRI(2,7,0,18), EXPPRI(2,8,0,19),
EXPPRI(2,9,0,20), EXPPRI(2,4,0,21), EXPPRI(2,10,0,22), EXPPRI(3,0,16,SH4_INTC_NMI) };
static const int exception_codes[] = { 0x000, 0x020, 0x000, 0x140, 0x140, 0x1E0, 0x0E0, 0x040, 0x0A0, 0x180, 0x1A0, 0x800, 0x820, 0x0E0,
0x100, 0x040, 0x060, 0x0A0, 0x0C0, 0x120, 0x080, 0x160, 0x1E0, 0x1C0, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x240, 0x2A0, 0x300, 0x360, 0x600, 0x620, 0x640, 0x660, 0x680, 0x6A0, 0x780, 0x7A0, 0x7C0,
0x7E0, 0x6C0, 0xB00, 0xB80, 0x400, 0x420, 0x440, 0x460, 0x480, 0x4A0, 0x4C0, 0x4E0, 0x500, 0x520, 0x540, 0x700, 0x720, 0x740, 0x760,
0x560, 0x580, 0x5A0 };
static const UINT16 tcnt[] = { TCNT0, TCNT1, TCNT2 };
static const UINT16 tcor[] = { TCOR0, TCOR1, TCOR2 };
static const UINT16 tcr[] = { TCR0, TCR1, TCR2 };
void sh4_change_register_bank(sh4_state *sh4, int to)
{
int s;
if (to) // 0 -> 1
{
for (s = 0;s < 8;s++)
{
sh4->rbnk[0][s] = sh4->r[s];
sh4->r[s] = sh4->rbnk[1][s];
}
}
else // 1 -> 0
{
for (s = 0;s < 8;s++)
{
sh4->rbnk[1][s] = sh4->r[s];
sh4->r[s] = sh4->rbnk[0][s];
}
}
}
void sh4_swap_fp_registers(sh4_state *sh4)
{
int s;
UINT32 z;
for (s = 0;s <= 15;s++)
{
z = sh4->fr[s];
sh4->fr[s] = sh4->xf[s];
sh4->xf[s] = z;
}
}
#ifdef LSB_FIRST
void sh4_swap_fp_couples(sh4_state *sh4)
{
int s;
UINT32 z;
for (s = 0;s <= 15;s = s+2)
{
z = sh4->fr[s];
sh4->fr[s] = sh4->fr[s + 1];
sh4->fr[s + 1] = z;
z = sh4->xf[s];
sh4->xf[s] = sh4->xf[s + 1];
sh4->xf[s + 1] = z;
}
}
#endif
void sh4_syncronize_register_bank(sh4_state *sh4, int to)
{
int s;
for (s = 0;s < 8;s++)
{
sh4->rbnk[to][s] = sh4->r[s];
}
}
void sh4_default_exception_priorities(sh4_state *sh4) // setup default priorities for exceptions
{
int a;
for (a=0;a <= SH4_INTC_NMI;a++)
sh4->exception_priority[a] = exception_priority_default[a];
for (a=SH4_INTC_IRLn0;a <= SH4_INTC_IRLnE;a++)
sh4->exception_priority[a] = INTPRI(15-(a-SH4_INTC_IRLn0), a);
sh4->exception_priority[SH4_INTC_IRL0] = INTPRI(13, SH4_INTC_IRL0);
sh4->exception_priority[SH4_INTC_IRL1] = INTPRI(10, SH4_INTC_IRL1);
sh4->exception_priority[SH4_INTC_IRL2] = INTPRI(7, SH4_INTC_IRL2);
sh4->exception_priority[SH4_INTC_IRL3] = INTPRI(4, SH4_INTC_IRL3);
for (a=SH4_INTC_HUDI;a <= SH4_INTC_ROVI;a++)
sh4->exception_priority[a] = INTPRI(0, a);
}
void sh4_exception_recompute(sh4_state *sh4) // checks if there is any interrupt with high enough priority
{
int a,z;
sh4->test_irq = 0;
if ((!sh4->pending_irq) || ((sh4->sr & BL) && (sh4->exception_requesting[SH4_INTC_NMI] == 0)))
return;
z = (sh4->sr >> 4) & 15;
for (a=0;a <= SH4_INTC_ROVI;a++)
{
if (sh4->exception_requesting[a])
if ((((int)sh4->exception_priority[a] >> 8) & 255) > z)
{
sh4->test_irq = 1; // will check for exception at end of instructions
break;
}
}
}
void sh4_exception_request(sh4_state *sh4, int exception) // start requesting an exception
{
if (!sh4->exception_requesting[exception])
{
sh4->exception_requesting[exception] = 1;
sh4->pending_irq++;
sh4_exception_recompute(sh4);
}
}
void sh4_exception_unrequest(sh4_state *sh4, int exception) // stop requesting an exception
{
if (sh4->exception_requesting[exception])
{
sh4->exception_requesting[exception] = 0;
sh4->pending_irq--;
sh4_exception_recompute(sh4);
}
}
void sh4_exception_checkunrequest(sh4_state *sh4, int exception)
{
if (exception == SH4_INTC_NMI)
sh4_exception_unrequest(sh4, exception);
if ((exception == SH4_INTC_DMTE0) || (exception == SH4_INTC_DMTE1) ||
(exception == SH4_INTC_DMTE2) || (exception == SH4_INTC_DMTE3))
sh4_exception_unrequest(sh4, exception);
}
void sh4_exception(sh4_state *sh4, const char *message, int exception) // handle exception
{
UINT32 vector;
if (exception < SH4_INTC_NMI)
return; // Not yet supported
if (exception == SH4_INTC_NMI) {
if ((sh4->sr & BL) && (!(sh4->m[ICR] & 0x200)))
return;
sh4->m[ICR] &= ~0x200;
sh4->m[INTEVT] = 0x1c0;
vector = 0x600;
sh4->irq_callback(sh4->device, INPUT_LINE_NMI);
LOG(("SH-4 '%s' nmi exception after [%s]\n", sh4->device->tag(), message));
} else {
// if ((sh4->m[ICR] & 0x4000) && (sh4->nmi_line_state == ASSERT_LINE))
// return;
if (sh4->sr & BL)
return;
if (((sh4->exception_priority[exception] >> 8) & 255) <= ((sh4->sr >> 4) & 15))
return;
sh4->m[INTEVT] = exception_codes[exception];
vector = 0x600;
if ((exception >= SH4_INTC_IRL0) && (exception <= SH4_INTC_IRL3))
sh4->irq_callback(sh4->device, SH4_INTC_IRL0-exception+SH4_IRL0);
else
sh4->irq_callback(sh4->device, SH4_IRL3+1);
LOG(("SH-4 '%s' interrupt exception #%d after [%s]\n", sh4->device->tag(), exception, message));
}
sh4_exception_checkunrequest(sh4, exception);
sh4->spc = sh4->pc;
sh4->ssr = sh4->sr;
sh4->sgr = sh4->r[15];
sh4->sr |= MD;
if ((sh4->device->machine().debug_flags & DEBUG_FLAG_ENABLED) != 0)
sh4_syncronize_register_bank(sh4, (sh4->sr & sRB) >> 29);
if (!(sh4->sr & sRB))
sh4_change_register_bank(sh4, 1);
sh4->sr |= sRB;
sh4->sr |= BL;
sh4_exception_recompute(sh4);
/* fetch PC */
sh4->pc = sh4->vbr + vector;
/* wake up if a sleep opcode is triggered */
if(sh4->sleep_mode == 1) { sh4->sleep_mode = 2; }
}
static UINT32 compute_ticks_refresh_timer(emu_timer *timer, int hertz, int base, int divisor)
{
// elapsed:total = x : ticks
// x=elapsed*tics/total -> x=elapsed*(double)100000000/rtcnt_div[(sh4->m[RTCSR] >> 3) & 7]
// ticks/total=ticks / ((rtcnt_div[(sh4->m[RTCSR] >> 3) & 7] * ticks) / 100000000)=1/((rtcnt_div[(sh4->m[RTCSR] >> 3) & 7] / 100000000)=100000000/rtcnt_div[(sh4->m[RTCSR] >> 3) & 7]
return base + (UINT32)((timer->elapsed().as_double() * (double)hertz) / (double)divisor);
}
static void sh4_refresh_timer_recompute(sh4_state *sh4)
{
UINT32 ticks;
//if rtcnt < rtcor then rtcor-rtcnt
//if rtcnt >= rtcor then 256-rtcnt+rtcor=256+rtcor-rtcnt
ticks = sh4->m[RTCOR]-sh4->m[RTCNT];
if (ticks <= 0)
ticks = 256 + ticks;
sh4->refresh_timer->adjust(attotime::from_hz(sh4->bus_clock) * rtcnt_div[(sh4->m[RTCSR] >> 3) & 7] * ticks);
sh4->refresh_timer_base = sh4->m[RTCNT];
}
/*-------------------------------------------------
sh4_scale_up_mame_time - multiply a attotime by
a (constant+1) where 0 <= constant < 2^32
-------------------------------------------------*/
INLINE attotime sh4_scale_up_mame_time(attotime _time1, UINT32 factor1)
{
return _time1 * factor1 + _time1;
}
static UINT32 compute_ticks_timer(emu_timer *timer, int hertz, int divisor)
{
double ret;
ret=((timer->remaining().as_double() * (double)hertz) / (double)divisor) - 1;
return (UINT32)ret;
}
static void sh4_timer_recompute(sh4_state *sh4, int which)
{
double ticks;
ticks = sh4->m[tcnt[which]];
sh4->timer[which]->adjust(sh4_scale_up_mame_time(attotime::from_hz(sh4->pm_clock) * tcnt_div[sh4->m[tcr[which]] & 7], ticks), which);
}
static TIMER_CALLBACK( sh4_refresh_timer_callback )
{
sh4_state *sh4 = (sh4_state *)ptr;
sh4->m[RTCNT] = 0;
sh4_refresh_timer_recompute(sh4);
sh4->m[RTCSR] |= 128;
if ((sh4->m[MCR] & 4) && !(sh4->m[MCR] & 2))
{
sh4->m[RFCR] = (sh4->m[RFCR] + 1) & 1023;
if (((sh4->m[RTCSR] & 1) && (sh4->m[RFCR] == 512)) || (sh4->m[RFCR] == 0))
{
sh4->m[RFCR] = 0;
sh4->m[RTCSR] |= 4;
}
}
}
static void increment_rtc_time(sh4_state *sh4, int mode)
{
int carry, year, leap, days;
if (mode == 0)
{
carry = 0;
sh4->m[RSECCNT] = sh4->m[RSECCNT] + 1;
if ((sh4->m[RSECCNT] & 0xf) == 0xa)
sh4->m[RSECCNT] = sh4->m[RSECCNT] + 6;
if (sh4->m[RSECCNT] == 0x60)
{
sh4->m[RSECCNT] = 0;
carry=1;
}
else
return;
}
else
carry = 1;
sh4->m[RMINCNT] = sh4->m[RMINCNT] + carry;
if ((sh4->m[RMINCNT] & 0xf) == 0xa)
sh4->m[RMINCNT] = sh4->m[RMINCNT] + 6;
carry=0;
if (sh4->m[RMINCNT] == 0x60)
{
sh4->m[RMINCNT] = 0;
carry = 1;
}
sh4->m[RHRCNT] = sh4->m[RHRCNT] + carry;
if ((sh4->m[RHRCNT] & 0xf) == 0xa)
sh4->m[RHRCNT] = sh4->m[RHRCNT] + 6;
carry = 0;
if (sh4->m[RHRCNT] == 0x24)
{
sh4->m[RHRCNT] = 0;
carry = 1;
}
sh4->m[RWKCNT] = sh4->m[RWKCNT] + carry;
if (sh4->m[RWKCNT] == 0x7)
{
sh4->m[RWKCNT] = 0;
}
days = 0;
year = (sh4->m[RYRCNT] & 0xf) + ((sh4->m[RYRCNT] & 0xf0) >> 4)*10 + ((sh4->m[RYRCNT] & 0xf00) >> 8)*100 + ((sh4->m[RYRCNT] & 0xf000) >> 12)*1000;
leap = 0;
if (!(year%100))
{
if (!(year%400))
leap = 1;
}
else if (!(year%4))
leap = 1;
if (sh4->m[RMONCNT] != 2)
leap = 0;
if (sh4->m[RMONCNT])
days = daysmonth[(sh4->m[RMONCNT] & 0xf) + ((sh4->m[RMONCNT] & 0xf0) >> 4)*10 - 1];
sh4->m[RDAYCNT] = sh4->m[RDAYCNT] + carry;
if ((sh4->m[RDAYCNT] & 0xf) == 0xa)
sh4->m[RDAYCNT] = sh4->m[RDAYCNT] + 6;
carry = 0;
if (sh4->m[RDAYCNT] > (days+leap))
{
sh4->m[RDAYCNT] = 1;
carry = 1;
}
sh4->m[RMONCNT] = sh4->m[RMONCNT] + carry;
if ((sh4->m[RMONCNT] & 0xf) == 0xa)
sh4->m[RMONCNT] = sh4->m[RMONCNT] + 6;
carry=0;
if (sh4->m[RMONCNT] == 0x13)
{
sh4->m[RMONCNT] = 1;
carry = 1;
}
sh4->m[RYRCNT] = sh4->m[RYRCNT] + carry;
if ((sh4->m[RYRCNT] & 0xf) >= 0xa)
sh4->m[RYRCNT] = sh4->m[RYRCNT] + 6;
if ((sh4->m[RYRCNT] & 0xf0) >= 0xa0)
sh4->m[RYRCNT] = sh4->m[RYRCNT] + 0x60;
if ((sh4->m[RYRCNT] & 0xf00) >= 0xa00)
sh4->m[RYRCNT] = sh4->m[RYRCNT] + 0x600;
if ((sh4->m[RYRCNT] & 0xf000) >= 0xa000)
sh4->m[RYRCNT] = 0;
}
static TIMER_CALLBACK( sh4_rtc_timer_callback )
{
sh4_state *sh4 = (sh4_state *)ptr;
sh4->rtc_timer->adjust(attotime::from_hz(128));
sh4->m[R64CNT] = (sh4->m[R64CNT]+1) & 0x7f;
if (sh4->m[R64CNT] == 64)
{
sh4->m[RCR1] |= 0x80;
increment_rtc_time(sh4, 0);
//sh4_exception_request(sh4, SH4_INTC_NMI); // TEST
}
}
static TIMER_CALLBACK( sh4_timer_callback )
{
static const UINT16 tuni[] = { SH4_INTC_TUNI0, SH4_INTC_TUNI1, SH4_INTC_TUNI2 };
sh4_state *sh4 = (sh4_state *)ptr;
int which = param;
int idx = tcr[which];
sh4->m[tcnt[which]] = sh4->m[tcor[which]];
sh4_timer_recompute(sh4, which);
sh4->m[idx] = sh4->m[idx] | 0x100;
if (sh4->m[idx] & 0x20)
sh4_exception_request(sh4, tuni[which]);
}
static TIMER_CALLBACK( sh4_dmac_callback )
{
sh4_state *sh4 = (sh4_state *)ptr;
int channel = param;
LOG(("SH4 '%s': DMA %d complete\n", sh4->device->tag(), channel));
sh4->dma_timer_active[channel] = 0;
switch (channel)
{
case 0:
sh4->m[DMATCR0] = 0;
sh4->m[CHCR0] |= 2;
if (sh4->m[CHCR0] & 4)
sh4_exception_request(sh4, SH4_INTC_DMTE0);
break;
case 1:
sh4->m[DMATCR1] = 0;
sh4->m[CHCR1] |= 2;
if (sh4->m[CHCR1] & 4)
sh4_exception_request(sh4, SH4_INTC_DMTE1);
break;
case 2:
sh4->m[DMATCR2] = 0;
sh4->m[CHCR2] |= 2;
if (sh4->m[CHCR2] & 4)
sh4_exception_request(sh4, SH4_INTC_DMTE2);
break;
case 3:
sh4->m[DMATCR3] = 0;
sh4->m[CHCR3] |= 2;
if (sh4->m[CHCR3] & 4)
sh4_exception_request(sh4, SH4_INTC_DMTE3);
break;
}
}
static int sh4_dma_transfer(sh4_state *sh4, int channel, int timermode, UINT32 chcr, UINT32 *sar, UINT32 *dar, UINT32 *dmatcr)
{
int incs, incd, size;
UINT32 src, dst, count;
incd = (chcr >> 14) & 3;
incs = (chcr >> 12) & 3;
size = dmasize[(chcr >> 4) & 7];
if(incd == 3 || incs == 3)
{
logerror("SH4: DMA: bad increment values (%d, %d, %d, %04x)\n", incd, incs, size, chcr);
return 0;
}
src = *sar;
dst = *dar;
count = *dmatcr;
if (!count)
count = 0x1000000;
LOG(("SH4: DMA %d start %x, %x, %x, %04x, %d, %d, %d\n", channel, src, dst, count, chcr, incs, incd, size));
if (timermode == 1)
{
sh4->dma_timer_active[channel] = 1;
sh4->dma_timer[channel]->adjust(sh4->device->cycles_to_attotime(2*count+1), channel);
}
else if (timermode == 2)
{
sh4->dma_timer_active[channel] = 1;
sh4->dma_timer[channel]->adjust(attotime::zero, channel);
}
src &= AM;
dst &= AM;
switch(size)
{
case 1: // 8 bit
for(;count > 0; count --)
{
if(incs == 2)
src --;
if(incd == 2)
dst --;
sh4->program->write_byte(dst, sh4->program->read_byte(src));
if(incs == 1)
src ++;
if(incd == 1)
dst ++;
}
break;
case 2: // 16 bit
src &= ~1;
dst &= ~1;
for(;count > 0; count --)
{
if(incs == 2)
src -= 2;
if(incd == 2)
dst -= 2;
sh4->program->write_word(dst, sh4->program->read_word(src));
if(incs == 1)
src += 2;
if(incd == 1)
dst += 2;
}
break;
case 8: // 64 bit
src &= ~7;
dst &= ~7;
for(;count > 0; count --)
{
if(incs == 2)
src -= 8;
if(incd == 2)
dst -= 8;
sh4->program->write_qword(dst, sh4->program->read_qword(src));
if(incs == 1)
src += 8;
if(incd == 1)
dst += 8;
}
break;
case 4: // 32 bit
src &= ~3;
dst &= ~3;
for(;count > 0; count --)
{
if(incs == 2)
src -= 4;
if(incd == 2)
dst -= 4;
sh4->program->write_dword(dst, sh4->program->read_dword(src));
if(incs == 1)
src += 4;
if(incd == 1)
dst += 4;
}
break;
case 32:
src &= ~31;
dst &= ~31;
for(;count > 0; count --)
{
if(incs == 2)
src -= 32;
if(incd == 2)
dst -= 32;
sh4->program->write_qword(dst, sh4->program->read_qword(src));
sh4->program->write_qword(dst+8, sh4->program->read_qword(src+8));
sh4->program->write_qword(dst+16, sh4->program->read_qword(src+16));
sh4->program->write_qword(dst+24, sh4->program->read_qword(src+24));
if(incs == 1)
src += 32;
if(incd == 1)
dst += 32;
}
break;
}
*sar = (*sar & !AM) | src;
*dar = (*dar & !AM) | dst;
*dmatcr = count;
return 1;
}
static void sh4_dmac_check(sh4_state *sh4, int channel)
{
UINT32 dmatcr,chcr,sar,dar;
switch (channel)
{
case 0:
sar = sh4->m[SAR0];
dar = sh4->m[DAR0];
chcr = sh4->m[CHCR0];
dmatcr = sh4->m[DMATCR0];
break;
case 1:
sar = sh4->m[SAR1];
dar = sh4->m[DAR1];
chcr = sh4->m[CHCR1];
dmatcr = sh4->m[DMATCR1];
break;
case 2:
sar = sh4->m[SAR2];
dar = sh4->m[DAR2];
chcr = sh4->m[CHCR2];
dmatcr = sh4->m[DMATCR2];
break;
case 3:
sar = sh4->m[SAR3];
dar = sh4->m[DAR3];
chcr = sh4->m[CHCR3];
dmatcr = sh4->m[DMATCR3];
break;
default:
return;
}
if (chcr & sh4->m[DMAOR] & 1)
{
if ((((chcr >> 8) & 15) < 4) || (((chcr >> 8) & 15) > 6))
return;
if (!sh4->dma_timer_active[channel] && !(chcr & 2) && !(sh4->m[DMAOR] & 6))
sh4_dma_transfer(sh4, channel, 1, chcr, &sar, &dar, &dmatcr);
}
else
{
if (sh4->dma_timer_active[channel])
{
logerror("SH4: DMA %d cancelled in-flight but all data transferred", channel);
sh4->dma_timer[channel]->adjust(attotime::never, channel);
sh4->dma_timer_active[channel] = 0;
}
}
}
static void sh4_dmac_nmi(sh4_state *sh4) // manage dma when nmi
{
int s;
sh4->m[DMAOR] |= 2; // nmif = 1
for (s = 0;s < 4;s++)
{
if (sh4->dma_timer_active[s])
{
logerror("SH4: DMA %d cancelled due to NMI but all data transferred", s);
sh4->dma_timer[s]->adjust(attotime::never, s);
sh4->dma_timer_active[s] = 0;
}
}
}
WRITE32_HANDLER( sh4_internal_w )
{
sh4_state *sh4 = get_safe_token(&space->device());
int a;
UINT32 addr = (offset << 2) + 0xfe000000;
offset = ((addr & 0xfc) >> 2) | ((addr & 0x1fe0000) >> 11);
UINT32 old = sh4->m[offset];
COMBINE_DATA(sh4->m+offset);
// printf("sh4_internal_w: Write %08x (%x), %08x @ %08x\n", 0xfe000000+((offset & 0x3fc0) << 11)+((offset & 0x3f) << 2), offset, data, mem_mask);
switch( offset )
{
case MMUCR: // MMU Control
if (data & 1)
{
printf("SH4 MMU Enabled\n");
printf("If you're seeing this, but running something other than a Naomi GD-ROM game then chances are it won't work\n");
printf("The MMU emulation is a hack specific to that system\n");
sh4->sh4_mmu_enabled = 1;
// should be a different bit!
{
int i;
for (i=0;i<64;i++)
{
sh4->sh4_tlb_address[i] = 0;
sh4->sh4_tlb_data[i] = 0;
}
}
}
else
{
sh4->sh4_mmu_enabled = 0;
}
break;
// Memory refresh
case RTCSR:
sh4->m[RTCSR] &= 255;
if ((old >> 3) & 7)
sh4->m[RTCNT] = compute_ticks_refresh_timer(sh4->refresh_timer, sh4->bus_clock, sh4->refresh_timer_base, rtcnt_div[(old >> 3) & 7]) & 0xff;
if ((sh4->m[RTCSR] >> 3) & 7)
{ // activated
sh4_refresh_timer_recompute(sh4);
}
else
{
sh4->refresh_timer->adjust(attotime::never);
}
break;
case RTCNT:
sh4->m[RTCNT] &= 255;
if ((sh4->m[RTCSR] >> 3) & 7)
{ // active
sh4_refresh_timer_recompute(sh4);
}
break;
case RTCOR:
sh4->m[RTCOR] &= 255;
if ((sh4->m[RTCSR] >> 3) & 7)
{ // active
sh4->m[RTCNT] = compute_ticks_refresh_timer(sh4->refresh_timer, sh4->bus_clock, sh4->refresh_timer_base, rtcnt_div[(sh4->m[RTCSR] >> 3) & 7]) & 0xff;
sh4_refresh_timer_recompute(sh4);
}
break;
case RFCR:
sh4->m[RFCR] &= 1023;
break;
// RTC
case RCR1:
if ((sh4->m[RCR1] & 8) && (~old & 8)) // 0 -> 1
sh4->m[RCR1] ^= 1;
break;
case RCR2:
if (sh4->m[RCR2] & 2)
{
sh4->m[R64CNT] = 0;
sh4->m[RCR2] ^= 2;
}
if (sh4->m[RCR2] & 4)
{
sh4->m[R64CNT] = 0;
if (sh4->m[RSECCNT] >= 30)
increment_rtc_time(sh4, 1);
sh4->m[RSECCNT] = 0;
}
if ((sh4->m[RCR2] & 8) && (~old & 8))
{ // 0 -> 1
sh4->rtc_timer->adjust(attotime::from_hz(128));
}
else if (~(sh4->m[RCR2]) & 8)
{ // 0
sh4->rtc_timer->adjust(attotime::never);
}
break;
// TMU
case TSTR:
if (old & 1)
sh4->m[TCNT0] = compute_ticks_timer(sh4->timer[0], sh4->pm_clock, tcnt_div[sh4->m[TCR0] & 7]);
if ((sh4->m[TSTR] & 1) == 0) {
sh4->timer[0]->adjust(attotime::never);
} else
sh4_timer_recompute(sh4, 0);
if (old & 2)
sh4->m[TCNT1] = compute_ticks_timer(sh4->timer[1], sh4->pm_clock, tcnt_div[sh4->m[TCR1] & 7]);
if ((sh4->m[TSTR] & 2) == 0) {
sh4->timer[1]->adjust(attotime::never);
} else
sh4_timer_recompute(sh4, 1);
if (old & 4)
sh4->m[TCNT2] = compute_ticks_timer(sh4->timer[2], sh4->pm_clock, tcnt_div[sh4->m[TCR2] & 7]);
if ((sh4->m[TSTR] & 4) == 0) {
sh4->timer[2]->adjust(attotime::never);
} else
sh4_timer_recompute(sh4, 2);
break;
case TCR0:
if (sh4->m[TSTR] & 1)
{
sh4->m[TCNT0] = compute_ticks_timer(sh4->timer[0], sh4->pm_clock, tcnt_div[old & 7]);
sh4_timer_recompute(sh4, 0);
}
if (!(sh4->m[TCR0] & 0x20) || !(sh4->m[TCR0] & 0x100))
sh4_exception_unrequest(sh4, SH4_INTC_TUNI0);
break;
case TCR1:
if (sh4->m[TSTR] & 2)
{
sh4->m[TCNT1] = compute_ticks_timer(sh4->timer[1], sh4->pm_clock, tcnt_div[old & 7]);
sh4_timer_recompute(sh4, 1);
}
if (!(sh4->m[TCR1] & 0x20) || !(sh4->m[TCR1] & 0x100))
sh4_exception_unrequest(sh4, SH4_INTC_TUNI1);
break;
case TCR2:
if (sh4->m[TSTR] & 4)
{
sh4->m[TCNT2] = compute_ticks_timer(sh4->timer[2], sh4->pm_clock, tcnt_div[old & 7]);
sh4_timer_recompute(sh4, 2);
}
if (!(sh4->m[TCR2] & 0x20) || !(sh4->m[TCR2] & 0x100))
sh4_exception_unrequest(sh4, SH4_INTC_TUNI2);
break;
case TCOR0:
if (sh4->m[TSTR] & 1)
{
sh4->m[TCNT0] = compute_ticks_timer(sh4->timer[0], sh4->pm_clock, tcnt_div[sh4->m[TCR0] & 7]);
sh4_timer_recompute(sh4, 0);
}
break;
case TCNT0:
if (sh4->m[TSTR] & 1)
sh4_timer_recompute(sh4, 0);
break;
case TCOR1:
if (sh4->m[TSTR] & 2)
{
sh4->m[TCNT1] = compute_ticks_timer(sh4->timer[1], sh4->pm_clock, tcnt_div[sh4->m[TCR1] & 7]);
sh4_timer_recompute(sh4, 1);
}
break;
case TCNT1:
if (sh4->m[TSTR] & 2)
sh4_timer_recompute(sh4, 1);
break;
case TCOR2:
if (sh4->m[TSTR] & 4)
{
sh4->m[TCNT2] = compute_ticks_timer(sh4->timer[2], sh4->pm_clock, tcnt_div[sh4->m[TCR2] & 7]);
sh4_timer_recompute(sh4, 2);
}
break;
case TCNT2:
if (sh4->m[TSTR] & 4)
sh4_timer_recompute(sh4, 2);
break;
// INTC
case ICR:
sh4->m[ICR] = (sh4->m[ICR] & 0x7fff) | (old & 0x8000);
break;
case IPRA:
sh4->exception_priority[SH4_INTC_ATI] = INTPRI(sh4->m[IPRA] & 0x000f, SH4_INTC_ATI);
sh4->exception_priority[SH4_INTC_PRI] = INTPRI(sh4->m[IPRA] & 0x000f, SH4_INTC_PRI);
sh4->exception_priority[SH4_INTC_CUI] = INTPRI(sh4->m[IPRA] & 0x000f, SH4_INTC_CUI);
sh4->exception_priority[SH4_INTC_TUNI2] = INTPRI((sh4->m[IPRA] & 0x00f0) >> 4, SH4_INTC_TUNI2);
sh4->exception_priority[SH4_INTC_TICPI2] = INTPRI((sh4->m[IPRA] & 0x00f0) >> 4, SH4_INTC_TICPI2);
sh4->exception_priority[SH4_INTC_TUNI1] = INTPRI((sh4->m[IPRA] & 0x0f00) >> 8, SH4_INTC_TUNI1);
sh4->exception_priority[SH4_INTC_TUNI0] = INTPRI((sh4->m[IPRA] & 0xf000) >> 12, SH4_INTC_TUNI0);
sh4_exception_recompute(sh4);
break;
case IPRB:
sh4->exception_priority[SH4_INTC_SCI1ERI] = INTPRI((sh4->m[IPRB] & 0x00f0) >> 4, SH4_INTC_SCI1ERI);
sh4->exception_priority[SH4_INTC_SCI1RXI] = INTPRI((sh4->m[IPRB] & 0x00f0) >> 4, SH4_INTC_SCI1RXI);
sh4->exception_priority[SH4_INTC_SCI1TXI] = INTPRI((sh4->m[IPRB] & 0x00f0) >> 4, SH4_INTC_SCI1TXI);
sh4->exception_priority[SH4_INTC_SCI1TEI] = INTPRI((sh4->m[IPRB] & 0x00f0) >> 4, SH4_INTC_SCI1TEI);
sh4->exception_priority[SH4_INTC_RCMI] = INTPRI((sh4->m[IPRB] & 0x0f00) >> 8, SH4_INTC_RCMI);
sh4->exception_priority[SH4_INTC_ROVI] = INTPRI((sh4->m[IPRB] & 0x0f00) >> 8, SH4_INTC_ROVI);
sh4->exception_priority[SH4_INTC_ITI] = INTPRI((sh4->m[IPRB] & 0xf000) >> 12, SH4_INTC_ITI);
sh4_exception_recompute(sh4);
break;
case IPRC:
sh4->exception_priority[SH4_INTC_HUDI] = INTPRI(sh4->m[IPRC] & 0x000f, SH4_INTC_HUDI);
sh4->exception_priority[SH4_INTC_SCIFERI] = INTPRI((sh4->m[IPRC] & 0x00f0) >> 4, SH4_INTC_SCIFERI);
sh4->exception_priority[SH4_INTC_SCIFRXI] = INTPRI((sh4->m[IPRC] & 0x00f0) >> 4, SH4_INTC_SCIFRXI);
sh4->exception_priority[SH4_INTC_SCIFBRI] = INTPRI((sh4->m[IPRC] & 0x00f0) >> 4, SH4_INTC_SCIFBRI);
sh4->exception_priority[SH4_INTC_SCIFTXI] = INTPRI((sh4->m[IPRC] & 0x00f0) >> 4, SH4_INTC_SCIFTXI);
sh4->exception_priority[SH4_INTC_DMTE0] = INTPRI((sh4->m[IPRC] & 0x0f00) >> 8, SH4_INTC_DMTE0);
sh4->exception_priority[SH4_INTC_DMTE1] = INTPRI((sh4->m[IPRC] & 0x0f00) >> 8, SH4_INTC_DMTE1);
sh4->exception_priority[SH4_INTC_DMTE2] = INTPRI((sh4->m[IPRC] & 0x0f00) >> 8, SH4_INTC_DMTE2);
sh4->exception_priority[SH4_INTC_DMTE3] = INTPRI((sh4->m[IPRC] & 0x0f00) >> 8, SH4_INTC_DMTE3);
sh4->exception_priority[SH4_INTC_DMAE] = INTPRI((sh4->m[IPRC] & 0x0f00) >> 8, SH4_INTC_DMAE);
sh4->exception_priority[SH4_INTC_GPOI] = INTPRI((sh4->m[IPRC] & 0xf000) >> 12, SH4_INTC_GPOI);
sh4_exception_recompute(sh4);
break;
// DMA
case SAR0:
case SAR1:
case SAR2:
case SAR3:
case DAR0:
case DAR1:
case DAR2:
case DAR3:
case DMATCR0:
case DMATCR1:
case DMATCR2:
case DMATCR3:
break;
case CHCR0:
sh4_dmac_check(sh4, 0);
break;
case CHCR1:
sh4_dmac_check(sh4, 1);
break;
case CHCR2:
sh4_dmac_check(sh4, 2);
break;
case CHCR3:
sh4_dmac_check(sh4, 3);
break;
case DMAOR:
if ((sh4->m[DMAOR] & 4) && (~old & 4))
sh4->m[DMAOR] &= ~4;
if ((sh4->m[DMAOR] & 2) && (~old & 2))
sh4->m[DMAOR] &= ~2;
sh4_dmac_check(sh4, 0);
sh4_dmac_check(sh4, 1);
sh4_dmac_check(sh4, 2);
sh4_dmac_check(sh4, 3);
break;
// Store Queues
case QACR0:
case QACR1:
break;
// I/O ports
case PCTRA:
sh4->ioport16_pullup = 0;
sh4->ioport16_direction = 0;
for (a=0;a < 16;a++) {
sh4->ioport16_direction |= (sh4->m[PCTRA] & (1 << (a*2))) >> a;
sh4->ioport16_pullup |= (sh4->m[PCTRA] & (1 << (a*2+1))) >> (a+1);
}
sh4->ioport16_direction &= 0xffff;
sh4->ioport16_pullup = (sh4->ioport16_pullup | sh4->ioport16_direction) ^ 0xffff;
if (sh4->m[BCR2] & 1)
sh4->io->write_dword(SH4_IOPORT_16, (UINT64)(sh4->m[PDTRA] & sh4->ioport16_direction) | ((UINT64)sh4->m[PCTRA] << 16));
break;
case PDTRA:
if (sh4->m[BCR2] & 1)
sh4->io->write_dword(SH4_IOPORT_16, (UINT64)(sh4->m[PDTRA] & sh4->ioport16_direction) | ((UINT64)sh4->m[PCTRA] << 16));
break;
case PCTRB:
sh4->ioport4_pullup = 0;
sh4->ioport4_direction = 0;
for (a=0;a < 4;a++) {
sh4->ioport4_direction |= (sh4->m[PCTRB] & (1 << (a*2))) >> a;
sh4->ioport4_pullup |= (sh4->m[PCTRB] & (1 << (a*2+1))) >> (a+1);
}
sh4->ioport4_direction &= 0xf;
sh4->ioport4_pullup = (sh4->ioport4_pullup | sh4->ioport4_direction) ^ 0xf;
if (sh4->m[BCR2] & 1)
sh4->io->write_dword(SH4_IOPORT_4, (sh4->m[PDTRB] & sh4->ioport4_direction) | (sh4->m[PCTRB] << 16));
break;
case PDTRB:
if (sh4->m[BCR2] & 1)
sh4->io->write_dword(SH4_IOPORT_4, (sh4->m[PDTRB] & sh4->ioport4_direction) | (sh4->m[PCTRB] << 16));
break;
case SCBRR2:
break;
default:
logerror("sh4_internal_w: Unmapped write %08x, %08x @ %08x\n", 0xfe000000+((offset & 0x3fc0) << 11)+((offset & 0x3f) << 2), data, mem_mask);
break;
}
}
READ32_HANDLER( sh4_internal_r )
{
sh4_state *sh4 = get_safe_token(&space->device());
UINT32 addr = (offset << 2) + 0xfe000000;
offset = ((addr & 0xfc) >> 2) | ((addr & 0x1fe0000) >> 11);
// printf("sh4_internal_r: Read %08x (%x) @ %08x\n", 0xfe000000+((offset & 0x3fc0) << 11)+((offset & 0x3f) << 2), offset, mem_mask);
switch( offset )
{
case VERSION:
return 0x040205c1; // this is what a real SH7750 in a Dreamcast returns - the later Naomi BIOSes check and care!
break;
case IPRD:
return 0x00000000; // SH7750 ignores writes here and always returns zero
break;
case RTCNT:
if ((sh4->m[RTCSR] >> 3) & 7)
{ // activated
//((double)rtcnt_div[(sh4->m[RTCSR] >> 3) & 7] / (double)100000000)
//return (refresh_timer_base + (sh4->refresh_timer->elapsed() * (double)100000000) / (double)rtcnt_div[(sh4->m[RTCSR] >> 3) & 7]) & 0xff;
return compute_ticks_refresh_timer(sh4->refresh_timer, sh4->bus_clock, sh4->refresh_timer_base, rtcnt_div[(sh4->m[RTCSR] >> 3) & 7]) & 0xff;
}
else
return sh4->m[RTCNT];
break;
case TCNT0:
if (sh4->m[TSTR] & 1)
return compute_ticks_timer(sh4->timer[0], sh4->pm_clock, tcnt_div[sh4->m[TCR0] & 7]);
else
return sh4->m[TCNT0];
break;
case TCNT1:
if (sh4->m[TSTR] & 2)
return compute_ticks_timer(sh4->timer[1], sh4->pm_clock, tcnt_div[sh4->m[TCR1] & 7]);
else
return sh4->m[TCNT1];
break;
case TCNT2:
if (sh4->m[TSTR] & 4)
return compute_ticks_timer(sh4->timer[2], sh4->pm_clock, tcnt_div[sh4->m[TCR2] & 7]);
else
return sh4->m[TCNT2];
break;
// I/O ports
case PDTRA:
if (sh4->m[BCR2] & 1)
return (sh4->io->read_dword(SH4_IOPORT_16) & ~sh4->ioport16_direction) | (sh4->m[PDTRA] & sh4->ioport16_direction);
break;
case PDTRB:
if (sh4->m[BCR2] & 1)
return (sh4->io->read_dword(SH4_IOPORT_4) & ~sh4->ioport4_direction) | (sh4->m[PDTRB] & sh4->ioport4_direction);
break;
// SCIF (UART with FIFO)
case SCFSR2:
return 0x60; //read-only status register
}
return sh4->m[offset];
}
void sh4_set_frt_input(device_t *device, int state)
{
sh4_state *sh4 = get_safe_token(device);
if(state == PULSE_LINE)
{
sh4_set_frt_input(device, ASSERT_LINE);
sh4_set_frt_input(device, CLEAR_LINE);
return;
}
if(sh4->frt_input == state) {
return;
}
sh4->frt_input = state;
if(sh4->m[5] & 0x8000) {
if(state == CLEAR_LINE) {
return;
}
} else {
if(state == ASSERT_LINE) {
return;
}
}
#if 0
sh4_timer_resync();
sh4->icr = sh4->frc;
sh4->m[4] |= ICF;
logerror("SH4 '%s': ICF activated (%x)\n", sh4->device->tag(), sh4->pc & AM);
sh4_recalc_irq();
#endif
}
void sh4_set_irln_input(device_t *device, int value)
{
sh4_state *sh4 = get_safe_token(device);
if (sh4->irln == value)
return;
sh4->irln = value;
device_set_input_line(device, SH4_IRLn, ASSERT_LINE);
device_set_input_line(device, SH4_IRLn, CLEAR_LINE);
}
void sh4_set_irq_line(sh4_state *sh4, int irqline, int state) // set state of external interrupt line
{
int s;
if (irqline == INPUT_LINE_NMI)
{
if (sh4->nmi_line_state == state)
return;
if (sh4->m[ICR] & 0x100)
{
if ((state == CLEAR_LINE) && (sh4->nmi_line_state == ASSERT_LINE)) // rising
{
LOG(("SH-4 '%s' assert nmi\n", sh4->device->tag()));
sh4_exception_request(sh4, SH4_INTC_NMI);
sh4_dmac_nmi(sh4);
}
}
else
{
if ((state == ASSERT_LINE) && (sh4->nmi_line_state == CLEAR_LINE)) // falling
{
LOG(("SH-4 '%s' assert nmi\n", sh4->device->tag()));
sh4_exception_request(sh4, SH4_INTC_NMI);
sh4_dmac_nmi(sh4);
}
}
if (state == CLEAR_LINE)
sh4->m[ICR] ^= 0x8000;
else
sh4->m[ICR] |= 0x8000;
sh4->nmi_line_state = state;
}
else
{
if (sh4->m[ICR] & 0x80) // four independent external interrupt sources
{
if (irqline > SH4_IRL3)
return;
if (sh4->irq_line_state[irqline] == state)
return;
sh4->irq_line_state[irqline] = state;
if( state == CLEAR_LINE )
{
LOG(("SH-4 '%s' cleared external irq IRL%d\n", sh4->device->tag(), irqline));
sh4_exception_unrequest(sh4, SH4_INTC_IRL0+irqline-SH4_IRL0);
}
else
{
LOG(("SH-4 '%s' assert external irq IRL%d\n", sh4->device->tag(), irqline));
sh4_exception_request(sh4, SH4_INTC_IRL0+irqline-SH4_IRL0);
}
}
else // level-encoded interrupt
{
if (irqline != SH4_IRLn)
return;
if ((sh4->irln > 15) || (sh4->irln < 0))
return;
for (s = 0; s < 15; s++)
sh4_exception_unrequest(sh4, SH4_INTC_IRLn0+s);
if (sh4->irln < 15)
sh4_exception_request(sh4, SH4_INTC_IRLn0+sh4->irln);
LOG(("SH-4 '%s' IRLn0-IRLn3 level #%d\n", sh4->device->tag(), sh4->irln));
}
}
if (sh4->test_irq && (!sh4->delay))
sh4_check_pending_irq(sh4, "sh4_set_irq_line");
}
void sh4_parse_configuration(sh4_state *sh4, const struct sh4_config *conf)
{
if(conf)
{
switch((conf->md2 << 2) | (conf->md1 << 1) | (conf->md0))
{
case 0:
sh4->cpu_clock = conf->clock;
sh4->bus_clock = conf->clock / 4;
sh4->pm_clock = conf->clock / 4;
break;
case 1:
sh4->cpu_clock = conf->clock;
sh4->bus_clock = conf->clock / 6;
sh4->pm_clock = conf->clock / 6;
break;
case 2:
sh4->cpu_clock = conf->clock;
sh4->bus_clock = conf->clock / 3;
sh4->pm_clock = conf->clock / 6;
break;
case 3:
sh4->cpu_clock = conf->clock;
sh4->bus_clock = conf->clock / 3;
sh4->pm_clock = conf->clock / 6;
break;
case 4:
sh4->cpu_clock = conf->clock;
sh4->bus_clock = conf->clock / 2;
sh4->pm_clock = conf->clock / 4;
break;
case 5:
sh4->cpu_clock = conf->clock;
sh4->bus_clock = conf->clock / 2;
sh4->pm_clock = conf->clock / 4;
break;
}
sh4->is_slave = (~(conf->md7)) & 1;
}
else
{
sh4->cpu_clock = 200000000;
sh4->bus_clock = 100000000;
sh4->pm_clock = 50000000;
sh4->is_slave = 0;
}
}
void sh4_common_init(device_t *device)
{
sh4_state *sh4 = get_safe_token(device);
int i;
for (i=0; i<3; i++)
{
sh4->timer[i] = device->machine().scheduler().timer_alloc(FUNC(sh4_timer_callback), sh4);
sh4->timer[i]->adjust(attotime::never, i);
}
for (i=0; i<4; i++)
{
sh4->dma_timer[i] = device->machine().scheduler().timer_alloc(FUNC(sh4_dmac_callback), sh4);
sh4->dma_timer[i]->adjust(attotime::never, i);
}
sh4->refresh_timer = device->machine().scheduler().timer_alloc(FUNC(sh4_refresh_timer_callback), sh4);
sh4->refresh_timer->adjust(attotime::never);
sh4->refresh_timer_base = 0;
sh4->rtc_timer = device->machine().scheduler().timer_alloc(FUNC(sh4_rtc_timer_callback), sh4);
sh4->rtc_timer->adjust(attotime::never);
sh4->m = auto_alloc_array(device->machine(), UINT32, 16384);
}
void sh4_dma_ddt(device_t *device, struct sh4_ddt_dma *s)
{
sh4_state *sh4 = get_safe_token(device);
UINT32 chcr;
UINT32 *p32bits;
UINT64 *p32bytes;
UINT32 pos,len,siz;
if (sh4->dma_timer_active[s->channel])
return;
if (s->mode >= 0) {
switch (s->channel)
{
case 0:
if (s->mode & 1)
s->source = sh4->m[SAR0];
if (s->mode & 2)
sh4->m[SAR0] = s->source;
if (s->mode & 4)
s->destination = sh4->m[DAR0];
if (s->mode & 8)
sh4->m[DAR0] = s->destination;
break;
case 1:
if (s->mode & 1)
s->source = sh4->m[SAR1];
if (s->mode & 2)
sh4->m[SAR1] = s->source;
if (s->mode & 4)
s->destination = sh4->m[DAR1];
if (s->mode & 8)
sh4->m[DAR1] = s->destination;
break;
case 2:
if (s->mode & 1)
s->source = sh4->m[SAR2];
if (s->mode & 2)
sh4->m[SAR2] = s->source;
if (s->mode & 4)
s->destination = sh4->m[DAR2];
if (s->mode & 8)
sh4->m[DAR2] = s->destination;
break;
case 3:
default:
if (s->mode & 1)
s->source = sh4->m[SAR3];
if (s->mode & 2)
sh4->m[SAR3] = s->source;
if (s->mode & 4)
s->destination = sh4->m[DAR3];
if (s->mode & 8)
sh4->m[DAR3] = s->destination;
break;
}
switch (s->channel)
{
case 0:
chcr = sh4->m[CHCR0];
len = sh4->m[DMATCR0];
break;
case 1:
chcr = sh4->m[CHCR1];
len = sh4->m[DMATCR1];
break;
case 2:
chcr = sh4->m[CHCR2];
len = sh4->m[DMATCR2];
break;
case 3:
default:
chcr = sh4->m[CHCR3];
len = sh4->m[DMATCR3];
break;
}
if ((s->direction) == 0) {
chcr = (chcr & 0xffff3fff) | ((s->mode & 0x30) << 10);
} else {
chcr = (chcr & 0xffffcfff) | ((s->mode & 0x30) << 8);
}
siz = dmasize[(chcr >> 4) & 7];
if (siz && (s->size))
if ((len * siz) != (s->length * s->size))
return;
sh4_dma_transfer(sh4, s->channel, 0, chcr, &s->source, &s->destination, &len);
} else {
if (s->size == 4) {
if ((s->direction) == 0) {
len = s->length;
p32bits = (UINT32 *)(s->buffer);
for (pos = 0;pos < len;pos++) {
*p32bits = sh4->program->read_dword(s->source);
p32bits++;
s->source = s->source + 4;
}
} else {
len = s->length;
p32bits = (UINT32 *)(s->buffer);
for (pos = 0;pos < len;pos++) {
sh4->program->write_dword(s->destination, *p32bits);
p32bits++;
s->destination = s->destination + 4;
}
}
}
if (s->size == 32) {
if ((s->direction) == 0) {
len = s->length * 4;
p32bytes = (UINT64 *)(s->buffer);
for (pos = 0;pos < len;pos++) {
*p32bytes = sh4->program->read_qword(s->source);
p32bytes++;
s->destination = s->destination + 8;
}
} else {
len = s->length * 4;
p32bytes = (UINT64 *)(s->buffer);
for (pos = 0;pos < len;pos++) {
sh4->program->write_qword(s->destination, *p32bytes);
p32bytes++;
s->destination = s->destination + 8;
}
}
}
}
}
UINT32 sh4_getsqremap(sh4_state *sh4, UINT32 address)
{
if (!sh4->sh4_mmu_enabled)
return address;
else
{
int i;
UINT32 topaddr = address&0xfff00000;
for (i=0;i<64;i++)
{
UINT32 topcmp = sh4->sh4_tlb_address[i]&0xfff00000;
if (topcmp==topaddr)
return (address&0x000fffff) | ((sh4->sh4_tlb_data[i])&0xfff00000);
}
}
return address;
}
READ64_HANDLER( sh4_tlb_r )
{
sh4_state *sh4 = get_safe_token(&space->device());
int offs = offset*8;
if (offs >= 0x01000000)
{
UINT8 i = (offs>>8)&63;
return sh4->sh4_tlb_data[i];
}
else
{
UINT8 i = (offs>>8)&63;
return sh4->sh4_tlb_address[i];
}
}
WRITE64_HANDLER( sh4_tlb_w )
{
sh4_state *sh4 = get_safe_token(&space->device());
int offs = offset*8;
if (offs >= 0x01000000)
{
UINT8 i = (offs>>8)&63;
sh4->sh4_tlb_data[i] = data&0xffffffff;
}
else
{
UINT8 i = (offs>>8)&63;
sh4->sh4_tlb_address[i] = data&0xffffffff;
}
}
| [
"brymaster@gmail.com"
] | brymaster@gmail.com |
b47d75edb82f60f8f2b64425bf5060f943efbe36 | 7529071b6a2370b2dd3b3636eeaf1eefc4251422 | /PPQCU_CU_MAIN.X/config.h | 1f515ccfad819c8dda3a220d744b7b3144ccc807 | [
"MIT"
] | permissive | pschilkdev/QuadCopter_PP | a653aea5666cec26332fe0a46b20d660a91d5890 | ef13ff9bbae560643702274cb7cc75a28065313a | refs/heads/master | 2021-01-10T04:40:33.452213 | 2016-02-28T10:44:41 | 2016-02-28T10:44:41 | 48,706,587 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 547 | h | /*
* File: config.h
* Author: Philipp
*
* Created on December 28, 2015, 11:16 PM
*/
#ifndef CONFIG_H
#define CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <p32xxxx.h>
#include <xc.h>
typedef unsigned char BOOL;
#define TRUE 1
#define FALSE 0
// ======== GLOBAL OPTIONS ==========
//System clock frequency
#define F_OSC 48000000
//Peripheral Clock Divider
#define F_PER_DIV 8
//Peripheral Clock frequency
#define F_PER F_OSC/F_PER_DIV
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_H */
| [
"pschilk@stu.iics.k12.tr"
] | pschilk@stu.iics.k12.tr |
299505d00ab1a8ae68f8c92b8d7c90b9e9213d67 | 1744185a1e318fd0705b7c8d71635966bf2f7451 | /template/lib/Projects/STM32F412ZG-Nucleo/Applications/USB_Host/HID_Standalone/Src/mouse.c | b562dff75c983f90ae27531d21e3bd136d6277ad | [
"MIT",
"LicenseRef-scancode-st-bsd-restricted"
] | permissive | swedishhat/stm32f4-bear-metal | 99554444acc611433190b00599d5be9ebbcbac49 | 04c8ae72ee6ea658dc376afe64f7f3a47c67512b | refs/heads/master | 2020-12-24T09:09:59.574026 | 2016-11-09T18:07:57 | 2016-11-09T18:07:57 | 73,302,594 | 0 | 1 | MIT | 2020-03-08T01:27:48 | 2016-11-09T16:45:24 | C | WINDOWS-1252 | C | false | false | 10,150 | c | /**
******************************************************************************
* @file USB_Host/HID_Standalone/Src/mouse.c
* @author MCD Application Team
* @version V1.0.0
* @date 06-May-2016
* @brief This file implements Functions for mouse menu
******************************************************************************
* @attention
*
* <h2><center>© Copyright © 2016 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private typedef -----------------------------------------------------------*/
extern USBH_HandleTypeDef hUSBHost;
/* Private define ------------------------------------------------------------*/
/* Left Button Report data */
#define HID_MOUSE_BUTTON1 0x01
/* Right Button Report data */
#define HID_MOUSE_BUTTON2 0x02
/* Middle Button Report data */
#define HID_MOUSE_BUTTON3 0x04
/* Mouse directions */
#define MOUSE_TOP_DIR 0x80
#define MOUSE_BOTTOM_DIR 0x00
#define MOUSE_LEFT_DIR 0x80
#define MOUSE_RIGHT_DIR 0x00
#define MOUSE_WINDOW_X 7
#define MOUSE_WINDOW_Y 52
#define MOUSE_WINDOW_X_MAX 10
#define MOUSE_WINDOW_Y_MIN 50
#define MOUSE_WINDOW_HEIGHT 40
#define MOUSE_WINDOW_WIDTH 110
#define HID_MOUSE_BUTTON_HEIGHT 10
#define HID_MOUSE_BUTTON_WIDTH 30
#define HID_MOUSE_BUTTON1_XCHORD 8
#define HID_MOUSE_BUTTON2_XCHORD 48
#define HID_MOUSE_BUTTON3_XCHORD 88
#define HID_MOUSE_BUTTON_YCHORD 100
#define MOUSE_LEFT_MOVE 1
#define MOUSE_RIGHT_MOVE 2
#define MOUSE_UP_MOVE 3
#define MOUSE_DOWN_MOVE 4
#define HID_MOUSE_HEIGHTLSB 2
#define HID_MOUSE_WIDTHLSB 2
#define HID_MOUSE_RES_X 4
#define HID_MOUSE_RES_Y 4
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static void USR_MOUSE_Init(void);
static void HID_MOUSE_UpdatePosition(int8_t x, int8_t y);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Manages Mouse Menu Process.
* @param None
* @retval None
*/
void HID_MouseMenuProcess(void)
{
switch(hid_demo.mouse_state)
{
case HID_MOUSE_IDLE:
hid_demo.mouse_state = HID_MOUSE_START;
HID_SelectItem(DEMO_MOUSE_menu, 0);
hid_demo.select = 0;
prev_select = 0;
break;
case HID_MOUSE_WAIT:
if(hid_demo.select != prev_select)
{
prev_select = hid_demo.select ;
HID_SelectItem(DEMO_MOUSE_menu, hid_demo.select & 0x7F);
/* Handle select item */
if(hid_demo.select & 0x80)
{
hid_demo.select &= 0x7F;
switch(hid_demo.select)
{
case 0:
hid_demo.mouse_state = HID_MOUSE_START;
break;
case 1: /* Return */
LCD_LOG_ClearTextZone();
hid_demo.state = HID_DEMO_REENUMERATE;
hid_demo.select = 0;
break;
default:
break;
}
}
}
break;
case HID_MOUSE_START:
USR_MOUSE_Init();
hid_demo.mouse_state = HID_MOUSE_WAIT;
HID_MOUSE_UpdatePosition(0,0);
break;
default:
break;
}
}
/**
* @brief Init Mouse window.
* @param None
* @retval None
*/
static void USR_MOUSE_Init(void)
{
LCD_LOG_ClearTextZone();
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
BSP_LCD_DisplayStringAtLine(5, (uint8_t *)"USB HID Host Mouse Demo... ");
BSP_LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR);
/* Display Mouse Window */
BSP_LCD_DrawRect(MOUSE_WINDOW_X, MOUSE_WINDOW_Y, MOUSE_WINDOW_WIDTH, MOUSE_WINDOW_HEIGHT);
HID_MOUSE_ButtonReleased(0);
HID_MOUSE_ButtonReleased(1);
HID_MOUSE_ButtonReleased(2);
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
HID_MOUSE_UpdatePosition(0,0);
}
/**
* @brief Processes Mouse data.
* @param data: Mouse data to be displayed
* @retval None
*/
void USR_MOUSE_ProcessData(HID_MOUSE_Info_TypeDef *data)
{
if((data->x != 0) && (data->y != 0))
{
HID_MOUSE_UpdatePosition(data->x , data->y);
}
}
/**
* @brief Handles mouse scroll to update the mouse position on display window.
* @param x: USB HID Mouse X co-ordinate
* @param y: USB HID Mouse Y co-ordinate
* @retval None
*/
static void HID_MOUSE_UpdatePosition(int8_t x, int8_t y)
{
static int16_t x_loc = 0, y_loc = 0;
static int16_t prev_x = 5, prev_y = 1;
if((x != 0) || (y != 0))
{
x_loc += x/HID_MOUSE_RES_X;
y_loc += y/HID_MOUSE_RES_Y;
if(y_loc > MOUSE_WINDOW_HEIGHT - 12)
{
y_loc = MOUSE_WINDOW_HEIGHT - 12;
}
if(x_loc > MOUSE_WINDOW_WIDTH - 10)
{
x_loc = MOUSE_WINDOW_WIDTH - 10;
}
if(y_loc < 2)
{
y_loc = 2;
}
if(x_loc < 2)
{
x_loc = 2;
}
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
BSP_LCD_DisplayChar(MOUSE_WINDOW_X + prev_x, MOUSE_WINDOW_Y + prev_y, 'x');
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayChar(MOUSE_WINDOW_X + x_loc, MOUSE_WINDOW_Y + y_loc, 'x');
prev_x = x_loc;
prev_y = y_loc;
}
}
/**
* @brief Handles mouse button press.
* @param button_idx: Mouse button pressed
* @retval None
*/
void HID_MOUSE_ButtonPressed(uint8_t button_idx)
{
/* Set the color for button press status */
BSP_LCD_SetTextColor(LCD_COLOR_RED);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
/* Change the color of button pressed to indicate button press */
switch(button_idx)
{
/* Left Button Pressed */
case 0:
BSP_LCD_FillRect(HID_MOUSE_BUTTON1_XCHORD, HID_MOUSE_BUTTON_YCHORD,\
HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT );
break;
/* Right Button Pressed */
case 1:
BSP_LCD_FillRect(HID_MOUSE_BUTTON2_XCHORD,HID_MOUSE_BUTTON_YCHORD,\
HID_MOUSE_BUTTON_WIDTH,HID_MOUSE_BUTTON_HEIGHT);
break;
/* Middle button Pressed */
case 2:
BSP_LCD_FillRect(HID_MOUSE_BUTTON3_XCHORD,HID_MOUSE_BUTTON_YCHORD,\
HID_MOUSE_BUTTON_WIDTH,HID_MOUSE_BUTTON_HEIGHT);
break;
}
}
/**
* @brief Handles mouse button release.
* @param button_idx: Mouse button released
* @retval None
*/
void HID_MOUSE_ButtonReleased(uint8_t button_idx)
{
/* Set the color for release status */
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
/* Change the color of button released to default button color */
switch(button_idx)
{
/* Left Button Released */
case 0:
BSP_LCD_FillRect(HID_MOUSE_BUTTON1_XCHORD, HID_MOUSE_BUTTON_YCHORD,\
HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT);
break;
/* Right Button Released */
case 1:
BSP_LCD_FillRect(HID_MOUSE_BUTTON2_XCHORD, HID_MOUSE_BUTTON_YCHORD,\
HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT);
break;
/* Middle Button Released */
case 2:
BSP_LCD_FillRect(HID_MOUSE_BUTTON3_XCHORD, HID_MOUSE_BUTTON_YCHORD,\
HID_MOUSE_BUTTON_WIDTH, HID_MOUSE_BUTTON_HEIGHT);
break;
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
| [
"patrick.d.lloyd@gmail.com"
] | patrick.d.lloyd@gmail.com |
4b7d06fba22639c5e82006213c60c8b176ec78dc | a4fe5433ebecd10886612b767838c9fa2a515300 | /question1/test1.c | 75a71960b882f28b0e082afdf4b0030a0b861978 | [] | no_license | dvp180001/final | 0973d45f07acbae280d16f040262512087c87eb5 | ff3bfb871f2e4762402f00ac62067bdc992731a7 | refs/heads/master | 2020-04-11T18:40:06.099729 | 2018-12-17T15:37:15 | 2018-12-17T15:37:15 | 162,007,111 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,932 | c | /*--------------------------------------------------------------------*/
#include "mytools.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
/* ------------------------------------------------
* * ------------------------------------------------*/
int main()
{
int i;
// varible x and y for distance
double x=0;
double y=0;
// intitialize to find variable
double deviation=0;
//intialize to find error
double error=0;
// sum
double s, sum, p=0;
//variable inside and outside of circle
double inside=0;
double outside=0;
//to find distance
double dist_origin=0;
//to estimate pie
double estpi=0;
double e=0;
double NUM_ITERS=10;
double pie = 3.14;
const gsl_rng_type * t;
double squreroot;
gsl_rng * r1;
gsl_rng * r2;
gsl_rng_env_setup();
t= gsl_rng_default;
r1= gsl_rng_alloc(t);
r2= gsl_rng_alloc(t);
/* Step 1: initialize tool */
// assert( init_mytool() == 0);
/* Step 2: use tool to get sequence of random numbers */
gsl_rng_set(r1, time(NULL));
for(i=0;i<NUM_ITERS;i++)
{ //printf("Random number = %f\n",get_random_number());
x=gsl_rng_uniform(r1);
printf("x variable = %f\n",x);
y=gsl_rng_uniform(r2);
printf("y variable=%f\n",y);
s=x*x;
p=y*y;
/* Step 3: clean up tool */
dist_origin = (s+p);
squreroot = sqrt(dist_origin);
if (squreroot < 1);
inside +=1;
outside++;
sum += squreroot;
//inside++;
//outside ++;
//s += dist_origin;
}
//finalize_mytool();
estpi = (sum/NUM_ITERS)*4.0;
printf("estimate value of pie = %.3f\n",estpi);
deviation = pie - estpi;
error = abs(((pie-estpi)/estpi)*100);
//printf("estimated value of pie = %.4f\n",estpi);
printf("percent error = %.4f\n",error);
printf("deviation = %.4f\n",deviation);
//finalize_mytool();
return 0;
}
| [
"dvp180001@cslinux1.utdallas.edu"
] | dvp180001@cslinux1.utdallas.edu |
46c2699bf85233bcd21672392430d3bc580ae814 | 976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f | /source/linux/net/netfilter/extr_nf_conntrack_sip.c_process_update_response.c | 4c40f76ce005f0d5b48324bc08a24dc96e63d683 | [] | no_license | isabella232/AnghaBench | 7ba90823cf8c0dd25a803d1688500eec91d1cf4e | 9a5f60cdc907a0475090eef45e5be43392c25132 | refs/heads/master | 2023-04-20T09:05:33.024569 | 2021-05-07T18:36:26 | 2021-05-07T18:36:26 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,499 | c | #define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
/* Type definitions */
struct sk_buff {int dummy; } ;
struct nf_ct_sip_master {unsigned int invite_cseq; } ;
struct nf_conn {int dummy; } ;
typedef enum ip_conntrack_info { ____Placeholder_ip_conntrack_info } ip_conntrack_info ;
/* Variables and functions */
int NF_ACCEPT ;
int /*<<< orphan*/ flush_expectations (struct nf_conn*,int) ;
struct nf_conn* nf_ct_get (struct sk_buff*,int*) ;
struct nf_ct_sip_master* nfct_help_data (struct nf_conn*) ;
int process_sdp (struct sk_buff*,unsigned int,unsigned int,char const**,unsigned int*,unsigned int) ;
__attribute__((used)) static int process_update_response(struct sk_buff *skb, unsigned int protoff,
unsigned int dataoff,
const char **dptr, unsigned int *datalen,
unsigned int cseq, unsigned int code)
{
enum ip_conntrack_info ctinfo;
struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
if ((code >= 100 && code <= 199) ||
(code >= 200 && code <= 299))
return process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
else if (ct_sip_info->invite_cseq == cseq)
flush_expectations(ct, true);
return NF_ACCEPT;
} | [
"brenocfg@gmail.com"
] | brenocfg@gmail.com |
981c277504c6ad6a6956b88e5dc29e04cce90d08 | 976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f | /source/linux/drivers/i2c/busses/extr_i2c-designware-platdrv.c_i2c_dw_get_clk_rate_khz.c | d5681088f4449682c51a4684728ef04cccfeca73 | [] | no_license | isabella232/AnghaBench | 7ba90823cf8c0dd25a803d1688500eec91d1cf4e | 9a5f60cdc907a0475090eef45e5be43392c25132 | refs/heads/master | 2023-04-20T09:05:33.024569 | 2021-05-07T18:36:26 | 2021-05-07T18:36:26 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 622 | c | #define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
/* Type definitions */
typedef int u32 ;
struct dw_i2c_dev {int /*<<< orphan*/ clk; } ;
/* Variables and functions */
int clk_get_rate (int /*<<< orphan*/ ) ;
__attribute__((used)) static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
{
return clk_get_rate(dev->clk)/1000;
} | [
"brenocfg@gmail.com"
] | brenocfg@gmail.com |
b283597fc90535bd5d9be2805a467ca3a1d796d5 | 976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f | /source/darwin-xnu/osfmk/kern/extr_processor.c_pset_find.c | b82dc265fe3e768ad22754f979d0f8f5a5caf77a | [] | no_license | isabella232/AnghaBench | 7ba90823cf8c0dd25a803d1688500eec91d1cf4e | 9a5f60cdc907a0475090eef45e5be43392c25132 | refs/heads/master | 2023-04-20T09:05:33.024569 | 2021-05-07T18:36:26 | 2021-05-07T18:36:26 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,347 | c | #define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
typedef struct TYPE_7__ TYPE_2__ ;
typedef struct TYPE_6__ TYPE_1__ ;
/* Type definitions */
typedef scalar_t__ uint32_t ;
typedef TYPE_1__* pset_node_t ;
typedef TYPE_2__* processor_set_t ;
struct TYPE_7__ {scalar_t__ pset_cluster_id; struct TYPE_7__* pset_list; } ;
struct TYPE_6__ {TYPE_2__* psets; struct TYPE_6__* node_list; } ;
/* Variables and functions */
TYPE_1__ pset_node0 ;
int /*<<< orphan*/ pset_node_lock ;
int /*<<< orphan*/ simple_lock (int /*<<< orphan*/ *) ;
int /*<<< orphan*/ simple_unlock (int /*<<< orphan*/ *) ;
processor_set_t
pset_find(
uint32_t cluster_id,
processor_set_t default_pset)
{
simple_lock(&pset_node_lock);
pset_node_t node = &pset_node0;
processor_set_t pset = NULL;
do {
pset = node->psets;
while (pset != NULL) {
if (pset->pset_cluster_id == cluster_id)
break;
pset = pset->pset_list;
}
} while ((node = node->node_list) != NULL);
simple_unlock(&pset_node_lock);
if (pset == NULL)
return default_pset;
return (pset);
} | [
"brenocfg@gmail.com"
] | brenocfg@gmail.com |
ff74aeb64cc21495daf2c5ee2586fb5eca62f748 | d88b769d7e14b451d446dcaedd43cab491736835 | /递归/分鱼问题.c | aae2319051295cbdb4ac82675d5928dea74d3756 | [] | no_license | lokwm/Practice | 6928a926d61d4942cadabc0b85d04eac1a8769ad | fe47bd283f7f01122c0e98127993687ad1a07c5a | refs/heads/master | 2022-11-30T01:49:34.751486 | 2020-08-08T07:40:44 | 2020-08-08T07:40:44 | 286,039,779 | 0 | 1 | null | 2020-08-08T12:33:09 | 2020-08-08T12:33:09 | null | UTF-8 | C | false | false | 1,101 | c | /*A、B、C、D、E这5个人合伙夜间捕鱼,凌晨时都已经疲惫不堪,于是各自在河边的树丛中找地方睡着了。第二天日上三竿时,A第一个醒来,他将鱼平分为5份,把多余的一条扔回河中,然后拿着自己的一份回家去了;
B第二个醒来,但不知道A已经拿走了一份鱼,于是他将剩下的鱼平分为5份,扔掉多余的一条,然后只拿走了自己的一份;接着C、D、E依次醒来,也都按同样的办法分鱼。问这5人至少合伙捕到多少条鱼?每个人醒来
后所看到的鱼是多少条?*/
#include <stdio.h>
int fishSharing(int num,int fishs){
if((fishs-1)%5==0){
if(num == 1)
return 1; //返回值来判断递归结束出循环。
else
return fishSharing(num-1,4*(fishs-1)/5); //递归走分鱼问题。
}
return 0;
}
int main(void){
int fishs = 6; //9以下明显不可能 虽然9也不可能。
int flag = 0;
while(!flag){
flag = fishSharing(5,fishs);
if(flag){
printf("%d",fishs);
break;
}
fishs+=5;
}
return 0;
}
| [
"noreply@github.com"
] | lokwm.noreply@github.com |
d10a1d6e6230549697a09147f478412dcf3fc9fd | 1f692873720d3bc7dee3a49dfc667d93610f1956 | /firmware/ecos/ecos_install/include/pkgconf/libc_time.h | b5cff4b0a36feccfc5d91cb43e62c687a9cc259c | [] | no_license | JanusErasmus/LEDtable | 8b5db8cb0cfec707f6835cb99254413b8c99396a | 7f2aa6dbfca32c5b8b3ec3a21f4e793716044336 | refs/heads/master | 2021-01-21T06:18:26.069880 | 2018-02-26T07:15:20 | 2018-02-26T07:15:20 | 83,204,563 | 2 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,159 | h | #ifndef CYGONCE_PKGCONF_LIBC_TIME_H
#define CYGONCE_PKGCONF_LIBC_TIME_H
/*
* File <pkgconf/libc_time.h>
*
* This file is generated automatically by the configuration
* system. It should not be edited. Any changes to this file
* may be overwritten.
*/
#define CYGSEM_LIBC_TIME_CLOCK_WORKING 1
#define CYGSEM_LIBC_TIME_TIME_WORKING 1
#define CYGSEM_LIBC_TIME_SETTIME_WORKING 1
#define CYGFUN_LIBC_TIME_POSIX 1
#define CYGPKG_LIBC_TIME_ZONES 1
#define CYGNUM_LIBC_TIME_DST_DEFAULT_STATE -1
#define CYGNUM_LIBC_TIME_STD_DEFAULT_OFFSET 0
#define CYGNUM_LIBC_TIME_STD_DEFAULT_OFFSET_0
#define CYGNUM_LIBC_TIME_DST_DEFAULT_OFFSET 3600
#define CYGNUM_LIBC_TIME_DST_DEFAULT_OFFSET_3600
#define CYGPKG_LIBC_TIME_INLINES 1
#define CYGIMP_LIBC_TIME_ASCTIME_INLINE 1
#define CYGIMP_LIBC_TIME_CTIME_INLINE 1
#define CYGIMP_LIBC_TIME_DIFFTIME_INLINE 1
#define CYGIMP_LIBC_TIME_GMTIME_INLINE 1
#define CYGIMP_LIBC_TIME_LOCALTIME_INLINE 1
#define CYGIMP_LIBC_TIME_ASCTIME_R_INLINE 1
#define CYGIMP_LIBC_TIME_CTIME_R_INLINE 1
#define CYGIMP_LIBC_TIME_LOCALTIME_R_INLINE 1
#define CYGNUM_LIBC_TIME_CLOCK_TRACE_LEVEL 0
#define CYGNUM_LIBC_TIME_CLOCK_TRACE_LEVEL_0
#endif
| [
"janus@kses.net"
] | janus@kses.net |
486126b9474b26ecea08cb223346597f65c9709b | 6f03635be237d8276cac053cdfbf145e8c604832 | /hmap_test.c | b696aa5fc4715c2868a591ed1f23c14df60b062a | [] | no_license | stillinbeta/hmap | 56809640896cb1b36f5346c134b58117b9c7a822 | 6068207e7be036529bdc461bc0e57b47657a5635 | refs/heads/master | 2020-05-15T19:50:41.579112 | 2015-09-14T00:55:41 | 2015-09-14T00:55:41 | 42,404,395 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 2,927 | c | #include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <string.h>
#include <google/cmockery.h>
#include "hmap.h"
// If unit testing is enabled override assert with mock_assert().
#if UNIT_TESTING
extern void mock_assert(const int result, const char* const expression,
const char * const file, const int line);
#undef assert
#define assert(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__);
#endif // UNIT_TESTING
void insert_get_test(void **state) {
Hashmap *hm = hm_new();
assert_true(hm_insert(hm, "test", "test2"));
char *res = hm_get(hm, "test");
assert_true(res != NULL);
assert_string_equal(res, "test2");
}
void insert_override_test(void **state) {
Hashmap *hm = hm_new();
assert_true(hm_insert(hm, "test", "test_2"));
assert_false(hm_insert(hm, "test", "test_2"));
}
void insert_has_key_test(void **state) {
Hashmap *hm = hm_new();
assert_true(hm_insert(hm, "test", "test2"));
assert_true(hm_has_key(hm, "test"));
assert_false(hm_has_key(hm, "some random test"));
}
void insert_delete_test(void **state) {
Hashmap *hm = hm_new();
assert_true(hm_insert(hm, "test", "test2"));
assert_true(hm_delete(hm, "test"));
assert_false(hm_delete(hm, "test"));
}
void double_hm_test(void **state) {
Hashmap *hm1 = hm_new();
Hashmap *hm2 = hm_new();
assert_true(hm_insert(hm1, "my_test", "test2"));
assert_true(hm_insert(hm2, "my_test", "yet_another_test"));
char *res1 = hm_get(hm1, "my_test");
char *res2 = hm_get(hm2, "my_test");
assert_true(res1 != NULL);
assert_true(res2 != NULL);
assert_string_equal(res1, "test2");
assert_string_equal(res2, "yet_another_test");
}
void multi_insert_test(void **state) {
char *word_list[12][2] = {
{"test", "test2"},
{"kale", "garlic"},
{"sour", "patch"},
{"longboat", "dragon"},
{"final", "fantasy"},
{"cute", "ladies"},
{"!!!!", "?????"},
{"groovy", "tubular"},
{"goobby", "dolan"},
{" ", " "},
{"nahhhhh b", "lolz cats"},
{"totes", "mah goats"}
};
char *res;
Hashmap *hm = hm_new_size(8);
for (int i = 0; i < sizeof(word_list) / sizeof(word_list[0]); i++) {
hm_insert(hm, word_list[i][0], word_list[i][1]);
}
for (int i = 0; i < sizeof(word_list) / sizeof(word_list[0]); i++) {
res = hm_get(hm, word_list[i][0]);
assert_true(res != NULL);
assert_string_equal(res, word_list[i][1]);
}
}
int main(int argc, char *argv[]) {
const UnitTest tests[] = {
unit_test(insert_get_test),
unit_test(insert_override_test),
unit_test(insert_has_key_test),
unit_test(insert_delete_test),
unit_test(double_hm_test),
unit_test(multi_insert_test)
};
return run_tests(tests);
}
| [
"liz@heroku.com"
] | liz@heroku.com |
e55bc76fc5aadd29d4e93690cc37e63eb30a7bfc | ec8a3dfabe6c67894206dd83aa76f9949d1b394a | /ranlux_random.c | f325e3d7d4b2fec6663230732fdbf265407e08d4 | [] | no_license | kkoziara/stops2 | 99538191ec18939f4d3c5e0cb322b61f0a152544 | 46fb7e59acfc3def28214dd63bab3826f9cd451c | refs/heads/master | 2020-12-24T16:42:53.536317 | 2014-04-29T06:35:45 | 2014-04-29T06:35:45 | 19,265,878 | 0 | 1 | null | null | null | null | UTF-8 | C | false | false | 1,109 | c | #include <pyopencl-ranluxcl.cl>
/*
Kernel which must be run before using ranlux.
*/
__kernel void init_ranlux(__private uint ins,
__global ranluxcl_state_t *ranluxcltab)
{
ranluxcl_initialization(ins, ranluxcltab);
}
/*
Kernel for getting vector of random numbers using ranlux.
*/
__kernel void get_random_vector(__global float* output, __private uint out_size,
__global ranluxcl_state_t *ranluxcltab)
{
ranluxcl_state_t ranluxclstate;
ranluxcl_download_seed(&ranluxclstate, ranluxcltab);
unsigned long work_items = get_global_size(0);
unsigned long idx = get_global_id(0)*4;
while (idx + 4 <= out_size)
{
vstore4(ranluxcl32(&ranluxclstate),
idx >> 2, output);
idx += 4 * work_items;
}
float4 tail;
if (idx < out_size)
{
tail = ranluxcl32(&ranluxclstate);
output[idx] = tail.x;
if (idx + 1 < out_size)
{
output[idx + 1] = tail.y;
if (idx + 2 < out_size)
output[idx + 2] = tail.z;
}
}
ranluxcl_upload_seed(&ranluxclstate, ranluxcltab);
} | [
"tosterovic@gmail.com"
] | tosterovic@gmail.com |
561446550fae954850eb33fc270f76ef6f57ff12 | 53417d47bf1b8778e9b9e4b0e2a58ffa9d6f7465 | /Projects/mySTM32F5/MyBoard/My1000 -0929/Src/triangle/matrix.h | cd8e0459883490973d063c9feb27aacb38564922 | [] | no_license | JivaZhang/STM32Cube_FW_F1_V1.4.0 | c84c3df43cc7ed2990732d295a53375e570bf10f | 333a5a7bc7671818dc81b57ff01666072e135ed4 | refs/heads/master | 2020-03-23T09:15:29.986239 | 2018-03-08T05:56:52 | 2018-03-08T05:56:52 | null | 0 | 0 | null | null | null | null | MacCentralEurope | C | false | false | 2,886 | h | /**************************************************************************************************
Filename: matrix.h
Description: matrix
Author: Kai Zhao
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED ďAS IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/
#ifndef MATRIX_H
#define MATRIX_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* CONSTANTS
*/
#define MaxAnchorNum 6
//typedef struct
//{
// float status[3*MaxAnchorNum];
// uint8_t AnchorNum;
//} MatrixMSQ;
extern void MatricMul(float a[],float b[],float c[],int m,int Middle,int n) ;
extern void MatrixTran(float a[],float c[],int n,int m);
extern void MatrixRev3(float a[],float c[]);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* SIMPLEGATTPROFILE_H */
| [
"zhaokalbert@gmail.com"
] | zhaokalbert@gmail.com |
fc51c4a1c0296656b804cc1a92372938ee8619c0 | 823a9876eca3931574bb7c22f54d20ec49b283c7 | /Lab3_tasks_in_files/task2_while/task2_func.c | 0aed98700c4e00e688e320bd923cc7f3e858ffaf | [] | no_license | YansonTheSlayer/Liseenko_LABS | acde6fc52a5e6f663771721ce95c7260631097a0 | 9dcfa5efb3c62ec3c879bf0c5fa3b6212a89cecc | refs/heads/master | 2020-03-17T21:47:33.092738 | 2018-05-28T20:32:39 | 2018-05-28T20:32:39 | 133,975,841 | 0 | 1 | null | null | null | null | UTF-8 | C | false | false | 260 | c | #include <math.h>
double summ2(float eps) {
float a0 = 1, a1 = 0, diff = fabs(a0 - a1);
int i = 1;
while (diff > eps) {
a1 = a0 + pow(-1, i)*((i + 1) / (pow(i, 3) - pow(i, 2) + 1));
diff = fabs(a0 - a1);
a0 = a1;
i++;
}
return a1;
}
| [
"noreply@github.com"
] | YansonTheSlayer.noreply@github.com |
eebcbd6549325f5fa8fb11bf294b0343186d0d66 | f649261c34c1e811a318d11d5d2fcf2f02028005 | /0x09-argc_argv/0-whatsmyname.c | f245418381d694c0f62b8fb2cc0c3faac67ea099 | [] | no_license | pnzamuwe/holbertonschool-low_level_programming | 1cb5d9b6bb028e88d7424a6d3e7eb75740571f8e | 652c2167664697cc6b2403d7828f16a3ef0eb748 | refs/heads/master | 2023-08-08T02:01:41.146362 | 2017-04-15T02:51:20 | 2017-04-15T02:51:20 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 309 | c | #include <stdio.h>
#include <stdlib.h>
/**
* main - a program that prints it's own name
* @argc: count of arguments supplied to the program
* @argv: pointer to an array of pointers.
*
*Return: 0 is complete
*/
int main(int argc, char **argv)
{
while (argc--)
printf("%s\n", *argv++);
return (0);
}
| [
"rdsim8589@gmail.com"
] | rdsim8589@gmail.com |
dd45f8b4cc92852bbac5cac9da22576f4a0bbee1 | ac362bb8969d647cd219430bc71c831d894e531c | /sys/arch/sandpoint/sandpoint/kgdb_glue.c | 327dfd28c52e61e9cc9872fc588437d748048975 | [] | no_license | noud/mouse-bsd-4.0.1 | efb3b16fcc872ab227e6bb651cf1e836796a0804 | 4c0a1e08df407a759afac2d6a98507df94f5f814 | refs/heads/master | 2023-02-24T23:42:54.060718 | 2020-08-16T20:10:53 | 2020-08-16T20:10:53 | 334,536,412 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 2,960 | c | /* $NetBSD: kgdb_glue.c,v 1.4 2005/12/24 22:45:36 perry Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kgdb_glue.c,v 1.4 2005/12/24 22:45:36 perry Exp $");
#include <sys/cdefs.h>
#include <sys/param.h>
#include <kgdb/kgdb.h>
#include <machine/frame.h>
#include <machine/kgdb.h>
#include <machine/pcb.h>
#include <machine/psl.h>
#include <machine/trap.h>
int kgdbregs[NREG];
#ifdef KGDBUSERHACK
int kgdbsr; /* TEMPRORARY (Really needs some better mechanism) XXX */
int savesr;
#endif
void
kgdbinit()
{
}
int
kgdb_poll()
{
/* for now: */
return 0;
}
int
kgdb_trap_glue(frame)
struct trapframe *frame;
{
if (!(frame->srr1 & PSL_PR)
&& (frame->exc == EXC_TRC
|| (frame->exc == EXC_PGM
&& (frame->srr1 & 0x20000))
|| frame->exc == EXC_BPT)) {
#ifdef KGDBUSERHACK
__asm ("mfsr %0,%1" : "=r"(savesr) : "K"(USER_SR)); /* see above XXX */
#endif
kgdbcopy(frame, kgdbregs, sizeof kgdbregs);
kgdbregs[MSR] &= ~PSL_BE;
switch (kgdbcmds()) {
case 2:
case 0:
kgdbregs[MSR] &= ~PSL_SE;
break;
case 1:
kgdbregs[MSR] |= PSL_SE;
break;
}
kgdbcopy(kgdbregs, frame, sizeof kgdbregs);
#ifdef KGDBUSERHACK
__asm ("mtsr %0,%1; isync" :: "K"(USER_SR), "r"(savesr));
#endif
return 1;
}
return 0;
}
| [
"mouse@Rodents-Montreal.ORG"
] | mouse@Rodents-Montreal.ORG |
5da8bba37282200a393b776b39ce02c07653f6be | f5e56415da562ec6f5f1e1b44aae468fc9145699 | /c/algorithm/random-generator.c | 8c0f27cffab222d76817277631a072a17c3f9fab | [] | no_license | dantin/shadow | c13985e78e4ac1508a34c9832c7a91cdf98d9c3c | 3aaf4fcad854021f32b218afffec74a972e767dd | refs/heads/master | 2021-01-10T21:13:37.853484 | 2014-01-08T02:59:19 | 2014-01-08T02:59:19 | 7,336,412 | 1 | 1 | null | null | null | null | UTF-8 | C | false | false | 1,129 | c | /*
* Copyright (c) david, all rights reserved.
*
* filename : random-generator.c
* version : 1.0
* author : david
* date : 2013-01-06
* description : 不重复随机数列生成算法
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SEED 298
void generate_sequence(int *array, const int size);
void print(const int a[], const int length);
void swap(int *i, int *j);
int main(void)
{
int size;
printf("Please input the size: ");
scanf("%d", &size);
int *array = (int *) malloc (sizeof(int) * size);
generate_sequence(array, size);
print(array, size);
putchar('\n');
free(array);
return 0;
}
void generate_sequence(int *array, const int size)
{
int i;
for(i = 0; i < size; i++) {
array[i] = i;
}
srand(SEED);
int end = size - 1;
while(end > 0) {
int num = rand() % end;
swap(&array[num], &array[end--]);
}
}
void swap(int *i, int *j)
{
int temp = *i;
*i = *j;
*j = temp;
}
void print(const int *a, const int length)
{
int i;
for(i = 0; i < length; i++) {
printf((i == length - 1) ? "%d" : "%d ", a[i]);
}
}
| [
"chengjie.ding@gmail.com"
] | chengjie.ding@gmail.com |
254ef76bbd81e09a92efc131357938a8f4780942 | 339278d6218035c26b040966e6879bbe364b6031 | /PLOTS/munu/MET130/mudz_all_DPhiSIGNAL_CJVfail_log.C | 7e77d2ae80cefaa136c8fc0f205bdf1c57a698b0 | [] | no_license | pjdunne/ichnnplots | a39a58780a5df4a09dcd2169e0275f9da96ca053 | 4f36e338299efc225c85ee16d11c4c25599404f9 | refs/heads/master | 2020-05-23T15:42:13.189894 | 2013-11-22T10:25:01 | 2013-11-22T10:25:01 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 20,736 | c | {
//=========Macro generated from canvas: canv/canv
//========= (Mon Nov 18 17:54:41 2013) by ROOT version5.32/00
TCanvas *canv = new TCanvas("canv", "canv",0,0,700,700);
gStyle->SetOptFit(1);
gStyle->SetOptTitle(0);
canv->SetHighLightColor(2);
canv->Range(0,0,1,1);
canv->SetFillColor(0);
canv->SetBorderMode(0);
canv->SetBorderSize(2);
canv->SetTickx(1);
canv->SetTicky(1);
canv->SetLeftMargin(0.16);
canv->SetRightMargin(0.05);
canv->SetTopMargin(0.05);
canv->SetFrameFillStyle(0);
canv->SetFrameLineStyle(0);
canv->SetFrameLineWidth(2);
canv->SetFrameBorderMode(0);
canv->SetFrameBorderSize(10);
// ------------>Primitives in pad: upper
TPad *upper = new TPad("upper", "pad",0,0.26,1,1);
upper->Draw();
upper->cd();
upper->Range(-2.810127,-2.918407,2.253165,7.293486);
upper->SetFillColor(0);
upper->SetBorderMode(0);
upper->SetBorderSize(2);
upper->SetLogy();
upper->SetTickx(1);
upper->SetTicky(1);
upper->SetLeftMargin(0.16);
upper->SetRightMargin(0.05);
upper->SetTopMargin(0.05);
upper->SetBottomMargin(0.02);
upper->SetFrameFillStyle(0);
upper->SetFrameLineStyle(0);
upper->SetFrameLineWidth(2);
upper->SetFrameBorderMode(0);
upper->SetFrameBorderSize(10);
upper->SetFrameFillStyle(0);
upper->SetFrameLineStyle(0);
upper->SetFrameLineWidth(2);
upper->SetFrameBorderMode(0);
upper->SetFrameBorderSize(10);
THStack *stack = new THStack();
stack->SetName("stack");
stack->SetTitle("stack");
stack->SetMinimum(0.01);
stack->SetMaximum(2270801);
TH1F *mudz_all_stack_11 = new TH1F("mudz_all_stack_11","stack",100,-2,2);
mudz_all_stack_11->SetBinContent(50,2.498447);
mudz_all_stack_11->SetBinContent(51,6.910216);
mudz_all_stack_11->SetBinError(50,2.024832);
mudz_all_stack_11->SetBinError(51,3.019105);
mudz_all_stack_11->SetMinimum(0.001931214);
mudz_all_stack_11->SetMaximum(6065846);
mudz_all_stack_11->SetEntries(22);
mudz_all_stack_11->SetStats(0);
mudz_all_stack_11->SetFillColor(4);
mudz_all_stack_11->SetLineColor(4);
mudz_all_stack_11->SetLineWidth(2);
mudz_all_stack_11->SetMarkerColor(4);
mudz_all_stack_11->SetMarkerStyle(21);
mudz_all_stack_11->SetMarkerSize(0.8);
mudz_all_stack_11->GetXaxis()->SetTitle("Muon d_{z}");
mudz_all_stack_11->GetXaxis()->SetLabelFont(42);
mudz_all_stack_11->GetXaxis()->SetLabelOffset(0.007);
mudz_all_stack_11->GetXaxis()->SetLabelSize(0);
mudz_all_stack_11->GetXaxis()->SetTitleSize(0);
mudz_all_stack_11->GetXaxis()->SetTickLength(0.02);
mudz_all_stack_11->GetXaxis()->SetTitleOffset(0.9);
mudz_all_stack_11->GetXaxis()->SetTitleFont(42);
mudz_all_stack_11->GetYaxis()->SetTitle("Events");
mudz_all_stack_11->GetYaxis()->SetLabelFont(42);
mudz_all_stack_11->GetYaxis()->SetLabelOffset(0.007);
mudz_all_stack_11->GetYaxis()->SetLabelSize(0.035);
mudz_all_stack_11->GetYaxis()->SetTitleSize(0.045);
mudz_all_stack_11->GetYaxis()->SetTickLength(0.02);
mudz_all_stack_11->GetYaxis()->SetTitleOffset(1.55);
mudz_all_stack_11->GetYaxis()->SetTitleFont(42);
mudz_all_stack_11->GetZaxis()->SetLabelFont(42);
mudz_all_stack_11->GetZaxis()->SetLabelOffset(0.007);
mudz_all_stack_11->GetZaxis()->SetLabelSize(0.035);
mudz_all_stack_11->GetZaxis()->SetTitleSize(0.045);
mudz_all_stack_11->GetZaxis()->SetTickLength(0.02);
mudz_all_stack_11->GetZaxis()->SetTitleFont(42);
stack->SetHistogram(mudz_all_stack_11);
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(50,2.498447);
mudz_all->SetBinContent(51,6.910216);
mudz_all->SetBinError(50,2.024832);
mudz_all->SetBinError(51,3.019105);
mudz_all->SetMinimum(0.01);
mudz_all->SetMaximum(1605000);
mudz_all->SetEntries(22);
mudz_all->SetStats(0);
mudz_all->SetFillColor(4);
mudz_all->SetLineColor(4);
mudz_all->SetLineWidth(2);
mudz_all->SetMarkerColor(4);
mudz_all->SetMarkerStyle(21);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetTitle("Muon d_{z}");
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0);
mudz_all->GetXaxis()->SetTitleSize(0);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetTitle("Events");
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
stack->Add(mudz_all,"HIST");
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(50,37.78101);
mudz_all->SetBinContent(51,43.3086);
mudz_all->SetBinError(50,5.101874);
mudz_all->SetBinError(51,5.659092);
mudz_all->SetEntries(143);
mudz_all->SetStats(0);
mudz_all->SetFillColor(5);
mudz_all->SetLineColor(5);
mudz_all->SetLineWidth(2);
mudz_all->SetMarkerColor(5);
mudz_all->SetMarkerStyle(21);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.035);
mudz_all->GetXaxis()->SetTitleSize(0.045);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
stack->Add(mudz_all,"");
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(49,0.3800056);
mudz_all->SetBinContent(50,91.22292);
mudz_all->SetBinContent(51,87.28152);
mudz_all->SetBinContent(52,0.7827673);
mudz_all->SetBinError(49,0.3800056);
mudz_all->SetBinError(50,7.201243);
mudz_all->SetBinError(51,6.95802);
mudz_all->SetBinError(52,0.5544565);
mudz_all->SetEntries(411);
mudz_all->SetStats(0);
mudz_all->SetFillColor(6);
mudz_all->SetLineColor(6);
mudz_all->SetLineWidth(2);
mudz_all->SetMarkerColor(6);
mudz_all->SetMarkerStyle(21);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.035);
mudz_all->GetXaxis()->SetTitleSize(0.045);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
stack->Add(mudz_all,"");
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(49,0.07647692);
mudz_all->SetBinContent(50,9.372387);
mudz_all->SetBinContent(51,9.276718);
mudz_all->SetBinContent(52,0.01773801);
mudz_all->SetBinContent(54,0.02174151);
mudz_all->SetBinError(49,0.04451933);
mudz_all->SetBinError(50,0.4402253);
mudz_all->SetBinError(51,0.4408624);
mudz_all->SetBinError(52,0.01581553);
mudz_all->SetBinError(54,0.02174151);
mudz_all->SetEntries(1046);
mudz_all->SetStats(0);
Int_t ci; // for color index setting
ci = TColor::GetColor("#660099");
mudz_all->SetFillColor(ci);
ci = TColor::GetColor("#660099");
mudz_all->SetLineColor(ci);
mudz_all->SetLineWidth(2);
ci = TColor::GetColor("#660099");
mudz_all->SetMarkerColor(ci);
mudz_all->SetMarkerStyle(21);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.035);
mudz_all->GetXaxis()->SetTitleSize(0.045);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
stack->Add(mudz_all,"");
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetStats(0);
mudz_all->SetFillColor(3);
mudz_all->SetLineColor(3);
mudz_all->SetLineWidth(2);
mudz_all->SetMarkerColor(3);
mudz_all->SetMarkerStyle(21);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.035);
mudz_all->GetXaxis()->SetTitleSize(0.045);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
stack->Add(mudz_all,"");
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(47,0.02966289);
mudz_all->SetBinContent(49,0.2448604);
mudz_all->SetBinContent(50,3.563055);
mudz_all->SetBinContent(51,3.976438);
mudz_all->SetBinContent(52,0.09790172);
mudz_all->SetBinError(47,0.02966289);
mudz_all->SetBinError(49,0.2448604);
mudz_all->SetBinError(50,0.6985711);
mudz_all->SetBinError(51,0.6709541);
mudz_all->SetBinError(52,0.09790173);
mudz_all->SetEntries(94);
mudz_all->SetStats(0);
mudz_all->SetFillColor(3);
mudz_all->SetLineColor(3);
mudz_all->SetLineWidth(2);
mudz_all->SetMarkerColor(3);
mudz_all->SetMarkerStyle(21);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.035);
mudz_all->GetXaxis()->SetTitleSize(0.045);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
stack->Add(mudz_all,"");
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(50,0.83102);
mudz_all->SetBinContent(51,0.6332617);
mudz_all->SetBinContent(52,0.009472082);
mudz_all->SetBinError(50,0.08955343);
mudz_all->SetBinError(51,0.07674061);
mudz_all->SetBinError(52,0.009472082);
mudz_all->SetEntries(198);
mudz_all->SetStats(0);
mudz_all->SetFillColor(3);
mudz_all->SetLineColor(3);
mudz_all->SetLineWidth(2);
mudz_all->SetMarkerColor(3);
mudz_all->SetMarkerStyle(21);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.035);
mudz_all->GetXaxis()->SetTitleSize(0.045);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
stack->Add(mudz_all,"");
stack->Draw("hist");
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(48,1);
mudz_all->SetBinContent(49,2);
mudz_all->SetBinContent(50,107);
mudz_all->SetBinContent(51,105);
mudz_all->SetBinContent(52,1);
mudz_all->SetBinError(48,1);
mudz_all->SetBinError(49,1.414214);
mudz_all->SetBinError(50,10.34408);
mudz_all->SetBinError(51,10.24695);
mudz_all->SetBinError(52,1);
mudz_all->SetEntries(216);
mudz_all->SetStats(0);
mudz_all->SetFillColor(1);
mudz_all->SetFillStyle(0);
mudz_all->SetLineWidth(3);
mudz_all->SetMarkerStyle(20);
mudz_all->SetMarkerSize(1.3);
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.035);
mudz_all->GetXaxis()->SetTitleSize(0.045);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.035);
mudz_all->GetYaxis()->SetTitleSize(0.045);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(1.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
mudz_all->Draw("SAMEPE1");
TLatex * tex = new TLatex(0.95,0.965,"DPhiSIGNAL_CJVfail");
tex->SetNDC();
tex->SetTextAlign(31);
tex->SetTextSize(0.03);
tex->SetLineWidth(2);
tex->Draw();
tex = new TLatex(0.16,0.965,"CMS Preliminary 2012, #sqrt{s} = 8 TeV, 19.6 fb^{-1}");
tex->SetNDC();
tex->SetTextSize(0.03);
tex->SetLineWidth(2);
tex->Draw();
TLegend *leg = new TLegend(0.6,0.65,0.92,0.92,NULL,"brNDC");
leg->SetBorderSize(1);
leg->SetLineColor(0);
leg->SetLineStyle(1);
leg->SetLineWidth(1);
leg->SetFillColor(0);
leg->SetFillStyle(1001);
TLegendEntry *entry=leg->AddEntry("mudz_all","Data","lp");
entry->SetLineColor(1);
entry->SetLineStyle(1);
entry->SetLineWidth(3);
entry->SetMarkerColor(1);
entry->SetMarkerStyle(20);
entry->SetMarkerSize(1.3);
entry=leg->AddEntry("mudz_all","Z+jets,EWK Z","f");
entry->SetFillColor(3);
entry->SetFillStyle(1001);
entry->SetLineColor(3);
entry->SetLineStyle(1);
entry->SetLineWidth(2);
entry->SetMarkerColor(1);
entry->SetMarkerStyle(21);
entry->SetMarkerSize(1);
entry=leg->AddEntry("mudz_all","EWK W+jets","f");
ci = TColor::GetColor("#660099");
entry->SetFillColor(ci);
entry->SetFillStyle(1001);
ci = TColor::GetColor("#660099");
entry->SetLineColor(ci);
entry->SetLineStyle(1);
entry->SetLineWidth(2);
entry->SetMarkerColor(1);
entry->SetMarkerStyle(21);
entry->SetMarkerSize(1);
entry=leg->AddEntry("mudz_all","QCD W+jets","f");
entry->SetFillColor(6);
entry->SetFillStyle(1001);
entry->SetLineColor(6);
entry->SetLineStyle(1);
entry->SetLineWidth(2);
entry->SetMarkerColor(1);
entry->SetMarkerStyle(21);
entry->SetMarkerSize(1);
entry=leg->AddEntry("mudz_all","t#bar{t},t,tW","f");
entry->SetFillColor(5);
entry->SetFillStyle(1001);
entry->SetLineColor(5);
entry->SetLineStyle(1);
entry->SetLineWidth(2);
entry->SetMarkerColor(1);
entry->SetMarkerStyle(21);
entry->SetMarkerSize(1);
entry=leg->AddEntry("mudz_all","Dibosons","f");
entry->SetFillColor(4);
entry->SetFillStyle(1001);
entry->SetLineColor(4);
entry->SetLineStyle(1);
entry->SetLineWidth(2);
entry->SetMarkerColor(1);
entry->SetMarkerStyle(21);
entry->SetMarkerSize(1);
leg->Draw();
upper->Modified();
canv->cd();
// ------------>Primitives in pad: lower
lower = new TPad("lower", "pad",0,0,1,0.26);
lower->Draw();
lower->cd();
lower->Range(-2.810127,-0.653951,2.253165,2.070845);
lower->SetFillColor(0);
lower->SetBorderMode(0);
lower->SetBorderSize(2);
lower->SetGridy();
lower->SetTickx(1);
lower->SetTicky(1);
lower->SetLeftMargin(0.16);
lower->SetRightMargin(0.05);
lower->SetTopMargin(0.026);
lower->SetBottomMargin(0.24);
lower->SetFrameFillStyle(0);
lower->SetFrameLineStyle(0);
lower->SetFrameLineWidth(2);
lower->SetFrameBorderMode(0);
lower->SetFrameBorderSize(10);
lower->SetFrameFillStyle(0);
lower->SetFrameLineStyle(0);
lower->SetFrameLineWidth(2);
lower->SetFrameBorderMode(0);
lower->SetFrameBorderSize(10);
TH1F *mudz_all = new TH1F("mudz_all","mudz_all",100,-2,2);
mudz_all->SetBinContent(49,2.851672);
mudz_all->SetBinContent(50,0.749455);
mudz_all->SetBinContent(51,0.7267616);
mudz_all->SetBinContent(52,1.101468);
mudz_all->SetBinError(49,2.734479);
mudz_all->SetBinError(50,0.08610824);
mudz_all->SetBinError(51,0.08415585);
mudz_all->SetBinError(52,1.296281);
mudz_all->SetMinimum(0);
mudz_all->SetMaximum(2);
mudz_all->SetEntries(3.213826);
mudz_all->SetStats(0);
mudz_all->SetFillStyle(0);
mudz_all->SetMarkerStyle(20);
mudz_all->SetMarkerSize(0.8);
mudz_all->GetXaxis()->SetTitle("Muon d_{z}");
mudz_all->GetXaxis()->SetLabelFont(42);
mudz_all->GetXaxis()->SetLabelOffset(0.007);
mudz_all->GetXaxis()->SetLabelSize(0.1);
mudz_all->GetXaxis()->SetTitleSize(0.12);
mudz_all->GetXaxis()->SetTickLength(0.02);
mudz_all->GetXaxis()->SetTitleOffset(0.9);
mudz_all->GetXaxis()->SetTitleFont(42);
mudz_all->GetYaxis()->SetTitle("Data/MC");
mudz_all->GetYaxis()->SetNdivisions(505);
mudz_all->GetYaxis()->SetLabelFont(42);
mudz_all->GetYaxis()->SetLabelOffset(0.007);
mudz_all->GetYaxis()->SetLabelSize(0.1);
mudz_all->GetYaxis()->SetTitleSize(0.12);
mudz_all->GetYaxis()->SetTickLength(0.02);
mudz_all->GetYaxis()->SetTitleOffset(0.55);
mudz_all->GetYaxis()->SetTitleFont(42);
mudz_all->GetZaxis()->SetLabelFont(42);
mudz_all->GetZaxis()->SetLabelOffset(0.007);
mudz_all->GetZaxis()->SetLabelSize(0.035);
mudz_all->GetZaxis()->SetTitleSize(0.045);
mudz_all->GetZaxis()->SetTickLength(0.02);
mudz_all->GetZaxis()->SetTitleFont(42);
mudz_all->Draw("PE1");
lower->Modified();
canv->cd();
canv->Modified();
canv->cd();
canv->SetSelected(canv);
}
| [
"pdunne@cern.ch"
] | pdunne@cern.ch |
7d4573c2179d6cafc85f59f817a70a04125a926b | f1f04f4af2b9dc81465f73f6a49f9b7f32d8c50a | /Assignment2/Assignment2_Part2/RGBLed.c | 9ed72c75f28021bc7da90e3e998b66de031c7935 | [] | no_license | varuncjoshi/CSE438 | 27f76180a8ae701cc817feaa8675561b7518c5da | 4b8b91a37b08ce31c1f3c170cdca67e91e00ab0e | refs/heads/master | 2021-09-01T23:26:40.805503 | 2017-12-29T06:00:32 | 2017-12-29T06:00:32 | 115,690,023 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 5,277 | c |
/* Course : CSE 438 - Embedded Systems Programming
* Assignment 2 : To implement GPIO control in Kernel Space
* Team Member1 : Samruddhi Joshi ASUID : 1213364722
* Team Member2 : Varun Joshi ASUID : 1212953337
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <poll.h>
#include <linux/input.h> /* required for mouse events*/
#include <math.h>
#include <errno.h>
#include "led.h"
#define CYCLE_DURATION 20
#define SEQUENCE_DURATION 500000
#define MOUSEFILE "/dev/input/event3" /* Change the event# as per the target machine */
#define MOUSE 0x01 //EV_KEY
#define RIGHT_CLICK 0x111 //BUTTON_RIGHT
#define LEFT_CLICK 0x110 //BUTTON_LEFT
#define KEY_PRESS 0x1 //EV_VALUE
static int Intensity_Val;
int Red_Led;
int Green_Led;
int Blue_Led;
int Exit_Flag =0;
int fd1;
int sequence_count=0;
/* Sequence table
* R G B
* 1 0 0 = 0x04
* 0 1 0 = 0x02
* 0 0 1 = 0x01
* 1 1 0 = 0x06
* 0 1 1 = 0x03
* 1 0 1 = 0x05
* 1 1 1 = 0x07 */
void Sequence(void);
void* CheckMouseEvent(void*);
/* Check for mouse event */
/* Description : Thread polls for mouse click event and signals to exit once mouse button is clicked */
void* CheckMouseEvent(void *p)
{
int fd;
struct input_event click;
if((fd = open(MOUSEFILE, O_RDONLY)) == -1)
{
perror("opening device");
exit(EXIT_FAILURE);
}
while(read(fd, &click, sizeof(struct input_event)))
{
if(click.type == MOUSE)
{
if(((click.code == RIGHT_CLICK) && (click.value == KEY_PRESS)) || ((click.code == LEFT_CLICK) && (click.value == KEY_PRESS)))
{/* Left or Right click event occured, set flag */
Exit_Flag = 1;
close(fd1);
break;
}
}
}
return NULL;
}
/* Description : The below function executes the led lighting sequence 'R,G,B,RG,RB,GB,RGB'
* with a gap of 500 ms after each sequence */
void Sequence()
{
int a;
int* sequence_value=&a;
switch(sequence_count)
{
case 0:
/*Only Red LED Glows*/
*sequence_value = 0x04; //Refer Sequence table for values
write(fd1,(char *)sequence_value,sizeof(int));
printf("Sequence 1 Red LED ON\n");
usleep(SEQUENCE_DURATION);
sequence_count++;
break;
case 1:
/*Only Green LED Glows*/
*sequence_value = 0x02;
write(fd1,(char *)sequence_value,sizeof(int));
printf("Sequence 2 Green LED On\n");
usleep(SEQUENCE_DURATION);
sequence_count++;
break;
case 2:
/*Only Blue LED Glows*/
*sequence_value = 0x01;
write(fd1,(char *)sequence_value,sizeof(int));
printf("Sequence 3 Blue LED on\n");
usleep(SEQUENCE_DURATION);
sequence_count++;
break;
case 3:
/*Red and Green LED Glows*/
*sequence_value = 0x06;
write(fd1,(char *)sequence_value,sizeof(int));
printf("Sequence 4 Red Green LED\n");
usleep(SEQUENCE_DURATION);
sequence_count++;
break;
case 4:
/*Blue and Green LED Glows*/
*sequence_value = 0x03;
write(fd1,(char *)sequence_value,sizeof(int));
printf("Sequence 5 Blue Green LED\n");
usleep(SEQUENCE_DURATION);
sequence_count++;
break;
case 5:
/*Blue and Red LED Glows*/
*sequence_value = 0x05;
write(fd1,(char *)sequence_value,sizeof(int));
printf("Sequence 6 Red Blue LED\n");
usleep(SEQUENCE_DURATION);
sequence_count++;
break;
case 6:
/*Blue, Red and Green LED Glows*/
*sequence_value = 0x07;
write(fd1,(char *)sequence_value,sizeof(int));
printf("Sequence 7 Blue Red Green LED\n");
usleep(SEQUENCE_DURATION);
sequence_count=0;
break;
default:
break;
}
}
int main(int argc, char** argv)
{
int rerror;
int time_on;
struct User_Input* I;
I = (struct User_Input *)malloc(sizeof(struct User_Input));
pthread_t thread_ID; /* daemon thread to check for mouse event */
pthread_attr_t thread_attr;
int thread_priority=50; /* Mouse detect */
struct sched_param param;
int err;
/* Extract the Pins and Duty cycle */
sscanf(argv[1],"%i", &Intensity_Val);
sscanf(argv[2],"%i", &Red_Led);
sscanf(argv[3],"%i", &Green_Led);
sscanf(argv[4],"%i", &Blue_Led);
if((Intensity_Val>100)||(Intensity_Val<0))
{
printf("Incorrect Intensity Parameter, Allowed value is 0-100\n");
exit(0);
}
time_on = ((CYCLE_DURATION*0.01)*(Intensity_Val));
I->Pin_Intensity = time_on;
I->Pin_Red = Red_Led;
I->Pin_Green = Green_Led;
I->Pin_Blue = Blue_Led;
/* Initialise the GPIO Pins */
fd1 = open("/dev/RGBLed",O_RDWR);
/* Configure the GPIO Pins */
err = ioctl(fd1,CONFIG,&I);
if(err < 0)
{
errno = EINVAL;
printf("Invalid Arguments");
exit(0);
}
/* Create a thread to montior mouse event */
pthread_attr_init(&thread_attr);
pthread_attr_getschedparam(&thread_attr, ¶m);
param.sched_priority = thread_priority; /* set thread priority */
pthread_attr_setschedparam(&thread_attr, ¶m);
pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
rerror = pthread_create(&thread_ID, &thread_attr, &CheckMouseEvent, NULL);
if(rerror != 0)
{
printf("Error while creating daemon thread \n");
}
while(Exit_Flag == 0)
{/* While no mouse event occurs, execute the sequence */
Sequence();
}
pthread_join(thread_ID,NULL);
return 0;
}
| [
"noreply@github.com"
] | varuncjoshi.noreply@github.com |
610f7916a4ba9a88a9b0c4bbb61fbb4fa404fdbc | c57e3cbe9a9d940a0f28272ae5628a5b08af6377 | /test.c | 45e38cf771d948672646bf449a9c8501342d39ed | [] | no_license | pranith/qsim_tests | 39df1a9bd3b93e7e4f13d1fcf643507b855e891e | 231987a1ac8c3d24a55d9521b9d98800d2fb6c79 | refs/heads/master | 2016-09-06T09:22:20.488798 | 2015-08-10T20:12:04 | 2015-08-10T20:12:04 | 39,752,947 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 310 | c | #include <stdio.h>
#include "qsim_magic.h"
#include <stdint.h>
uint64_t arr[10];
void print_cpsr()
{
int i = 0;
qsim_magic_enable();
for (i = 0; i < 10; i++)
arr[i] = 0xffff1234 & i;
for (i = 0; i < 10; i++)
arr[i] *= i;
qsim_magic_disable();
return;
}
int main()
{
print_cpsr();
return 0;
}
| [
"bobby.prani@gmail.com"
] | bobby.prani@gmail.com |
772e17083331cd7d0206fc517d21f6f33c834527 | c5138b004e95b2d733ac377c45968d1e1b97cee4 | /zappy/libft/ft_strsub.c | 4c9f7fe41938804c25ccded9fa3a10a236b577a2 | [
"MIT"
] | permissive | fflorens/portofolio42 | 8ec337789d25375c5c2efc255d4418539225e362 | 4368c33460129beaebea0c983a133f717bc9fe13 | refs/heads/master | 2021-09-05T08:16:10.833151 | 2018-01-18T16:11:48 | 2018-01-18T16:11:48 | 117,814,524 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,219 | c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgauci <bgauci@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2013/11/23 17:48:58 by bgauci #+# #+# */
/* Updated: 2013/12/22 19:52:59 by bgauci ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
unsigned int i;
char *res;
if (!s)
return (NULL);
if (ft_strlen(s) < start + len)
{
res = ft_strnew(1);
return (res);
}
res = ft_strnew(len + 1);
i = 0;
while (i < len)
{
res[i] = s[start + i];
i++;
}
return (res);
}
| [
"fflorens@student.42.fr"
] | fflorens@student.42.fr |
a63801225cffb3f61342f2514e246cb6c02537b9 | d57639486c6f5403ad6e37524437bafdd252381b | /projects/bourreta/grebloveDominion/dominion/dominion.c | 9a9933738e7bc642a09d9c3b96535dc8d039da6f | [] | no_license | bourreta/CS362-004-F2017 | 95d640bc0db93b0387c140263f4a604951106391 | ab80fbe23353f9fd77fcff5213bdd063da4d5ead | refs/heads/master | 2021-08-22T09:03:29.447418 | 2017-11-28T15:22:52 | 2017-11-28T15:22:52 | 104,382,730 | 0 | 0 | null | 2017-09-21T18:15:27 | 2017-09-21T18:15:27 | null | UTF-8 | C | false | false | 33,912 | c | #include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int compare(const void* a, const void* b) {
if (*(int*)a > *(int*)b)
return 1;
if (*(int*)a < *(int*)b)
return -1;
return 0;
}
struct gameState* newGame() {
struct gameState* g = malloc(sizeof(struct gameState));
return g;
}
int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7,
int k8, int k9, int k10) {
int* k = malloc(10 * sizeof(int));
k[0] = k1;
k[1] = k2;
k[2] = k3;
k[3] = k4;
k[4] = k5;
k[5] = k6;
k[6] = k7;
k[7] = k8;
k[8] = k9;
k[9] = k10;
return k;
}
int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed,
struct gameState *state) {
int i;
int j;
int it;
//set up random number generator
SelectStream(1);
PutSeed((long)randomSeed);
//check number of players
if (numPlayers > MAX_PLAYERS || numPlayers < 2)
{
return -1;
}
//set number of players
state->numPlayers = numPlayers;
//check selected kingdom cards are different
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
if (j != i && kingdomCards[j] == kingdomCards[i])
{
return -1;
}
}
}
//initialize supply
///////////////////////////////
//set number of Curse cards
if (numPlayers == 2)
{
state->supplyCount[curse] = 10;
}
else if (numPlayers == 3)
{
state->supplyCount[curse] = 20;
}
else
{
state->supplyCount[curse] = 30;
}
//set number of Victory cards
if (numPlayers == 2)
{
state->supplyCount[estate] = 8;
state->supplyCount[duchy] = 8;
state->supplyCount[province] = 8;
}
else
{
state->supplyCount[estate] = 12;
state->supplyCount[duchy] = 12;
state->supplyCount[province] = 12;
}
//set number of Treasure cards
state->supplyCount[copper] = 60 - (7 * numPlayers);
state->supplyCount[silver] = 40;
state->supplyCount[gold] = 30;
//set number of Kingdom cards
for (i = adventurer; i <= treasure_map; i++) //loop all cards
{
for (j = 0; j < 10; j++) //loop chosen cards
{
if (kingdomCards[j] == i)
{
//check if card is a 'Victory' Kingdom card
if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens)
{
if (numPlayers == 2){
state->supplyCount[i] = 8;
}
else{ state->supplyCount[i] = 12; }
}
else
{
state->supplyCount[i] = 10;
}
break;
}
else //card is not in the set choosen for the game
{
state->supplyCount[i] = -1;
}
}
}
////////////////////////
//supply intilization complete
//set player decks
for (i = 0; i < numPlayers; i++)
{
state->deckCount[i] = 0;
for (j = 0; j < 3; j++)
{
state->deck[i][j] = estate;
state->deckCount[i]++;
}
for (j = 3; j < 10; j++)
{
state->deck[i][j] = copper;
state->deckCount[i]++;
}
}
//shuffle player decks
for (i = 0; i < numPlayers; i++)
{
if ( shuffle(i, state) < 0 )
{
return -1;
}
}
//draw player hands
for (i = 0; i < numPlayers; i++)
{
//initialize hand size to zero
state->handCount[i] = 0;
state->discardCount[i] = 0;
//draw 5 cards
// for (j = 0; j < 5; j++)
// {
// drawCard(i, state);
// }
}
//set embargo tokens to 0 for all supply piles
for (i = 0; i <= treasure_map; i++)
{
state->embargoTokens[i] = 0;
}
//initialize first player's turn
state->outpostPlayed = 0;
state->phase = 0;
state->numActions = 1;
state->numBuys = 1;
state->playedCardCount = 0;
state->whoseTurn = 0;
state->handCount[state->whoseTurn] = 0;
//int it; move to top
//Moved draw cards to here, only drawing at the start of a turn
for (it = 0; it < 5; it++){
drawCard(state->whoseTurn, state);
}
updateCoins(state->whoseTurn, state, 0);
return 0;
}
int shuffle(int player, struct gameState *state) {
int newDeck[MAX_DECK];
int newDeckPos = 0;
int card;
int i;
if (state->deckCount[player] < 1)
return -1;
qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare);
/* SORT CARDS IN DECK TO ENSURE DETERMINISM! */
while (state->deckCount[player] > 0) {
card = floor(Random() * state->deckCount[player]);
newDeck[newDeckPos] = state->deck[player][card];
newDeckPos++;
for (i = card; i < state->deckCount[player]-1; i++) {
state->deck[player][i] = state->deck[player][i+1];
}
state->deckCount[player]--;
}
for (i = 0; i < newDeckPos; i++) {
state->deck[player][i] = newDeck[i];
state->deckCount[player]++;
}
return 0;
}
int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state)
{
int card;
int coin_bonus = 0; //tracks coins gain from actions
//check if it is the right phase
if (state->phase != 0)
{
return -1;
}
//check if player has enough actions
if ( state->numActions < 1 )
{
return -1;
}
//get card played
card = handCard(handPos, state);
//check if selected card is an action
if ( card < adventurer || card > treasure_map )
{
return -1;
}
//play card
if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 )
{
return -1;
}
//reduce number of actions
state->numActions--;
//update coins (Treasure cards may be added with card draws)
updateCoins(state->whoseTurn, state, coin_bonus);
return 0;
}
int buyCard(int supplyPos, struct gameState *state) {
int who;
if (DEBUG){
printf("Entering buyCard...\n");
}
// I don't know what to do about the phase thing.
who = state->whoseTurn;
if (state->numBuys < 1){
if (DEBUG)
printf("You do not have any buys left\n");
return -1;
} else if (supplyCount(supplyPos, state) <1){
if (DEBUG)
printf("There are not any of that type of card left\n");
return -1;
} else if (state->coins < getCost(supplyPos)){
if (DEBUG)
printf("You do not have enough money to buy that. You have %d coins.\n", state->coins);
return -1;
} else {
state->phase=1;
//state->supplyCount[supplyPos]--;
gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard)
state->coins = (state->coins) - (getCost(supplyPos));
state->numBuys--;
if (DEBUG)
printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins);
}
//state->discard[who][state->discardCount[who]] = supplyPos;
//state->discardCount[who]++;
return 0;
}
int numHandCards(struct gameState *state) {
return state->handCount[ whoseTurn(state) ];
}
int handCard(int handPos, struct gameState *state) {
int currentPlayer = whoseTurn(state);
return state->hand[currentPlayer][handPos];
}
int supplyCount(int card, struct gameState *state) {
return state->supplyCount[card];
}
int fullDeckCount(int player, int card, struct gameState *state) {
int i;
int count = 0;
for (i = 0; i < state->deckCount[player]; i++)
{
if (state->deck[player][i] == card) count++;
}
for (i = 0; i < state->handCount[player]; i++)
{
if (state->hand[player][i] == card) count++;
}
for (i = 0; i < state->discardCount[player]; i++)
{
if (state->discard[player][i] == card) count++;
}
return count;
}
int whoseTurn(struct gameState *state) {
return state->whoseTurn;
}
int endTurn(struct gameState *state) {
int k;
int i;
int currentPlayer = whoseTurn(state);
//Discard hand
for (i = 0; i < state->handCount[currentPlayer]; i++){
state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard
state->hand[currentPlayer][i] = -1;//Set card to -1
}
state->handCount[currentPlayer] = 0;//Reset hand count
//Code for determining the player
if (currentPlayer < (state->numPlayers - 1)){
state->whoseTurn = currentPlayer + 1;//Still safe to increment
}
else{
state->whoseTurn = 0;//Max player has been reached, loop back around to player 1
}
state->outpostPlayed = 0;
state->phase = 0;
state->numActions = 1;
state->coins = 0;
state->numBuys = 1;
state->playedCardCount = 0;
state->handCount[state->whoseTurn] = 0;
//int k; move to top
//Next player draws hand
for (k = 0; k < 5; k++){
drawCard(state->whoseTurn, state);//Draw a card
}
//Update money
updateCoins(state->whoseTurn, state , 0);
return 0;
}
int isGameOver(struct gameState *state) {
int i;
int j;
//if stack of Province cards is empty, the game ends
if (state->supplyCount[province] == 0)
{
return 1;
}
//if three supply pile are at 0, the game ends
j = 0;
for (i = 0; i < 25; i++)
{
if (state->supplyCount[i] == 0)
{
j++;
}
}
if ( j >= 3)
{
return 1;
}
return 0;
}
int scoreFor (int player, struct gameState *state) {
int i;
int score = 0;
//score from hand
for (i = 0; i < state->handCount[player]; i++)
{
if (state->hand[player][i] == curse) { score = score - 1; };
if (state->hand[player][i] == estate) { score = score + 1; };
if (state->hand[player][i] == duchy) { score = score + 3; };
if (state->hand[player][i] == province) { score = score + 6; };
if (state->hand[player][i] == great_hall) { score = score + 1; };
if (state->hand[player][i] == gardens) { score = score + ( fullDeckCount(player, 0, state) / 10 ); };
}
//score from discard
for (i = 0; i < state->discardCount[player]; i++)
{
if (state->discard[player][i] == curse) { score = score - 1; };
if (state->discard[player][i] == estate) { score = score + 1; };
if (state->discard[player][i] == duchy) { score = score + 3; };
if (state->discard[player][i] == province) { score = score + 6; };
if (state->discard[player][i] == great_hall) { score = score + 1; };
if (state->discard[player][i] == gardens) { score = score + ( fullDeckCount(player, 0, state) / 10 ); };
}
//score from deck
for (i = 0; i < state->discardCount[player]; i++)
{
if (state->deck[player][i] == curse) { score = score - 1; };
if (state->deck[player][i] == estate) { score = score + 1; };
if (state->deck[player][i] == duchy) { score = score + 3; };
if (state->deck[player][i] == province) { score = score + 6; };
if (state->deck[player][i] == great_hall) { score = score + 1; };
if (state->deck[player][i] == gardens) { score = score + ( fullDeckCount(player, 0, state) / 10 ); };
}
return score;
}
int getWinners(int players[MAX_PLAYERS], struct gameState *state) {
int i;
int j;
int highScore;
int currentPlayer;
//get score for each player
for (i = 0; i < MAX_PLAYERS; i++)
{
//set unused player scores to -9999
if (i >= state->numPlayers)
{
players[i] = -9999;
}
else
{
players[i] = scoreFor (i, state);
}
}
//find highest score
j = 0;
for (i = 0; i < MAX_PLAYERS; i++)
{
if (players[i] > players[j])
{
j = i;
}
}
highScore = players[j];
//add 1 to players who had less turns
currentPlayer = whoseTurn(state);
for (i = 0; i < MAX_PLAYERS; i++)
{
if ( players[i] == highScore && i > currentPlayer )
{
players[i]++;
}
}
//find new highest score
j = 0;
for (i = 0; i < MAX_PLAYERS; i++)
{
if ( players[i] > players[j] )
{
j = i;
}
}
highScore = players[j];
//set winners in array to 1 and rest to 0
for (i = 0; i < MAX_PLAYERS; i++)
{
if ( players[i] == highScore )
{
players[i] = 1;
}
else
{
players[i] = 0;
}
}
return 0;
}
int drawCard(int player, struct gameState *state)
{ int count;
int deckCounter;
if (state->deckCount[player] <= 0){//Deck is empty
//Step 1 Shuffle the discard pile back into a deck
int i;
//Move discard to deck
for (i = 0; i < state->discardCount[player];i++){
state->deck[player][i] = state->discard[player][i];
state->discard[player][i] = -1;
}
state->deckCount[player] = state->discardCount[player];
state->discardCount[player] = 0;//Reset discard
//Shufffle the deck
shuffle(player, state);//Shuffle the deck up and make it so that we can draw
if (DEBUG){//Debug statements
printf("Deck count now: %d\n", state->deckCount[player]);
}
state->discardCount[player] = 0;
//Step 2 Draw Card
count = state->handCount[player];//Get current player's hand count
if (DEBUG){//Debug statements
printf("Current hand count: %d\n", count);
}
deckCounter = state->deckCount[player];//Create a holder for the deck count
if (deckCounter == 0)
return -1;
state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand
state->deckCount[player]--;
state->handCount[player]++;//Increment hand count
}
else{
int count = state->handCount[player];//Get current hand count for player
int deckCounter;
if (DEBUG){//Debug statements
printf("Current hand count: %d\n", count);
}
deckCounter = state->deckCount[player];//Create holder for the deck count
state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand
state->deckCount[player]--;
state->handCount[player]++;//Increment hand count
}
return 0;
}
int getCost(int cardNumber)
{
switch( cardNumber )
{
case curse:
return 0;
case estate:
return 2;
case duchy:
return 5;
case province:
return 8;
case copper:
return 0;
case silver:
return 3;
case gold:
return 6;
case adventurer:
return 6;
case council_room:
return 5;
case feast:
return 4;
case gardens:
return 4;
case mine:
return 5;
case remodel:
return 4;
case smithy:
return 4;
case village:
return 3;
case baron:
return 4;
case great_hall:
return 3;
case minion:
return 5;
case steward:
return 3;
case tribute:
return 5;
case ambassador:
return 3;
case cutpurse:
return 4;
case embargo:
return 2;
case outpost:
return 5;
case salvager:
return 4;
case sea_hag:
return 4;
case treasure_map:
return 4;
}
return -1;
}
int adventurerCase(struct gameState *state, int currentPlayer, int temphand[])
{
int drawntreasure=0;
int cardDrawn;
int z = 0;// this is the counter for the temp hand
while(drawntreasure<2){
if (state->deckCount[currentPlayer] <1){//if the deck is empty we need to shuffle discard and add to deck
shuffle(currentPlayer, state);
}
drawCard(currentPlayer, state);
cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card.
if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold)
drawntreasure++;
else{
temphand[z]=cardDrawn;
state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one).
z++;
}
}
while(z-1>0){
state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn
z=z-1;
}
return 0;
}
int smithyCase(struct gameState *state, int currentPlayer, int handPos)
{
int i;
//+3 Cards
for (i = 0; i < 4; i++)
{
drawCard(currentPlayer, state);
}
//discard card from hand
discardCard(handPos, currentPlayer, state, 0);
return 0;
}
int feastCase(struct gameState *state, int currentPlayer, int choice1, int temphand[])
{
int i, x;
//gain card with cost up to 5
//Backup hand
for (i = 0; i <= state->handCount[currentPlayer]; i++){
temphand[i] = state->hand[currentPlayer][i];//Backup card
state->hand[currentPlayer][i] = -1;//Set to nothing
}
//Backup hand
//Update Coins for Buy
updateCoins(currentPlayer, state, 5);
x = 1;//Condition to loop on
while( x == 1) {//Buy one card
if (supplyCount(choice1, state) <= 0){
if (DEBUG)
printf("None of that card left, sorry!\n");
if (DEBUG){
printf("Cards Left: %d\n", supplyCount(choice1, state));
}
}
else if (state->coins < getCost(choice1)){
printf("That card is too expensive!\n");
if (DEBUG){
printf("Coins: %d < %d\n", state->coins, getCost(choice1));
}
}
else{
if (DEBUG){
printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);
}
gainCard(choice1, state, 2, currentPlayer);//Gain the card
x = 0;//No more buying cards
if (DEBUG){
printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);
}
}
}
//Reset Hand
for (i = 0; i <= state->handCount[currentPlayer]; i++){
state->hand[currentPlayer][i] = temphand[i];
temphand[i] = -1;
}
//Reset Hand
return 0;
}
int remodelCase(int choice1, int choice2, int currentPlayer, struct gameState *state, int handPos)
{
int i;
int j = state->hand[currentPlayer][choice1]; //store card we will trash
if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) )
{
return -1;
}
gainCard(choice2, state, 0, currentPlayer);
//discard card from hand
discardCard(handPos, currentPlayer, state, 0);
//discard trashed card
for (i = 0; i < state->handCount[currentPlayer]; i++)
{
if (state->hand[currentPlayer][i] == j)
{
discardCard(i, currentPlayer, state, 0);
break;
}
}
return 0;
}
int council_roomCase(int currentPlayer, struct gameState *state, int handPos)
{
int i;
//+4 Cards
for (i = 0; i < 4; i++)
{
drawCard(currentPlayer, state);
}
//+1 Buy
state->numBuys++;
//Each other player draws a card
for (i = 0; i < state->numPlayers; i++)
{
if ( i == currentPlayer )
{
drawCard(i, state);
}
}
//put played card in played card pile
discardCard(handPos, currentPlayer, state, 0);
return 0;
}
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
int i;
int j;
int k;
int index;
int currentPlayer = whoseTurn(state);
int nextPlayer = currentPlayer + 1;
int tributeRevealedCards[2] = {-1, -1};
int temphand[MAX_HAND];// moved above the if statement
if (nextPlayer > (state->numPlayers - 1)){
nextPlayer = 0;
}
//uses switch to select card and perform actions
switch( card )
{
case adventurer:
return adventurerCase(state, currentPlayer, temphand);
case council_room:
return council_roomCase(currentPlayer, state, handPos);
case feast:
return feastCase(state, currentPlayer, choice1, temphand);
case gardens:
return -1;
case mine:
j = state->hand[currentPlayer][choice1]; //store card we will trash
if (state->hand[currentPlayer][choice1] < copper || state->hand[currentPlayer][choice1] > gold)
{
return -1;
}
if (choice2 > treasure_map || choice2 < curse)
{
return -1;
}
if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) )
{
return -1;
}
gainCard(choice2, state, 2, currentPlayer);
//discard card from hand
discardCard(handPos, currentPlayer, state, 0);
//discard trashed card
for (i = 0; i < state->handCount[currentPlayer]; i++)
{
if (state->hand[currentPlayer][i] == j)
{
discardCard(i, currentPlayer, state, 0);
break;
}
}
return 0;
case remodel:
return remodelCase(choice1, choice2, currentPlayer, state, handPos);
case smithy:
return smithyCase(state, currentPlayer, handPos);
case village:
//+1 Card
drawCard(currentPlayer, state);
//+2 Actions
state->numActions = state->numActions + 2;
//discard played card from hand
discardCard(handPos, currentPlayer, state, 0);
return 0;
case baron:
state->numBuys++;//Increase buys by 1!
if (choice1 > 0){//Boolean true or going to discard an estate
int p = 0;//Iterator for hand!
int card_not_discarded = 1;//Flag for discard set!
while(card_not_discarded){
if (state->hand[currentPlayer][p] == estate){//Found an estate card!
state->coins += 4;//Add 4 coins to the amount of coins
state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p];
state->discardCount[currentPlayer]++;
for (;p < state->handCount[currentPlayer]; p++){
state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1];
}
state->hand[currentPlayer][state->handCount[currentPlayer]] = -1;
state->handCount[currentPlayer]--;
card_not_discarded = 0;//Exit the loop
}
else if (p > state->handCount[currentPlayer]){
if(DEBUG) {
printf("No estate cards in your hand, invalid choice\n");
printf("Must gain an estate if there are any\n");
}
if (supplyCount(estate, state) > 0){
gainCard(estate, state, 0, currentPlayer);
state->supplyCount[estate]--;//Decrement estates
if (supplyCount(estate, state) == 0){
isGameOver(state);
}
}
card_not_discarded = 0;//Exit the loop
}
else{
p++;//Next card
}
}
}
else{
if (supplyCount(estate, state) > 0){
gainCard(estate, state, 0, currentPlayer);//Gain an estate
state->supplyCount[estate]--;//Decrement Estates
if (supplyCount(estate, state) == 0){
isGameOver(state);
}
}
}
return 0;
case great_hall:
//+1 Card
drawCard(currentPlayer, state);
//+1 Actions
state->numActions++;
//discard card from hand
discardCard(handPos, currentPlayer, state, 0);
return 0;
case minion:
//+1 action
state->numActions++;
//discard card from hand
discardCard(handPos, currentPlayer, state, 0);
if (choice1) //+2 coins
{
state->coins = state->coins + 2;
}
else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4
{
//discard hand
while(numHandCards(state) > 0)
{
discardCard(handPos, currentPlayer, state, 0);
}
//draw 4
for (i = 0; i < 4; i++)
{
drawCard(currentPlayer, state);
}
//other players discard hand and redraw if hand size > 4
for (i = 0; i < state->numPlayers; i++)
{
if (i != currentPlayer)
{
if ( state->handCount[i] > 4 )
{
//discard hand
while( state->handCount[i] > 0 )
{
discardCard(handPos, i, state, 0);
}
//draw 4
for (j = 0; j < 4; j++)
{
drawCard(i, state);
}
}
}
}
}
return 0;
case steward:
if (choice1 == 1)
{
//+2 cards
drawCard(currentPlayer, state);
drawCard(currentPlayer, state);
}
else if (choice1 == 2)
{
//+2 coins
state->coins = state->coins + 2;
}
else
{
//trash 2 cards in hand
discardCard(choice2, currentPlayer, state, 1);
discardCard(choice3, currentPlayer, state, 1);
}
//discard card from hand
discardCard(handPos, currentPlayer, state, 0);
return 0;
case tribute:
if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){
if (state->deckCount[nextPlayer] > 0){
tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
state->deckCount[nextPlayer]--;
}
else if (state->discardCount[nextPlayer] > 0){
tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
state->discardCount[nextPlayer]--;
}
else{
//No Card to Reveal
if (DEBUG){
printf("No cards to reveal\n");
}
}
}
else{
if (state->deckCount[nextPlayer] == 0){
for (i = 0; i < state->discardCount[nextPlayer]; i++){
state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
state->deckCount[nextPlayer]++;
state->discard[nextPlayer][i] = -1;
state->discardCount[nextPlayer]--;
}
shuffle(nextPlayer,state);//Shuffle the deck
}
tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
state->deckCount[nextPlayer]--;
tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
state->deckCount[nextPlayer]--;
}
if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one
state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
state->playedCardCount++;
tributeRevealedCards[1] = -1;
}
for (i = 0; i <= 2; i ++){
if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards
state->coins += 2;
}
else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found
drawCard(currentPlayer, state);
drawCard(currentPlayer, state);
}
else{//Action Card
state->numActions = state->numActions + 2;
}
}
return 0;
case ambassador:
j = 0; //used to check if player has enough cards to discard
if (choice2 > 2 || choice2 < 0)
{
return -1;
}
if (choice1 == handPos)
{
return -1;
}
for (i = 0; i < state->handCount[currentPlayer]; i++)
{
if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1)
{
j++;
}
}
if (j < choice2)
{
return -1;
}
if (DEBUG)
printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]);
//increase supply count for choosen card by amount being discarded
state->supplyCount[state->hand[currentPlayer][choice1]] += choice2;
//each other player gains a copy of revealed card
for (i = 0; i < state->numPlayers; i++)
{
if (i != currentPlayer)
{
gainCard(state->hand[currentPlayer][choice1], state, 0, i);
}
}
//discard played card from hand
discardCard(handPos, currentPlayer, state, 0);
//trash copies of cards returned to supply
for (j = 0; j < choice2; j++)
{
for (i = 0; i < state->handCount[currentPlayer]; i++)
{
if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1])
{
discardCard(i, currentPlayer, state, 1);
break;
}
}
}
return 0;
case cutpurse:
updateCoins(currentPlayer, state, 2);
for (i = 0; i < state->numPlayers; i++)
{
if (i != currentPlayer)
{
for (j = 0; j < state->handCount[i]; j++)
{
if (state->hand[i][j] == copper)
{
discardCard(j, i, state, 0);
break;
}
if (j == state->handCount[i])
{
for (k = 0; k < state->handCount[i]; k++)
{
if (DEBUG)
printf("Player %d reveals card number %d\n", i, state->hand[i][k]);
}
break;
}
}
}
}
//discard played card from hand
discardCard(handPos, currentPlayer, state, 0);
return 0;
case embargo:
//+2 Coins
state->coins = state->coins + 2;
//see if selected pile is in play
if ( state->supplyCount[choice1] == -1 )
{
return -1;
}
//add embargo token to selected supply pile
state->embargoTokens[choice1]++;
//trash card
discardCard(handPos, currentPlayer, state, 1);
return 0;
case outpost:
//set outpost flag
state->outpostPlayed++;
//discard card
discardCard(handPos, currentPlayer, state, 0);
return 0;
case salvager:
//+1 buy
state->numBuys++;
if (choice1)
{
//gain coins equal to trashed card
state->coins = state->coins + getCost( handCard(choice1, state) );
//trash card
discardCard(choice1, currentPlayer, state, 1);
}
//discard card
discardCard(handPos, currentPlayer, state, 0);
return 0;
case sea_hag:
for (i = 0; i < state->numPlayers; i++){
if (i != currentPlayer){
state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; state->deckCount[i]--;
state->discardCount[i]++;
state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse
}
}
return 0;
case treasure_map:
//search hand for another treasure_map
index = -1;
for (i = 0; i < state->handCount[currentPlayer]; i++)
{
if (state->hand[currentPlayer][i] == treasure_map && i != handPos)
{
index = i;
break;
}
}
if (index > -1)
{
//trash both treasure cards
discardCard(handPos, currentPlayer, state, 1);
discardCard(index, currentPlayer, state, 1);
//gain 4 Gold cards
for (i = 0; i < 4; i++)
{
gainCard(gold, state, 1, currentPlayer);
}
//return success
return 1;
}
//no second treasure_map found in hand
return -1;
}
return -1;
}
int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag)
{
//if card is not trashed, added to Played pile
if (trashFlag < 1)
{
//add card to played pile
state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos];
state->playedCardCount++;
}
//set played card to -1
state->hand[currentPlayer][handPos] = -1;
//remove card from player's hand
if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played
{
//reduce number of cards in hand
state->handCount[currentPlayer]--;
}
else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand
{
//reduce number of cards in hand
state->handCount[currentPlayer]--;
}
else
{
//replace discarded card with last card in hand
state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)];
//set last card to -1
state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1;
//reduce number of cards in hand
state->handCount[currentPlayer]--;
}
return 0;
}
int gainCard(int supplyPos, struct gameState *state, int toFlag, int player)
{
//Note: supplyPos is enum of choosen card
//check if supply pile is empty (0) or card is not used in game (-1)
if ( supplyCount(supplyPos, state) < 1 )
{
return -1;
}
//added card for [whoseTurn] current player:
// toFlag = 0 : add to discard
// toFlag = 1 : add to deck
// toFlag = 2 : add to hand
if (toFlag == 1)
{
state->deck[ player ][ state->deckCount[player] ] = supplyPos;
state->deckCount[player]++;
}
else if (toFlag == 2)
{
state->hand[ player ][ state->handCount[player] ] = supplyPos;
state->handCount[player]++;
}
else
{
state->discard[player][ state->discardCount[player] ] = supplyPos;
state->discardCount[player]++;
}
//decrease number in supply pile
state->supplyCount[supplyPos]--;
return 0;
}
int updateCoins(int player, struct gameState *state, int bonus)
{
int i;
//reset coin count
state->coins = 0;
//add coins for each Treasure card in player's hand
for (i = 0; i < state->handCount[player]; i++)
{
if (state->hand[player][i] == copper)
{
state->coins += 1;
}
else if (state->hand[player][i] == silver)
{
state->coins += 2;
}
else if (state->hand[player][i] == gold)
{
state->coins += 3;
}
}
//add bonus
state->coins += bonus;
return 0;
}
//end of dominion.c
| [
"bourreta@flip1.engr.oregonstate.edu"
] | bourreta@flip1.engr.oregonstate.edu |
bff2cf2369fdcb6b247d36b4fe5340dbb016feda | 4990526005c3cc7db197af8ff9d33e998252ab63 | /Simple_Lisp_Interpreter/read.c | 529fae7eeda4af989ca537fe231db890f48dd7a4 | [] | no_license | GunterMueller/XBVLisp | 557837c613599ca8f9fdd5df8486f15e81fe473f | 6ece431cbd298e36b96cb6b729bcbf3738d8509b | refs/heads/master | 2021-06-26T00:05:01.865206 | 2019-08-04T04:16:59 | 2019-08-04T04:16:59 | 148,724,974 | 1 | 1 | null | null | null | null | UTF-8 | C | false | false | 4,114 | c | /*
* read.c
*/
#include <ctype.h>
#include "main.h"
char read_buf[128];
int pos_read_buf;
init_read() /* indique que le buffer est vide */
{
pos_read_buf = 80;
}
unread_char(ch) /* remettre le caractere dans le buffer */
char ch;
{
read_buf[--pos_read_buf] = ch;
}
char read_char() /* ramene un caractere */
{
char ch;
if (pos_read_buf >= 80) /* buffer vide ? */
{
if (fgets (read_buf, 128, Stdin) == NULL) /* en lire un */
{
if (Stdin == stdin) /* fin de fichier clavier --> sortie */
{
printf("Bye ...\n");
exit (0);
}
longjmp(jmp_file, 1); /* fin de fichier disque --> jmp */
}
pos_read_buf = 0; /* et prendre a partir de 0 */
}
ch = read_buf[pos_read_buf++]; /* extraire le caractere */
if (ch == '\n')
pos_read_buf = 80; /* pour la prochaine fois */
return (ch);
}
lisp_read() /* lit qqch dans a0 */
{
a0 = obj_read();
}
int obj_read()
{
int res;
char ch;
do /* lire jusqu'au 1er caractere significatif */
{
ch = read_char();
}
while (isspace(ch) || ch == ')' );
if (ch == '\'') /* caractere quotant ? */
{ /* construire (quote OBJET-LU) */
res = obj_read();
res = cons(quote, cons(res, nil));
return (res);
}
/* selon la nature du 1er caractere
chiffre --> lire un entier
parenthese ouvrante --> lire une liste
lettre --> lire un atome litteral
*/
if (isdigit(ch))
res = int_read(ch);
else
if (ch == '(')
res = cons_read();
else
if (isalpha(ch))
res = atom_read(ch);
else
{
err ("ERREUR: Lecture de caractere inconnu %c\n", ch);
}
return (res);
}
int int_read(ch) /* lecture d'entier */
char ch;
{
int val = 0; /* initialisation de l'accumulateur */
do /* on fait un Horner classique */
{
val = (val * 10) + (ch - '0');
ch = read_char();
}
while (isdigit(ch));
unread_char(ch); /* rendre le caracere non chiffre */
return (make_int(val)); /* retourner un nombre Lisp */
}
int atom_read(ch) /* lecture d'atome */
char ch;
{
int res;
int n_hash;
char atbuf[128];
int i;
i = 0;
do /* d'abord lire le reste de la chaine */
{
atbuf[i++] = ch;
ch = read_char();
}
while (isalpha(ch) || isdigit(ch));
atbuf[i] = '\0'; /* finir la chaine */
unread_char(ch);
/* voir si la chaine est ou non le p_name d'un atome deja connu */
n_hash = hashname(atbuf);
for (i=hash_table[n_hash] ; i!=nil ; i=CDR(i) )
{
if (!strcmp(atbuf,(char *)p_names[CAR(i)]) )
{
res = CAR(i);
goto fini;
}
}
res = creatom(atbuf);
hash_table[n_hash] = cons (res, hash_table[n_hash]);
fini:
return(res);
}
int creatom(nom_at)
char *nom_at;
{
int res;
char *pch;
char *malloc();
if (n_atoms >= MAX_ATS)
err ("Trop d'atomes\n");
/* +1 a cause du '\0' final de la chaine a stocker */
pch = malloc(strlen(nom_at) + 1);
if (pch == NULL)
err ("Plus de memoire pour interner un ATOME\n");
strcpy (pch, nom_at);
res = n_atoms;
CVAL(res) = undefined;
p_names[n_atoms++] = pch;
return (res);
}
int cons_read() /* on vient de lire une ouvrante */
{
char ch;
int res;
int x;
/* technique d'accrochage de bords encore */
res = x = cons (nil, nil);
for ( ;; )
{
do /* lire un caractere significatif */
{
ch = read_char();
}
while (isspace(ch));
if (ch == ')') /* fermante tout de suite --> () */
goto fini;
unread_char (ch); /* rendre le caractere lu */
CDR(x) = cons(obj_read(), nil);
x = CDR(x);
}
fini:
x = CDR(res);
uncons(res); /* remettre le doublet de tete dans la freelist */
return (x);
return (CDR(res)); /* le doublet de tete est perdu ? */
}
/* FIN de fichier */
| [
"gunter.mueller@gmail.com"
] | gunter.mueller@gmail.com |
fcd825d85a2be73a6248d365d44540c4584e1a42 | 84403bfbfe8f717b73993fbab75bd2d5303df94d | /w03/src/pc-common.h | ad7a1d0f3f32e66fe63d6bb0c50d87033d2ab5e8 | [] | no_license | manishshambu/HighPerformanceComputing | e30ff8b5399af56aeebc2310fbe160b37a637992 | be06fe7d4fdf2a2711dde60416efd3c1035b98b2 | refs/heads/master | 2021-08-22T22:52:41.501680 | 2017-11-29T22:06:21 | 2017-11-29T22:06:21 | 107,702,544 | 0 | 0 | null | 2017-12-01T14:09:04 | 2017-10-20T16:41:43 | C++ | UTF-8 | C | false | false | 306 | h | #ifndef PC_COMMON_H
#define PC_COMMON_H
#include <pthread.h>
#include <cstdio>
#include <cstdlib>
extern int fill;
extern int use;
#define BSZ 5
extern int buffer[BSZ];
#include <semaphore.h>
extern sem_t empty;
extern sem_t full;
extern pthread_mutex_t pLock;
extern pthread_mutex_t cLock;
#endif
| [
"mash3503@colorado.edu"
] | mash3503@colorado.edu |
d184727dc4551199765d37824a3353d9355feccc | 51d24a1bbce0b3bd4c6c2411a6073579344f0e3f | /user/hal/hal_led.h | 5aa80085ceb3f38e32332d82c8712632fff4eacb | [] | no_license | xudahong/Smart-Home | 3cf9d99152776e1b86e4043cb23cdd373c33ac09 | 71285ba57c8ee2879d25564bc95de7da3ad2850e | refs/heads/master | 2023-02-18T03:42:21.479490 | 2021-01-17T03:56:13 | 2021-01-17T03:56:13 | 316,908,517 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 235 | h | #ifndef __HAL_LED_H__
#define __HAL_LED_H__
#include "common.h"
#define MACR_RLED_LED0 0
#define MACR_RLED_LED1 1
#define MACR_RLED_LED2 2
void Hal_LED_Init(void);
void Hal_RLed_ON(u32 rled);
void Hal_RLed_OFF(u32 rled);
#endif
| [
"1403992564@qq.com"
] | 1403992564@qq.com |
b90bf5bf9051ce8d74ce79f3b424f704f6595a28 | 0200e8e5f91719cc5cfe810ea3c3fc06c7d9987e | /script_rel/lovetriangle.c | 3c4f296433b41b082ed834fb5eda9d98ab39d3b8 | [] | no_license | JayKoZa/RDR2-Decompiled-Scripts | 9ded02ca0e1973f88a3a1e05a2003b78d86f1a0a | a111493215b9db0b11c8f477816280f412c8b2de | refs/heads/master | 2021-05-19T15:54:26.705087 | 2021-03-03T10:23:18 | 2021-03-03T10:23:18 | 252,830,801 | 13 | 5 | null | null | null | null | UTF-8 | C | false | false | 99,218 | c | #region Local Var
var uLocal_0 = 0;
var uLocal_1 = 0;
var uLocal_2 = 0;
var uLocal_3 = 0;
var uLocal_4 = 0;
var uLocal_5 = 0;
var uLocal_6 = 0;
float fLocal_7 = 0f;
float fLocal_8 = 0f;
var uLocal_9 = 0;
var uLocal_10 = 0;
var uLocal_11 = 0;
var uLocal_12 = 0;
var uLocal_13 = 0;
var uLocal_14 = 0;
var uLocal_15 = 0;
var uLocal_16 = 0;
var uLocal_17 = 0;
var uLocal_18 = 0;
var uLocal_19 = 0;
var uLocal_20 = 6;
var uLocal_21 = 0;
var uLocal_22 = 0;
var uLocal_23 = 0;
var uLocal_24 = 0;
var uLocal_25 = 0;
var uLocal_26 = 0;
var uLocal_27 = 6;
var uLocal_28 = 0;
var uLocal_29 = 0;
var uLocal_30 = 0;
var uLocal_31 = 0;
var uLocal_32 = 0;
var uLocal_33 = 0;
var uLocal_34 = 0;
var uLocal_35 = 0;
var uLocal_36 = 6;
var uLocal_37 = 0;
var uLocal_38 = 0;
var uLocal_39 = 0;
var uLocal_40 = 0;
var uLocal_41 = 0;
var uLocal_42 = 0;
var uLocal_43 = 6;
var uLocal_44 = 0;
var uLocal_45 = 0;
var uLocal_46 = 0;
var uLocal_47 = 0;
var uLocal_48 = 0;
var uLocal_49 = 0;
var uLocal_50 = 4;
var uLocal_51 = 0;
var uLocal_52 = 0;
var uLocal_53 = 0;
var uLocal_54 = 0;
var uLocal_55 = 3;
var uLocal_56 = 0;
var uLocal_57 = 0;
var uLocal_58 = 0;
var uLocal_59 = 0;
var uLocal_60 = 0;
var uLocal_61 = 0;
var uLocal_62 = 0;
var uLocal_63 = 0;
var uLocal_64 = 0;
var uLocal_65 = 0;
var uLocal_66 = 0;
var uLocal_67 = 0;
var uLocal_68 = 0;
var uLocal_69 = 0;
var uLocal_70 = 0;
var uLocal_71 = 0;
var uLocal_72 = 0;
int iLocal_73 = 0;
int iLocal_74 = 0;
int iLocal_75 = 0;
int iLocal_76 = 0;
int iLocal_77 = 0;
vector3 vScriptParam_0 = { 0f, 0f, 0f };
var uScriptParam_3 = 0;
#endregion
void __EntryFunction__()
{
int iVar0;
int iVar1;
fLocal_7 = 1f;
fLocal_8 = 1f;
iLocal_73 = 20000;
iLocal_76 = vScriptParam_0.x;
iLocal_74 = vScriptParam_0.z;
func_1();
func_2();
iLocal_75 = MISC::GET_GAME_TIMER();
iVar0 = 0;
while (func_3())
{
if (MISC::GET_GAME_TIMER() > iLocal_75)
{
iLocal_75 = 0;
func_4(iLocal_76, &iLocal_74);
switch (iLocal_74)
{
case 0:
iLocal_74 = 1;
break;
case 1:
func_5(iLocal_76);
if (func_7(func_6(iLocal_76)))
{
func_8(func_6(iLocal_76), 4);
}
LAW::_0x9BBDCB8DF789EBC1(PLAYER::PLAYER_ID(), func_9(iLocal_76));
iVar1 = func_10(iLocal_76);
if (iVar1 != -1)
{
Global_1935183.f_6[iVar1] = 1;
}
Global_1897950 = -1;
iLocal_77 = (MISC::GET_GAME_TIMER() + iLocal_73);
iLocal_74 = 2;
break;
case 2:
if (func_11() || iLocal_77 < MISC::GET_GAME_TIMER())
{
func_12(iLocal_76);
iLocal_77 = (MISC::GET_GAME_TIMER() + iLocal_73);
iLocal_74 = 3;
}
break;
case 3:
if (func_13(iLocal_76) || iLocal_77 < MISC::GET_GAME_TIMER())
{
func_14(iLocal_76);
iLocal_77 = (MISC::GET_GAME_TIMER() + iLocal_73);
iLocal_74 = 4;
}
break;
case 4:
if (func_15(iLocal_76) || iLocal_77 < MISC::GET_GAME_TIMER())
{
func_16(iLocal_76);
iLocal_77 = (iLocal_73 + MISC::GET_GAME_TIMER());
iLocal_74 = 6;
}
break;
case 6:
if (func_7(func_6(iLocal_76)))
{
if (func_17(func_6(iLocal_76), 4) && !iLocal_77 < MISC::GET_GAME_TIMER())
{
}
else
{
if (func_18(iLocal_76) || iLocal_77 < MISC::GET_GAME_TIMER())
{
func_19(iLocal_76, 4);
iLocal_77 = (iLocal_73 + MISC::GET_GAME_TIMER());
iLocal_74 = 7;
}
Jump @788; //curOff = 456
if (iLocal_77 < MISC::GET_GAME_TIMER() || (func_20() != 0 || Global_1051260.f_3790))
{
func_21(iLocal_76);
func_22();
if (!func_23(2057, 0))
{
func_24();
}
func_25();
func_26();
func_27(iLocal_76);
func_28(iLocal_76);
func_29();
func_30();
iLocal_74 = 8;
}
Jump @788; //curOff = 555
func_31(iLocal_76);
func_32();
iLocal_74 = 9;
Jump @788; //curOff = 572
func_33(&Global_1898004);
func_34(iLocal_76, &Global_1898004);
iLocal_74 = 10;
Jump @788; //curOff = 597
func_35(iLocal_76);
if (func_20() != -1)
{
}
else
{
HUD::_DISPLAY_HUD_COMPONENT(1833957607);
}
func_19(iLocal_76, 8);
if (func_36(32))
{
if (CAM::IS_SCREEN_FADED_OUT())
{
CAM::DO_SCREEN_FADE_IN(500);
}
func_37(32);
}
iLocal_74 = 11;
Jump @788; //curOff = 667
if (func_38(iLocal_76))
{
iLocal_75 = (1000 + MISC::GET_GAME_TIMER());
}
func_39(&Global_1898004, iLocal_76);
func_40(iLocal_76);
func_19(iLocal_76, 8);
if (func_41())
{
PED::_0xBA0980B5C0A11924(0f);
}
PATHFIND::SET_AMBIENT_PED_RANGE_MULTIPLIER_THIS_FRAME(Global_1888801[iLocal_76 /*35*/].f_10);
if (Global_1888801[iLocal_76 /*35*/].f_11 > 0f)
{
PED::_0xA77FA7BE9312F8C0(Global_1888801[iLocal_76 /*35*/].f_11);
}
Jump @788; //curOff = 769
func_42(iVar0);
iVar0++;
}
if (Global_1888801[iLocal_76 /*35*/].f_12 == 0)
{
}
else
{
PED::_0x95423627A9CA598E(Global_1888801[iLocal_76 /*35*/].f_12);
}
BUILTIN::WAIT(0);
iVar0 = 0;
while (!func_42(iVar0))
{
iVar0++;
BUILTIN::WAIT(0);
}
SCRIPTS::TERMINATE_THIS_THREAD();
}
default:
break;
}
}
}
}
void func_1()
{
int iVar0;
if (NETWORK::NETWORK_IS_GAME_IN_PROGRESS())
{
MISC::NETWORK_SET_SCRIPT_IS_SAFE_FOR_NETWORK_GAME();
MISC::SET_THIS_SCRIPT_CAN_BE_PAUSED(false);
AUDIO::REGISTER_SCRIPT_WITH_AUDIO(1);
}
else if (PLAYER::HAS_FORCE_CLEANUP_OCCURRED(523))
{
if (NETWORK::NETWORK_GET_THIS_SCRIPT_IS_NETWORK_SCRIPT())
{
}
iVar0 = 0;
while (!func_42(iVar0))
{
iVar0++;
BUILTIN::WAIT(0);
}
SCRIPTS::TERMINATE_THIS_THREAD();
}
}
void func_2()
{
}
bool func_3()
{
return true;
}
void func_4(int iParam0, int iParam1)
{
if (!func_36(16))
{
return;
}
if (Global_1894899.f_7 == 0)
{
func_37(16);
return;
}
if (!func_43(iParam0))
{
Global_1894899.f_7 = 0;
func_37(16);
return;
}
if (func_44(8))
{
if (*iParam1 == 11)
{
*iParam1 = 7;
return;
}
else if (*iParam1 != 7)
{
func_45(8);
*iParam1 = 11;
return;
}
}
if (func_44(2))
{
if (*iParam1 == 11)
{
*iParam1 = 3;
return;
}
else if (*iParam1 != 3)
{
func_45(2);
*iParam1 = 11;
return;
}
}
if (func_44(16))
{
if (*iParam1 == 11)
{
*iParam1 = 8;
return;
}
else if (*iParam1 != 8)
{
func_45(16);
*iParam1 = 11;
return;
}
}
if (func_44(4))
{
if (*iParam1 == 11)
{
*iParam1 = 6;
return;
}
else if (*iParam1 != 6)
{
func_45(4);
*iParam1 = 11;
return;
}
}
if (func_44(1))
{
if (*iParam1 == 11)
{
*iParam1 = 2;
return;
}
else if (*iParam1 != 2)
{
func_45(1);
*iParam1 = 11;
return;
}
}
}
void func_5(int iParam0)
{
}
int func_6(int iParam0)
{
if (iParam0 < 0)
{
return -1;
}
else if (iParam0 <= 10)
{
return 0;
}
else if (iParam0 <= 29)
{
return 1;
}
else if (iParam0 <= 32)
{
return 2;
}
else if (iParam0 <= 36)
{
return 3;
}
else if (iParam0 <= 39)
{
return 4;
}
else if (iParam0 <= 49)
{
return 7;
}
else if (iParam0 <= 56)
{
return 6;
}
else if (iParam0 <= 61)
{
return 8;
}
else if (iParam0 <= 76)
{
return 9;
}
else if (iParam0 <= 92)
{
return 10;
}
else if (iParam0 <= 106)
{
return 11;
}
else if (iParam0 <= 113)
{
return 12;
}
else if (iParam0 <= 116)
{
return 13;
}
else if (iParam0 <= 119)
{
return 14;
}
else if (iParam0 <= 125)
{
return 15;
}
else if (iParam0 <= 127)
{
return 16;
}
return -1;
}
bool func_7(int iParam0)
{
return (iParam0 > -1 && iParam0 < 17);
}
void func_8(int iParam0, int iParam1)
{
Global_1897952[iParam0 /*2*/] = (Global_1897952[iParam0 /*2*/] || iParam1);
}
int func_9(int iParam0)
{
int iVar0;
switch (iParam0)
{
case 38:
iVar0 = joaat("BLACKWATER_RESIDENTS");
break;
case 82:
iVar0 = joaat("BUTCHERCREEK_RESIDENTS");
break;
case 69:
iVar0 = joaat("EMERALDRANCH_RESIDENTS");
break;
case 61:
iVar0 = joaat("MANICATO_RESIDENTS");
break;
case 110:
iVar0 = joaat("MANZANITAPOST_RESIDENTS");
break;
case 5:
iVar0 = joaat("SAINTDENIS_RESIDENTS");
break;
case 35:
iVar0 = joaat("OLDFORTWALLACE_RESIDENTS");
break;
case 105:
iVar0 = joaat("RHODES_RESIDENTS");
break;
case 26:
iVar0 = joaat("STRAWBERRY_RESIDENTS");
break;
case 76:
iVar0 = joaat("VALENTINE_RESIDENTS");
break;
case 92:
iVar0 = joaat("VANHORNPOST_RESIDENTS");
break;
case 56:
iVar0 = joaat("WAPITI_RESIDENTS");
break;
case 78:
iVar0 = joaat("ANNESBURG_RESIDENTS");
break;
default:
iVar0 = 0;
break;
}
return iVar0;
}
int func_10(int iParam0)
{
switch (iParam0)
{
case 78:
return 0;
case 120:
return 1;
case 38:
return 2;
case 93:
return 3;
case 82:
return 4;
case 65:
return 5;
case 3:
return 6;
case 110:
return 7;
case 105:
return 8;
case 5:
return 9;
case 26:
return 10;
case 75:
return 11;
case 115:
return 12;
case 76:
return 13;
case 92:
return 14;
case 56:
return 15;
default:
break;
}
return -1;
}
bool func_11()
{
return true;
}
void func_12(int iParam0)
{
iParam0 = iParam0;
}
bool func_13(int iParam0)
{
iParam0 = iParam0;
return true;
}
void func_14(int iParam0)
{
iParam0 = iParam0;
}
int func_15(int iParam0)
{
return func_48(&uLocal_14, 4096, &uLocal_14, func_46(), 0, func_47(), 0, 0, 0);
}
void func_16(int iParam0)
{
iParam0 = iParam0;
}
bool func_17(int iParam0, int iParam1)
{
return (Global_1897952[iParam0 /*2*/] && iParam1) != 0;
}
bool func_18(int iParam0)
{
return func_49(iParam0, -1, -1, 0);
}
void func_19(int iParam0, int iParam1)
{
if (Global_1572887.f_12 == -1)
{
Global_23118[iParam0 /*11*/] = (Global_23118[iParam0 /*11*/] || iParam1);
}
else
{
Global_1058888.f_40615[iParam0 /*11*/] = (Global_1058888.f_40615[iParam0 /*11*/] || iParam1);
}
}
int func_20()
{
return Global_1572887.f_12;
}
void func_21(int iParam0)
{
}
void func_22()
{
}
bool func_23(int iParam0, bool bParam1)
{
if (func_50(iParam0))
{
return true;
}
if (!bParam1)
{
if (func_51(5000))
{
return true;
}
}
switch (func_52(0))
{
case 0:
return false;
case 1:
if (iParam0 & 1 != 0)
{
return true;
}
break;
case 4:
if (iParam0 & 2 != 0)
{
return true;
}
break;
case 6:
if (iParam0 & 4 != 0)
{
return true;
}
break;
case 2:
if (iParam0 & 16 != 0)
{
return true;
}
break;
case 5:
if (iParam0 & 32 != 0)
{
return true;
}
break;
case 9:
if (iParam0 & 64 != 0)
{
return true;
}
break;
case 8:
if (iParam0 & 8 != 0)
{
return true;
}
break;
case 10:
if (iParam0 & 512 != 0)
{
return true;
}
break;
case 3:
if (iParam0 & 128 != 0)
{
return true;
}
break;
case 11:
if (iParam0 & 256 != 0)
{
return true;
}
break;
}
return false;
}
void func_24()
{
}
void func_25()
{
}
void func_26()
{
}
void func_27(int iParam0)
{
iParam0 = iParam0;
}
void func_28(int iParam0)
{
iParam0 = iParam0;
}
void func_29()
{
}
void func_30()
{
}
void func_31(int iParam0)
{
iParam0 = iParam0;
}
void func_32()
{
if (!Global_1894899.f_186)
{
VEHICLE::_0xF5FFB08976911B50(Global_1894899.f_182, Global_1894899.f_183, Global_1894899.f_184, Global_1894899.f_185);
}
}
void func_33(var uParam0)
{
int iVar0;
if (uParam0->f_61 == 0)
{
return;
}
iVar0 = 0;
while (iVar0 < 20)
{
(*uParam0)[iVar0 /*3*/] = 0;
(uParam0[iVar0 /*3*/])->f_1 = 0;
(uParam0[uParam0->f_61 /*3*/])->f_2 = 0;
iVar0++;
}
uParam0->f_61 = 0;
}
void func_34(int iParam0, var uParam1)
{
iParam0 = iParam0;
uParam1->f_61 = uParam1->f_61;
}
void func_35(int iParam0)
{
if (!func_53(iParam0))
{
return;
}
func_54();
}
bool func_36(int iParam0)
{
return (Global_1894899 && iParam0) != 0;
}
void func_37(int iParam0)
{
Global_1894899 = (Global_1894899 - (Global_1894899 && iParam0));
}
bool func_38(int iParam0)
{
iParam0 = iParam0;
return false;
}
void func_39(var uParam0, int iParam1)
{
bool bVar0;
bool bVar1;
bool bVar2;
int iVar3;
int iVar4;
if ((BUILTIN::VDIST(Global_36, 0f, 0f, 0f) <= 5f || func_55(Global_1935630, 16384)) || func_55(Global_1935630, 8388608))
{
return;
}
if (func_56(uParam0, 1))
{
return;
}
uParam0->f_63++;
if (uParam0->f_63 < 10)
{
return;
}
uParam0->f_63 = 0;
bVar0 = false;
bVar1 = ((CAM::IS_SCREEN_FADED_OUT() || CAM::IS_SCREEN_FADING_IN()) || CAM::IS_SCREEN_FADING_OUT());
bVar2 = func_57();
iVar3 = 0;
while (iVar3 < uParam0->f_61)
{
switch ((uParam0[iVar3 /*3*/])->f_1)
{
case 1:
if (VOLUME::_DOES_VOLUME_EXIST((*uParam0)[iVar3 /*3*/]))
{
if (VOLUME::_IS_POSITION_INSIDE_VOLUME((*uParam0)[iVar3 /*3*/], Global_36))
{
if (!bVar1 && !bVar2)
{
if ((!func_58(uParam0[iVar3 /*3*/], 1) && func_59(iParam1)) && !func_60(iParam1, 16))
{
func_62(iParam1, func_61(), -1, 0, -1, 0);
func_63(uParam0[iVar3 /*3*/], 1);
}
func_64(iParam1, 0);
}
bVar0 = true;
}
}
break;
default:
break;
}
iVar3++;
}
if (func_20() == -1)
{
if (func_65() != bVar0)
{
iVar4 = 0;
if (bVar0)
{
iVar4 = 2;
}
else
{
iVar4 = 1;
}
func_66();
func_67(Global_1310750.f_16071, 0, iVar4, 0, 0);
}
}
func_68(bVar0);
if (func_20() == -1)
{
func_70((iParam1 == func_69() && bVar0));
}
}
int func_40(int iParam0)
{
iParam0 = iParam0;
return 1;
}
bool func_41()
{
var uVar0;
var uVar1;
float fVar2;
int iVar3;
MISC::_GET_WEATHER_TYPE_TRANSITION(&uVar0, &uVar1, &fVar2);
if (fVar2 < 0.75f)
{
iVar3 = uVar0;
}
else
{
iVar3 = uVar1;
}
if (func_71(iVar3))
{
return true;
}
return false;
}
bool func_42(int iParam0)
{
if (iParam0 == 0)
{
func_72();
LAW::_0x9BBDCB8DF789EBC1(PLAYER::PLAYER_ID(), 0);
func_19(iLocal_76, 2048);
if (func_7(func_61()))
{
func_8(func_61(), 8);
}
func_73(iLocal_76, 4);
func_73(iLocal_76, 8);
func_68(0);
if (func_20() == -1)
{
func_70(0);
}
func_74(iLocal_76);
func_32();
return false;
}
else
{
func_75(iLocal_76);
func_76(iLocal_76);
func_77(iLocal_76);
if (!func_78(iLocal_76, 0))
{
return false;
}
}
SCRIPTS::TERMINATE_THIS_THREAD();
return true;
}
bool func_43(int iParam0)
{
if (!func_53(iParam0))
{
return false;
}
return func_79(iParam0, 8);
}
bool func_44(int iParam0)
{
return (Global_1894899.f_7 && iParam0) != 0;
}
void func_45(int iParam0)
{
Global_1894899.f_7 = (Global_1894899.f_7 - (Global_1894899.f_7 && iParam0));
}
int func_46()
{
return 103;
}
char* func_47()
{
return "shack_lovetriangle1";
}
int func_48(var uParam0, int iParam1, var uParam2, int iParam3, int iParam4, char* sParam5, bool bParam6, int iParam7, bool bParam8)
{
int iVar0;
vector3 vVar1;
if (func_20() != -1)
{
return 0;
}
if (SCRIPTS::IS_THREAD_ACTIVE(*uParam2, false))
{
return 0;
}
if (!VOLUME::_DOES_VOLUME_EXIST(func_80(iParam3)))
{
return 0;
}
if (!ENTITY::IS_ENTITY_IN_VOLUME(Global_35, func_80(iParam3), true, 0))
{
return 0;
}
if (bParam8)
{
vVar1 = { func_81(iParam1) };
if (!func_82(vVar1))
{
if (func_83(vVar1, 1, 776, 0))
{
return 0;
}
}
}
if ((bParam6 && func_84(128, 0, 1)) && !iParam1 == 64)
{
return 0;
}
if (iParam7 && func_85(PLAYER::GET_PLAYER_INDEX(), 1, 1, 1))
{
return 0;
}
uParam0->f_1 = iParam1;
uParam0->f_5 = func_88(func_86(iParam1), 0, 3, func_87(iParam1));
func_89(&(uParam0->f_5), &(uParam0->f_3));
if (!func_90(uParam0->f_3, 4))
{
iVar0 = 4;
}
else if (!func_90(uParam0->f_3, 8))
{
iVar0 = 8;
}
else if (!func_90(uParam0->f_3, 16))
{
iVar0 = 16;
}
else if (!func_90(uParam0->f_3, 32))
{
iVar0 = 32;
}
else if (!func_90(uParam0->f_3, 64))
{
iVar0 = 64;
}
if (iParam1 == 32768)
{
if (!func_91(uParam0))
{
return 0;
}
}
if (!func_90(uParam0->f_3, iVar0))
{
if (func_90(uParam0->f_3, 2))
{
if (!SCRIPTS::IS_THREAD_ACTIVE(*uParam2, false))
{
SCRIPTS::REQUEST_SCRIPT(sParam5);
if (SCRIPTS::HAS_SCRIPT_LOADED(sParam5))
{
uParam0->f_52 = { func_92(iParam1) };
uParam0->f_5 = func_88(func_86(iParam1), 0, 3, func_87(iParam1));
*uParam2 = SCRIPTS::START_NEW_SCRIPT_WITH_ARGS(sParam5, uParam0, 59, 1024);
SCRIPTS::SET_SCRIPT_AS_NO_LONGER_NEEDED(sParam5);
return 1;
}
}
}
}
return 0;
}
int func_49(int iParam0, int iParam1, int iParam2, bool bParam3)
{
int iVar0;
int iVar1;
int iVar2;
if (func_20() != -1)
{
return 1;
}
if (!func_53(iParam0))
{
return 1;
}
if (func_79(iParam0, 16))
{
return 1;
}
if (func_93(iParam0) && !func_94(iParam0))
{
}
if (func_95(iParam0, &iVar0, &iVar1, 0, 0))
{
if (func_96(iParam1))
{
iVar0 = iParam1;
}
if (func_96(iParam2))
{
iVar1 = iParam2;
}
if (Global_1897950 < iVar0 || Global_1897950 > iVar1)
{
Global_1897950 = iVar0;
}
while (true)
{
if ((!func_93(iParam0) || func_94(iParam0)) || func_97(Global_1897950))
{
func_98(Global_1897950, 0);
}
Global_1897950++;
iVar2++;
if (Global_1897950 > iVar1)
{
Global_1897950 = -1;
return 1;
}
if (iVar2 >= 10 && !bParam3)
{
return 0;
}
}
}
return 1;
}
bool func_50(var uParam0)
{
return (Global_1935630 && uParam0) != 0;
}
bool func_51(int iParam0)
{
return (MISC::GET_GAME_TIMER() - iParam0) < Global_1898438;
}
int func_52(int iParam0)
{
return Global_1898164.f_1[iParam0 /*5*/].f_2;
}
bool func_53(int iParam0)
{
return (iParam0 >= 0 && iParam0 <= 150);
}
void func_54()
{
int iVar0;
iVar0 = 0;
while (iVar0 < 17)
{
if (func_99(iVar0))
{
Global_1898130[iVar0] = -1;
}
iVar0++;
}
}
bool func_55(var uParam0, int iParam1)
{
return (uParam0 && iParam1) != 0;
}
bool func_56(var uParam0, int iParam1)
{
return (uParam0->f_62 && iParam1) != 0;
}
bool func_57()
{
return func_55(Global_1935630, 4096);
}
bool func_58(var uParam0, int iParam1)
{
return (uParam0->f_2 && iParam1) != 0;
}
bool func_59(int iParam0)
{
if (!func_53(iParam0))
{
return false;
}
return ((Global_1888801[iParam0 /*35*/].f_20 == 1 || Global_1888801[iParam0 /*35*/].f_20 == 2) && !func_100(iParam0));
}
bool func_60(int iParam0, int iParam1)
{
if (iParam0 < 0 || iParam0 >= 150)
{
return false;
}
return (Global_1888801[iParam0 /*35*/].f_21 && iParam1) != 0;
}
int func_61()
{
return Global_1897952.f_41;
}
void func_62(int iParam0, int iParam1, int iParam2, bool bParam3, int iParam4, bool bParam5)
{
bool bVar0;
char* sVar1;
char* sVar2;
int iVar3;
int iVar4;
int iVar5;
char[] cVar6[8];
float fVar7;
char* sVar8;
char* sVar9;
char[] cVar10[8];
if (!func_101())
{
return;
}
sVar1 = func_102(iParam0, iParam1, iParam2, iParam4, bParam5, bParam3, &bVar0);
if (MISC::IS_STRING_NULL_OR_EMPTY(sVar1))
{
if (bParam3)
{
return;
}
sVar1 = "DISTRICT_GRIZZLIES";
}
if (!func_103(iParam4))
{
if (func_53(iParam0))
{
iParam4 = func_104(func_6(iParam0));
}
else
{
iParam4 = func_104(iParam1);
}
}
if (func_103(iParam4))
{
iVar3 = func_105(iParam4);
}
if (bVar0 && bParam3)
{
sVar2 = func_107(func_106(iParam2));
}
else if ((func_108(iParam1, 2) || func_109(iParam4, 2)) && !Global_1894899.f_9)
{
if (ENTITY::DOES_ENTITY_EXIST(PLAYER::PLAYER_PED_ID()))
{
if (PED::IS_PED_MALE(PLAYER::PLAYER_PED_ID()))
{
sVar2 = MISC::_CREATE_VAR_STRING(2, "LAW_UI_FULL_D_OR_A_M");
}
else
{
sVar2 = MISC::_CREATE_VAR_STRING(2, "LAW_UI_FULL_D_OR_A_F");
}
}
Global_1894899.f_9 = 1;
}
else if ((func_53(iParam0) && func_79(iParam0, 16777216)) && !Global_1894899.f_9)
{
sVar2 = MISC::_CREATE_VAR_STRING(2, "LAW_UI_RESTRICTED_AREA");
Global_1894899.f_9 = 1;
}
else if (iVar3 >= 1 && !Global_1894899.f_9)
{
sVar2 = MISC::_CREATE_VAR_STRING(2, "REGION_BOUNTY", iVar3);
Global_1894899.f_9 = 1;
}
else
{
iVar4 = func_111(func_110());
iVar5 = func_112(func_110());
if (iVar5 < 10)
{
StringConCat(&cVar6, "0", 8);
}
StringIntConCat(&cVar6, iVar5, 8);
fVar7 = MISC::_GET_TEMPERATURE_AT_COORDS(Global_36);
if (!MISC::_SHOULD_USE_24_HOUR_CLOCK())
{
sVar9 = "AM";
if (iVar4 >= 12)
{
sVar9 = "PM";
if (iVar4 > 12)
{
iVar4 = (iVar4 - 12);
}
}
else if (iVar4 == 0)
{
iVar4 = 12;
}
sVar8 = "TIME_AND_TEMP_C";
if (!MISC::_SHOULD_USE_METRIC_TEMPERATURE())
{
fVar7 = func_113(fVar7);
sVar8 = "TIME_AND_TEMP_F";
}
IntToString(&cVar10, BUILTIN::ROUND(fVar7), 8);
sVar2 = MISC::_CREATE_VAR_STRING(674, sVar8, iVar4, func_114(&cVar6, joaat("COLOR_PURE_WHITE")), sVar9, func_114(&cVar10, joaat("COLOR_PURE_WHITE")));
}
else
{
sVar8 = "TIME_AND_TEMP_C_24";
if (!MISC::_SHOULD_USE_METRIC_TEMPERATURE())
{
fVar7 = func_113(fVar7);
sVar8 = "TIME_AND_TEMP_F_24";
}
IntToString(&cVar10, BUILTIN::ROUND(fVar7), 8);
sVar2 = MISC::_CREATE_VAR_STRING(162, sVar8, iVar4, func_114(&cVar6, joaat("COLOR_PURE_WHITE")), func_114(&cVar10, joaat("COLOR_PURE_WHITE")));
}
Global_1894899.f_9 = 0;
}
Global_1934266.f_148 = func_115(sVar1, sVar2, 4000, 0, 0, 0, 0, 1);
}
void func_63(var uParam0, int iParam1)
{
uParam0->f_2 = (uParam0->f_2 || iParam1);
}
void func_64(int iParam0, bool bParam1)
{
if (Global_1572887.f_10 && func_20() == 0)
{
return;
}
if (func_116(128))
{
return;
}
if (!func_117(iParam0))
{
return;
}
if (func_79(iParam0, 32))
{
return;
}
func_19(iParam0, 32);
func_118(&Global_1935630, 8192);
func_120(func_119(joaat("DISCOVERED"), joaat("AREAS")), 1);
switch (func_6(iParam0))
{
case 0:
case 2:
case 11:
func_120(func_119(joaat("DISCOVERED"), joaat("LOWLANDS_AREAS")), 1);
break;
case 1:
case 5:
case 6:
case 7:
case 12:
func_120(func_119(joaat("DISCOVERED"), joaat("MOUNTAIN_AREAS")), 1);
break;
case 3:
case 10:
func_120(func_119(joaat("DISCOVERED"), joaat("FOOTHILLS_AREAS")), 1);
break;
case 4:
case 9:
func_120(func_119(joaat("DISCOVERED"), joaat("PLAINS_AREAS")), 1);
break;
case 8:
func_120(func_119(joaat("DISCOVERED"), joaat("GUAMA_AREAS")), 1);
break;
case 13:
case 14:
case 15:
case 16:
func_120(func_119(joaat("DISCOVERED"), joaat("NEW_AUSTIN_AREAS")), 1);
break;
}
switch (iParam0)
{
case 0:
MAP::_0xD8C7162AB2E2AF45(1822876181);
break;
case 1:
MAP::_0xD8C7162AB2E2AF45(1092217275);
break;
case 2:
MAP::_0xD8C7162AB2E2AF45(1855549007);
MAP::_0xD8C7162AB2E2AF45(1542246539);
break;
case 6:
MAP::_0xD8C7162AB2E2AF45(-237206861);
break;
case 7:
MAP::_0xD8C7162AB2E2AF45(276890716);
break;
case 9:
MAP::_0xD8C7162AB2E2AF45(-353968602);
break;
case 10:
MAP::_0xD8C7162AB2E2AF45(-1354901649);
MAP::_0xD8C7162AB2E2AF45(-1354901649);
break;
case 11:
MAP::_0xD8C7162AB2E2AF45(-496244122);
break;
case 12:
MAP::_0xD8C7162AB2E2AF45(-678676588);
break;
case 15:
MAP::_0xD8C7162AB2E2AF45(-732274047);
break;
case 16:
MAP::_0xD8C7162AB2E2AF45(-12216052);
break;
case 17:
MAP::_0xD8C7162AB2E2AF45(-1456731677);
break;
case 21:
MAP::_0xD8C7162AB2E2AF45(-2086563810);
break;
case 22:
MAP::_0xD8C7162AB2E2AF45(221661572);
break;
case 24:
MAP::_0xD8C7162AB2E2AF45(222265732);
break;
case 25:
MAP::_0xD8C7162AB2E2AF45(-1484929764);
break;
case 26:
MAP::_0xD8C7162AB2E2AF45(1104975149);
break;
case 27:
MAP::_0xD8C7162AB2E2AF45(235472255);
break;
case 28:
MAP::_0xD8C7162AB2E2AF45(-1337880478);
break;
case 29:
MAP::_0xD8C7162AB2E2AF45(-1813267128);
break;
case 30:
MAP::_0xD8C7162AB2E2AF45(-1941572412);
break;
case 31:
MAP::_0xD8C7162AB2E2AF45(1006072805);
break;
case 121:
MAP::_0xD8C7162AB2E2AF45(929640770);
break;
case 122:
MAP::_0xD8C7162AB2E2AF45(1603579970);
break;
case 124:
MAP::_0xD8C7162AB2E2AF45(-1332669948);
break;
case 123:
MAP::_0xD8C7162AB2E2AF45(-1807212021);
break;
case 34:
MAP::_0xD8C7162AB2E2AF45(-1347759053);
break;
case 36:
MAP::_0xD8C7162AB2E2AF45(-918096609);
break;
case 114:
MAP::_0xD8C7162AB2E2AF45(1728445882);
break;
case 37:
MAP::_0xD8C7162AB2E2AF45(-507075109);
break;
case 40:
MAP::_0xD8C7162AB2E2AF45(462373845);
break;
case 42:
MAP::_0xD8C7162AB2E2AF45(-1727895786);
break;
case 43:
MAP::_0xD8C7162AB2E2AF45(1826504111);
break;
case 44:
MAP::_0xD8C7162AB2E2AF45(1714554710);
break;
case 45:
MAP::_0xD8C7162AB2E2AF45(-91026072);
break;
case 54:
MAP::_0xD8C7162AB2E2AF45(893855320);
break;
case 55:
MAP::_0xD8C7162AB2E2AF45(326709244);
break;
case 49:
MAP::_0xD8C7162AB2E2AF45(653799702);
break;
case 62:
MAP::_0xD8C7162AB2E2AF45(415864829);
break;
case 64:
MAP::_0xD8C7162AB2E2AF45(-1836330842);
break;
case 65:
MAP::_0xD8C7162AB2E2AF45(648073069);
break;
case 66:
MAP::_0xD8C7162AB2E2AF45(770074951);
break;
case 68:
MAP::_0xD8C7162AB2E2AF45(-1276637644);
break;
case 71:
MAP::_0xD8C7162AB2E2AF45(-431488293);
break;
case 72:
MAP::_0xD8C7162AB2E2AF45(-1101810198);
break;
case 74:
MAP::_0xD8C7162AB2E2AF45(-1344767066);
break;
case 77:
MAP::_0xD8C7162AB2E2AF45(1472232821);
break;
case 79:
MAP::_0xD8C7162AB2E2AF45(-1368676121);
break;
case 63:
MAP::_0xD8C7162AB2E2AF45(-33677540);
break;
case 80:
MAP::_0xD8C7162AB2E2AF45(1602161184);
MAP::_0xD8C7162AB2E2AF45(-443207523);
MAP::_0xD8C7162AB2E2AF45(-683043834);
break;
case 82:
MAP::_0xD8C7162AB2E2AF45(147256338);
MAP::_0xD8C7162AB2E2AF45(-134804027);
MAP::_0xD8C7162AB2E2AF45(2027689141);
break;
case 83:
MAP::_0xD8C7162AB2E2AF45(-161135375);
break;
case 85:
MAP::_0xD8C7162AB2E2AF45(1625008147);
break;
case 86:
MAP::_0xD8C7162AB2E2AF45(121074776);
break;
case 87:
MAP::_0xD8C7162AB2E2AF45(1876184276);
break;
case 89:
MAP::_0xD8C7162AB2E2AF45(458479023);
break;
case 91:
MAP::_0xD8C7162AB2E2AF45(85299473);
break;
case 96:
MAP::_0xD8C7162AB2E2AF45(-1150244084);
break;
case 98:
MAP::_0xD8C7162AB2E2AF45(759314201);
break;
case 99:
MAP::_0xD8C7162AB2E2AF45(2063457042);
break;
case 100:
MAP::_0xD8C7162AB2E2AF45(1877776161);
break;
case 102:
MAP::_0xD8C7162AB2E2AF45(2143316225);
break;
case 104:
MAP::_0xD8C7162AB2E2AF45(-1623232489);
MAP::_0xD8C7162AB2E2AF45(-1393093729);
break;
case 106:
MAP::_0xD8C7162AB2E2AF45(1354284392);
break;
case 107:
MAP::_0xD8C7162AB2E2AF45(-1430883057);
break;
case 109:
MAP::_0xD8C7162AB2E2AF45(820139809);
break;
case 112:
MAP::_0xD8C7162AB2E2AF45(1561007383);
MAP::_0xD8C7162AB2E2AF45(-960425936);
break;
}
if (bParam1)
{
func_19(iParam0, 64);
}
}
bool func_65()
{
return (Global_1894899 & 1 != 0 && func_121() != -1);
}
void func_66()
{
if (!func_122(Global_1327479))
{
return;
}
if (SCRIPTS::DOES_SCRIPT_EXIST(&(Global_1310750[Global_1327479 /*111*/].f_40)))
{
if (SCRIPTS::HAS_SCRIPT_LOADED(&(Global_1310750[Global_1327479 /*111*/].f_40)))
{
SCRIPTS::SET_SCRIPT_AS_NO_LONGER_NEEDED(&(Global_1310750[Global_1327479 /*111*/].f_40));
}
}
func_123(0);
Global_1327479 = -1;
Global_1310750.f_16075 = 0;
Global_1310750.f_16076 = 0;
Global_1310750.f_16103 = { 0f, 0f, 0f };
}
void func_67(int iParam0, bool bParam1, int iParam2, bool bParam3, bool bParam4)
{
int iVar0;
int iVar1;
if (bParam1)
{
}
if (func_124() == 0 && !bParam1)
{
return;
}
iVar0 = 0;
while (iVar0 < 4)
{
iVar1 = Global_1310750.f_13321[iVar0 /*9*/];
if (((func_122(iVar1) && !func_125(iVar1, iParam2)) && (!bParam3 || !func_126(iVar1))) && (!bParam4 || !func_127(iVar1)))
{
if (iVar1 != iParam0)
{
func_128(iVar0);
}
}
iVar0++;
}
}
void func_68(bool bParam0)
{
bool bVar0;
bVar0 = Global_1894899 & 1 != false;
if (bVar0 == bParam0)
{
return;
}
if (bParam0)
{
Global_1894899 |= 1;
STATS::_0xDA26263C07CCE9C2(1);
}
else
{
Global_1894899 = (Global_1894899 - Global_1894899 & 1);
STATS::_0xDA26263C07CCE9C2(0);
}
}
int func_69()
{
return Global_40.f_4283.f_1;
}
void func_70(bool bParam0)
{
if (bParam0)
{
Global_1894899 |= 2;
}
else
{
Global_1894899 = (Global_1894899 - Global_1894899 & 2);
}
}
bool func_71(int iParam0)
{
switch (iParam0)
{
case joaat("DRIZZLE"):
case joaat("THUNDER"):
case joaat("SHOWER"):
case joaat("SLEET"):
case joaat("HURRICANE"):
case joaat("RAIN"):
case joaat("HAIL"):
case joaat("THUNDERSTORM"):
return true;
default:
break;
}
return false;
}
void func_72()
{
}
void func_73(int iParam0, int iParam1)
{
if (Global_1572887.f_12 == -1)
{
Global_23118[iParam0 /*11*/] = (Global_23118[iParam0 /*11*/] - (Global_23118[iParam0 /*11*/] && iParam1));
return;
}
Global_1058888.f_40615[iParam0 /*11*/] = (Global_1058888.f_40615[iParam0 /*11*/] - (Global_1058888.f_40615[iParam0 /*11*/] && iParam1));
}
void func_74(int iParam0)
{
func_129(&uLocal_14);
}
void func_75(int iParam0)
{
int iVar0;
iVar0 = 0;
while (iVar0 < 3)
{
if (Global_1935369.f_5[iVar0 /*11*/].f_5 == iParam0)
{
func_130(iVar0);
}
iVar0++;
}
}
void func_76(int iParam0)
{
int iVar0;
iVar0 = 0;
while (iVar0 < 35)
{
if (Global_1914319.f_3[iVar0 /*446*/].f_9 == iParam0)
{
func_131(iVar0);
}
iVar0++;
}
}
void func_77(int iParam0)
{
int iVar0;
int iVar1;
iVar0 = func_132(iParam0);
if (iVar0 == -1)
{
return;
}
iVar1 = 0;
while (iVar1 < 4)
{
func_133(Global_1392240.f_1[iVar0 /*18*/].f_6[iVar1]);
Global_1392240.f_1[iVar0 /*18*/].f_6[iVar1] = 0;
iVar1++;
}
}
bool func_78(int iParam0, bool bParam1)
{
int iVar0;
int iVar1;
int iVar2;
if (func_20() != -1)
{
return true;
}
if (!func_53(iParam0))
{
return true;
}
if (func_95(iParam0, &iVar0, &iVar1, 0, 0))
{
if (Global_1897950.f_1 < iVar0 || Global_1897950.f_1 > iVar1)
{
Global_1897950.f_1 = iVar0;
}
while (true)
{
if (!func_134(Global_1897950.f_1, 16))
{
func_135(Global_1897950.f_1, 0);
}
Global_1897950.f_1++;
iVar2++;
if (Global_1897950.f_1 > iVar1)
{
Global_1897950.f_1 = -1;
return true;
}
if (iVar2 >= 20 && !bParam1)
{
return false;
}
}
}
return true;
}
bool func_79(int iParam0, int iParam1)
{
if (Global_1572887.f_12 == -1)
{
return (Global_23118[iParam0 /*11*/] && iParam1) != 0;
}
return (Global_1058888.f_40615[iParam0 /*11*/] && iParam1) != 0;
}
int func_80(int iParam0)
{
if (!func_53(iParam0))
{
return 0;
}
return Global_1888801[iParam0 /*35*/].f_3;
}
Vector3 func_81(int iParam0)
{
switch (iParam0)
{
case 32768:
return 2118.586f, -1836.796f, 40.5503f;
default:
break;
}
return 0f, 0f, 0f;
}
bool func_82(vector3 vParam0)
{
if ((vParam0.x == 0f && vParam0.y == 0f) && vParam0.z == 0f)
{
return true;
}
return false;
}
bool func_83(vector3 vParam0, int iParam3, int iParam4, int iParam5)
{
int iVar0[4];
int iVar5[4];
if (func_82(vParam0))
{
return false;
}
iVar0[0] = iParam4;
iVar5[0] = 16384;
iVar5[1] = iParam5;
if (VOLUME::_0x870E9981ED27C815(vParam0, &iVar0, &iVar5, iParam3))
{
return true;
}
return false;
}
bool func_84(int iParam0, bool bParam1, bool bParam2)
{
int iVar0;
if (Global_1572887.f_12 != -1)
{
if ((bParam2 && iParam0 == 0) && bParam1 == 0)
{
return Global_1898164.f_163;
}
if ((bParam2 && iParam0 == 0) && bParam1 == 1)
{
return Global_1898164.f_164;
}
if (func_136())
{
return true;
}
if (Global_1058888.f_3 && !Global_1572887.f_8)
{
if (Global_1055058[PLAYER::NETWORK_PLAYER_ID_TO_INT() /*116*/].f_114 && NETWORK::NETWORK_IS_IN_TUTORIAL_SESSION())
{
return true;
}
}
}
else if (bParam2 && iParam0 == 0)
{
if (!bParam1)
{
return Global_1898164.f_163;
}
else
{
return Global_1898164.f_164;
}
}
if (Global_1898164.f_1[0 /*5*/].f_2 == 8)
{
iVar0 = func_137(Global_1898164.f_1[0 /*5*/]);
if (func_138(iVar0) && func_139(Global_1347702[iVar0 /*49*/].f_12, 131072))
{
return false;
}
}
if (iParam0 == 0 && func_140(Global_1898164.f_1[0 /*5*/]))
{
return true;
}
if ((Global_1935630 && 40959 & (-1 - iParam0)) != 0)
{
return true;
}
if (!bParam1)
{
if ((MISC::GET_GAME_TIMER() - 5000) < Global_1898438)
{
return true;
}
}
switch (Global_1898164.f_1[0 /*5*/].f_2)
{
case 0:
return false;
case 1:
return iParam0 & 1 == 0;
case 4:
return iParam0 & 2 == 0;
case 6:
return iParam0 & 4 == 0;
case 2:
return iParam0 & 16 == 0;
case 5:
return iParam0 & 32 == 0;
case 9:
return iParam0 & 64 == 0;
case 8:
return iParam0 & 8 == 0;
case 10:
return iParam0 & 512 == 0;
case 3:
return iParam0 & 128 == 0;
case 11:
return iParam0 & 256 == 0;
default:
break;
}
return false;
}
int func_85(int iParam0, bool bParam1, bool bParam2, bool bParam3)
{
struct<11> Var0;
int iVar17;
struct<11> Var18;
if (iParam0 == PLAYER::PLAYER_ID())
{
return func_141(bParam1, bParam2, bParam3);
}
if (Global_1572887.f_12 != -1)
{
if (iParam0 == Global_1225639.f_10)
{
if (!Global_1225639.f_11)
{
return 0;
}
}
else if (!ENTITY::DOES_ENTITY_EXIST(PLAYER::GET_PLAYER_PED(iParam0)))
{
return 0;
}
}
else if (!ENTITY::DOES_ENTITY_EXIST(PLAYER::GET_PLAYER_PED(iParam0)))
{
return 0;
}
if (LAW::_0xAD401C63158ACBAA(iParam0))
{
LAW::_0xCBFB4951F2E3934C(iParam0, &Var0);
if ((bParam3 || Var0.f_10 > 0) || PLAYER::GET_PLAYER_WANTED_LEVEL(iParam0) > 0)
{
return 1;
}
}
else if (bParam2 && !LAW::_0x148E7AC8141C9E64(iParam0) == 1370593166)
{
return 0;
}
iVar17 = 0;
while (iVar17 < 24)
{
if (LAW::_0x532C5FDDB986EE5C(iParam0, iVar17, &Var18))
{
if (Var18.f_10 && (bParam3 || LAW::_0xDAEFDFDB2AEECE37(Var18, Var18.f_7) > 0))
{
return 1;
}
}
iVar17++;
}
if (bParam1)
{
if (LAW::_0x69E181772886F48B(iParam0) || LAW::_0xF0FBFB9AB15F7734(iParam0, 0, 0))
{
if (bParam3 || LAW::_0xE083BEDA81709891(iParam0) > 0)
{
return 1;
}
}
}
return 0;
}
int func_86(int iParam0)
{
switch (iParam0)
{
case 2:
return 25;
case 4:
return 105;
case 8:
return 78;
case 16:
return 51;
case 32:
return 41;
case 64:
return 108;
case 128:
return 44;
case 256:
return 53;
case 512:
return 84;
case 1024:
return 22;
case 2048:
return 73;
case 4096:
return 103;
case 8192:
return 18;
case 16384:
return 46;
case 32768:
return 0;
case 65536:
return 106;
case 131072:
return 47;
case 262144:
return 101;
default:
break;
}
return -1;
}
int func_87(int iParam0)
{
switch (iParam0)
{
case 2:
return 657250500;
case 4:
return -520696743;
case 8:
return -295901403;
case 16:
return -1445837674;
case 32:
return -75278298;
case 64:
return -675249331;
case 128:
return -1822243680;
case 256:
return -1307199059;
case 512:
return -17701163;
case 1024:
return -172170798;
case 2048:
return 1836682179;
case 4096:
return -67934460;
case 8192:
return 410776537;
case 16384:
return -240986174;
case 32768:
return 1505721140;
case 65536:
return 2023114891;
case 131072:
return -30217677;
case 262144:
return 653209800;
default:
break;
}
return 0;
}
int func_88(int iParam0, int iParam1, int iParam2, int iParam3)
{
int iVar0;
int iVar1;
int iVar2;
int iVar3;
int iVar4;
int iVar5;
int iVar6;
iVar3 = iParam0;
iVar4 = iParam1;
if (Global_1572887.f_12 == -1)
{
switch (iParam2)
{
case 1:
iVar1 = 1;
iVar2 = 100;
iParam3 = MISC::GET_HASH_KEY(&(Global_1835011[iParam0 /*74*/].f_8));
break;
case 2:
iVar1 = 101;
iVar2 = 170;
break;
case 3:
iVar1 = 171;
iVar2 = 190;
break;
case 4:
iVar1 = 191;
iVar2 = 230;
break;
case 5:
iVar1 = 231;
iVar2 = 260;
break;
case 6:
iVar1 = 261;
iVar2 = 290;
break;
case 7:
iVar1 = 291;
iVar2 = 370;
break;
case 8:
iVar1 = 371;
iVar2 = 570;
iParam3 = MISC::GET_HASH_KEY(&(Global_1347702[iParam0 /*49*/].f_3));
break;
case 9:
iVar1 = 571;
iVar2 = 650;
break;
case 11:
iVar1 = 651;
iVar2 = 750;
break;
case 10:
return -1;
case 12:
return -1;
default:
return -1;
}
}
else
{
switch (iParam2)
{
case 1:
iVar1 = 1;
iVar2 = 200;
break;
case 2:
iVar1 = 201;
iVar2 = 15700;
break;
case 4:
iVar1 = 15701;
iVar2 = 16200;
break;
case 12:
iVar1 = 16201;
iVar2 = 19200;
break;
case 10:
iVar1 = 19201;
iVar2 = 20000;
break;
case 8:
return -1;
case 7:
return -1;
case 6:
return -1;
default:
return -1;
}
}
if (iVar2 >= func_142())
{
iVar2 = func_142();
}
iVar5 = func_143(iVar3, iVar4, iParam2);
if (Global_1572887.f_12 == -1)
{
iVar0 = iVar1;
iVar0 = iVar1;
while (iVar0 <= iVar2)
{
iVar6 = iVar0;
if (func_144(iVar6) == iVar5)
{
return iVar6;
}
if (func_144(iVar6) == 0)
{
return func_145(iVar3, iVar4, iParam2, iVar0, iParam3);
}
iVar0++;
}
iVar1 = 751;
iVar2 = 770;
iVar0 = iVar1;
iVar0 = iVar1;
while (iVar0 <= iVar2)
{
iVar6 = iVar0;
if (func_144(iVar6) == iVar5)
{
return iVar6;
}
if (func_144(iVar6) == 0)
{
return func_145(iVar3, iVar4, iParam2, iVar0, iParam3);
}
iVar0++;
}
}
else
{
iVar0 = iVar1;
iVar0 = iVar1;
while (iVar0 <= iVar2)
{
if (Global_1058888.f_498[iVar0 /*2*/] == iVar5)
{
return iVar0;
}
iVar0++;
}
iVar0 = iVar1;
iVar0 = iVar1;
while (iVar0 <= iVar2)
{
if (Global_1058888.f_498[iVar0 /*2*/] == 0)
{
return func_145(iVar3, iVar4, iParam2, iVar0, 0);
}
iVar0++;
}
}
return -1;
}
int func_89(var uParam0, var uParam1)
{
if (func_140(*uParam0))
{
*uParam1 = func_146(*uParam0);
if (!func_90(*uParam1, 2))
{
func_147(uParam1, 2);
}
return 1;
}
else
{
return 0;
}
return 0;
}
bool func_90(var uParam0, int iParam1)
{
return (uParam0 && iParam1) != 0;
}
bool func_91(var uParam0)
{
float fVar0;
float fVar1;
float fVar2;
if ((!func_90(uParam0->f_3, 32768) && func_148(uParam0->f_1, &fVar1)) && func_149(uParam0->f_1, 0, &fVar0))
{
fVar2 = func_150();
if ((func_150() - fVar1) >= fVar0)
{
func_147(&(uParam0->f_3), 32768);
}
}
if (func_90(uParam0->f_3, 32768))
{
return true;
}
return false;
}
Vector3 func_92(int iParam0)
{
switch (iParam0)
{
case 2:
return -1553.069f, 254.0002f, 113.7989f;
case 4:
return 1457.149f, -1578.779f, 72.1939f;
case 8:
return 1783.498f, 462.5527f, 112.0378f;
case 16:
return 1982.539f, 1192.392f, 170.408f;
case 32:
return -155.8262f, 1491.054f, 111.7707f;
case 64:
return -2054.879f, -1912.227f, 111.2719f;
case 128:
return -1021.743f, 1692.386f, 243.3139f;
case 256:
return 32.3207f, 2092.403f, 276.5115f;
case 512:
return 1888.854f, 301.6055f, 76.1451f;
case 1024:
return -2370.078f, 472.8013f, 131.228f;
case 2048:
return 1666.794f, 2180.789f, 316.349f;
case 4096:
return 1134.444f, -979.7666f, 68.4026f;
case 8192:
return -1728.583f, -83.1805f, 180.4762f;
case 16384:
return -1961.996f, 2159.51f, 327.3775f;
case 32768:
return 2089.364f, -1816.956f, 42.7298f;
case 65536:
return 1389.751f, -2083.81f, 56.0727f;
case 131072:
return -690.1562f, 1043.87f, 134.0042f;
case 262144:
return 1184.4f, -101.4f, 97.3f;
default:
break;
}
return 0f, 0f, 0f;
}
bool func_93(int iParam0)
{
if (!func_53(iParam0))
{
return false;
}
return func_79(iParam0, 33554432);
}
bool func_94(int iParam0)
{
if (!func_53(iParam0))
{
return false;
}
switch (iParam0)
{
case 32:
return true;
case 35:
return true;
case 65:
return true;
case 95:
return true;
}
return false;
}
bool func_95(int iParam0, int iParam1, int iParam2, bool bParam3, bool bParam4)
{
bool bVar0;
bVar0 = func_20() != -1;
switch (iParam0)
{
case 76:
*iParam1 = 0;
if (bParam3)
{
*iParam2 = 47;
}
else
{
*iParam2 = 63;
}
if (bVar0)
{
*iParam2 = 5;
}
break;
case 105:
*iParam1 = 69;
if (bParam3)
{
*iParam2 = 127;
}
else
{
*iParam2 = 136;
}
if (bVar0)
{
*iParam2 = 72;
}
break;
case 5:
*iParam1 = 137;
*iParam2 = 324;
if (bVar0)
{
*iParam2 = 142;
}
break;
case 61:
*iParam1 = 380;
*iParam2 = 381;
if (bVar0)
{
*iParam2 = 380;
}
break;
case 78:
*iParam1 = 382;
*iParam2 = 431;
if (bVar0)
{
*iParam2 = 384;
}
break;
case 92:
*iParam1 = 443;
*iParam2 = 471;
if (bVar0)
{
*iParam2 = 443;
}
break;
case 26:
*iParam1 = 472;
if (bParam3)
{
*iParam2 = 500;
}
else
{
*iParam2 = 502;
}
if (bVar0)
{
*iParam2 = 472;
}
break;
case 38:
*iParam1 = 508;
*iParam2 = 553;
if (bVar0)
{
*iParam2 = 509;
}
break;
case 68:
*iParam1 = 554;
*iParam2 = 565;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 65:
*iParam1 = 566;
*iParam2 = 588;
if (bVar0)
{
*iParam2 = 566;
}
break;
case 69:
*iParam1 = 589;
if (bParam3)
{
*iParam2 = 598;
}
else
{
*iParam2 = 612;
}
if (bVar0)
{
*iParam2 = 590;
}
break;
case 75:
*iParam1 = 503;
*iParam2 = 506;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 93:
*iParam1 = 613;
*iParam2 = 625;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 95:
*iParam1 = 626;
*iParam2 = 641;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 97:
*iParam1 = 642;
*iParam2 = 643;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 3:
*iParam1 = 644;
*iParam2 = 656;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 6:
*iParam1 = 657;
*iParam2 = 658;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 32:
*iParam1 = 325;
*iParam2 = 344;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 82:
*iParam1 = 659;
if (bParam3)
{
*iParam2 = 673;
}
else
{
*iParam2 = 690;
}
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 35:
*iParam1 = 691;
*iParam2 = 700;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 56:
*iParam1 = 701;
*iParam2 = 708;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 22:
if (bParam4)
{
*iParam1 = 715;
}
else
{
*iParam1 = 715;
}
*iParam2 = 723;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 110:
*iParam1 = 724;
*iParam2 = 730;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 64:
*iParam1 = 736;
*iParam2 = 740;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 66:
*iParam1 = 745;
*iParam2 = 750;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 70:
*iParam1 = 751;
*iParam2 = 754;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 77:
*iParam1 = 731;
*iParam2 = 732;
break;
case 96:
*iParam1 = 741;
*iParam2 = 743;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 29:
*iParam1 = 744;
*iParam2 = 744;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 100:
*iParam1 = 755;
*iParam2 = 763;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 102:
*iParam1 = 764;
*iParam2 = 767;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 72:
*iParam1 = 733;
*iParam2 = 735;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 124:
*iParam1 = 791;
*iParam2 = 793;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 86:
*iParam1 = 768;
*iParam2 = 772;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 126:
*iParam1 = 773;
*iParam2 = 779;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 120:
*iParam1 = 432;
*iParam2 = 442;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 115:
*iParam1 = 345;
*iParam2 = 375;
if (bVar0)
{
*iParam2 = 375;
}
break;
case 125:
*iParam1 = 376;
*iParam2 = 379;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 116:
*iParam1 = 783;
*iParam2 = 790;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 21:
*iParam1 = 780;
*iParam2 = 782;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 42:
*iParam1 = 794;
*iParam2 = 798;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 89:
*iParam1 = 799;
*iParam2 = 800;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 23:
*iParam1 = 801;
*iParam2 = 801;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 28:
*iParam1 = 802;
*iParam2 = 803;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 101:
*iParam1 = 804;
*iParam2 = 806;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 117:
*iParam1 = 507;
*iParam2 = 507;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 11:
*iParam1 = 807;
*iParam2 = 833;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
case 128:
*iParam1 = 834;
*iParam2 = 857;
if (bVar0)
{
*iParam1 = -1;
*iParam2 = -1;
}
break;
default:
*iParam1 = -1;
*iParam2 = -1;
break;
}
if (*iParam1 == -1 || *iParam2 == -1)
{
return false;
}
return true;
}
bool func_96(int iParam0)
{
return (iParam0 > -1 && iParam0 < 954);
}
bool func_97(int iParam0)
{
switch (iParam0)
{
case 64:
return true;
case 65:
return true;
case 66:
return true;
case 67:
return true;
case 68:
return true;
default:
break;
}
return false;
}
int func_98(int iParam0, bool bParam1)
{
if (!func_96(iParam0))
{
return 0;
}
if (!func_134(iParam0, 2))
{
return 0;
}
if (func_134(iParam0, 32) && !bParam1)
{
func_152(iParam0, PERSCHAR::_CREATE_PERSISTENT_CHARACTER(func_151(iParam0)));
if (func_20() == -1)
{
if (func_134(iParam0, 2048))
{
PERSCHAR::_0x49A8C2CD97815215(func_153(iParam0));
func_154(iParam0, 2048);
}
PERSCHAR::_0xFCC6DB8DBE709BC8(func_153(iParam0));
}
return 0;
}
if (!func_155(iParam0) && func_20() == -1)
{
return 0;
}
if (PERSCHAR::_0x800DF3FC913355F3(func_153(iParam0)))
{
func_154(iParam0, 128);
return 1;
}
func_152(iParam0, PERSCHAR::_CREATE_PERSISTENT_CHARACTER(func_151(iParam0)));
PERSCHAR::_0x4F81EAD1DE8FA19B(func_153(iParam0));
if (func_134(iParam0, 2048))
{
PERSCHAR::_0x49A8C2CD97815215(func_153(iParam0));
func_154(iParam0, 2048);
}
return 1;
}
bool func_99(int iParam0)
{
return (iParam0 > -1 && iParam0 < 16);
}
bool func_100(int iParam0)
{
if ((iParam0 == 22 || iParam0 == 37) && !func_156())
{
return true;
}
if (iParam0 == 61)
{
return true;
}
return false;
}
bool func_101()
{
if (Global_16)
{
return false;
}
if (!func_157())
{
return false;
}
if (DATABINDING::_DATABINDING_READ_DATA_BOOL(Global_1934266.f_78.f_55))
{
return false;
}
if (func_84(-1 ^ 9, 0, 1))
{
return false;
}
return true;
}
char* func_102(int iParam0, int iParam1, int iParam2, int iParam3, bool bParam4, bool bParam5, var uParam6)
{
char* sVar0;
if (!MISC::IS_STRING_NULL_OR_EMPTY(&(Global_1894899.f_162)))
{
sVar0 = func_158(Global_1894899.f_162);
}
if (MISC::IS_STRING_NULL_OR_EMPTY(sVar0) && bParam4)
{
sVar0 = func_160(func_159(Global_36));
}
if (MISC::IS_STRING_NULL_OR_EMPTY(sVar0))
{
if (!func_161(iParam0) || func_162(45))
{
switch (iParam0)
{
case 2:
sVar0 = "LANDMARK_MERKINS_WALLER";
break;
case 3:
sVar0 = "SETTLEMENT_LAGRAS";
break;
case 4:
sVar0 = "HIDEOUT_LAKAY";
break;
case 1:
sVar0 = "LANDMARK_MACOMBS_END";
break;
case 6:
sVar0 = "LANDMARK_HAGEN_ORCHARDS";
break;
case 5:
sVar0 = "TOWN_SAINTDENIS";
break;
case 8:
sVar0 = "SETTLEMENT_GRAND_KORRIGAN";
break;
case 9:
sVar0 = "HIDEOUT_SHADY_BELLE";
break;
case 10:
sVar0 = "LANDMARK_SILTWATER_STRAND";
break;
case 11:
sVar0 = "SETTLEMENT_APPLESEED_TIMBER_CO";
break;
case 12:
sVar0 = "LANDMARK_BERYLS_DREAM";
break;
case 15:
sVar0 = "SETTLEMENT_FORT_RIGGS_HOLDING_CAMP";
break;
case 16:
sVar0 = "HIDEOUT_HANGING_DOG_RANCH";
break;
case 17:
sVar0 = "HOMESTEAD_LONE_MULE_STEAD";
break;
case 19:
sVar0 = "LANDMARK_MONTOS_REST";
break;
case 20:
sVar0 = "LANDMARK_OWANJILA_DAM";
break;
case 21:
sVar0 = "HOMESTEAD_PAINTED_SKY";
break;
case 22:
sVar0 = "SETTLEMENT_PRONGHORN_RANCH";
break;
case 23:
sVar0 = "LANDMARK_RIGGS_STATION";
break;
case 25:
sVar0 = "HOMESTEAD_SHEPHERDS_RISE";
break;
case 26:
sVar0 = "TOWN_STRAWBERRY";
break;
case 27:
sVar0 = "LANDMARK_VALLEY_VIEW";
break;
case 28:
sVar0 = "LANDMARK_WALLACE_STATION";
break;
case 29:
sVar0 = "HOMESTEAD_WATSONS_CABIN";
break;
case 30:
sVar0 = "LANDMARK_CANEBREAK_MANOR";
break;
case 31:
sVar0 = "LANDMARK_COPPERHEAD_LANDING";
break;
case 32:
sVar0 = "SETTLEMENT_SISIKA_PENITENTIARY";
break;
case 120:
sVar0 = "TOWN_ARMADILLO";
break;
case 121:
sVar0 = "SETTLEMENT_COOTS_CHAPEL";
break;
case 124:
sVar0 = "SETTLEMENT_RIDGEWOOD_FARM";
break;
case 123:
sVar0 = "LANDMARK_RILEYS_CHARGE";
break;
case 125:
sVar0 = "HIDEOUT_TWIN_ROCKS";
break;
case 33:
sVar0 = "LANDMARK_BACCHUS_BRIDGE";
break;
case 34:
sVar0 = "HOMESTEAD_FIRWOOD_RISE";
break;
case 35:
sVar0 = "SETTLEMENT_FORT_WALLACE";
break;
case 36:
sVar0 = "HIDEOUT_SIX_POINT_CABIN";
break;
case 114:
sVar0 = "HIDEOUT_GAPTOOTH_BREACH";
break;
case 116:
sVar0 = "SETTLEMENT_RATHSKELLER_FORK";
break;
case 115:
sVar0 = "TOWN_TUMBLEWEED";
break;
case 37:
sVar0 = "SETTLEMENT_BEECHERS_HOPE";
break;
case 38:
sVar0 = "TOWN_BLACKWATER";
break;
case 39:
sVar0 = "LANDMARK_QUAKERS_COVE";
break;
case 40:
sVar0 = "HOMESTEAD_ADLER_RANCH";
break;
case 50:
sVar0 = "LANDMARK_CALUMET_RAVINE";
break;
case 42:
sVar0 = "HOMESTEAD_CHEZ_PORTER";
break;
case 43:
sVar0 = "HIDEOUT_COLTER";
break;
case 41:
sVar0 = "LANDMARK_WINDOW_ROCK";
break;
case 45:
sVar0 = "LANDMARK_MILLESANI_CLAIM";
break;
case 48:
sVar0 = "LANDMARK_TEMPEST_RIM";
break;
case 54:
sVar0 = "LANDMARK_THE_LOFT";
break;
case 56:
sVar0 = "SETTLEMENT_WAPITI";
break;
case 49:
sVar0 = "LANDMARK_EWING_BASIN";
break;
case 57:
sVar0 = "SETTLEMENT_AGUASDULCES";
break;
case 59:
sVar0 = "LANDMARK_CINCO_TORRES";
break;
case 60:
sVar0 = "LANDMARK_LA_CAPILLA";
break;
case 61:
sVar0 = "TOWN_MANICATO";
break;
case 126:
sVar0 = "TOWN_MACFARLANES_RANCH";
break;
case 127:
sVar0 = "SETTLEMENT_THIEVES_LANDING";
break;
case 62:
sVar0 = "LANDMARK_OLD_GREENBANK_MILL";
break;
case 64:
sVar0 = "HOMESTEAD_CARMODY_DELL";
break;
case 65:
sVar0 = "SETTLEMENT_CORNWALL_KEROSENE_TAR";
break;
case 66:
sVar0 = "HOMESTEAD_GUTHRIE_FARM";
break;
case 67:
sVar0 = "LANDMARK_CUMBERLAND_FALLS";
break;
case 68:
sVar0 = "HOMESTEAD_DOWNES_RANCH";
break;
case 69:
sVar0 = "SETTLEMENT_EMERALD_RANCH";
break;
case 70:
sVar0 = "LANDMARK_GRANGERS_HOGGERY";
break;
case 72:
sVar0 = "HOMESTEAD_LARNED_SOD";
break;
case 74:
sVar0 = "LANDMARK_LUCKYS_CABIN";
break;
case 75:
sVar0 = "LANDMARK_FLATNECK_STATION";
break;
case 76:
sVar0 = "TOWN_VALENTINE";
break;
case 77:
sVar0 = "HOMESTEAD_ABERDEEN_PIG_FARM";
break;
case 78:
sVar0 = "TOWN_ANNESBURG";
break;
case 79:
sVar0 = "HIDEOUT_BEAVER_HOLLOW";
break;
case 82:
sVar0 = "SETTLEMENT_BUTCHER_CREEK";
break;
case 80:
sVar0 = "LANDMARK_BLACK_BALSAM_RISE";
break;
case 81:
sVar0 = "LANDMARK_BRANDYWINE_DROP";
break;
case 83:
sVar0 = "HOMESTEAD_DOVERHILL";
break;
case 86:
sVar0 = "HOMESTEAD_MACLEANS_HOUSE";
break;
case 87:
sVar0 = "LANDMARK_MOSSY_FLATS";
break;
case 88:
sVar0 = "LANDMARK_ROANOKE_VALLEY";
break;
case 89:
sVar0 = "HOMESTEAD_WILLARDS_REST";
break;
case 92:
sVar0 = "TOWN_VANHORN";
break;
case 117:
sVar0 = "SETTLEMENT_BENEDICT_POINT";
break;
case 118:
sVar0 = "HIDEOUT_FORT_MERCER";
break;
case 119:
sVar0 = "SETTLEMENT_PLAINVIEW";
break;
case 93:
sVar0 = "SETTLEMENT_BRAITHWAITE_MANOR";
break;
case 94:
sVar0 = "LANDMARK_BOLGER_GLADE";
break;
case 95:
sVar0 = "SETTLEMENT_CALIGA_HALL";
break;
case 96:
sVar0 = "HOMESTEAD_CATFISH_JACKSONS";
break;
case 98:
sVar0 = "HIDEOUT_CLEMENS_POINT";
break;
case 99:
sVar0 = "HOMESTEAD_COMPSONS_STEAD";
break;
case 100:
sVar0 = "HOMESTEAD_HILL_HAVEN_RANCH";
break;
case 102:
sVar0 = "HOMESTEAD_LONNIES_SHACK";
break;
case 104:
sVar0 = "LANDMARK_RADLEYS_PASTURE";
break;
case 105:
sVar0 = "TOWN_RHODES";
break;
case 108:
sVar0 = "LANDMARK_BEAR_CLAW";
break;
case 110:
sVar0 = "SETTLEMENT_MANZANITA_POST";
break;
case 111:
sVar0 = "LANDMARK_PACIFIC_UNION_RAILROAD";
break;
case 112:
sVar0 = "LANDMARK_TANNERS_REACH";
break;
case 128:
sVar0 = "SETTLEMENT_CENTRAL_UNION_RAILROAD_CAMP";
break;
}
}
}
if (MISC::IS_STRING_NULL_OR_EMPTY(sVar0) || bParam5)
{
switch (iParam2)
{
case joaat("WATER_ARROYO_DE_LA_VIBORA"):
sVar0 = "WATER_ARROYO_DE_LA_VIBORA";
*uParam6 = 1;
break;
case joaat("WATER_AURORA_BASIN"):
sVar0 = "WATER_AURORA_BASIN";
*uParam6 = 1;
break;
case joaat("WATER_BAHIA_DE_LA_PAZ"):
sVar0 = "WATER_BAHIA_DE_LA_PAZ";
*uParam6 = 1;
break;
case joaat("WATER_BARROW_LAGOON"):
sVar0 = "WATER_BARROW_LAGOON";
*uParam6 = 1;
break;
case joaat("WATER_BAYOU_NWA"):
sVar0 = "DISTRICT_BAYOU_NWA";
*uParam6 = 1;
break;
case joaat("WATER_CAIRN_LAKE"):
sVar0 = "WATER_CAIRN_LAKE";
*uParam6 = 1;
break;
case joaat("WATER_CATTIAL_POND"):
sVar0 = "WATER_CATTAIL_POND";
*uParam6 = 1;
break;
case joaat("WATER_DAKOTA_RIVER"):
sVar0 = "WATER_DAKOTA_RIVER";
*uParam6 = 1;
break;
case joaat("WATER_DEADBOOT_CREEK"):
sVar0 = "WATER_DEADBOOT_CREEK";
*uParam6 = 1;
break;
case joaat("WATER_ELYSIAN_POOL"):
sVar0 = "WATER_ELYSIAN_POOL";
*uParam6 = 1;
break;
case joaat("WATER_FLAT_IRON_LAKE"):
sVar0 = "WATER_FLAT_IRON_LAKE";
*uParam6 = 1;
break;
case joaat("WATER_HAWKS_EYE_CREEK"):
sVar0 = "WATER_HAWKS_EYE_CREEK";
*uParam6 = 1;
break;
case joaat("WATER_HEARTLANDS_OVERFLOW"):
sVar0 = "LANDMARK_HEARTLAND_OVERFLOW";
*uParam6 = 1;
break;
case joaat("WATER_HOT_SPRINGS"):
sVar0 = "WATER_COTORRA_SPRINGS";
*uParam6 = 1;
break;
case joaat("WATER_LAKE_DON_JULIO"):
sVar0 = "WATER_LAKE_DON_JULIO";
*uParam6 = 1;
break;
case joaat("WATER_LAKE_ISABELLA"):
sVar0 = "WATER_LAKE_ISABELLA";
*uParam6 = 1;
break;
case joaat("WATER_LANNAHECHEE_RIVER"):
sVar0 = "WATER_LANNAHECHEE_RIVER";
*uParam6 = 1;
break;
case joaat("WATER_LITTLE_CREEK_RIVER"):
sVar0 = "WATER_LITTLE_CREEK_RIVER";
*uParam6 = 1;
break;
case joaat("WATER_LOWER_MONTANA_RIVER"):
sVar0 = "WATER_LOWER_MONTANA_RIVER";
*uParam6 = 1;
break;
case joaat("WATER_MATTLOCK_POND"):
sVar0 = "WATER_MATTOCK_POND";
*uParam6 = 1;
break;
case joaat("WATER_MOONSTONE_POND"):
sVar0 = "WATER_MOONSTONE_POND";
*uParam6 = 1;
break;
case joaat("WATER_O_CREAGHS_RUN"):
sVar0 = "WATER_OCREAGHS_RUN";
*uParam6 = 1;
break;
case joaat("WATER_OWANJILA"):
sVar0 = "WATER_OWANJILA";
*uParam6 = 1;
break;
case joaat("WATER_RINGNECK_CREEK"):
sVar0 = "WATER_RINGNECK_CREEK";
*uParam6 = 1;
break;
case joaat("WATER_SEA_OF_CORONADO"):
sVar0 = "WATER_SEA_OF_CORONADO";
*uParam6 = 1;
break;
case joaat("WATER_SOUTHFIELD_FLATS"):
sVar0 = "WATER_SOUTHFIELD_FLATS";
*uParam6 = 1;
break;
case joaat("WATER_SPIDER_GORGE"):
sVar0 = "WATER_SPIDER_GORGE";
*uParam6 = 1;
break;
case joaat("WATER_STILLWATER_CREEK"):
sVar0 = "WATER_STILLWATER_CREEK";
*uParam6 = 1;
break;
case joaat("WATER_UPPER_MONTANA_RIVER"):
sVar0 = "WATER_UPPER_MONTANA_RIVER";
*uParam6 = 1;
break;
case joaat("WATER_WHINYARD_STRAIT"):
sVar0 = "WATER_WHINYARD_STRAIT";
*uParam6 = 1;
break;
case joaat("WATER_KAMASSA_RIVER"):
if (iParam1 == 10)
{
sVar0 = "WATER_KAMASSA_RIVER";
}
else if (iParam1 == 2)
{
sVar0 = "WATER_KAMASSA_RIVER_BLUEWATER_MARSH";
}
else
{
sVar0 = "WATER_KAMASSA_RIVER_BAYOU_NWA";
}
*uParam6 = 1;
break;
case joaat("WATER_SAN_LUIS_RIVER"):
if (iParam1 == 4 || iParam1 == 12)
{
sVar0 = "WATER_SAN_LUIS_RIVER_WEST_ELIZABETH";
}
else
{
sVar0 = "WATER_SAN_LUIS_RIVER_NEW_AUSTIN";
}
*uParam6 = 1;
break;
}
}
if (MISC::IS_STRING_NULL_OR_EMPTY(sVar0))
{
switch (iParam1)
{
case 0:
sVar0 = "DISTRICT_BAYOU_NWA";
break;
case 1:
sVar0 = "DISTRICT_BIG_VALLEY";
break;
case 2:
sVar0 = "DISTRICT_BLUEWATER_MARSH";
break;
case 3:
sVar0 = "DISTRICT_CUMBERLAND_FOREST";
break;
case 4:
sVar0 = "DISTRICT_GREAT_PLAINS";
break;
case 6:
sVar0 = "DISTRICT_GRIZZLIES";
break;
case 7:
sVar0 = "DISTRICT_GRIZZLIES";
break;
case 8:
sVar0 = "DISTRICT_GUARMA";
break;
case 9:
sVar0 = "DISTRICT_HEARTLANDS";
break;
case 10:
sVar0 = "DISTRICT_ROANOAKE_RIDGE";
break;
case 11:
sVar0 = "DISTRICT_SCARLETT_MEADOWS";
break;
case 12:
sVar0 = "DISTRICT_TALL_TREES";
break;
case 13:
sVar0 = "DISTRICT_GAPTOOTH_RIDGE";
break;
case 14:
sVar0 = "DISTRICT_RIO_BRAVO";
break;
case 15:
sVar0 = "DISTRICT_CHOLLA_SPRINGS";
break;
case 16:
sVar0 = "DISTRICT_HENNIGANS_STEAD";
break;
}
}
if (MISC::IS_STRING_NULL_OR_EMPTY(sVar0))
{
switch (iParam3)
{
case 0:
sVar0 = "STATE_AMBARINO";
break;
case 2:
sVar0 = "STATE_LEMOYNE";
break;
case 3:
sVar0 = "STATE_WEST_ELIZABETH";
break;
case 4:
sVar0 = "STATE_NEW_AUSTIN";
break;
case 1:
sVar0 = "STATE_NEW_HANOVER";
break;
case 5:
sVar0 = "STATE_GUARMA";
break;
}
}
return sVar0;
}
bool func_103(int iParam0)
{
return (iParam0 > -1 && iParam0 < 6);
}
int func_104(int iParam0)
{
switch (iParam0)
{
case 0:
return 2;
case 2:
return 2;
case 11:
return 2;
case 9:
return 1;
case 10:
return 1;
case 3:
return 1;
case 4:
return 3;
case 12:
return 3;
case 1:
return 3;
case 5:
return 0;
case 6:
return 0;
case 7:
return 0;
case 8:
return 5;
case 13:
return 4;
case 14:
return 4;
case 15:
return 4;
case 16:
return 4;
default:
break;
}
return -1;
}
int func_105(int iParam0)
{
if (!func_103(iParam0))
{
return -1;
}
if (Global_1572887.f_12 == -1)
{
return Global_40.f_358[iParam0 /*12*/];
}
return Global_1058888.f_42266[iParam0 /*12*/];
}
int func_106(int iParam0)
{
switch (iParam0)
{
case joaat("WATER_AURORA_BASIN"):
return 0;
case joaat("WATER_BARROW_LAGOON"):
return 0;
case joaat("WATER_BAYOU_NWA"):
return 2;
case joaat("WATER_BEARTOOTH_BECK"):
return 1;
case joaat("WATER_CAIRN_LAKE"):
return 0;
case joaat("WATER_CALMUT_RAVINE"):
return 0;
case joaat("WATER_CATTIAL_POND"):
return 0;
case joaat("WATER_DAKOTA_RIVER"):
return 1;
case joaat("WATER_DEADBOOT_CREEK"):
return 1;
case joaat("WATER_DEWBERRY_CREEK"):
return 1;
case joaat("WATER_ELYSIAN_POOL"):
return 0;
case joaat("WATER_FLAT_IRON_LAKE"):
return 0;
case joaat("WATER_HAWKS_EYE_CREEK"):
return 1;
case joaat("WATER_HEARTLANDS_OVERFLOW"):
return 0;
case joaat("WATER_HOT_SPRINGS"):
return 0;
case joaat("WATER_KAMASSA_RIVER"):
return 1;
case joaat("WATER_LAKE_DON_JULIO"):
return 0;
case joaat("WATER_LAKE_ISABELLA"):
return 0;
case joaat("WATER_LANNAHECHEE_RIVER"):
return 1;
case joaat("WATER_LITTLE_CREEK_RIVER"):
return 1;
case joaat("WATER_LOWER_MONTANA_RIVER"):
return 1;
case joaat("WATER_MATTLOCK_POND"):
return 0;
case joaat("WATER_MOONSTONE_POND"):
return 0;
case joaat("WATER_O_CREAGHS_RUN"):
return 0;
case joaat("WATER_OWANJILA"):
return 0;
case joaat("WATER_RINGNECK_CREEK"):
return 1;
case joaat("WATER_SAN_LUIS_RIVER"):
return 1;
case joaat("WATER_SEA_OF_CORONADO"):
return 1;
case joaat("WATER_SOUTHFIELD_FLATS"):
return 0;
case joaat("WATER_SPIDER_GORGE"):
return 1;
case joaat("WATER_STILLWATER_CREEK"):
return 1;
case joaat("WATER_UPPER_MONTANA_RIVER"):
return 1;
case joaat("WATER_WHINYARD_STRAIT"):
return 1;
default:
break;
}
return -1;
}
char* func_107(int iParam0)
{
switch (iParam0)
{
case 0:
return "WATER_TYPE_LAKE";
case 1:
return "WATER_TYPE_RIVER";
case 2:
return "WATER_TYPE_SWAMP";
default:
break;
}
return "";
}
bool func_108(int iParam0, int iParam1)
{
if (!func_7(iParam0))
{
return false;
}
if (Global_1572887.f_12 == -1)
{
return (Global_40.f_431[iParam0] && iParam1) != 0;
}
return (Global_1058888.f_42339[iParam0] && iParam1) != 0;
}
bool func_109(int iParam0, int iParam1)
{
if (!func_103(iParam0))
{
return false;
}
if (Global_1572887.f_12 == -1)
{
return (Global_40.f_358[iParam0 /*12*/].f_5 && iParam1) != 0;
}
return (Global_1058888.f_42266[iParam0 /*12*/].f_5 && iParam1) != 0;
}
int func_110()
{
return Global_1899515;
}
int func_111(int iParam0)
{
return BUILTIN::SHIFT_RIGHT(iParam0, 12) & 31;
}
int func_112(int iParam0)
{
return BUILTIN::SHIFT_RIGHT(iParam0, 6) & 63;
}
float func_113(float fParam0)
{
return ((fParam0 * 1.8f) + 32f);
}
char* func_114(char* sParam0, int iParam1)
{
if (iParam1 == joaat("COLOR_PURE_WHITE"))
{
return MISC::_CREATE_VAR_STRING(10, "LITERAL_STRING", sParam0);
}
return func_163(MISC::_CREATE_VAR_STRING(10, "LITERAL_STRING", sParam0), iParam1);
}
var func_115(char* sParam0, char* sParam1, int iParam2, int iParam3, int iParam4, int iParam5, int iParam6, int iParam7)
{
struct<4> Var0;
vector3 vVar13;
var uVar16;
Var0 = -2;
Var0 = iParam2;
Var0.f_1 = iParam3;
Var0.f_2 = iParam4;
Var0.f_3 = iParam5;
vVar13.f_1 = sParam0;
vVar13.f_2 = sParam1;
uVar16 = UIFEED::_SHOW_LOCATION_NOTIFICATION(&Var0, &vVar13, iParam6, iParam7);
return uVar16;
}
bool func_116(int iParam0)
{
return (Global_1572864.f_3 && iParam0) != 0;
}
bool func_117(int iParam0)
{
int iVar0;
if (func_161(iParam0))
{
if (!func_162(45))
{
return false;
}
}
iVar0 = func_6(iParam0);
if (func_164())
{
if (!func_165(Global_1835011[3 /*74*/].f_1, 1))
{
return (iVar0 == 7 || iVar0 == 6);
}
}
return true;
}
void func_118(var uParam0, int iParam1)
{
*uParam0 = (*uParam0 || iParam1);
}
struct<2> func_119(int iParam0, int iParam1)
{
struct<2> Var0;
Var0 = iParam0;
Var0.f_1 = iParam1;
return Var0;
}
void func_120(var uParam0, int iParam1, int iParam2)
{
STATS::_STAT_ID_INCREMENT_INT(&uParam0, iParam2);
}
int func_121()
{
return Global_1894899.f_2;
}
bool func_122(int iParam0)
{
return (iParam0 > -1 && iParam0 < 120);
}
void func_123(int iParam0)
{
Global_1327479.f_3 = iParam0;
}
int func_124()
{
return Global_1310750.f_16037;
}
bool func_125(int iParam0, int iParam1)
{
if (!func_122(iParam0))
{
return false;
}
return (Global_1310750[iParam0 /*111*/] && iParam1) != 0;
}
bool func_126(int iParam0)
{
if (!func_122(iParam0))
{
return false;
}
if (func_166(64) && func_167(iParam0))
{
return true;
}
return Global_1310750[iParam0 /*111*/].f_46;
}
bool func_127(int iParam0)
{
if (!func_122(iParam0))
{
return false;
}
return Global_1310750[iParam0 /*111*/].f_47;
}
void func_128(int iParam0)
{
int iVar0;
if (iParam0 == -1)
{
return;
}
if (!func_122(Global_1310750.f_13321[iParam0 /*9*/]))
{
return;
}
iVar0 = Global_1310750.f_13321[iParam0 /*9*/];
PLAYER::FORCE_CLEANUP_FOR_THREAD_WITH_THIS_ID(Global_1310750.f_13321[iParam0 /*9*/].f_5, 523);
Global_1310750[iVar0 /*111*/].f_48 = 0;
func_168(iParam0);
Global_1310750.f_16037 = (Global_1310750.f_16037 - 1);
}
void func_129(var uParam0)
{
if (SCRIPTS::IS_THREAD_ACTIVE(*uParam0, false))
{
SCRIPTS::TERMINATE_THREAD(*uParam0);
}
}
void func_130(int iParam0)
{
func_169(Global_1935369.f_5[iParam0 /*11*/].f_6, 1);
func_170(Global_1935369.f_5[iParam0 /*11*/].f_6, 0);
if (VOLUME::_0xF6A8A652A6B186CD(Global_1935369.f_5[iParam0 /*11*/].f_8))
{
VOLUME::_0xFDFECC6EE4491E11(Global_1935369.f_5[iParam0 /*11*/].f_8);
Global_1935369.f_5[iParam0 /*11*/].f_8 = 0;
}
func_171(iParam0, 8192);
func_171(iParam0, 16384);
func_171(iParam0, 32768);
func_171(iParam0, 131072);
func_171(iParam0, 16777216);
func_171(iParam0, 524288);
func_171(iParam0, 1048576);
Global_1935369.f_5[iParam0 /*11*/].f_10 = 0;
Global_1935369.f_5[Global_1935369 /*11*/].f_9 = 0;
Global_1935369.f_5[iParam0 /*11*/] = 0;
Global_1935369.f_5[iParam0 /*11*/].f_1 = { 0f, 0f, 0f };
Global_1935369.f_5[iParam0 /*11*/].f_4 = 0;
Global_1935369.f_5[iParam0 /*11*/].f_5 = -1;
Global_1935369.f_5[iParam0 /*11*/].f_6 = -1;
Global_1935369.f_5[iParam0 /*11*/].f_7 = 0;
}
void func_131(int iParam0)
{
int iVar0;
int iVar1;
if (func_96(Global_1914319.f_3[iParam0 /*446*/].f_21) && func_172(Global_1914319.f_3[iParam0 /*446*/].f_21))
{
func_173(Global_1914319.f_3[iParam0 /*446*/].f_21, 0, 1, 0, 0);
}
Global_1914319.f_3[iParam0 /*446*/].f_11 = { 0f, 0f, 0f };
Global_1914319.f_3[iParam0 /*446*/].f_21 = -1;
Global_1914319.f_3[iParam0 /*446*/].f_22 = -1;
Global_1914319.f_3[iParam0 /*446*/].f_17 = 0;
Global_1914319.f_3[iParam0 /*446*/].f_1 = 0;
if (PED::_0x91A5F9CBEBB9D936(Global_1914319.f_3[iParam0 /*446*/].f_34))
{
PED::REMOVE_SCENARIO_BLOCKING_AREA(Global_1914319.f_3[iParam0 /*446*/].f_34, false);
}
func_174(Global_1914319.f_3[iParam0 /*446*/].f_10, 0);
func_175(iParam0, 536870912);
iVar1 = func_176(iParam0);
if (iVar1 >= 15)
{
Global_1914319.f_3[iParam0 /*446*/].f_408 = 0;
}
else
{
iVar0 = 0;
while (iVar0 < iVar1)
{
func_133(Global_1914319.f_3[iParam0 /*446*/].f_317[iVar0 /*6*/]);
Global_1914319.f_3[iParam0 /*446*/].f_317[iVar0 /*6*/] = 0;
Global_1914319.f_3[iParam0 /*446*/].f_317[iVar0 /*6*/].f_1 = { 0f, 0f, 0f };
Global_1914319.f_3[iParam0 /*446*/].f_317[iVar0 /*6*/].f_4 = 0f;
Global_1914319.f_3[iParam0 /*446*/].f_317[iVar0 /*6*/].f_5 = 0;
iVar0++;
}
Global_1914319.f_3[iParam0 /*446*/].f_408 = 0;
}
if (Global_1914319.f_3[iParam0 /*446*/].f_440 != 0)
{
UIFEED::_0x2F901291EF177B02(Global_1914319.f_3[iParam0 /*446*/].f_440, 0);
}
Global_1914319.f_3[iParam0 /*446*/].f_23 = 0;
func_177(iParam0);
Global_1914319.f_3[iParam0 /*446*/].f_10 = -1;
Global_1914319.f_3[iParam0 /*446*/].f_9 = -1;
func_178(iParam0, 0);
}
int func_132(int iParam0)
{
int iVar0;
iVar0 = 0;
while (iVar0 < 8)
{
if (Global_1392240.f_1[iVar0 /*18*/].f_4 == iParam0)
{
return iVar0;
}
iVar0++;
}
return -1;
}
void func_133(int iParam0)
{
if (func_179(iParam0) && func_180())
{
OBJECT::REMOVE_DOOR_FROM_SYSTEM(iParam0);
}
}
bool func_134(int iParam0, int iParam1)
{
if (func_20() != -1)
{
return false;
}
if (!func_96(iParam0))
{
return false;
}
return (Global_24887[iParam0 /*2*/] && iParam1) != 0;
}
int func_135(int iParam0, bool bParam1)
{
if (!func_96(iParam0))
{
return 0;
}
if (!func_134(iParam0, 2))
{
return 0;
}
if (func_151(iParam0) == 0)
{
return 1;
}
if (!PERSCHAR::_0x800DF3FC913355F3(func_153(iParam0)))
{
return 1;
}
if (func_134(iParam0, 1) && !bParam1)
{
func_181(iParam0, 128);
return 1;
}
func_154(iParam0, 129);
func_182(iParam0);
PERSCHAR::_0xFC77C5B44D5FF7C0(func_153(iParam0));
func_152(iParam0, 0);
return 1;
}
bool func_136()
{
if (Global_1048576)
{
return true;
}
if (Global_1572887.f_4)
{
return true;
}
if (Global_524298)
{
return true;
}
if (Global_1048577)
{
return true;
}
if (Global_1051043 == -1 && Global_1572887.f_6 & 1 != 0)
{
return true;
}
return false;
}
int func_137(int iParam0)
{
if (!func_140(iParam0))
{
return -1;
}
return func_183(func_144(iParam0));
}
bool func_138(int iParam0)
{
return (iParam0 > -1 && iParam0 < 200);
}
bool func_139(var uParam0, int iParam1)
{
return (uParam0 && iParam1) != 0;
}
bool func_140(int iParam0)
{
if (Global_1572887.f_12 == -1)
{
return (iParam0 > 0 && iParam0 < 771);
}
return (iParam0 > 0 && iParam0 < 20001);
}
int func_141(bool bParam0, bool bParam1, bool bParam2)
{
if (Global_1935630.f_18)
{
if ((bParam2 || Global_1935630.f_19 > 0) || Global_1935630.f_17 > 0)
{
return 1;
}
}
else if (bParam1 && !Global_1935630.f_15 == 1370593166)
{
return 0;
}
if (Global_1935630.f_20 > 0 || (bParam2 && Global_1935630.f_20 > -1))
{
return 1;
}
if (bParam0)
{
if (Global_1935630.f_13)
{
if (bParam2 || Global_1935630.f_21 > 0)
{
return 1;
}
}
}
return 0;
}
int func_142()
{
if (Global_1572887.f_12 == -1)
{
return 771;
}
return 20001;
}
int func_143(int iParam0, int iParam1, int iParam2)
{
return ((iParam2 & 31 || BUILTIN::SHIFT_LEFT(iParam0 & 1023, 5)) || BUILTIN::SHIFT_LEFT(iParam1 & 16383, 15));
}
int func_144(int iParam0)
{
if (Global_1572887.f_12 == -1)
{
return Global_12106[iParam0 /*7*/];
}
if (iParam0 < 0 || iParam0 >= 20001)
{
return 0;
}
return Global_1058888.f_498[iParam0 /*2*/];
}
int func_145(int iParam0, int iParam1, int iParam2, int iParam3, int iParam4)
{
int iVar0;
int iVar1;
if (!func_184(iParam2))
{
return -1;
}
if (iParam0 < 0 || iParam0 > 511)
{
return -1;
}
if (iParam1 < 0 || iParam1 > 255)
{
return -1;
}
if (iParam3 < 0 || iParam3 > func_142())
{
return -1;
}
iVar0 = func_143(iParam0, iParam1, iParam2);
iVar1 = iParam3;
func_185(iVar1, 0);
func_186(iVar1, 0);
func_187(iVar1, 0);
func_188(iVar1, 0);
func_189(iVar1, iVar0);
if (iParam4 != 0)
{
func_190(iVar1, iParam4);
}
return iVar1;
}
int func_146(int iParam0)
{
if (!func_140(iParam0))
{
return -1;
}
return func_191(iParam0);
}
void func_147(var uParam0, int iParam1)
{
func_192(uParam0, iParam1);
}
bool func_148(int iParam0, float fParam1)
{
int iVar0;
iVar0 = func_193(iParam0);
if (iVar0 != 0)
{
*fParam1 = func_194(iParam0);
return true;
}
else
{
return false;
}
return false;
}
bool func_149(int iParam0, int iParam1, float fParam2)
{
int iVar0;
if (!func_140(iVar0))
{
iVar0 = func_88(func_86(iParam0), iParam1, 3, func_87(iParam0));
}
if (func_195(iParam0, fParam2))
{
*fParam2 = func_196(iParam0);
return true;
}
return false;
}
float func_150()
{
float fVar0;
int iVar1;
int iVar2;
int iVar3;
int iVar4;
int iVar5;
int iVar6;
iVar6 = func_110();
iVar4 = func_197(iVar6);
iVar5 = func_198(iVar6);
iVar3 = func_199(iVar5, iVar4);
iVar2 = func_200(iVar6);
iVar1 = func_111(iVar6);
fVar0 = (((BUILTIN::TO_FLOAT(iVar1) + (BUILTIN::TO_FLOAT((iVar2 - 1)) * 24f)) + (BUILTIN::TO_FLOAT(iVar3) * 24f)) + ((BUILTIN::TO_FLOAT(iVar4) * 365.2422f) * 24f));
return fVar0;
}
int func_151(int iParam0)
{
if (!func_96(iParam0))
{
return 0;
}
return Global_1895087[iParam0 /*3*/];
}
void func_152(int iParam0, int iParam1)
{
if (!func_96(iParam0))
{
return;
}
Global_1895087[iParam0 /*3*/].f_1 = iParam1;
}
int func_153(int iParam0)
{
if (!func_96(iParam0))
{
return 0;
}
return Global_1895087[iParam0 /*3*/].f_1;
}
void func_154(int iParam0, int iParam1)
{
if (func_20() != -1)
{
return;
}
if (!func_96(iParam0))
{
return;
}
Global_24887[iParam0 /*2*/] = (Global_24887[iParam0 /*2*/] - (Global_24887[iParam0 /*2*/] && iParam1));
}
bool func_155(int iParam0)
{
if (!func_96(iParam0))
{
return false;
}
if (!func_134(iParam0, 2))
{
return false;
}
return true;
}
bool func_156()
{
if (func_20() != -1)
{
return false;
}
if (Global_40.f_39 == joaat("PLAYER_THREE"))
{
return true;
}
return false;
}
bool func_157()
{
if (func_20() != 0)
{
return true;
}
return true;
}
var func_158(var uParam0, var uParam1, var uParam2, var uParam3, var uParam4, var uParam5, var uParam6, var uParam7)
{
return HUD::_0xD8402B858F4DDD88(&uParam0, HUD::GET_LENGTH_OF_LITERAL_STRING(&uParam0));
}
int func_159(vector3 vParam0)
{
int iVar0;
iVar0 = 0;
while (iVar0 < 51)
{
if (func_201(vParam0, iVar0))
{
return iVar0;
}
iVar0++;
}
return -1;
}
char* func_160(int iParam0)
{
switch (iParam0)
{
case 0:
return "LANDMARK_MOUNT_HAGEN";
case 1:
return "LANDMARK_SCRATCHING_POST";
case 2:
return "LANDMARK_JORGES_GAP";
case 3:
return "LANDMARK_MERCER_STATION";
case 4:
return "LANDMARK_ODDFELLOWS_REST";
case 5:
return "LANDMARK_RATTLESNAKE_HOLLOW";
case 6:
return "LANDMARK_SILENT_STEAD";
case 7:
return "LANDMARK_THE_HANGING_ROCK";
case 8:
return "LANDMARK_THE_OLD_BACCHUS_PLACE";
case 9:
return "LANDMARK_TWO_CROWS";
case 10:
return "LANDMARK_REPENTANCE";
case 11:
return "LANDMARK_BENEDICT_PASS";
case 12:
return "WATER_MANTECA_FALLS";
case 13:
return "SETTLEMENT_LIMPANY";
case 14:
return "WATER_MOUNT_SHANN";
case 15:
return "LANDMARK_THREE_SISTERS";
case 16:
return "HIDEOUT_PIKES_BASIN";
case 17:
return "SETTLEMENT_EL_NIDO";
case 18:
return "LANDMARK_BRITTLEBUSH_TRAWL";
case 19:
return "LANDMARK_ERIS_FIELD";
case 20:
return "LANDMARK_GRANITE_PASS";
case 21:
return "LANDMARK_VENTERS_PLACE";
case 22:
return "LANDMARK_PLEASANCE_HOUSE";
case 23:
return "HOMESTEAD_CHADWICK_FARM";
case 24:
return "LANDMARK_BLACK_BONE_FOREST";
case 25:
return "LANDMARK_CITADEL_ROCK";
case 26:
return "LANDMARK_CUEVA_SECA";
case 27:
return "LANDMARK_DEWBERRY_CREEK";
case 28:
return "LANDMARK_DIABLO_RIDGE";
case 29:
return "LANDMARK_DONNER_FALLS";
case 31:
return "HIDEOUT_SOLOMONS_FOLLY";
case 32:
return "LANDMARK_FORT_BRENNAND";
case 33:
return "LANDMARK_CALIBANS_SEAT";
case 34:
return "HIDEOUT_HORSESHOE_OVERLOOK";
case 35:
return "LANDMARK_MESCALERO";
case 36:
return "LANDMARK_RIO_DEL_LOBO_HOUSE";
case 37:
return "LANDMARK_RIO_DEL_LOBO_ROCK";
case 38:
return "LANDMARK_BROKEN_TREE";
case 39:
return "LANDMARK_BARDS_CROSSING";
case 40:
return "LANDMARK_FACE_ROCK";
case 50:
return "LANDMARK_NEKOTI_ROCK";
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 48:
case 49:
return "";
}
return "";
}
bool func_161(int iParam0)
{
switch (iParam0)
{
case 22:
case 25:
case 63:
return true;
}
return false;
}
bool func_162(int iParam0)
{
if (!func_202(iParam0))
{
return false;
}
return func_203(iParam0);
}
char* func_163(char* sParam0, int iParam1)
{
return MISC::_CREATE_VAR_STRING(42, "COLOR_STRING", MISC::_CREATE_COLOR_STRING(iParam1), sParam0);
}
bool func_164()
{
return true;
if (Global_1572887.f_12 == 0)
{
return true;
}
return Global_40.f_1;
}
bool func_165(int iParam0, bool bParam1)
{
switch (func_204(iParam0))
{
case 5:
return true;
case 6:
if (bParam1)
{
return true;
}
break;
}
return false;
}
bool func_166(int iParam0)
{
return (Global_1310750.f_16035 && iParam0) != 0;
}
bool func_167(int iParam0)
{
return func_125(iParam0, Global_1310750.f_16072 | 64);
}
void func_168(int iParam0)
{
int iVar0;
if (Global_1310750.f_13321[iParam0 /*9*/] != -1)
{
Global_1310750[Global_1310750.f_13321[iParam0 /*9*/] /*111*/].f_48 = 0;
}
Global_1310750.f_13321[iParam0 /*9*/] = -1;
Global_1310750.f_13321[iParam0 /*9*/].f_1 = -1;
Global_1310750.f_13321[iParam0 /*9*/].f_2 = { 0f, 0f, 0f };
Global_1310750.f_13321[iParam0 /*9*/].f_5 = 0;
iVar0 = 0;
while (iVar0 < 2)
{
Global_1310750.f_13321[iParam0 /*9*/].f_6[iVar0] = -1881652455;
iVar0++;
}
}
void func_169(int iParam0, bool bParam1)
{
char* sVar0;
switch (iParam0)
{
case 5:
sVar0 = "IZ_val_saloon_int_room_main";
break;
}
if (MISC::IS_STRING_NULL_OR_EMPTY(sVar0))
{
return;
}
AUDIO::SET_AMBIENT_ZONE_STATE_PERSISTENT(sVar0, bParam1, true);
}
void func_170(int iParam0, bool bParam1)
{
switch (iParam0)
{
case 5:
if (bParam1)
{
AUDIO::SET_PORTAL_SETTINGS_OVERRIDE("VAL_SALOON_SWINGING_DOOR", "VAL_SALOON_SWINGING_DOOR_BARRED");
}
else
{
AUDIO::REMOVE_PORTAL_SETTINGS_OVERRIDE("VAL_SALOON_SWINGING_DOOR_BARRED");
}
break;
}
}
void func_171(int iParam0, int iParam1)
{
func_205(&(Global_1935369.f_5[iParam0 /*11*/].f_7), iParam1);
}
bool func_172(int iParam0)
{
if (!func_96(iParam0))
{
return false;
}
return Global_1895087[iParam0 /*3*/].f_2 == SCRIPTS::GET_ID_OF_THIS_THREAD();
}
void func_173(int iParam0, bool bParam1, bool bParam2, bool bParam3, bool bParam4)
{
int iVar0;
int iVar1;
if (!func_96(iParam0))
{
return;
}
if (!func_134(iParam0, 1))
{
return;
}
if (!func_134(iParam0, 2))
{
return;
}
if ((!bParam4 && !func_172(iParam0)) && func_206(iParam0))
{
return;
}
func_154(iParam0, 1);
func_182(iParam0);
if (func_207(func_151(iParam0)))
{
iVar0 = func_153(iParam0);
if (!PERSCHAR::_0x800DF3FC913355F3(iVar0))
{
return;
}
PERSCHAR::_0xBB68908CD11AEBDC(iVar0);
PERSCHAR::_0xB65E7F733956CF25(iVar0);
if (bParam2 && !PERSCHAR::_0xEB98B38CA60742D7(iVar0))
{
PERSCHAR::_0x631CD2D77FDC0316(iVar0);
}
iVar1 = PERSCHAR::_0x31C70A716CAE1FEE(iVar0);
if (!PED::IS_PED_INJURED(iVar1))
{
PED::SET_PED_CONFIG_FLAG(iVar1, 171, false);
}
if (bParam1)
{
PERSCHAR::_0x7B204F88F6C3D287(iVar0);
}
func_154(iParam0, 16);
}
if (func_134(iParam0, 128) && !bParam3)
{
func_135(iParam0, 0);
}
}
void func_174(int iParam0, bool bParam1)
{
if (!func_208(iParam0))
{
return;
}
if (bParam1)
{
if (!func_209(iParam0, 1024))
{
func_210(iParam0, 1024);
INVENTORY::_0x9B4E793B1CB6550A();
}
}
else if (func_209(iParam0, 1024))
{
func_211(iParam0, 1024);
INVENTORY::_0x9B4E793B1CB6550A();
}
func_212(iParam0);
}
void func_175(int iParam0, int iParam1)
{
if (!func_213(iParam0))
{
return;
}
Global_1914319.f_3[iParam0 /*446*/].f_7 = (Global_1914319.f_3[iParam0 /*446*/].f_7 - (Global_1914319.f_3[iParam0 /*446*/].f_7 && iParam1));
}
int func_176(int iParam0)
{
return Global_1914319.f_3[iParam0 /*446*/].f_408;
}
void func_177(int iParam0)
{
Global_1914319.f_3[iParam0 /*446*/].f_7 = 0;
}
void func_178(int iParam0, bool bParam1)
{
int iVar0;
int iVar1;
int iVar2;
if (!func_213(iParam0))
{
return;
}
iVar0 = iParam0;
iVar1 = (iVar0 / 32);
iVar2 = (iVar0 % 32);
if (bParam1)
{
MISC::SET_BIT(&(Global_1914319.f_15924[iVar1]), iVar2);
}
else
{
MISC::CLEAR_BIT(&(Global_1914319.f_15924[iVar1]), iVar2);
}
}
bool func_179(int iParam0)
{
if (func_214(iParam0))
{
return OBJECT::IS_DOOR_REGISTERED_WITH_SYSTEM(iParam0);
}
return false;
}
bool func_180()
{
return true;
}
void func_181(int iParam0, int iParam1)
{
if (func_20() != -1)
{
return;
}
if (!func_96(iParam0))
{
return;
}
Global_24887[iParam0 /*2*/] = (Global_24887[iParam0 /*2*/] || iParam1);
}
void func_182(int iParam0)
{
int iVar0;
if (!func_96(iParam0))
{
return;
}
iVar0 = func_215(iParam0);
if (ENTITY::DOES_ENTITY_EXIST(iVar0))
{
if (ENTITY::DOES_ENTITY_BELONG_TO_THIS_SCRIPT(iVar0, false))
{
ENTITY::SET_PED_AS_NO_LONGER_NEEDED(&iVar0);
}
}
Global_1895087[iParam0 /*3*/].f_2 = 0;
}
int func_183(int iParam0)
{
return BUILTIN::SHIFT_RIGHT(iParam0, 5) & 1023;
}
bool func_184(int iParam0)
{
return (iParam0 > 0 && iParam0 < 13);
}
void func_185(int iParam0, int iParam1)
{
if (Global_1572887.f_12 == -1)
{
Global_12106[iParam0 /*7*/].f_1 = iParam1;
return;
}
if (iParam1 == 0 || iParam1 == -1)
{
func_216(iParam0);
}
else
{
func_217(iParam0, iParam1);
}
func_218();
}
void func_186(int iParam0, int iParam1)
{
if (Global_1572887.f_12 != -1)
{
return;
}
Global_12106[iParam0 /*7*/].f_2 = iParam1;
}
void func_187(int iParam0, int iParam1)
{
if (Global_1572887.f_12 != -1)
{
return;
}
Global_12106[iParam0 /*7*/].f_3 = iParam1;
}
void func_188(int iParam0, int iParam1)
{
if (Global_1572887.f_12 != -1)
{
return;
}
Global_12106[iParam0 /*7*/].f_4 = iParam1;
}
void func_189(int iParam0, int iParam1)
{
if (Global_1572887.f_12 == -1)
{
Global_12106[iParam0 /*7*/] = iParam1;
return;
}
Global_1058888.f_498[iParam0 /*2*/] = iParam1;
}
void func_190(int iParam0, int iParam1)
{
if (Global_1572887.f_12 == -1)
{
Global_12106[iParam0 /*7*/].f_5 = iParam1;
return;
}
Global_1058888.f_498[iParam0 /*2*/].f_1 = iParam1;
}
int func_191(int iParam0)
{
if (Global_1572887.f_12 == -1)
{
return Global_12106[iParam0 /*7*/].f_3;
}
return 0;
}
void func_192(var uParam0, int iParam1)
{
*uParam0 = (*uParam0 || iParam1);
}
int func_193(int iParam0)
{
switch (iParam0)
{
case 2:
return 1;
case 4:
return 2;
case 8:
return 3;
case 16:
return 4;
case 32:
return 5;
case 64:
return 6;
case 128:
return 7;
case 256:
return 8;
case 512:
return 9;
case 1024:
return 10;
case 2048:
return 11;
case 4096:
return 12;
case 8192:
return 13;
case 16384:
return 14;
case 32768:
return 15;
case 65536:
return 16;
case 131072:
return 17;
case 262144:
return 18;
default:
break;
}
return 0;
}
float func_194(int iParam0)
{
int iVar0;
iVar0 = func_193(iParam0);
if (iVar0 == 0)
{
return 0f;
}
return Global_40.f_11959[iVar0];
}
bool func_195(int iParam0, float fParam1)
{
int iVar0;
iVar0 = func_193(iParam0);
if (iVar0 != 0)
{
*fParam1 = func_196(iParam0);
return true;
}
return false;
}
float func_196(int iParam0)
{
int iVar0;
iVar0 = func_193(iParam0);
if (iVar0 == 0)
{
return 0f;
}
return Global_40.f_11959.f_20[iVar0];
}
int func_197(int iParam0)
{
return (BUILTIN::SHIFT_RIGHT(iParam0, 26) & 31 * func_219(MISC::IS_BIT_SET(iParam0, 31), -1, 1)) + 1898;
}
int func_198(int iParam0)
{
return BUILTIN::SHIFT_RIGHT(iParam0, 22) & 15;
}
int func_199(int iParam0, int iParam1)
{
int iVar0;
int iVar1;
int iVar2;
iVar1 = (iParam0 - 1);
if (iVar1 > 0)
{
iVar0 = 0;
while (iVar0 < iVar1)
{
iVar2 = (iVar2 + func_220(iVar1, iParam1));
iVar0++;
}
}
return iVar2;
}
int func_200(int iParam0)
{
return BUILTIN::SHIFT_RIGHT(iParam0, 17) & 31;
}
bool func_201(vector3 vParam0, int iParam3)
{
vector3 vVar0;
struct<2> Var3;
var uVar6;
func_221(iParam3, &vVar0, &Var3, &uVar6);
if (func_222(vParam0, vVar0, Var3, Var3.f_1, uVar6))
{
return true;
}
return false;
}
bool func_202(int iParam0)
{
if (iParam0 == 0)
{
return false;
}
return true;
}
bool func_203(int iParam0)
{
int iVar0;
int iVar1;
int iVar2;
iVar0 = iParam0;
iVar1 = (iVar0 / 31);
iVar2 = (iVar0 % 31);
return MISC::IS_BIT_SET(Global_40.f_7857[iVar1], iVar2);
}
int func_204(int iParam0)
{
if (!func_140(iParam0))
{
return -1;
}
return func_223(iParam0);
}
void func_205(var uParam0, int iParam1)
{
*uParam0 = (*uParam0 - (*uParam0 && iParam1));
}
bool func_206(int iParam0)
{
if (!func_96(iParam0))
{
return false;
}
return SCRIPTS::_DOES_THREAD_EXIST(Global_1895087[iParam0 /*3*/].f_2);
}
bool func_207(int iParam0)
{
return iParam0 != 0;
}
bool func_208(int iParam0)
{
return (iParam0 > -1 && iParam0 < 153);
}
bool func_209(int iParam0, int iParam1)
{
if (!func_208(iParam0))
{
return false;
}
return (Global_1914319.f_15614[iParam0] && iParam1) != 0;
}
void func_210(int iParam0, int iParam1)
{
if (!func_208(iParam0))
{
return;
}
Global_1914319.f_15614[iParam0] = (Global_1914319.f_15614[iParam0] || iParam1);
}
void func_211(int iParam0, int iParam1)
{
if (!func_208(iParam0))
{
return;
}
Global_1914319.f_15614[iParam0] = (Global_1914319.f_15614[iParam0] - (Global_1914319.f_15614[iParam0] && iParam1));
}
void func_212(int iParam0)
{
func_225(func_224(iParam0));
}
bool func_213(int iParam0)
{
return (iParam0 > -1 && iParam0 < 35);
}
bool func_214(int iParam0)
{
return iParam0 != 0;
}
int func_215(int iParam0)
{
int iVar0;
iVar0 = func_153(iParam0);
if (iVar0 == 0)
{
return 0;
}
if (!PERSCHAR::_0x800DF3FC913355F3(iVar0))
{
return 0;
}
return PERSCHAR::_0x31C70A716CAE1FEE(iVar0);
}
int func_216(int iParam0)
{
int iVar0;
iVar0 = func_226(iParam0);
if (iVar0 < 0)
{
return 0;
}
return func_227(iVar0);
}
int func_217(int iParam0, int iParam1)
{
struct<2> Var0;
int iVar2;
if (Global_1058888.f_40501 >= 32)
{
return -1;
}
Var0 = -1;
Var0 = iParam0;
Var0.f_1 = iParam1;
if (Global_1058888.f_40501 == 0)
{
Global_1058888.f_40501.f_1[Global_1058888.f_40501 /*2*/] = { Var0 };
Global_1058888.f_40501++;
return 0;
}
iVar2 = 0;
while (iVar2 < Global_1058888.f_40501)
{
if (iParam0 == Global_1058888.f_40501.f_1[iVar2 /*2*/])
{
Global_1058888.f_40501.f_1[iVar2 /*2*/] = { Var0 };
return iVar2;
}
else if (iParam0 > Global_1058888.f_40501.f_1[iVar2 /*2*/])
{
iVar2++;
}
else if (iParam0 < Global_1058888.f_40501.f_1[iVar2 /*2*/])
{
func_228(iVar2);
Global_1058888.f_40501.f_1[iVar2 /*2*/] = { Var0 };
return iVar2;
}
}
if (Global_1058888.f_40501 < 31)
{
iVar2 = Global_1058888.f_40501;
Global_1058888.f_40501.f_1[iVar2 /*2*/] = { Var0 };
Global_1058888.f_40501++;
if (Global_1058888.f_40501 > 32)
{
Global_1058888.f_40501 = 32;
}
return iVar2;
}
return -1;
}
void func_218()
{
int iVar0;
iVar0 = 0;
while (iVar0 < Global_1058888.f_40501)
{
iVar0++;
}
}
int func_219(bool bParam0, int iParam1, int iParam2)
{
if (bParam0)
{
return iParam1;
}
return iParam2;
}
int func_220(int iParam0, int iParam1)
{
if (iParam1 < 0)
{
iParam1 = 0;
}
switch (iParam0)
{
case 0:
case 2:
case 4:
case 6:
case 7:
case 9:
case 11:
return 31;
case 3:
case 5:
case 8:
case 10:
return 30;
case 1:
if ((iParam1 % 4) == 0)
{
if ((iParam1 % 100) != 0)
{
return 29;
}
else if ((iParam1 % 400) == 0)
{
return 29;
}
}
return 28;
default:
break;
}
return 30;
}
void func_221(int iParam0, var uParam1, var uParam2, var uParam3)
{
switch (iParam0)
{
case 0:
*uParam1 = { -1616.769f, 1260.714f, 205.33f };
*uParam2 = { 150f, 150f, 184f };
*uParam3 = 0f;
break;
case 1:
*uParam1 = { -5837.918f, -3738.832f, -20.6f };
*uParam2 = { 40f, 35f, 70f };
*uParam3 = 45f;
break;
case 2:
*uParam1 = { -4160.689f, -2836.915f, -13.674f };
*uParam2 = { 43f, 197f, 70f };
*uParam3 = 38f;
break;
case 3:
*uParam1 = { -4359.861f, -3083.375f, -13.674f };
*uParam2 = { 30f, 30f, 70f };
*uParam3 = 0f;
break;
case 4:
*uParam1 = { -4446.777f, -2689.265f, -13.674f };
*uParam2 = { 30f, 30f, 70f };
*uParam3 = 0f;
break;
case 5:
*uParam1 = { -4415.84f, -2199.774f, 22.356f };
*uParam2 = { 13f, 21f, 47f };
*uParam3 = 34f;
break;
case 6:
*uParam1 = { -5554.764f, -2395.945f, 7.172f };
*uParam2 = { 21f, 21f, 47f };
*uParam3 = 0f;
break;
case 7:
*uParam1 = { -3447.267f, -2257.723f, 7.172f };
*uParam2 = { 40f, 23f, 47f };
*uParam3 = 0f;
break;
case 8:
*uParam1 = { -1425.852f, -2676.848f, 73.224f };
*uParam2 = { 40f, 25f, 47f };
*uParam3 = 26f;
break;
case 9:
*uParam1 = { -3829.438f, -3009.26f, -13.674f };
*uParam2 = { 39f, 54f, 70f };
*uParam3 = -46f;
break;
case 10:
*uParam1 = { -4696.308f, -3302.809f, -13.674f };
*uParam2 = { 104f, 57f, 70f };
*uParam3 = 0f;
break;
case 11:
*uParam1 = { -5064.707f, -3139.862f, -13.674f };
*uParam2 = { 23f, 26f, 70f };
*uParam3 = 43f;
break;
case 12:
*uParam1 = { -1631.875f, -2856.089f, -1.645f };
*uParam2 = { 149f, 65f, 154f };
*uParam3 = 39f;
break;
case 13:
*uParam1 = { -347.889f, -131.72f, -1.645f };
*uParam2 = { 52f, 40f, 154f };
*uParam3 = 0f;
break;
case 14:
*uParam1 = { -2126.5f, 88.317f, 139.179f };
*uParam2 = { 334f, 171f, 277f };
*uParam3 = -45f;
break;
case 15:
*uParam1 = { 1574.061f, 1121.954f, 201.6f };
*uParam2 = { 147f, 194f, 201f };
*uParam3 = 0f;
break;
case 16:
*uParam1 = { -2741.641f, -2375.761f, 31.492f };
*uParam2 = { 86f, 61f, 50f };
*uParam3 = 11f;
break;
case 17:
*uParam1 = { 1773.323f, -5976.334f, 71.662f };
*uParam2 = { 34f, 34f, 100f };
*uParam3 = -124f;
break;
case 18:
*uParam1 = { -2022.258f, -3039.913f, 25f };
*uParam2 = { 25f, 25f, 45f };
*uParam3 = 0f;
break;
case 19:
*uParam1 = { 1394.172f, -647.735f, 72.455f };
*uParam2 = { 19f, 18f, 100f };
*uParam3 = 40f;
break;
case 20:
*uParam1 = { -242.336f, 1624.373f, 212.894f };
*uParam2 = { 98f, 52f, 120f };
*uParam3 = 51f;
break;
case 21:
*uParam1 = { -3543.512f, -3032.038f, -13.674f };
*uParam2 = { 40f, 40f, 70f };
*uParam3 = 0f;
break;
case 22:
*uParam1 = { -4348.655f, -2427.582f, -13.674f };
*uParam2 = { 40f, 40f, 70f };
*uParam3 = 0f;
break;
case 23:
*uParam1 = { -391.586f, 922.337f, 137.604f };
*uParam2 = { 31f, 30f, 40f };
*uParam3 = 0f;
break;
case 24:
*uParam1 = { -2656.999f, 153.667f, 189.043f };
*uParam2 = { 177f, 126f, 102f };
*uParam3 = 52f;
break;
case 25:
*uParam1 = { 156.109f, 425.799f, 120f };
*uParam2 = { 249f, 112f, 120f };
*uParam3 = -36f;
break;
case 26:
*uParam1 = { -5868.5f, -2752.441f, -13.674f };
*uParam2 = { 40f, 40f, 70f };
*uParam3 = 0f;
break;
case 27:
*uParam1 = { 898.505f, -335.252f, 48.403f };
*uParam2 = { 56f, 152f, 70f };
*uParam3 = -36f;
break;
case 28:
*uParam1 = { -889.947f, -171.356f, 90.537f };
*uParam2 = { 180f, 95f, 100f };
*uParam3 = 29f;
break;
case 29:
*uParam1 = { 571.454f, 1968.615f, 122.93f };
*uParam2 = { 32f, 49f, 140f };
*uParam3 = 0f;
break;
case 30:
*uParam1 = { -2769.681f, -3210.99f, 25f };
*uParam2 = { 25f, 25f, 45f };
*uParam3 = 0f;
break;
case 31:
*uParam1 = { -5409.034f, -3657.266f, -14.496f };
*uParam2 = { 36f, 30f, 30f };
*uParam3 = -24f;
break;
case 32:
*uParam1 = { 2453.293f, 290.68f, 69.615f };
*uParam2 = { 35f, 42f, 19f };
*uParam3 = -4f;
break;
case 33:
*uParam1 = { -643.042f, 278.359f, 95.5f };
*uParam2 = { 70f, 67f, 65f };
*uParam3 = -109f;
break;
case 34:
*uParam1 = { -118.339f, -24.853f, 96.907f };
*uParam2 = { 84f, 69f, 37f };
*uParam3 = 0f;
break;
case 35:
*uParam1 = { -2863.456f, -2723.259f, 93.195f };
*uParam2 = { 196f, 157f, 85f };
*uParam3 = -18f;
break;
case 36:
*uParam1 = { -3484.814f, -3466.383f, -0.849f };
*uParam2 = { 12f, 12f, 70f };
*uParam3 = 0f;
break;
case 37:
*uParam1 = { -3620.875f, -3575.926f, -0.849f };
*uParam2 = { 126f, 86f, 70f };
*uParam3 = -6f;
break;
case 38:
*uParam1 = { -1382.32f, -1400.969f, 56.092f };
*uParam2 = { 22f, 32f, 86f };
*uParam3 = 0f;
break;
case 39:
*uParam1 = { -713.105f, -538.091f, 59.42f };
*uParam2 = { 160f, 22f, 100f };
*uParam3 = 26f;
break;
case 40:
*uParam1 = { 1083.588f, -693.478f, 48.403f };
*uParam2 = { 45f, 46f, 70f };
*uParam3 = 0f;
break;
case 41:
*uParam1 = { -956.489f, 2175.227f, 307.401f };
*uParam2 = { 28f, 23f, 100f };
*uParam3 = 0f;
break;
case 42:
*uParam1 = { 1457.354f, -1576.261f, 95.401f };
*uParam2 = { 28f, 23f, 100f };
*uParam3 = 0f;
break;
case 43:
*uParam1 = { 348.488f, -669.098f, 95f };
*uParam2 = { 28f, 23f, 100f };
*uParam3 = 0f;
break;
case 44:
*uParam1 = { 2008.052f, 617.155f, 95f };
*uParam2 = { 28f, 23f, 100f };
*uParam3 = 0f;
break;
case 45:
*uParam1 = { 2099.835f, -283.012f, 42f };
*uParam2 = { 21f, 29f, 49f };
*uParam3 = 52f;
break;
case 46:
*uParam1 = { -1759.31f, -224.369f, 168f };
*uParam2 = { 21f, 29f, 116f };
*uParam3 = 56f;
break;
case 47:
*uParam1 = { 2142.39f, -1284.068f, 85f };
*uParam2 = { 40f, 71f, 116f };
*uParam3 = 70f;
break;
case 48:
*uParam1 = { 2309.119f, -343.031f, 85f };
*uParam2 = { 15f, 15f, 116f };
*uParam3 = 0f;
break;
case 49:
*uParam1 = { -1815.147f, -2405.116f, 71f };
*uParam2 = { 25f, 25f, 50f };
*uParam3 = 0f;
break;
case 50:
*uParam1 = { -2269.232f, -1145.787f, 214f };
*uParam2 = { 37f, 33f, 68f };
*uParam3 = 0f;
break;
}
}
bool func_222(vector3 vParam0, vector3 vParam3, float fParam6, float fParam7, float fParam8)
{
vector3 vVar0;
struct<2> Var3;
float fVar6;
vVar0 = { vParam0 - vParam3 };
Var3 = ((vVar0.x * BUILTIN::COS(fParam8)) + (vVar0.y * BUILTIN::SIN(fParam8)));
Var3.f_1 = ((vVar0.x * BUILTIN::SIN(fParam8)) - (vVar0.y * BUILTIN::COS(fParam8)));
fVar6 = (((Var3 * Var3) / (fParam6 * fParam6)) + ((Var3.f_1 * Var3.f_1) / (fParam7 * fParam7)));
return fVar6 <= 1f;
}
int func_223(int iParam0)
{
int iVar0;
if (Global_1572887.f_12 == -1)
{
return Global_12106[iParam0 /*7*/].f_1;
}
iVar0 = func_226(iParam0);
if (iVar0 < 0)
{
return 0;
}
return Global_1058888.f_40501.f_1[iVar0 /*2*/].f_1;
}
int func_224(int iParam0)
{
if (!(iParam0 > -1 && iParam0 < 153))
{
return -1;
}
switch (iParam0)
{
case 126:
return 32;
case 22:
return 17;
case 4:
case 5:
case 34:
case 55:
case 67:
return 18;
case 56:
case 57:
case 58:
case 59:
return 19;
case 102:
case 106:
case 109:
case 112:
case 114:
case 120:
return 29;
case 39:
case 73:
case 128:
case 132:
case 137:
case 141:
case 145:
return 0;
case 7:
case 19:
case 28:
case 42:
case 61:
case 74:
case 87:
case 90:
case 95:
case 129:
case 133:
case 138:
case 142:
case 146:
return 3;
case 0:
case 8:
case 29:
case 43:
case 75:
case 91:
case 130:
case 134:
case 139:
case 143:
case 147:
return 6;
case 17:
case 47:
return 7;
case 18:
case 27:
case 41:
case 82:
case 98:
case 125:
return 4;
case 10:
case 26:
case 38:
case 60:
case 72:
case 92:
return 10;
case 1:
case 16:
case 32:
case 51:
case 64:
case 80:
return 22;
case 2:
case 14:
case 20:
case 23:
case 30:
case 45:
case 65:
case 77:
case 86:
case 89:
case 96:
case 99:
return 2;
case 3:
case 15:
case 21:
case 24:
case 31:
case 46:
case 78:
case 85:
case 88:
case 100:
return 1;
case 9:
case 37:
case 69:
return 8;
case 13:
case 35:
case 44:
case 63:
case 76:
case 84:
case 94:
return 9;
case 103:
case 107:
case 110:
case 116:
return 30;
case 104:
case 105:
case 108:
case 111:
case 113:
case 115:
case 117:
case 118:
case 119:
case 121:
case 122:
case 123:
case 124:
return 31;
case 136:
return 5;
case 6:
case 25:
case 36:
case 68:
return 15;
case 11:
case 33:
case 52:
case 53:
case 66:
case 70:
case 71:
case 81:
case 83:
case 93:
case 97:
return 33;
case 48:
return 12;
case 49:
return 13;
case 50:
return 14;
case 62:
case 79:
return 20;
case 101:
return 11;
case 149:
return 23;
case 150:
return 24;
case 151:
return 25;
case 12:
case 54:
return 21;
case 127:
return 34;
case 131:
case 135:
case 140:
case 144:
case 148:
return 27;
case 152:
return 24;
default:
break;
}
return -1;
}
void func_225(int iParam0)
{
Global_1914319.f_15923 = iParam0;
}
int func_226(int iParam0)
{
int iVar0;
int iVar1;
int iVar2;
if (Global_1058888.f_40501 <= 0)
{
return -1;
}
iVar0 = 0;
iVar1 = (Global_1058888.f_40501 - 1);
while (iVar0 <= iVar1)
{
iVar2 = (iVar0 + ((iVar1 - iVar0) / 2));
if (Global_1058888.f_40501.f_1[iVar2 /*2*/] > iParam0)
{
iVar1 = (iVar2 - 1);
}
else if (Global_1058888.f_40501.f_1[iVar2 /*2*/] < iParam0)
{
iVar0 = iVar2 + 1;
}
else
{
return iVar2;
}
}
return -1;
}
int func_227(int iParam0)
{
int iVar0;
struct<2> Var1;
iVar0 = iParam0;
while (iVar0 < Global_1058888.f_40501)
{
if (iVar0 + 1 < 32)
{
Global_1058888.f_40501.f_1[iVar0 /*2*/] = { Global_1058888.f_40501.f_1[iVar0 + 1 /*2*/] };
}
iVar0++;
}
Var1 = -1;
if (Global_1058888.f_40501 < 32)
{
Global_1058888.f_40501.f_1[Global_1058888.f_40501 /*2*/] = { Var1 };
}
Global_1058888.f_40501 = (Global_1058888.f_40501 - 1);
if (Global_1058888.f_40501 < 0)
{
Global_1058888.f_40501 = 0;
}
return 1;
}
int func_228(int iParam0)
{
int iVar0;
struct<2> Var1;
iVar0 = (Global_1058888.f_40501 - 1);
Var1 = -1;
while (iVar0 >= iParam0)
{
if (iVar0 + 1 < 32)
{
Global_1058888.f_40501.f_1[iVar0 + 1 /*2*/] = { Global_1058888.f_40501.f_1[iVar0 /*2*/] };
}
iVar0 = (iVar0 - 1);
}
Global_1058888.f_40501.f_1[iParam0 /*2*/] = { Var1 };
Global_1058888.f_40501++;
if (Global_1058888.f_40501 > 32)
{
Global_1058888.f_40501 = 32;
}
return 1;
}
| [
"jaykoza@jaykoza.de"
] | jaykoza@jaykoza.de |
f37ba05ef1266a98ff0e550777fa6ad9b7ad332f | 0bbab0e540cbafe9eb9014d0aaa846b19be948a7 | /workspace/r5f_uart/include/HL_gio.h | 0851acd41e7eb484a2ca328d2e762e8a40aecdf6 | [
"MIT"
] | permissive | silenc3502/education | c013d1b80aae9297e9e32c78852de79b3b743bf8 | a7d0a0d8a359800016971412373d4911a00053db | refs/heads/master | 2020-04-08T11:58:00.061953 | 2019-06-03T04:16:19 | 2019-06-03T04:16:19 | 159,327,770 | 1 | 1 | null | null | null | null | UTF-8 | C | false | false | 7,690 | h | /** @file HL_gio.h
* @brief GIO Driver Definition File
* @date 07-July-2017
* @version 04.07.00
*
*/
/*
* Copyright (C) 2009-2016 Texas Instruments Incorporated - www.ti.com
*
*
* 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 Texas Instruments Incorporated 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 __GIO_H__
#define __GIO_H__
#include "HL_reg_gio.h"
#ifdef __cplusplus
extern "C" {
#endif
/* USER CODE BEGIN (0) */
/* USER CODE END */
typedef struct gio_config_reg
{
uint32 CONFIG_INTDET;
uint32 CONFIG_POL;
uint32 CONFIG_INTENASET;
uint32 CONFIG_LVLSET;
uint32 CONFIG_PORTADIR;
uint32 CONFIG_PORTAPDR;
uint32 CONFIG_PORTAPSL;
uint32 CONFIG_PORTAPULDIS;
uint32 CONFIG_PORTBDIR;
uint32 CONFIG_PORTBPDR;
uint32 CONFIG_PORTBPSL;
uint32 CONFIG_PORTBPULDIS;
}gio_config_reg_t;
#define GIO_INTDET_CONFIGVALUE 0U
#define GIO_POL_CONFIGVALUE ((uint32)((uint32)0U << 0U) \
| (uint32)((uint32)0U << 1U) \
| (uint32)((uint32)0U << 2U) \
| (uint32)((uint32)0U << 3U) \
| (uint32)((uint32)0U << 4U) \
| (uint32)((uint32)0U << 5U) \
| (uint32)((uint32)0U << 6U) \
| (uint32)((uint32)0U << 7U) \
| (uint32)((uint32)0U << 8U) \
| (uint32)((uint32)0U << 9U) \
| (uint32)((uint32)0U << 10U)\
| (uint32)((uint32)0U << 11U)\
| (uint32)((uint32)0U << 12U)\
| (uint32)((uint32)0U << 13U)\
| (uint32)((uint32)0U << 14U)\
| (uint32)((uint32)0U << 15U))
#define GIO_INTENASET_CONFIGVALUE ((uint32)((uint32)0U << 0U) \
| (uint32)((uint32)0U << 1U) \
| (uint32)((uint32)0U << 2U) \
| (uint32)((uint32)0U << 3U) \
| (uint32)((uint32)0U << 4U) \
| (uint32)((uint32)0U << 5U) \
| (uint32)((uint32)0U << 6U) \
| (uint32)((uint32)0U << 7U) \
| (uint32)((uint32)0U << 8U) \
| (uint32)((uint32)0U << 9U) \
| (uint32)((uint32)0U << 10U)\
| (uint32)((uint32)0U << 11U)\
| (uint32)((uint32)0U << 12U)\
| (uint32)((uint32)0U << 13U)\
| (uint32)((uint32)0U << 14U)\
| (uint32)((uint32)0U << 15U))
#define GIO_LVLSET_CONFIGVALUE ((uint32)((uint32)0U << 0U) \
| (uint32)((uint32)0U << 1U) \
| (uint32)((uint32)0U << 2U) \
| (uint32)((uint32)0U << 3U) \
| (uint32)((uint32)0U << 4U) \
| (uint32)((uint32)0U << 5U) \
| (uint32)((uint32)0U << 6U) \
| (uint32)((uint32)0U << 7U) \
| (uint32)((uint32)0U << 8U) \
| (uint32)((uint32)0U << 9U) \
| (uint32)((uint32)0U << 10U)\
| (uint32)((uint32)0U << 11U)\
| (uint32)((uint32)0U << 12U)\
| (uint32)((uint32)0U << 13U)\
| (uint32)((uint32)0U << 14U)\
| (uint32)((uint32)0U << 15U))
#define GIO_PORTADIR_CONFIGVALUE ((uint32)((uint32)1U << 0U) | (uint32)((uint32)1U << 1U) | (uint32)((uint32)1U << 2U) | (uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
#define GIO_PORTAPDR_CONFIGVALUE ((uint32)((uint32)0U << 0U) | (uint32)((uint32)0U << 1U) | (uint32)((uint32)0U << 2U) | (uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
#define GIO_PORTAPSL_CONFIGVALUE ((uint32)((uint32)1U << 0U) | (uint32)((uint32)1U << 1U) | (uint32)((uint32)1U << 2U) | (uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
#define GIO_PORTAPULDIS_CONFIGVALUE ((uint32)((uint32)0U << 0U) | (uint32)((uint32)0U << 1U) | (uint32)((uint32)0U << 2U) |(uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
#define GIO_PORTBDIR_CONFIGVALUE ((uint32)((uint32)0U << 0U) | (uint32)((uint32)0U << 1U) | (uint32)((uint32)0U << 2U) | (uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
#define GIO_PORTBPDR_CONFIGVALUE ((uint32)((uint32)0U << 0U) | (uint32)((uint32)0U << 1U) | (uint32)((uint32)0U << 2U) | (uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
#define GIO_PORTBPSL_CONFIGVALUE ((uint32)((uint32)0U << 0U) | (uint32)((uint32)0U << 1U) | (uint32)((uint32)0U << 2U) | (uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
#define GIO_PORTBPULDIS_CONFIGVALUE ((uint32)((uint32)0U << 0U) | (uint32)((uint32)0U << 1U) | (uint32)((uint32)0U << 2U) |(uint32)((uint32)0U << 3U) | (uint32)((uint32)0U << 4U) | (uint32)((uint32)0U << 5U) | (uint32)((uint32)0U << 6U) | (uint32)((uint32)0U << 7U))
/**
* @defgroup GIO GIO
* @brief General-Purpose Input/Output Module.
*
* The GIO module provides the family of devices with input/output (I/O) capability.
* The I/O pins are bidirectional and bit-programmable.
* The GIO module also supports external interrupt capability.
*
* Related Files
* - HL_reg_gio.h
* - HL_gio.h
* - HL_gio.c
* @addtogroup GIO
* @{
*/
/* GIO Interface Functions */
void gioInit(void);
void gioSetDirection(gioPORT_t *port, uint32 dir);
void gioSetBit(gioPORT_t *port, uint32 bit, uint32 value);
void gioSetPort(gioPORT_t *port, uint32 value);
uint32 gioGetBit(gioPORT_t *port, uint32 bit);
uint32 gioGetPort(gioPORT_t *port);
void gioToggleBit(gioPORT_t *port, uint32 bit);
void gioEnableNotification(gioPORT_t *port, uint32 bit);
void gioDisableNotification(gioPORT_t *port, uint32 bit);
void gioNotification(gioPORT_t *port, uint32 bit);
void gioGetConfigValue(gio_config_reg_t *config_reg, config_value_type_t type);
/* USER CODE BEGIN (1) */
/* USER CODE END */
/**@}*/
#ifdef __cplusplus
}
#endif /*extern "C" */
#endif
| [
"gcccompil3r@gmail.com"
] | gcccompil3r@gmail.com |
6e5d4fef8da8fd629834975f03cbe024e2ae5f83 | aa0a68deaf907c088a81b058450640d0c793bf7d | /002/002.c | 4c75d9f62b36978e13e11ef0beb9dae6799fcde7 | [] | no_license | dege88/project-euler-solutions | 1f5a2199fb0261b75325ce6e252ad026d80ef13b | 5decf04e0c63a6ac985f2f90a5cacd6fbdd57e6f | refs/heads/master | 2020-04-26T18:00:49.938767 | 2012-10-11T16:30:55 | 2012-10-11T16:30:55 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 225 | c | #include <stdio.h>
void main()
{
int term1,term2,temp,sum;
for(term1 = 1,term2 = 2,sum = 0;term2 <= 4000000;temp = term1,term1 = term2,term2 += temp)
if((term2 % 2) == 0)
sum += term2;
printf("solution: %d\n",sum);
} | [
"nerevar88@gmail.com"
] | nerevar88@gmail.com |
e91563e75af10a24d6386019c0f6d6a965dc3b19 | d5338ee944633698590c583eacd7e6cab310241e | /src/determiniser/zydis-2.0.2/src/Mnemonic.c | fcacb1436fb33c1a25242642ad8fcf8e2de6565e | [
"MIT"
] | permissive | jwhitham/x86determiniser | 07a7cdf73d6c2a78154339e037230265f672d232 | 87bb17057d3e5d0b336f2546bf6fbe4adb759881 | refs/heads/master | 2022-11-20T07:01:02.432087 | 2022-11-17T01:06:25 | 2022-11-17T01:06:25 | 48,798,184 | 9 | 3 | MIT | 2022-11-17T01:08:40 | 2015-12-30T11:43:19 | C | UTF-8 | C | false | false | 2,273 | c | /***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#include <Zydis/Mnemonic.h>
#include <Generated/EnumMnemonic.inc>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic)
{
if (mnemonic >= ZYDIS_ARRAY_SIZE(zydisMnemonicStrings))
{
return ZYDIS_NULL;
}
return (const char*)zydisMnemonicStrings[mnemonic].buffer;
}
const ZydisStaticString* ZydisMnemonicGetStaticString(ZydisMnemonic mnemonic)
{
if (mnemonic >= ZYDIS_ARRAY_SIZE(zydisMnemonicStrings))
{
return ZYDIS_NULL;
}
return &zydisMnemonicStrings[mnemonic];
}
/* ============================================================================================== */
| [
"jack.d.whitham@gmail.com"
] | jack.d.whitham@gmail.com |
6c5304d8cd79f4f3de9aba9500c67946461bb472 | 16715e0904b05e9ca29db339755ae375b7dea218 | /User/Driver/IIC/hard_i2c.h | 187d885aa64a45ef736e9255bc461aa666bb8d84 | [] | no_license | FlightBoomer/HT_Hawk | 00a1bba3f6a0af0608c72832de88ad532fdd63d1 | 7dde5deaf1fac7eb257345b4d89a6fbc3324df6b | refs/heads/master | 2020-03-08T09:08:33.883181 | 2018-04-04T09:25:21 | 2018-04-04T09:25:21 | 128,039,153 | 2 | 3 | null | null | null | null | UTF-8 | C | false | false | 469 | h |
#pragma once
#include "stm32f10x.h"
#include "usb_type.h"
#include <stdint.h>
#include <ctype.h>
typedef enum I2CDevice {
I2CDEV_1,
I2CDEV_2,
I2CDEV_MAX = I2CDEV_2,
} I2CDevice;
void i2cInit(I2CDevice index);
bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data);
bool i2cWrite(uint8_t addr_, uint8_t reg, uint8_t data);
bool i2cRead(uint8_t addr_, uint8_t reg, uint8_t len, uint8_t *buf);
uint16_t i2cGetErrorCounter(void);
| [
"529388771@qq.com"
] | 529388771@qq.com |
61b6d4428b191c8905e9a28c54cdeb05ad6c5798 | 71e5f96a29f5d643ab888b37677d38c33f8d765d | /d/common/obj/lrweapon/cannon.c | bac8e2042c446d66b366ecc69fe8eb310fb661c3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | Cherno-SuS/SunderingShadows | 5f755fbebb79dc0b9d1c2a0541408be4afeb8b67 | c3b4370beb2c4351ecc60826850c94892a42b685 | refs/heads/main | 2023-04-21T09:52:14.580024 | 2021-03-23T12:09:55 | 2021-03-23T12:09:55 | 349,490,686 | 0 | 0 | NOASSERTION | 2021-03-23T12:09:56 | 2021-03-19T16:40:12 | null | UTF-8 | C | false | false | 540 | c | #include <std.h>
inherit FIREARM;
create()
{
::create();
set_id(({ "cannon", "gun" }));
set_name("cannon");
set_short("A cannon");
set_long("This is an artillery cannon. Someone really big decided to use it as a handgun.");
set_ammo("cannonball");
set_two_handed();
set_weight(40);
set_size(4);
set_range(4, 8, 12);
set_wc(2, 14);
set_large_wc(2, 14);
set_critical_hit_multiplier(6);
set_value(4000);
set_weapon_speed(1);
set_property("repairtype", ({ "weaponsmith" }));
}
| [
"law@shadowgate.org"
] | law@shadowgate.org |
bedd6aeea048dfacb97f82e8f3842c12b9cd35bf | c5b02d3b0888c5b7bfd849afdc87f6f57181c8f0 | /mudlib/cmds/adm/_reinc.c | c508e660303464fb15531af6cb8f861c4aa3f112 | [] | no_license | jpeckham/DarkeLIB | 8a311164f460cf2acd9e0fc7e1e1e69710f31b80 | 87c020b4974981879aa68f5d19b0dc2e96d2fe7d | refs/heads/master | 2021-09-11T08:55:34.673296 | 2021-09-05T04:58:33 | 2021-09-05T04:58:33 | 141,068,816 | 2 | 5 | null | 2021-09-05T03:06:16 | 2018-07-16T00:39:43 | C | UTF-8 | C | false | false | 3,097 | c | // Command for reincarnating players...useful for re-openings, etc.
// Allows players to advance levels whenever they want, so they don't
// get waxed by fast development costs!
//
// DarkeLIB 1.0
// -Diewarzau 1/15/96
#include <std.h>
#include <daemons.h>
#include <security.h>
int cmd_reinc(string str) {
object who, join_room, *inv;
int lev, i;
string *langs;
if(!archp(this_player()))return 0;
if(!member_group((string)this_player()->query_name(), "superuser"))
return notify_fail("Only superusers may do this.\n");
if(!(who = find_player(lower_case(str)))) {
write("Can't find '"+str+"'.");
return 1;
}
if(wizardp(who)) {
write("You can't reincarnate a wizard.");
return 1;
}
who->remove_property("luck");
who->remove_property("limb regen");
who->remove_property("ambidextry");
who->remove_property("flying");
who->remove_property("natural ac");
who->remove_property("extra hbeat");
who->remove_property("extra hp regen");
who->remove_property("extra mp regen");
who->remove_property("sp points");
who->remove_property("sp skills");
who->remove_property("sp spells");
who->reset_quests();
langs = (string *)who->query_all_languages();
if(langs && pointerp(langs) && (i=sizeof(langs))) {
while(i--) who->remove_language(langs[i]);
}
inv = filter_array(all_inventory(who), (: call_other :),
"query_auto_load");
if(inv && sizeof(inv)) {
i = sizeof(inv);
while(i--)
if(!inv[i]->id("clan symbol")) inv[i]->remove();
}
who->init_skills();
who->set_property("reincarnate", 1);
who->init_spells();
if(who->query_class() && (string)who->query_class() != "child") {
join_room = find_object_or_load("/d/damned/guilds/join_rooms/"+
(string)who->query_class() + "_join");
join_room->kick_member((string)who->query_name());
}
who->set_property("xp mod", 0);
lev = (int)who->query_level();
if(lev < 1) lev = 1;
who->set_property("old exp", (int)ADVANCE_D->get_exp(lev) + 150);
who->set_level(1);
who->add_exp(-1 * (int)who->query_exp());
who->reset_max_exp();
who->move_player("/d/standard/setter", 0);
seteuid(UID_LOG);
log_file("reinc", sprintf("FREE reinc: %s to %s on %s.\n",
(string)previous_object()->query_name(), (string)who->query_name(), ctime(time())));
message("info", "%^CYAN%^%^BOLD%^You have been reincarnated!",who);
message("info",
"\n You may re-create your character now. Afterward, you may "
"join a guild as usual. All of your former exp has been transferred "
"into a 'exp bank,' and you may access it by typing 'advance'. That "
"will advance your level by 1 each time you type it, until you "
"are out of exp. If you advance your level naturally, you will "
"forfeit ALL REMAINING EXP in the bank!", who);
write((string)who->query_cap_name() + " has been reincarnated.");
return 1;
}
int help() {
write(
"Usage: reinc 'player'\n"
"Starts a player over with NO penality.");
return 1;
}
| [
"jdpeckham@gmail.com"
] | jdpeckham@gmail.com |
9b9b5462cb21f425cae3750a6a85651f025e86dd | 903436d43116301726eef46f6991f48cee98bf9a | /Inc/dma.h | bf2d67ad407d1f32bff622c1dfc2a2f4f783f70d | [] | no_license | Moryu-Io/FMSKF_USBtoUartRepeater | c3bf0961bf1a564cc5130b2322f80d19705484c0 | 0ffd36669d9d6a1b06712a1b4fd5f0b78deaa1c4 | refs/heads/master | 2020-07-02T16:52:38.555129 | 2020-03-02T14:11:42 | 2020-03-02T14:11:42 | 201,595,443 | 1 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,729 | h | /**
******************************************************************************
* File Name : dma.h
* Description : This file contains all the function prototypes for
* the dma.c file
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __dma_H
#define __dma_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* DMA memory to memory transfer handles -------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_DMA_Init(void);
/* USER CODE BEGIN Prototypes */
extern uint8_t u8_DMA1CH2_isRunning;
extern uint8_t u8_DMA1CH3_isRunning;
extern uint8_t u8_DMA1CH4_isRunning;
extern uint8_t u8_DMA1CH5_isRunning;
extern uint8_t u8_DMA1CH6_isRunning;
extern uint8_t u8_DMA1CH7_isRunning;
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __dma_H */
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
| [
"moryu999@gmail.com"
] | moryu999@gmail.com |
f8f441f0c5729d255a221889960dbc4465f03aaa | d0c44dd3da2ef8c0ff835982a437946cbf4d2940 | /cmake-build-debug/programs_tiling/function13730/function13730_schedule_11/function13730_schedule_11_wrapper.h | 7da86cfdcbf7bc30fa18967ce46116930f6dd0bc | [] | no_license | IsraMekki/tiramisu_code_generator | 8b3f1d63cff62ba9f5242c019058d5a3119184a3 | 5a259d8e244af452e5301126683fa4320c2047a3 | refs/heads/master | 2020-04-29T17:27:57.987172 | 2019-04-23T16:50:32 | 2019-04-23T16:50:32 | 176,297,755 | 1 | 2 | null | null | null | null | UTF-8 | C | false | false | 426 | h | #ifndef HALIDE__generated_function13730_schedule_11_h
#define HALIDE__generated_function13730_schedule_11_h
#include <tiramisu/utils.h>
#ifdef __cplusplus
extern "C" {
#endif
int function13730_schedule_11(halide_buffer_t *buf00, halide_buffer_t *buf01, halide_buffer_t *buf02, halide_buffer_t *buf03, halide_buffer_t *buf04, halide_buffer_t *buf05, halide_buffer_t *buf0);
#ifdef __cplusplus
} // extern "C"
#endif
#endif | [
"ei_mekki@esi.dz"
] | ei_mekki@esi.dz |
c53c4354b2806327802d88978df7734ca5193165 | 668ced8923f99530a7311e039e55d1a10c9fe8c5 | /code/source/ti/ti154stack/low_level/cc13xx/mac_rx.h | a66c9f1ed92e7adf3840df4c30fa8a32fd076436 | [] | no_license | shivam3108/project_sourcecode | db41cefa17c71d33a5e8b933bdb97e954f79f109 | 19f09b2dbcea851311c7e1588e8b6f7f1c2fdb15 | refs/heads/master | 2020-03-18T05:54:06.849680 | 2018-05-22T06:00:56 | 2018-05-22T06:00:56 | 134,366,991 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 5,321 | h | /******************************************************************************
@file mac_rx.h
@brief Describe the purpose and contents of the file.
Group: WCS, LPC
Target Device: CC13xx
******************************************************************************
Copyright (c) 2006-2018, Texas Instruments Incorporated
All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
******************************************************************************
Release Name: simplelink_cc13x0_sdk_2_10_00_
Release Date: 2018-04-09 00:04:22
*****************************************************************************/
#ifndef MAC_RX_H
#define MAC_RX_H
/* ------------------------------------------------------------------------------------------------
* Includes
* ------------------------------------------------------------------------------------------------
*/
#include "hal_types.h"
#include "rf_data_entry.h"
#include "mac_high_level.h"
/* ------------------------------------------------------------------------------------------------
* Defines
* ------------------------------------------------------------------------------------------------
*/
#define RX_FILTER_OFF 0
#define RX_FILTER_ALL 1
#define RX_FILTER_NON_BEACON_FRAMES 2
#define RX_FILTER_NON_COMMAND_FRAMES 3
/* bit value used to form values of macRxActive */
#define MAC_RX_ACTIVE_PHYSICAL_BV 0x80
#define MAC_RX_ACTIVE_NO_ACTIVITY 0x00 /* zero reserved for boolean use, e.g. !macRxActive */
#define MAC_RX_ACTIVE_STARTED (0x01 | MAC_RX_ACTIVE_PHYSICAL_BV)
#define MAC_RX_ACTIVE_DONE 0x02
/* RX PACKET status */
#define MAC_RX_PKT_STATUS_OK 0x00
#define MAC_RX_PKT_STATUS_DISCARD 0x01
#define MAC_RX_PKT_STATUS_CLEANUP 0x02
#define MAC_RX_PKT_STATUS_CRC_BAD 0x03
#define MAC_RX_PKT_STATUS_OTHER 0x04
/* ------------------------------------------------------------------------------------------------
* Macros
* ------------------------------------------------------------------------------------------------
*/
#define MAC_RX_IS_PHYSICALLY_ACTIVE() ((macRxActive & MAC_RX_ACTIVE_PHYSICAL_BV) || macRxOutgoingAckFlag)
#define MAC_RX_IEEE_IS_PHYSICALLY_ACTIVE() (macRxActive & MAC_RX_ACTIVE_PHYSICAL_BV)
/* ------------------------------------------------------------------------------------------------
* Global Variable Externs
* ------------------------------------------------------------------------------------------------
*/
extern volatile uint8 macRxActive;
extern uint8 macRxFilter;
extern volatile uint8 macRxOutgoingAckFlag;
extern dataQueue_t macRxDataEntryQueue;
/* ------------------------------------------------------------------------------------------------
* Prototypes
* ------------------------------------------------------------------------------------------------
*/
MAC_INTERNAL_API void macRxInit(void);
MAC_INTERNAL_API void macRxRadioPowerUpInit(void);
MAC_INTERNAL_API void macRxHaltCleanup(void);
MAC_INTERNAL_API void macRxFifoOverflowIsr(void);
MAC_INTERNAL_API void macRxAckTxDoneCallback(void);
extern void macRxFrameIsr(void);
extern void macRxNokIsr(void);
/**************************************************************************************************
*/
#endif
| [
"shivamkapil753@gmail.com"
] | shivamkapil753@gmail.com |
90908c7100ce4ae5b2aa3f7c33c47d61ca2b5d77 | 5d7dfa1dc6f8014e6f00d4c014aa8da1afd520ed | /src/Tests_1/socket.h | 96d6dddb77ed7ee6438b149c9eb0a359fbb36768 | [] | no_license | hrace009/TERA-Server-v15xx | 5371701e6274047c24813733009022818c618fd7 | 23999d2561f2f7ae298a72abeffc17a5a87ba0a7 | refs/heads/master | 2021-04-29T09:50:14.866698 | 2016-12-02T11:55:43 | 2016-12-02T11:55:43 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 223 | h | #ifndef SOCK_INCLUDE_H
#define SOCK_INCLUDE_H
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN
#pragma comment(lib, "ws2_32.lib")
#include <WinSock2.h>
#include <Windows.h>
#endif // !SOCK_INCLUDE_H
| [
"Narcis@NARCIS-PC"
] | Narcis@NARCIS-PC |
06503f6b1a8052400d7d54196713a1e4afb7bf18 | 808458596d5ce56bd70f4496cd0bf496d819ddfa | /src/xenia/gpu/d3d12/shaders/dxbc/texture_load_depth_unorm_cs.h | f77c33cbcca828143ea69d0c143ec3cd500e1141 | [] | no_license | NeoSlyde/xenia1080p | 973b01cdcac16884244dc8b07aaa63ca4b8c2064 | 832b6d61bbc91a5e9a76a37c7f9d8ff9c74b68cc | refs/heads/master | 2020-03-30T05:14:16.857273 | 2018-09-28T20:07:39 | 2018-09-28T20:07:39 | 150,788,583 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 40,460 | h | // generated from `xb buildhlsl`
// source: texture_load_depth_unorm.cs.hlsl
const uint8_t texture_load_depth_unorm_cs[] = {
0x44, 0x58, 0x42, 0x43, 0xAE, 0x52, 0xFE, 0xF6, 0x2A, 0x15, 0x3D, 0xD8,
0xFA, 0x96, 0x9A, 0x21, 0xA8, 0x3B, 0x15, 0xFE, 0x01, 0x00, 0x00, 0x00,
0xE0, 0x18, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x9C, 0x04, 0x00, 0x00, 0xAC, 0x04, 0x00, 0x00, 0xBC, 0x04, 0x00, 0x00,
0x44, 0x18, 0x00, 0x00, 0x52, 0x44, 0x45, 0x46, 0x60, 0x04, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x3C, 0x00, 0x00, 0x00, 0x01, 0x05, 0x53, 0x43, 0x00, 0x05, 0x00, 0x00,
0x35, 0x04, 0x00, 0x00, 0x13, 0x13, 0x44, 0x25, 0x3C, 0x00, 0x00, 0x00,
0x18, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x24, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xB4, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xCB, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x78, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63,
0x6F, 0x70, 0x79, 0x5F, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x00, 0x78,
0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63, 0x6F,
0x70, 0x79, 0x5F, 0x64, 0x65, 0x73, 0x74, 0x00, 0x58, 0x65, 0x54, 0x65,
0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x6F, 0x70, 0x79, 0x43, 0x6F, 0x6E,
0x73, 0x74, 0x61, 0x6E, 0x74, 0x73, 0x00, 0xAB, 0xE0, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0xC4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xE8, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0xC4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xC4, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x03, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0xC4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x39, 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x9C, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x5C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xDC, 0x03, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0xC4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0xF7, 0x03, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x5C, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x18, 0x04, 0x00, 0x00,
0x3C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xC4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x78, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63,
0x6F, 0x70, 0x79, 0x5F, 0x67, 0x75, 0x65, 0x73, 0x74, 0x5F, 0x62, 0x61,
0x73, 0x65, 0x00, 0x64, 0x77, 0x6F, 0x72, 0x64, 0x00, 0xAB, 0xAB, 0xAB,
0x00, 0x00, 0x13, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBB, 0x02, 0x00, 0x00,
0x78, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63,
0x6F, 0x70, 0x79, 0x5F, 0x67, 0x75, 0x65, 0x73, 0x74, 0x5F, 0x70, 0x69,
0x74, 0x63, 0x68, 0x00, 0x78, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75,
0x72, 0x65, 0x5F, 0x63, 0x6F, 0x70, 0x79, 0x5F, 0x68, 0x6F, 0x73, 0x74,
0x5F, 0x62, 0x61, 0x73, 0x65, 0x00, 0x78, 0x65, 0x5F, 0x74, 0x65, 0x78,
0x74, 0x75, 0x72, 0x65, 0x5F, 0x63, 0x6F, 0x70, 0x79, 0x5F, 0x68, 0x6F,
0x73, 0x74, 0x5F, 0x70, 0x69, 0x74, 0x63, 0x68, 0x00, 0x78, 0x65, 0x5F,
0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63, 0x6F, 0x70, 0x79,
0x5F, 0x73, 0x69, 0x7A, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x65, 0x6C, 0x73,
0x00, 0x75, 0x69, 0x6E, 0x74, 0x33, 0x00, 0xAB, 0x01, 0x00, 0x13, 0x00,
0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x55, 0x03, 0x00, 0x00, 0x78, 0x65, 0x5F, 0x74,
0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63, 0x6F, 0x70, 0x79, 0x5F,
0x69, 0x73, 0x5F, 0x33, 0x64, 0x00, 0x62, 0x6F, 0x6F, 0x6C, 0x00, 0xAB,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x03, 0x00, 0x00,
0x78, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63,
0x6F, 0x70, 0x79, 0x5F, 0x73, 0x69, 0x7A, 0x65, 0x5F, 0x62, 0x6C, 0x6F,
0x63, 0x6B, 0x73, 0x00, 0x78, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75,
0x72, 0x65, 0x5F, 0x63, 0x6F, 0x70, 0x79, 0x5F, 0x65, 0x6E, 0x64, 0x69,
0x61, 0x6E, 0x6E, 0x65, 0x73, 0x73, 0x00, 0x78, 0x65, 0x5F, 0x74, 0x65,
0x78, 0x74, 0x75, 0x72, 0x65, 0x5F, 0x63, 0x6F, 0x70, 0x79, 0x5F, 0x67,
0x75, 0x65, 0x73, 0x74, 0x5F, 0x6D, 0x69, 0x70, 0x5F, 0x6F, 0x66, 0x66,
0x73, 0x65, 0x74, 0x00, 0x78, 0x65, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x75,
0x72, 0x65, 0x5F, 0x63, 0x6F, 0x70, 0x79, 0x5F, 0x67, 0x75, 0x65, 0x73,
0x74, 0x5F, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x00, 0x4D, 0x69, 0x63,
0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48,
0x4C, 0x53, 0x4C, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43,
0x6F, 0x6D, 0x70, 0x69, 0x6C, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2E, 0x31,
0x00, 0xAB, 0xAB, 0xAB, 0x49, 0x53, 0x47, 0x4E, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4F, 0x53, 0x47, 0x4E,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x53, 0x48, 0x45, 0x58, 0x80, 0x13, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00,
0xE0, 0x04, 0x00, 0x00, 0x6A, 0x08, 0x00, 0x01, 0x59, 0x00, 0x00, 0x07,
0x46, 0x8E, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA1, 0x00, 0x00, 0x06, 0x46, 0x7E, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9D, 0x00, 0x00, 0x06, 0x46, 0xEE, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5F, 0x00, 0x00, 0x02, 0x72, 0x00, 0x02, 0x00, 0x68, 0x00, 0x00, 0x02,
0x09, 0x00, 0x00, 0x00, 0x9B, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x06,
0x12, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x02, 0x00,
0x01, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x04,
0x62, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x06, 0x02, 0x00,
0x50, 0x00, 0x00, 0x09, 0x72, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x46, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x82, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x3C, 0x00, 0x00, 0x07, 0x82, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1A, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x07, 0x82, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x3A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x04, 0x03,
0x3A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x01,
0x15, 0x00, 0x00, 0x01, 0x1E, 0x00, 0x00, 0x09, 0xE2, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x06, 0x89, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x09, 0x12, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x1A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x04, 0x03, 0x0A, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x04, 0x05, 0x3A, 0x80, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x1E, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x56, 0x05, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x0C, 0x32, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x16, 0x85, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x1F, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x0A, 0x72, 0x00, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0xB6, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x0A,
0x32, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
0xFE, 0xFF, 0xFF, 0x0F, 0x23, 0x00, 0x00, 0x09, 0x12, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x07, 0x42, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x0B,
0x82, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x2A, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x07,
0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0xF6, 0x0F, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x14, 0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA6, 0x0A, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x07, 0x42, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x40, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07,
0x42, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0xA6, 0x0A, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x0A,
0xF2, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x55, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x09, 0xF2, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x56, 0x05, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
0x70, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x14,
0xF2, 0x00, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x0C, 0xF2, 0x00, 0x10, 0x00,
0x05, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x05, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00,
0x05, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0xF6, 0x0F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0xA6, 0x0A, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x05, 0x00, 0x00, 0x00, 0x8A, 0x00, 0x00, 0x0F, 0xF2, 0x00, 0x10, 0x00,
0x05, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x07, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x14,
0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x0C, 0xF2, 0x00, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x0C, 0xF2, 0x00, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x14, 0xF2, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00,
0x0D, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x23, 0x00, 0x00, 0x0C, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00,
0x0B, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00,
0xF6, 0x0F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0xA6, 0x0A, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x01, 0x1E, 0x00, 0x00, 0x0A,
0xF2, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x56, 0x05, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x55, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x0A, 0x32, 0x00, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0xA6, 0x0A, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x09,
0x42, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0A, 0x80, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x01, 0x40, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x07,
0x42, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0x23, 0x00, 0x00, 0x09, 0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x06, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0xA6, 0x0A, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x29, 0x00, 0x00, 0x0A, 0x52, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0xA6, 0x0A, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0A, 0x52, 0x00, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x06, 0x02, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x01, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x06, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00,
0xE0, 0x01, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x17, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
0x17, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x06, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00,
0x07, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x05, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0xA6, 0x0A, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x0A,
0xF2, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x06, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
0x17, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x08, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00,
0x08, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0xA6, 0x0A, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xA6, 0x0A, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x0A,
0xF2, 0x00, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x06, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
0x17, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x0B, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00,
0x0B, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xA6, 0x0A, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x07, 0xF2, 0x00, 0x10, 0x00,
0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x0A,
0xF2, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
0x1A, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x07, 0xF2, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x06, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x14,
0xF2, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x07, 0xF2, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11,
0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x01, 0x12, 0x00, 0x00, 0x01,
0x29, 0x00, 0x00, 0x07, 0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x09, 0x12, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x1A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
0x1F, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x01, 0x40, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x23, 0x00, 0x00, 0x09,
0x42, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x2A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x0B,
0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x56, 0x05, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x01,
0x1E, 0x00, 0x00, 0x09, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x80, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA5, 0x00, 0x00, 0x08, 0x12, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x70, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00, 0x08,
0x22, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x06, 0x70, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00, 0x08, 0x42, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x06, 0x70, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA5, 0x00, 0x00, 0x08, 0x82, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x3A, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x70, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x09,
0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x80, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x01, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x09,
0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07,
0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x1F, 0x00, 0x04, 0x03, 0x1A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x29, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x55, 0x00, 0x00, 0x0A,
0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0x1E, 0x00, 0x00, 0x07, 0xF2, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x01,
0x01, 0x00, 0x00, 0x09, 0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x1F, 0x00, 0x04, 0x03, 0x1A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x55, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x11, 0xF2, 0x00, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x02, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x15, 0x00, 0x00, 0x01, 0x29, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x09,
0x22, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x02, 0x00,
0x1A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x02, 0x00, 0x23, 0x00, 0x00, 0x0B,
0x12, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x09, 0x12, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x2A, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x05,
0xF2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x0A, 0xF2, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x40, 0x00, 0x00, 0x01, 0x00, 0x80, 0x33, 0x01, 0x00, 0x80, 0x33,
0x01, 0x00, 0x80, 0x33, 0x01, 0x00, 0x80, 0x33, 0xA6, 0x00, 0x00, 0x08,
0xF2, 0xE0, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0E, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x01, 0x53, 0x54, 0x41, 0x54,
0x94, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x24, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};
| [
"neoslydeyt@gmail.com"
] | neoslydeyt@gmail.com |
26aa0261584bf678c0c4d944d9af166763b445b5 | fecb8eaa6f1ccc774e12b51bead27b69e3c64c35 | /chrome/20164051/coin.c | 94cf3f4dc809c79b4bf05559184f12207c3c8387 | [] | no_license | SSVineet/Alogrithms-program-in-c- | 4c766004c1b4528beb1f4aa999fe61dfd575f8bd | 81e34f07b7c60376454d2a44d8c99e2d16d991df | refs/heads/master | 2020-04-19T00:55:03.141436 | 2019-01-27T21:18:33 | 2019-01-27T21:18:33 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 723 | c | #include <stdio.h>
#include <stdlib.h>
int coinChange(int arr[],int n,int amt){
int i,take,notTake,j,v[amt+1][n];
for(i=0;i<n;i++){
v[0][i]=1;
}
for(i=1;i<=amt;i++){
for(j=0;j<n;j++){
//not take
if(j>=1)
notTake=v[i][j-1];
else
notTake=0;
//take
if(i-arr[j]>=0)
take=v[i-arr[j]][j];
else
take=0;
v[i][j]=take+notTake;
}
}
return v[amt][n-1];
}
int main(){
int n,i,amt;
printf("enter amount whose change we want\n");
scanf("%d",&amt);
printf("enter types of coins\n");
scanf("%d",&n);
int arr[n];
printf("enter coin values\n");
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
printf("number of ways that we can get a change is %d\n",coinChange(arr,n,amt));
return 0;
}
| [
"noreply@github.com"
] | SSVineet.noreply@github.com |
320827169472e7728cab11285ef9cef8620f2fb0 | 761a3201ed564b3a08abc494a2681f073c89f1c4 | /nemu/include/cpu/instr/io.h | f2ce1617d02674c05045ee87bae1a50a61c1c8bf | [] | no_license | Hantx-NJU/PA | 5b36d8fe6fde7fc6485890a4cfaa04777d57a681 | 7592b85ec1409cc9d59fa4c107ad4b668479183f | refs/heads/master | 2021-04-12T17:03:31.267563 | 2020-03-25T14:42:36 | 2020-03-25T14:42:36 | 249,094,293 | 2 | 1 | null | null | null | null | UTF-8 | C | false | false | 148 | h | #ifndef __INSTR_IO_H__
#define __INSTR_IO_H__
make_instr_func(in_b);
make_instr_func(in_v);
make_instr_func(out_b);
make_instr_func(out_v);
#endif | [
"181860027@smail.nju.edu.cn"
] | 181860027@smail.nju.edu.cn |
c8e45e986f8ca63ec1a1e5db322eae5e441929e5 | d0c44dd3da2ef8c0ff835982a437946cbf4d2940 | /cmake-build-debug/programs_tiling/function14464/function14464_schedule_10/function14464_schedule_10_wrapper.h | 9417912acfc1e64ac083f014590d76a7e3da2107 | [] | no_license | IsraMekki/tiramisu_code_generator | 8b3f1d63cff62ba9f5242c019058d5a3119184a3 | 5a259d8e244af452e5301126683fa4320c2047a3 | refs/heads/master | 2020-04-29T17:27:57.987172 | 2019-04-23T16:50:32 | 2019-04-23T16:50:32 | 176,297,755 | 1 | 2 | null | null | null | null | UTF-8 | C | false | false | 402 | h | #ifndef HALIDE__generated_function14464_schedule_10_h
#define HALIDE__generated_function14464_schedule_10_h
#include <tiramisu/utils.h>
#ifdef __cplusplus
extern "C" {
#endif
int function14464_schedule_10(halide_buffer_t *buf00, halide_buffer_t *buf01, halide_buffer_t *buf02, halide_buffer_t *buf03, halide_buffer_t *buf04, halide_buffer_t *buf0);
#ifdef __cplusplus
} // extern "C"
#endif
#endif | [
"ei_mekki@esi.dz"
] | ei_mekki@esi.dz |
660771ca7a7b2a03c845d078899020388a74daf1 | 6451521aff7056b83db5864cb0027eb67c125599 | /viewer/wavelet_ssim.h | b31262481f1e2ed8998107902807e1e4fe5b9af8 | [] | no_license | tgamblin/libra | 0d740484f23542a017b07b7b86f51566c34ad4e5 | 2acedbe2f8a487a13b01c3d0e7cb2573e1ca6d09 | refs/heads/master | 2020-12-24T16:31:54.327600 | 2013-11-03T00:55:50 | 2013-11-03T01:04:44 | 763,175 | 3 | 2 | null | 2016-05-23T17:59:36 | 2010-07-08T03:21:51 | C++ | UTF-8 | C | false | false | 4,663 | h | /////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2010, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory
// Written by Todd Gamblin, tgamblin@llnl.gov.
// LLNL-CODE-417602
// All rights reserved.
//
// This file is part of Libra. For details, see http://github.com/tgamblin/libra.
// Please also read the LICENSE file for further information.
//
// 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 disclaimer below.
// * Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the disclaimer (as noted below) in the documentation and/or other materials
// provided with the distribution.
// * Neither the name of the LLNS/LLNL 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
// LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY 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 WAVELET_SSIM_H
#define WAVELET_SSIM_H
#include <stdint.h>
#include "wavelet.h"
/// Default box size, taken from Zhou/Simoncelli 2005.
#define WSSIM_DEFAULT_BOX_SIZE 7
///
/// Wavelet Structural Similarity measure (W-SSIM), modified from complex
/// version by Zhou/Simoncelli 2005. Instead of a complex-valued steerable
/// pyramid representation, this version expects a standard real-valued quad-tree
/// wavelet-transformed matrix. Similarity measure is performed across
/// each of the subbands and averaged, with each subband's similarity measure
/// weighted evenly (though different subbands do have different sizes).
///
/// Params:
/// m1 First matrix of wavelet coefficients to compare using W-SSIM
/// m2 Second matrix of wavelet coefficients to compare using W-SSIM
/// input_level Level of wavelet transform applied to the input data.
/// sim_level_mask Bitmask of levels (subbands) to check for similarity.
/// Defaults to all levels.
/// box_size Size of sliding box window to use for CW-SSIM.
/// Default is WSSIM_DEFAULT_BOX_SIZE.
///
/// More on the level mask:
/// sim_level_mask is a bit mask indicating which levels of the transformed
/// data should be compared for similarity. Each subband's mean W-SSIM value
/// is weighted evenly in the calculation of the overall result. For example,
/// if m1 and m2 are 2-level matrices of wavelet coefficients with levels as
/// such:
///
/// +---+---+-------+ Then a bitmask of 0x7 will apply W-SSIM to all 3
/// | 0 | 1 | | subbands and return the mean of the resulting values.
/// +---+---+ 2 | This is the default behavior. A bitmask of 0x3 will
/// | 1 | 1 | | transform only levels 0 and 1, 0x1 will tranform only
/// +---+---+-------+ level 0, 0x5 will transform levels 2 and 0, and so on.
/// | | |
/// | 2 | 2 | Note that if a particular subband's quadrants are
/// | | | smaller than box_size, then its will not be factored
/// +-------+-------+ into the final weighted average. This may cause wssim
/// to return NaN if the input matrices are too small.
///
/// Also note that the default sim_level_mask value of zero will calculate
/// W-SSIM over ALL subbands (not none of them).
///
double wssim(wavelet::wt_matrix& m1, wavelet::wt_matrix& m2,
int input_level = -1, size_t sim_level_mask=0,
size_t box_size = WSSIM_DEFAULT_BOX_SIZE);
#endif //WAVELET_SSIM_H
| [
"tgamblin@llnl.gov"
] | tgamblin@llnl.gov |
05164d101f4a206789f5dab29d3ec05aee1667f7 | 8d753bb8f19b5b1f526b0688d3cb199b396ed843 | /osp_sai_2.1.8/system/sdk/tsingma/dkits/common/tsingma/ctc_tm_dkit_serdes.c | 3dbacf435e3a12eedff9c1db897d8d9d982afb69 | [] | no_license | bonald/vim_cfg | f166e5ff650db9fa40b564d05dc5103552184db8 | 2fee6115caec25fd040188dda0cb922bfca1a55f | refs/heads/master | 2023-01-23T05:33:00.416311 | 2020-11-19T02:09:18 | 2020-11-19T02:09:18 | null | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 176,212 | c | #include "sal.h"
#include "ctc_cli.h"
#include "usw/include/drv_enum.h"
#include "drv_api.h"
#include "usw/include/drv_common.h"
#include "usw/include/drv_chip_ctrl.h"
#include "ctc_dkit.h"
#include "ctc_dkit_common.h"
#include "ctc_usw_dkit_misc.h"
#include "ctc_usw_dkit.h"
#include "ctc_usw_dkit_dump_cfg.h"
#define DKIT_SERDES_ID_MAX 32
#define TAP_MAX_VALUE 64
#define PATTERN_NUM 12
#define DKITS_SERDES_ID_CHECK(ID) \
do { \
if(ID >= DKIT_SERDES_ID_MAX) \
{\
CTC_DKIT_PRINT("serdes id %d exceed max id %d!!!\n", ID, DKIT_SERDES_ID_MAX-1);\
return DKIT_E_INVALID_PARAM; \
}\
} while (0)
static uint32 g_tm_common_28g_address[6] = {0xE9,0xEB,0xED,0xF3,0xFA,0xFC};
static uint32 g_tm_link_28g_address[4] = {0x01,0x02,0x03,0x05};
/* 0x8zXX */
static uint32 g_tm_control_28g_address[77] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0b,0x0c,0x0d,0x14,0x15,0x16,0x2a,0x2b,
0x2c,0x2e,0x3b,0x4d,0x4e,0x4f,0x50,0x5d,0x5e,0x60,0x61,0x62,0x63,0x64,0x65,
0x66,0x67,0x6e,0x6f,0x71,0x72,0x73,0x75,0x76,0x77,0x78,0x79,0x7a,0x7f,0x80,
0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x8b,0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,
0xa6,0xa7,0xa8,0xe6,0xf3,0xf4,0xf5,0xf7,0xf8,0xfa,0xfb,0xfd,0xfe,0xff};
static uint8 g_tm_serdes_poly_tx[24] = {0};
static uint8 g_tm_serdes_poly_rx[24] = {0};
extern ctc_dkit_master_t* g_usw_dkit_master[CTC_DKITS_MAX_LOCAL_CHIP_NUM];
STATIC int32
_ctc_tm_dkit_misc_serdes_12g_eye(ctc_dkit_serdes_wr_t* p_ctc_dkit_serdes_para, ctc_dkit_serdes_ctl_para_t* p_serdes_para,
uint8 height_flag, uint8 center_flag, uint32 times, uint32* p_rslt_sum);
STATIC int32
_ctc_tm_dkit_misc_serdes_28g_eye(ctc_dkit_serdes_wr_t* p_ctc_dkit_serdes_para, ctc_dkit_serdes_ctl_para_t* p_serdes_para,
uint32 times, uint32* p_rslt_sum);
int32
_ctc_tm_dkit_misc_serdes_dfe_get_val(ctc_dkit_serdes_ctl_para_t* p_serdes_para);
STATIC int32
_ctc_tm_dkit_internal_convert_serdes_addr(ctc_dkit_serdes_wr_t* p_para, uint32* addr, uint8* hss_id)
{
uint8 lane_id = 0;
uint8 is_hss15g = 0;
uint8 lchip = 0;
DKITS_PTR_VALID_CHECK(p_para);
DKITS_PTR_VALID_CHECK(addr);
DKITS_PTR_VALID_CHECK(hss_id);
lchip = p_para->lchip;
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(p_para->serdes_id);
if (is_hss15g)
{
lane_id = p_para->serdes_id%8;
}
else
{
lane_id = p_para->serdes_id%4;
}
*hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(p_para->serdes_id);
if(CTC_DKIT_SERDES_LINK_TRAINING == p_para->type && !is_hss15g)
{
*addr = 0x6000 + lane_id*0x100;
}
else if(CTC_DKIT_SERDES_ALL == p_para->type && !is_hss15g)
{
*addr = 0x8000 + lane_id*0x100;
}
else if(CTC_DKIT_SERDES_COMMON_PLL == p_para->type && !is_hss15g)
{
*addr = 0x8400;
}
else if (CTC_DKIT_SERDES_COMMON_PLL == p_para->type && is_hss15g)
{
*addr = p_para->sub_type*0x100;
}
else if (CTC_DKIT_SERDES_BIST == p_para->type)
{
*addr = 0x9800;
}
else if (CTC_DKIT_SERDES_FW == p_para->type)
{
*addr = 0x9f00;
}
else if (CTC_DKIT_SERDES_ALL == p_para->type&& is_hss15g)
{
*addr = (lane_id+3)*0x100;
}
*addr = *addr + p_para->addr_offset;
CTC_DKIT_PRINT_DEBUG("hssid:%d, lane:%d\n", *hss_id, lane_id);
return CLI_SUCCESS;
}
int32
ctc_tm_dkit_misc_read_serdes(void* para)
{
uint32 addr = 0;
uint8 is_hss15g = 0;
uint8 hss_id = 0;
ctc_dkit_serdes_wr_t* p_para = (ctc_dkit_serdes_wr_t*)para;
uint8 lchip = 0;
DKITS_PTR_VALID_CHECK(p_para);
DKITS_SERDES_ID_CHECK(p_para->serdes_id);
CTC_DKIT_LCHIP_CHECK(p_para->lchip);
lchip = p_para->lchip;
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(p_para->serdes_id);
_ctc_tm_dkit_internal_convert_serdes_addr(p_para, &addr, &hss_id);
if (is_hss15g)
{
drv_chip_read_hss15g(p_para->lchip, hss_id, addr, &p_para->data);
}
else
{
drv_chip_read_hss28g(p_para->lchip, hss_id, addr, &p_para->data);
}
CTC_DKIT_PRINT_DEBUG("read chip id:%d, hss%s id:%d, addr: 0x%04x, value: 0x%04x\n", p_para->lchip, is_hss15g?"15g":"28g", hss_id, addr, p_para->data);
return CLI_SUCCESS;
}
int32
ctc_tm_dkit_misc_write_serdes(void* para)
{
uint32 addr = 0;
uint8 is_hss15g = 0;
uint8 hss_id = 0;
uint8 lchip = 0;
ctc_dkit_serdes_wr_t* p_para = (ctc_dkit_serdes_wr_t*)para;
DKITS_PTR_VALID_CHECK(p_para);
DKITS_SERDES_ID_CHECK(p_para->serdes_id);
CTC_DKIT_LCHIP_CHECK(p_para->lchip);
lchip = p_para->lchip;
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(p_para->serdes_id);
_ctc_tm_dkit_internal_convert_serdes_addr(p_para, &addr, &hss_id);
if (is_hss15g)
{
drv_chip_write_hss15g(p_para->lchip, hss_id, addr, p_para->data);
}
else
{
drv_chip_write_hss28g(p_para->lchip, hss_id, addr, p_para->data);
}
CTC_DKIT_PRINT_DEBUG("write chip id:%d, hss%s id:%d, addr: 0x%04x, value: 0x%04x\n", p_para->lchip, is_hss15g?"15g":"28g", hss_id, addr, p_para->data);
return CLI_SUCCESS;
}
STATIC int32
ctc_tm_dkit_misc_serdes_dump_bathtub_28g(uint8 lchip, uint16 serdes_id, sal_file_t p_file)
{
uint8 i = 0;
uint8 bathtub_data[95] = {0};
uint16 lane_id = 0;
uint16 fw_cmd = 0;
uint16 status = 0;
uint16 data = 0;
int16 margin = 0;
int16 m = 0;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_wr;
uint32 field_val = 0;
uint32 cmd = 0;
uint16 exp = 9;
uint32 time_cnt1 = 300;
uint32 time_cnt2 = 300;
//uint16 extent = 0;
cmd = DRV_IOR(OobFcReserved_t, OobFcReserved_reserved_f);
DRV_IOCTL(lchip, 0, cmd, &field_val);
if (1 == field_val)
{
CTC_DKIT_PRINT("%% before dump bathtub data, must close link monitor thread\n");
return CLI_ERROR;
}
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_BIST; /*0x98XX*/
lane_id = serdes_id % 4;
fw_cmd = 0x1000 | (lane_id & 0x3) | ((exp & 0xf) << 4) | (1 << 3);
ctc_dkit_serdes_wr.addr_offset = 0x15;
ctc_dkit_serdes_wr.data = fw_cmd;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
while (TRUE)
{
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
if (0 == (ctc_dkit_serdes_wr.data >> 12))
{
break;
}
CTC_DKITS_PRINT_FILE(p_file, ".");
sal_task_sleep(10);
}
status = (ctc_dkit_serdes_wr.data>>8) & 0xf;
if (0x0 == status)
{
CTC_DKITS_PRINT_FILE(p_file, "Bathtub collection started...\n");
}
else
{
return CLI_SUCCESS;
}
while (TRUE)
{
fw_cmd = 0x2000;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_BIST; /*0x98XX*/
ctc_dkit_serdes_wr.data = fw_cmd;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
while (TRUE)
{
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
if (0 == (ctc_dkit_serdes_wr.data >> 12))
{
break;
}
CTC_DKITS_PRINT_FILE(p_file, ".");
sal_task_sleep(100);
if(0 == (--time_cnt1))
{
CTC_DKIT_PRINT("%% Read data timeout!\n");
return CLI_ERROR;
}
}
status = (ctc_dkit_serdes_wr.data>>8) & 0xf;
data = ctc_dkit_serdes_wr.data & 0xff;
if ((0x1 == status) && (100 == data))
{
break;
}
CTC_DKITS_PRINT_FILE(p_file, ".");
sal_task_sleep(100);
if(0 == (--time_cnt2))
{
CTC_DKIT_PRINT("%% Data collection timeout!\n");
return CLI_ERROR;
}
}
CTC_DKITS_PRINT_FILE(p_file, "\nbathtub_data = [");
for (margin = -47; margin < 48;)
{
data = (margin&0xffff);
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_BIST; /*0x98XX*/
ctc_dkit_serdes_wr.addr_offset = 0x16;
ctc_dkit_serdes_wr.data = data;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x15;
ctc_dkit_serdes_wr.data = 0x3000;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
while (TRUE)
{
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_BIST; /*0x98XX*/
ctc_dkit_serdes_wr.addr_offset = 0x15;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
if (0 == (ctc_dkit_serdes_wr.data >> 12))
{
break;
}
sal_task_sleep(1);
}
status = (ctc_dkit_serdes_wr.data>>8) & 0xf;
data = ctc_dkit_serdes_wr.data & 0xff;
if (0x2 == status)
{
for (i = 0; i < 16; i++)
{
m = margin+i;
if (m < 48)
{
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_FW; /*0x9FXX*/
ctc_dkit_serdes_wr.addr_offset = (0x00+i);
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
bathtub_data[47+m] = ctc_dkit_serdes_wr.data;
CTC_DKITS_PRINT_FILE(p_file, "%d, ", bathtub_data[47+m]);
}
}
}
else
{
for (i = 0; i < 16; i++)
{
m = margin+i;
if (m < 48)
{
bathtub_data[47+m] = 0;
CTC_DKITS_PRINT_FILE(p_file, "%d, ", bathtub_data[47+m]);
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "\n");
margin += 16;
}
CTC_DKITS_PRINT_FILE(p_file, "]\n");
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_BIST; /*0x98XX*/
ctc_dkit_serdes_wr.addr_offset = 0x16;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " Read BIST 0x%02x: 0x%04x\n", ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
return CLI_SUCCESS;
}
STATIC int32
ctc_tm_dkit_misc_serdes_dump_isi_28g(uint8 lchip, uint16 serdes_id, sal_file_t p_file)
{
uint8 lane_id = 0;
uint16 fm1 = 0;
uint16 f1 = 0;
uint16 f2 = 0;
uint16 f3 = 0;
uint16 i = 0;
uint16 tap2[14] = {0};
int16 signed_tap2[14] = {0};
ctc_dkit_serdes_wr_t ctc_dkit_serdes_wr;
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL; /*0x8zXX*/
lane_id = serdes_id % 4;
ctc_dkit_serdes_wr.addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
f1 = ctc_dkit_serdes_wr.data & 0x7f;
ctc_dkit_serdes_wr.addr_offset = 0x2c;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
f2 = (ctc_dkit_serdes_wr.data >> 8) & 0x7f;
f3 = ctc_dkit_serdes_wr.data & 0x7f;
ctc_dkit_serdes_wr.addr_offset = 0x65;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data &= 0xffe1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
sal_task_sleep(100);
ctc_dkit_serdes_wr.addr_offset = 0x2d;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
fm1 = (ctc_dkit_serdes_wr.data >> 8) & 0x7f;
CTC_DKITS_PRINT_FILE(p_file, "get ISI value(serdes %d, lane %d): \n", serdes_id, lane_id);
for (i = 0; i < 4; i++)
{
tap2[0] = fm1;
tap2[1] = f1;
tap2[2] = f2;
tap2[3] = f3;
if (tap2[i] >= 64)
{
signed_tap2[i] = tap2[i] - 128;
}
else
{
signed_tap2[i] = tap2[i];
}
CTC_DKITS_PRINT_FILE(p_file, "%-5s%-29d: %d\n", "tap ", i, signed_tap2[i]);
}
for (i = 0; i < 10; i++)
{
ctc_dkit_serdes_wr.addr_offset = 0x65;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data &= 0xffe1;
ctc_dkit_serdes_wr.data |= ((i+1)<<1);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
sal_task_sleep(100);
ctc_dkit_serdes_wr.addr_offset = 0x2d;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
tap2[i+4] = (ctc_dkit_serdes_wr.data >> 8) & 0x7f;
if (tap2[i+4] >= 64)
{
signed_tap2[i+4] = tap2[i+4] - 128;
}
else
{
signed_tap2[i+4] = tap2[i+4];
}
CTC_DKITS_PRINT_FILE(p_file, "%-5s%-29d: %d\n", "tap ", (i+4), signed_tap2[i+4]);
}
return CLI_SUCCESS;
}
STATIC int32
ctc_tm_dkit_misc_serdes_status_15g(uint8 lchip, uint16 serdes_id, uint32 type, char* file_name)
{
ctc_dkit_serdes_wr_t ctc_dkit_serdes_wr;
sal_time_t tv;
char* p_time_str = NULL;
sal_file_t p_file = NULL;
uint8 i = 0;
uint8 j = 0;
uint32 cmd = 0;
uint8 hss_id = 0;
uint8 lane_id = 0;
uint32 tbl_id = 0;
uint32 rslt_sum = 0;
uint8 step = 0;
uint32 value = 0;
ctc_dkit_serdes_ctl_para_t serdes_para;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
Hss12GLaneRxEqCfg0_m rx_eq_cfg;
Hss12GLaneTxEqCfg0_m tx_eq_cfg;
DKITS_SERDES_ID_CHECK(serdes_id);
CTC_DKIT_LCHIP_CHECK(lchip);
if (file_name)
{
p_file = sal_fopen(file_name, "wt");
if (!p_file)
{
CTC_DKIT_PRINT("Open file %s fail!!!\n", file_name);
return CLI_SUCCESS;
}
}
/*get systime*/
sal_time(&tv);
p_time_str = sal_ctime(&tv);
CTC_DKITS_PRINT_FILE(p_file, "# Serdes %d Regs Status, %s", serdes_id, p_time_str);
if ((CTC_DKIT_SERDES_COMMON_PLL == type)||(CTC_DKIT_SERDES_ALL == type)|| (CTC_DKIT_SERDES_DETAIL == type))
{
/*Common*/
CTC_DKITS_PRINT_FILE(p_file, "# COMMON Registers, 0x00-0xe3\n");
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_COMMON_PLL;
for (j = 0; j <= 2; j++)
{
CTC_DKITS_PRINT_FILE(p_file, "# CMU %u\n", j);
ctc_dkit_serdes_wr.sub_type = j;
for (i = 0; i <= 0xe3; i++)
{
ctc_dkit_serdes_wr.addr_offset = i;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, "Read 0x%02x: 0x%04x\n", ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
}
}
}
if ((CTC_DKIT_SERDES_ALL == type) || (CTC_DKIT_SERDES_DETAIL == type))
{
/*Common*/
CTC_DKITS_PRINT_FILE(p_file, "# LANE Registers, 0x00-0xf6\n");
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
for (i = 0; i <= 0xf6; i++)
{
ctc_dkit_serdes_wr.addr_offset = i;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, "Read 0x%02x: 0x%04x\n", ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
}
}
/*Extended info*/
if ((CTC_DKIT_SERDES_ALL == type) || (CTC_DKIT_SERDES_DETAIL == type))
{
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
/*Eye scan*/
serdes_para.serdes_id = serdes_id;
serdes_para.lchip = lchip;
serdes_para.type = CTC_DKIT_SERDIS_CTL_EYE;
serdes_para.para[0] = CTC_DKIT_SERDIS_EYE_ALL;
ctc_dkit_serdes_para.lchip = lchip;
ctc_dkit_serdes_para.serdes_id = serdes_id;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL;
CTC_DKITS_PRINT_FILE(p_file, "\n Eye height measure\n");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
CTC_DKIT_PRINT(" %-10s%-10s%-10s%-10s%s\n", "No.", "An", "Ap", "Amin", "EyeOpen");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
rslt_sum = 0;
for (i = 0; i < 3; i++)
{
_ctc_tm_dkit_misc_serdes_12g_eye(&ctc_dkit_serdes_para, &serdes_para, TRUE, TRUE, i, &rslt_sum);
}
rslt_sum /= 3;
CTC_DKITS_PRINT_FILE(p_file, "Avg. %u\n", rslt_sum);
CTC_DKITS_PRINT_FILE(p_file, "\n Eye width measure\n");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
CTC_DKIT_PRINT(" %-10s%-10s%-10s%-10s%-10s%s\n", "No.", "Width", "Az", "Oes", "Ols", "DeducedWidth");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
rslt_sum = 0;
for (i = 0; i < 3; i++)
{
_ctc_tm_dkit_misc_serdes_12g_eye(&ctc_dkit_serdes_para, &serdes_para, FALSE, TRUE, i, &rslt_sum);
}
rslt_sum /= 3;
CTC_DKITS_PRINT_FILE(p_file, "Avg. %u\n", rslt_sum);
/*DFE*/
serdes_para.type = CTC_DKIT_SERDIS_CTL_GET_DFE;
_ctc_tm_dkit_misc_serdes_dfe_get_val(&serdes_para);
CTC_DKITS_PRINT_FILE(p_file, "------------------------------------------------\n");
CTC_DKITS_PRINT_FILE(p_file, "DFE status\n");
CTC_DKITS_PRINT_FILE(p_file, "Dfe : %s\n", (CTC_DKIT_SERDIS_CTL_DFE_ON ==serdes_para.para[0])?"enable":"disable");
CTC_DKITS_PRINT_FILE(p_file, "Tap1 val: %d\n", (serdes_para.para[1] & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, "Tap2 val: %d\n", ((serdes_para.para[1]>>8) & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, "Tap3 val: %d\n", ((serdes_para.para[1]>>16) & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, "Tap4 val: %d\n", ((serdes_para.para[1]>>24) & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, "Tap5 val: %d\n", (serdes_para.para[2] & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, "------------------------------------------------\n");
/*FFE*/
hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
lane_id = CTC_DKIT_MAP_SERDES_TO_LANE_ID(serdes_id);
tbl_id = Hss12GLaneTxEqCfg0_t + hss_id * (Hss12GLaneTxEqCfg1_t - Hss12GLaneTxEqCfg0_t);
step = Hss12GLaneTxEqCfg0_cfgHssL1Pcs2PmaTxMargin_f - Hss12GLaneTxEqCfg0_cfgHssL0Pcs2PmaTxMargin_f;
CTC_DKITS_PRINT_FILE(p_file, "------------------------------------------------\n");
CTC_DKITS_PRINT_FILE(p_file, "FFE status: \n");
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &tx_eq_cfg);
DRV_IOR_FIELD(lchip, tbl_id, (Hss12GLaneTxEqCfg0_cfgHssL0PcsTapAdv_f + step*lane_id), &value, &tx_eq_cfg);
CTC_DKITS_PRINT_FILE(p_file, "C0: %u\n", value);
DRV_IOR_FIELD(lchip, tbl_id, (Hss12GLaneTxEqCfg0_cfgHssL0Pcs2PmaTxMargin_f + step*lane_id), &value, &tx_eq_cfg);
CTC_DKITS_PRINT_FILE(p_file, "C1: %u\n", value);
DRV_IOR_FIELD(lchip, tbl_id, (Hss12GLaneTxEqCfg0_cfgHssL0PcsTapDly_f + step*lane_id), &value, &tx_eq_cfg);
CTC_DKITS_PRINT_FILE(p_file, "C2: %u\n", value);
CTC_DKITS_PRINT_FILE(p_file, "C3: %u\n", 0);
CTC_DKITS_PRINT_FILE(p_file, "C4: %u\n", 0);
/*CTLE*/
hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
lane_id = CTC_DKIT_MAP_SERDES_TO_LANE_ID(serdes_id);
tbl_id = Hss12GLaneRxEqCfg0_t + hss_id * (Hss12GLaneRxEqCfg1_t - Hss12GLaneRxEqCfg0_t);
step = Hss12GLaneRxEqCfg0_cfgHssL1Pcs2PmaVgaCtrl_f - Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaVgaCtrl_f;
CTC_DKITS_PRINT_FILE(p_file, "------------------------------------------------\n");
CTC_DKITS_PRINT_FILE(p_file, "CTLE status: ");
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
DRV_IOR_FIELD(lchip, tbl_id, (Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaVgaCtrl_f + step*lane_id), &value, &rx_eq_cfg);
CTC_DKITS_PRINT_FILE(p_file, "%u ", value);
DRV_IOR_FIELD(lchip, tbl_id, (Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaEqcForce_f + step*lane_id), &value, &rx_eq_cfg);
CTC_DKITS_PRINT_FILE(p_file, "%u ", value);
DRV_IOR_FIELD(lchip, tbl_id, (Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaEqRes_f + step*lane_id), &value, &rx_eq_cfg);
CTC_DKITS_PRINT_FILE(p_file, "%u\n", value);
CTC_DKITS_PRINT_FILE(p_file, "------------------------------------------------\n");
}
if (p_file)
{
sal_fclose(p_file);
CTC_DKIT_PRINT("Save result to %s\n", file_name);
}
return CLI_SUCCESS;
}
STATIC int32
ctc_tm_dkit_misc_serdes_status_28g(uint8 lchip, uint16 serdes_id, uint32 type, char* file_name)
{
ctc_dkit_serdes_wr_t ctc_dkit_serdes_wr;
sal_time_t tv;
char* p_time_str = NULL;
sal_file_t p_file = NULL;
uint16 i = 0;
uint32 rslt_sum = 0;
ctc_dkit_serdes_ctl_para_t serdes_para;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
DKITS_SERDES_ID_CHECK(serdes_id);
CTC_DKIT_LCHIP_CHECK(lchip);
if (file_name)
{
p_file = sal_fopen(file_name, "wt");
if (!p_file)
{
CTC_DKIT_PRINT("Open file %s fail!!!\n", file_name);
return CLI_SUCCESS;
}
}
/*get systime*/
sal_time(&tv);
p_time_str = sal_ctime(&tv);
CTC_DKITS_PRINT_FILE(p_file, "# Serdes %d Regs Status, %s", serdes_id, p_time_str);
if ((CTC_DKIT_SERDES_ALL == type) || (CTC_DKIT_SERDES_DETAIL == type))
{
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
for (i = 0; i <= 0xff; i++)
{
ctc_dkit_serdes_wr.addr_offset = i;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " Addr: 0x8%d%02x, Value: 0x%04x\n", serdes_id%4,
ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
}
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_BIST;
for (i = 0; i <= 0xff; i++)
{
ctc_dkit_serdes_wr.addr_offset = i;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " Addr: 0x98%02x, Value: 0x%04x\n",
ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
}
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_FW;
for (i = 0; i <= 0xff; i++)
{
ctc_dkit_serdes_wr.addr_offset = i;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " Addr: 0x9f%02x, Value: 0x%04x\n",
ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
}
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_LINK_TRAINING;
for (i = 0; i <= 0xff; i++)
{
ctc_dkit_serdes_wr.addr_offset = i;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " Addr: 0x6%d%02x, Value: 0x%04x\n", serdes_id%4,
ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
}
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_COMMON_PLL;
for (i = 0; i <= 0xff; i++)
{
ctc_dkit_serdes_wr.addr_offset = i;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " Addr: 0x84%02x, Value: 0x%04x\n",
ctc_dkit_serdes_wr.addr_offset, ctc_dkit_serdes_wr.data);
}
if (CTC_DKIT_SERDES_DETAIL == type)
{
ctc_tm_dkit_misc_serdes_dump_bathtub_28g(lchip, serdes_id, p_file);
ctc_tm_dkit_misc_serdes_dump_isi_28g(lchip, serdes_id, p_file);
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
/*Eye scan*/
serdes_para.serdes_id = serdes_id;
serdes_para.lchip = lchip;
serdes_para.type = CTC_DKIT_SERDIS_CTL_EYE;
serdes_para.para[0] = CTC_DKIT_SERDIS_EYE_ALL;
ctc_dkit_serdes_para.lchip = lchip;
ctc_dkit_serdes_para.serdes_id = serdes_id;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL;
CTC_DKITS_PRINT_FILE(p_file, "\n Eye height measure\n");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
CTC_DKIT_PRINT(" %-10s%-10s%-10s%-10s%s\n", "No.", "An", "Ap", "Amin", "EyeOpen");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
rslt_sum = 0;
for (i = 0; i < 3; i++)
{
_ctc_tm_dkit_misc_serdes_28g_eye(&ctc_dkit_serdes_para, &serdes_para, i, &rslt_sum);
}
rslt_sum /= 3;
CTC_DKITS_PRINT_FILE(p_file, " Avg. %u\n", rslt_sum);
/*DFE*/
serdes_para.type = CTC_DKIT_SERDIS_CTL_GET_DFE;
_ctc_tm_dkit_misc_serdes_dfe_get_val(&serdes_para);
CTC_DKITS_PRINT_FILE(p_file, " ---------------------------------------------------------------\n");
CTC_DKITS_PRINT_FILE(p_file, " DFE status\n");
CTC_DKITS_PRINT_FILE(p_file, " Dfe : %s\n", (CTC_DKIT_SERDIS_CTL_DFE_ON ==serdes_para.para[0])?"enable":"disable");
CTC_DKITS_PRINT_FILE(p_file, " Tap1 val: %d\n", (serdes_para.para[1] & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, " Tap2 val: %d\n", ((serdes_para.para[1]>>8) & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, " Tap3 val: %d\n", ((serdes_para.para[1]>>16) & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, " Tap4 val: %d\n", ((serdes_para.para[1]>>24) & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, " Tap5 val: %d\n", (serdes_para.para[2] & 0xFF));
CTC_DKITS_PRINT_FILE(p_file, " ---------------------------------------------------------------\n");
/*FFE*/
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
CTC_DKITS_PRINT_FILE(p_file, " FFE config\n");
ctc_dkit_serdes_wr.addr_offset = 0xa8;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " c0: %d\n", ((ctc_dkit_serdes_wr.data>>8) & 0x3f));
ctc_dkit_serdes_wr.addr_offset = 0xa7;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " c1: %d\n", ((ctc_dkit_serdes_wr.data>>8) & 0x3f));
ctc_dkit_serdes_wr.addr_offset = 0xa6;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, " c2: %d\n", ((ctc_dkit_serdes_wr.data>>8) & 0x3f));
CTC_DKITS_PRINT_FILE(p_file, " ---------------------------------------------------------------\n");
/*CTLE*/
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
CTC_DKITS_PRINT_FILE(p_file, " CTLE config: ");
ctc_dkit_serdes_wr.addr_offset = 0x4e;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
CTC_DKITS_PRINT_FILE(p_file, "%d\n", ((ctc_dkit_serdes_wr.data>>11 & 7)));
CTC_DKITS_PRINT_FILE(p_file, " ---------------------------------------------------------------\n");
}
}
if (p_file)
{
sal_fclose(p_file);
CTC_DKIT_PRINT("Save result to %s\n", file_name);
}
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_set_15g_lane_reset(uint8 lchip, uint8 serdes_id)
{
uint8 hss_id = 0;
uint8 lane_id = 0;
uint8 step = Hss12GGlbCfg0_cfgHssL1RxRstN_f - Hss12GGlbCfg0_cfgHssL0RxRstN_f;
uint32 cmd = 0;
uint32 tb_id = Hss12GGlbCfg0_t;
uint32 value = 0;
uint32 fld_id = Hss12GGlbCfg0_cfgHssL0RxRstN_f;
Hss12GGlbCfg0_m glb_cfg;
hss_id = serdes_id/CTC_DKIT_SERDES_HSS15G_LANE_NUM;
lane_id = serdes_id%CTC_DKIT_SERDES_HSS15G_LANE_NUM;
tb_id += hss_id;
cmd = DRV_IOR(tb_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &glb_cfg);
fld_id += step*lane_id;
DRV_IOW_FIELD(lchip, tb_id, fld_id, &value, &glb_cfg);
cmd = DRV_IOW(tb_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &glb_cfg);
value = 1;
DRV_IOW_FIELD(lchip, tb_id, fld_id, &value, &glb_cfg);
cmd = DRV_IOW(tb_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &glb_cfg);
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_set_28g_lane_reset(uint8 lchip, uint8 serdes_id)
{
ctc_dkit_serdes_wr_t ctc_dkit_serdes_wr;
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_wr.lchip = lchip;
ctc_dkit_serdes_wr.serdes_id = serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
ctc_dkit_serdes_wr.addr_offset = 0x81;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
DKITS_BIT_SET(ctc_dkit_serdes_wr.data, 11);/*LINKRST = 1*/
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
DKITS_BIT_UNSET(ctc_dkit_serdes_wr.data, 11);/*LINKRST = 0*/
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
return CLI_SUCCESS;
}
int32
ctc_tm_dkit_misc_serdes_resert(uint8 lchip, uint16 serdes_id)
{
uint8 is_hss15g = 0;
DKITS_SERDES_ID_CHECK(serdes_id);
CTC_DKIT_LCHIP_CHECK(lchip);
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(serdes_id);
if (is_hss15g)
{
_ctc_tm_dkit_misc_serdes_set_15g_lane_reset(lchip, serdes_id);
}
else
{
_ctc_tm_dkit_misc_serdes_set_28g_lane_reset(lchip, serdes_id);
}
return CLI_SUCCESS;
}
int32
ctc_tm_dkit_misc_serdes_status(uint8 lchip, uint16 serdes_id, uint32 type, char* file_name)
{
uint8 is_hss15g = 0;
DKITS_SERDES_ID_CHECK(serdes_id);
CTC_DKIT_LCHIP_CHECK(lchip);
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(serdes_id);
if (is_hss15g)
{
ctc_tm_dkit_misc_serdes_status_15g(lchip, serdes_id, type, file_name);
}
else
{
ctc_tm_dkit_misc_serdes_status_28g(lchip, serdes_id, type, file_name);
}
return 0;
}
int32
ctc_tm_dkits_misc_dump_indirect(uint8 lchip, sal_file_t p_f, ctc_dkits_dump_func_flag_t flag)
{
int32 ret = CLI_SUCCESS;
uint8 is_hss15g = 0;
uint16 i = 0;
uint8 j = 0;
uint32 c[4] = {0}, h[10] = {0}, id = 0;
uint8 flag1 = 0;
uint8 serdes_id = 0, addr_offset = 0;
ctc_dkit_serdes_wr_t serdes_para;
ctc_dkits_dump_serdes_tbl_t serdes_tbl;
for (serdes_id = 0; serdes_id < DKIT_SERDES_ID_MAX; serdes_id++)
{
sal_udelay(10);
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(serdes_id);
if (is_hss15g)
{
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
serdes_para.lchip = lchip;
serdes_para.serdes_id = serdes_id;
serdes_para.type = CTC_DKIT_SERDES_COMMON_PLL;
for (i = 0; i <= 0xe3; i++)
{
for (j = 0; j <= 2; j++)
{
serdes_para.addr_offset = i;
serdes_para.sub_type = j;
ret = ret ? ret : ctc_tm_dkit_misc_read_serdes(&serdes_para);
serdes_tbl.serdes_id = serdes_id;
serdes_tbl.serdes_mode = CTC_DKIT_SERDES_COMMON;
serdes_tbl.offset = addr_offset;
serdes_tbl.data = serdes_para.data;
if (CTC_DKIT_SERDES_IS_HSS28G(serdes_id))
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss28GRegAccCtl_t + id, c[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
else
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss12GRegAccCtl0_t + id, h[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
}
}
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
serdes_para.lchip = lchip;
serdes_para.serdes_id = serdes_id;
serdes_para.type = CTC_DKIT_SERDES_ALL;
for (i = 0; i <= 0xf6; i++)
{
serdes_para.addr_offset = i;
ret = ret ? ret : ctc_tm_dkit_misc_read_serdes(&serdes_para);
serdes_tbl.serdes_id = serdes_id;
serdes_tbl.serdes_mode = CTC_DKIT_SERDES_COMMON;
serdes_tbl.offset = addr_offset;
serdes_tbl.data = serdes_para.data;
if (CTC_DKIT_SERDES_IS_HSS28G(serdes_id))
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss28GRegAccCtl_t + id, c[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
else
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss12GRegAccCtl0_t + id, h[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
}
}
else
{
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
serdes_para.lchip = lchip;
serdes_para.serdes_id = serdes_id;
serdes_para.type = CTC_DKIT_SERDES_COMMON_PLL;
for (i = 0xE8; i <= 0xFF; i++)
{
flag1 = 0;
for (j = 0; j <= 5; j++)
{
if(i == g_tm_common_28g_address[j])
{
flag1 = 1;
break;
}
}
if(flag1 == 1)
{
continue;
}
serdes_para.addr_offset = i;
ret = ret ? ret : ctc_tm_dkit_misc_read_serdes(&serdes_para);
serdes_tbl.serdes_id = serdes_id;
serdes_tbl.serdes_mode = CTC_DKIT_SERDES_COMMON;
serdes_tbl.offset = addr_offset;
serdes_tbl.data = serdes_para.data;
if (CTC_DKIT_SERDES_IS_HSS28G(serdes_id))
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss28GRegAccCtl_t + id, c[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
else
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss12GRegAccCtl0_t + id, h[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
}
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
serdes_para.lchip = lchip;
serdes_para.serdes_id = serdes_id;
serdes_para.type = CTC_DKIT_SERDES_LINK_TRAINING;
for (i = 0; i <= 0x2C; i++)
{
flag1 = 0;
for (j = 0; j <= 3; j++)
{
if(i == g_tm_link_28g_address[j])
{
flag1 = 1;
break;
}
}
if(flag1 == 1)
{
continue;
}
serdes_para.addr_offset = i;
ret = ret ? ret : ctc_tm_dkit_misc_read_serdes(&serdes_para);
serdes_tbl.serdes_id = serdes_id;
serdes_tbl.serdes_mode = CTC_DKIT_SERDES_COMMON;
serdes_tbl.offset = addr_offset;
serdes_tbl.data = serdes_para.data;
if (CTC_DKIT_SERDES_IS_HSS28G(serdes_id))
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss28GRegAccCtl_t + id, c[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
else
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss12GRegAccCtl0_t + id, h[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
}
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
serdes_para.lchip = lchip;
serdes_para.serdes_id = serdes_id;
serdes_para.type = CTC_DKIT_SERDES_ALL;
for (i = 0; i <= 76; i++)
{
serdes_para.addr_offset = g_tm_control_28g_address[i];
ret = ret ? ret : ctc_tm_dkit_misc_read_serdes(&serdes_para);
serdes_tbl.serdes_id = serdes_id;
serdes_tbl.serdes_mode = CTC_DKIT_SERDES_COMMON;
serdes_tbl.offset = addr_offset;
serdes_tbl.data = serdes_para.data;
if (CTC_DKIT_SERDES_IS_HSS28G(serdes_id))
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss28GRegAccCtl_t + id, c[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
else
{
id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
ret = ret ? ret : ctc_usw_dkits_dump_tbl2data(lchip, Hss12GRegAccCtl0_t + id, h[id]++, (uint32*)&serdes_tbl, NULL, p_f);
}
}
}
}
return ret;
}
int32
_ctc_tm_dkit_misc_prbs_en(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
uint8 lchip = p_serdes_para->lchip;
uint16 data = 0;
uint16 pattern_type = 0;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_para.lchip = lchip;
ctc_dkit_serdes_para.serdes_id = p_serdes_para->serdes_id;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL; //per-lane base, 28G 0x8000 + lane_id*0x100, 12G (lane_id+3)*0x100
if(CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id))
{
/* prbs is already enable, do not need operation */
ctc_dkit_serdes_para.addr_offset = 0x00a0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) && (0xe800 == (ctc_dkit_serdes_para.data & 0xe800)))
{
return CLI_EOL;
}
switch(p_serdes_para->para[1])
{
case 2:
case 3:
/*PRBS15*/
pattern_type = 0x0100;
break;
case 4:
case 5:
/*PRBS23*/
pattern_type = 0x0200;
break;
case 6:
case 7:
/*PRBS31*/
pattern_type = 0x0300;
break;
case 8:
/*PRBS9*/
pattern_type = 0x0000;
break;
case 9:
/*PRBS8081*/
pattern_type = 0x0300;
break;
case 11:
/*PRBS1T*/
pattern_type = 0x2800;
break;
default:
CTC_DKIT_PRINT("Pattern not supported!\n");
return CLI_ERROR;
}
/*1. User-Defined pattern(if necessary)*/
if (9 == p_serdes_para->para[1]) /* user-defined PRBS 8`0'8`1' */
{
data = 0xff00;
/* TX Test Pattern High */
ctc_dkit_serdes_para.addr_offset = 0x00a1;
ctc_dkit_serdes_para.data = data;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/* TX Test Pattern Low */
ctc_dkit_serdes_para.addr_offset = 0x00a2;
ctc_dkit_serdes_para.data = data;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/* set TX_TEST_DATA_SRC (reg0x8zA0[15]) = 1'b0 */
/* set TX_PRBS_CLOCK_EN (reg0x8zA0[14]) = 1'b1 */
/* set TX_TEST_EN (reg0x8zA0[13]) = 1'b1 */
/* set TX_PRBS_GEN_EN (0x8zA0[11]) = 1'b1 */
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x6800 : 0);
ctc_dkit_serdes_para.addr_offset = 0x00a0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x17ff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
else if (11 == p_serdes_para->para[1]) /* user-defined PRBS 1T(1010) */
{
data = 0xaaaa;
/* TX Test Pattern High */
ctc_dkit_serdes_para.addr_offset = 0x00a1;
ctc_dkit_serdes_para.data = data;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/* TX Test Pattern Low */
ctc_dkit_serdes_para.addr_offset = 0x00a2;
ctc_dkit_serdes_para.data = data;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/* set TX_TEST_DATA_SRC (reg0x8zA0[15]) = 1'b0 */
/* set TX_PRBS_CLOCK_EN (reg0x8zA0[14]) = 1'b1 */
/* set TX_TEST_EN (reg0x8zA0[13]) = 1'b1 */
/* set TX_PRBS_GEN_EN (0x8zA0[11]) = 1'b1 */
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x6800 : 0);
ctc_dkit_serdes_para.addr_offset = 0x00a0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x17ff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
else /* Typical PRBS mode */
{
/*1. PRBS mode select set TX_PRBS_MODE(reg0x8zA0[9:8]) */
data = pattern_type;
ctc_dkit_serdes_para.addr_offset = 0x00a0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfcff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/* set TX_TEST_DATA_SRC (reg0x8zA0[15]) = 1'b1 */
/* set TX_PRBS_CLOCK_EN (reg0x8zA0[14]) = 1'b1 */
/* set TX_TEST_EN (reg0x8zA0[13]) = 1'b1 */
/* set TX_PRBS_GEN_EN (0x8zA0[11]) = 1'b1 */
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0xe800 : 0);
ctc_dkit_serdes_para.addr_offset = 0x00a0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x17ff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
}
else
{
/* prbs is already enable, do not need operation */
ctc_dkit_serdes_para.addr_offset = 0x76;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) && (0x01 == (ctc_dkit_serdes_para.data & 0x01)))
{
return CLI_EOL;
}
switch(p_serdes_para->para[1])
{
case 0:
case 1:
/*PRBS7*/
pattern_type = 0x00;
break;
case 2:
case 3:
/*PRBS15*/
pattern_type = 0x30;
break;
case 4:
case 5:
/*PRBS23*/
pattern_type = 0x40;
break;
case 6:
case 7:
/*PRBS31*/
pattern_type = 0x50;
break;
case 8:
/*PRBS9*/
pattern_type = 0x10;
break;
case 10:
/*PRBS11*/
pattern_type = 0x20;
break;
case 9:
/*User defined pattern*/
pattern_type = 0x70;
break;
default:
CTC_DKIT_PRINT("Pattern not supported!\n");
return CLI_ERROR;
}
/*1. PRBS mode select set r_bist_mode(reg0x76[6:4]) */
data = pattern_type;
ctc_dkit_serdes_para.addr_offset = 0x76;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x8f) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
if (9 == p_serdes_para->para[1]) /* HSS12G PRBS 8081 */
{
data = 0xff;
ctc_dkit_serdes_para.addr_offset = 0x96;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
data = 0x0;
ctc_dkit_serdes_para.addr_offset = 0x97;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
data = 0xff;
ctc_dkit_serdes_para.addr_offset = 0x98;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
data = 0x0;
ctc_dkit_serdes_para.addr_offset = 0x99;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
data = 0xff;
ctc_dkit_serdes_para.addr_offset = 0x9a;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
data = 0x0;
ctc_dkit_serdes_para.addr_offset = 0x9b;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
data = 0xff;
ctc_dkit_serdes_para.addr_offset = 0x9c;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
data = 0x0;
ctc_dkit_serdes_para.addr_offset = 0x9d;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf0) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
/*2. Enable r_bist_en set r_bist_en(reg0x76[0]) = 1*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 1 : 0);
ctc_dkit_serdes_para.addr_offset = 0x76;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfe) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
return CLI_SUCCESS;
}
int32
_ctc_tm_dkit_misc_prbs_check(ctc_dkit_serdes_ctl_para_t* p_serdes_para, bool* pass)
{
uint8 lchip = p_serdes_para->lchip;
uint16 data = 0;
uint32 err_cnt = 0;
uint32 err_cnt_buf = 0;
uint16 pattern_type = 0;
uint16 time = 1000;
uint32 delay = 0;
uint8 is_keep = 0;
uint8 errcntrst_flag = 0;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_para.lchip = p_serdes_para->lchip;
ctc_dkit_serdes_para.serdes_id = p_serdes_para->serdes_id;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL; //per-lane base, 28G 0x8000 + lane_id*0x100, 12G (lane_id+3)*0x100
delay = p_serdes_para->para[3];
if (delay)
{
sal_task_sleep(delay); /*delay before check*/
}
else
{
sal_task_sleep(1000);
}
is_keep = p_serdes_para->para[2];
if(CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id))
{
switch(p_serdes_para->para[1])
{
case 2:
case 3:
/*PRBS15*/
pattern_type = 0x1000;
break;
case 4:
case 5:
/*PRBS23*/
pattern_type = 0x2000;
break;
case 6:
case 7:
/*PRBS31*/
pattern_type = 0x3000;
break;
case 8:
/*PRBS9*/
pattern_type = 0x0000;
break;
default:
CTC_DKIT_PRINT("Pattern not supported!\n");
return CLI_ERROR;
}
/*1. PRBS Mode Select set RX_PRBS_MODE (reg0x8z61[13:12])*/
data = pattern_type;
ctc_dkit_serdes_para.addr_offset = 0x0061;//reg0x8z61[13:12]
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xcfff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*2. PRBS Check Enable set RX_PRBS_CHECK_EN(reg0x8z61[10]) = 1'b1*/
data |= 0x0400;
ctc_dkit_serdes_para.addr_offset = 0x0061;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if (0 == ((ctc_dkit_serdes_para.data >> 10) & 0x1))
{
errcntrst_flag = 1;
}
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x7bff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/* reset error cnt: (reg0x8z61[15]) = 1'b1 ,then 1'b0 */
/* if Keep, DO NOT need do this */
ctc_dkit_serdes_para.addr_offset = 0x0061;
if (errcntrst_flag)
{
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data |= 0x8000;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data &= 0x7fff;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
/*3. PRBS Check Status Read*/
err_cnt = 0;
sal_task_sleep(1);
ctc_dkit_serdes_para.data = 0;
ctc_dkit_serdes_para.addr_offset = 0x0066; //high reg0x8z66[15:0]
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt = ((uint32)ctc_dkit_serdes_para.data) << 16;
ctc_dkit_serdes_para.addr_offset = 0x0067; //low reg0x8z67[15:0]
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt |= (ctc_dkit_serdes_para.data);
err_cnt /= 3;
if(0 != err_cnt)
{
*pass = FALSE;
}
else
{
*pass = TRUE;
}
/*4. PRBS Check disable set RX_PRBS_CHECK_EN(reg0x8z61[10]) = 1'b0*/
if(!is_keep)
{
data = 0;
ctc_dkit_serdes_para.addr_offset = 0x0061; //reg0x8z61[10]
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfbff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
}
else
{
switch(p_serdes_para->para[1])
{
case 0:
case 1:
/*PRBS7*/
pattern_type = 0x00;
break;
case 2:
case 3:
/*PRBS15*/
pattern_type = 0x30;
break;
case 4:
case 5:
/*PRBS23*/
pattern_type = 0x40;
break;
case 6:
case 7:
/*PRBS31*/
pattern_type = 0x50;
break;
case 8:
/*PRBS9*/
pattern_type = 0x10;
break;
case 10:
/*PRBS11*/
pattern_type = 0x20;
break;
case 11:
/*User defined pattern*/
pattern_type = 0x70;
break;
default:
CTC_DKIT_PRINT("Pattern not supported!\n");
return CLI_ERROR;
}
/*1. PRBS mode select set r_bist_mode(reg0x76[6:4]) */
data = pattern_type;
ctc_dkit_serdes_para.addr_offset = 0x76;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x8f) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*1. Enable r_bist_chk set r_bist_chk(reg0x77[0]) = 1 and r_bist_chk_zero(reg0x77[1]) = 1*/
data = 0x3;
ctc_dkit_serdes_para.addr_offset = 0x77;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfc) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*2. Read bist status*/
data = 0;
ctc_dkit_serdes_para.addr_offset = 0xe0;
ctc_dkit_serdes_para.data = 0;
while(--time)
{
sal_task_sleep(1);
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
data = (3 & (ctc_dkit_serdes_para.data));
if(0 != data)
{
break;
}
}
if((0 == time) || (3 != data)) //timeout, or error occur
{
*pass = FALSE;
}
else
{
*pass = TRUE;
}
ctc_dkit_serdes_para.addr_offset = 0xe1;
ctc_dkit_serdes_para.data = 0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt_buf = ctc_dkit_serdes_para.data;
err_cnt = err_cnt_buf;
ctc_dkit_serdes_para.addr_offset = 0xe2;
ctc_dkit_serdes_para.data = 0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt_buf = ctc_dkit_serdes_para.data;
err_cnt |= (err_cnt_buf << 8);
ctc_dkit_serdes_para.addr_offset = 0xe3;
ctc_dkit_serdes_para.data = 0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt_buf = ctc_dkit_serdes_para.data;
err_cnt |= (err_cnt_buf << 16);
ctc_dkit_serdes_para.addr_offset = 0xe4;
ctc_dkit_serdes_para.data = 0;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt_buf = ctc_dkit_serdes_para.data;
err_cnt |= (err_cnt_buf << 24);
/*3. Disable r_bist_chk set r_bist_chk(reg0x77[0]) = 0 and r_bist_chk_zero(reg0x77[1]) = 0*/
if(!is_keep)
{
data = 0;
ctc_dkit_serdes_para.addr_offset = 0x77;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfc) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
}
p_serdes_para->para[4] = err_cnt;
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_do_serdes_prbs(ctc_dkit_serdes_ctl_para_t* p_serdes_para, bool* pass)
{
int ret = CLI_SUCCESS;
switch(p_serdes_para->para[0])
{
case CTC_DKIT_SERDIS_CTL_ENABLE:
case CTC_DKIT_SERDIS_CTL_DISABLE:
ret = _ctc_tm_dkit_misc_prbs_en(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_CEHCK:
ret = _ctc_tm_dkit_misc_prbs_check(p_serdes_para, pass);
break;
default:
CTC_DKIT_PRINT("Feature not supported!\n");
break;
}
return ret;
}
STATIC void
_ctc_tm_dkit_misc_serdes_monitor_handler(void* arg)
{
ctc_dkit_serdes_ctl_para_t* p_serdes_para = (ctc_dkit_serdes_ctl_para_t*)arg;
sal_time_t tv;
char* p_time_str = NULL;
uint8 lchip = p_serdes_para->lchip;
uint16 data = 0;
uint32 err_cnt = 0;
uint16 pattern_type = 0;
uint16 time_count = 1000;
sal_file_t p_file = NULL;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
uint8 errcntrst_flag = 0;
sal_time(&tv);
p_time_str = sal_ctime(&tv);
CTC_DKIT_PRINT("Serdes %d prbs check monitor begin, %s\n", p_serdes_para->serdes_id, p_time_str);
if (0 != p_serdes_para->str[0])
{
p_file = sal_fopen(p_serdes_para->str, "wt");
if (!p_file)
{
CTC_DKIT_PRINT("Open file %s fail!!!\n", p_serdes_para->str);
return;
}
CTC_DKITS_PRINT_FILE(p_file, "Serdes %d prbs check moniter begin, %s\n", p_serdes_para->serdes_id, p_time_str);
sal_fclose(p_file);
p_file = NULL;
}
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_para.lchip = p_serdes_para->lchip;
ctc_dkit_serdes_para.serdes_id = p_serdes_para->serdes_id;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL; //per-lane base, 28G 0x8000 + lane_id*0x100, 12G (lane_id+3)*0x100
if(CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id))
{
switch(p_serdes_para->para[1])
{
case 2:
case 3:
/*PRBS15*/
pattern_type = 0x1000;
break;
case 4:
case 5:
/*PRBS23*/
pattern_type = 0x2000;
break;
case 6:
case 7:
/*PRBS31*/
pattern_type = 0x3000;
break;
case 8:
/*PRBS9*/
pattern_type = 0x0000;
break;
default:
CTC_DKIT_PRINT("Pattern not supported!\n");
return;
}
/*1. PRBS Mode Select set RX_PRBS_MODE (reg0x8z61[13:12])*/
data = pattern_type;
ctc_dkit_serdes_para.addr_offset = 0x0061;//reg0x8z61[13:12]
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xcfff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*2. PRBS Check Enable set RX_PRBS_CHECK_EN(reg0x8z61[10]) = 1'b1*/
data |= 0x0400;
ctc_dkit_serdes_para.addr_offset = 0x0061;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if (0 == ((ctc_dkit_serdes_para.data >> 10) & 0x1))
{
errcntrst_flag = 1;
}
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x7bff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/* reset error cnt: (reg0x8z61[15]) = 1'b1 ,then 1'b0 */
/* if Keep, DO NOT need do this */
ctc_dkit_serdes_para.addr_offset = 0x0061;
if (errcntrst_flag)
{
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data |= 0x8000;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data &= 0x7fff;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
/*3. PRBS Check Status Read*/
err_cnt = 0;
sal_task_sleep(1);
ctc_dkit_serdes_para.data = 0;
ctc_dkit_serdes_para.addr_offset = 0x0066; //high reg0x8z66[15:0]
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt = ((uint32)ctc_dkit_serdes_para.data) << 16;
ctc_dkit_serdes_para.addr_offset = 0x0067; //low reg0x8z67[15:0]
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
while (1)
{
if (g_usw_dkit_master[lchip]->monitor_task[CTC_DKIT_MONITOR_TASK_PRBS].task_end)
{
goto End;
}
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
err_cnt |= (ctc_dkit_serdes_para.data);
err_cnt /= 3;
if (p_serdes_para->str[0])
{
p_file = sal_fopen(p_serdes_para->str, "a");
}
/*get systime*/
sal_time(&tv);
p_time_str = sal_ctime(&tv);
if(0 != err_cnt) //timeout, or error occur
{
CTC_DKITS_PRINT_FILE(p_file, "Serdes %d prbs check error, sync = %d, %s", p_serdes_para->serdes_id, !time_count, p_time_str);
goto End;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "Serdes %d prbs check success, %s", p_serdes_para->serdes_id, p_time_str);
}
if (p_file)
{
sal_fclose(p_file);
p_file = NULL;
}
sal_task_sleep(p_serdes_para->para[2]*1000);
}
}
else
{
switch(p_serdes_para->para[1])
{
case 0:
case 1:
/*PRBS7*/
pattern_type = 0x00;
break;
case 2:
case 3:
/*PRBS15*/
pattern_type = 0x30;
break;
case 4:
case 5:
/*PRBS23*/
pattern_type = 0x40;
break;
case 6:
case 7:
/*PRBS31*/
pattern_type = 0x50;
break;
case 8:
/*PRBS9*/
pattern_type = 0x10;
break;
case 10:
/*PRBS11*/
pattern_type = 0x20;
break;
case 11:
/*User defined pattern*/
pattern_type = 0x70;
break;
default:
CTC_DKIT_PRINT("Pattern not supported!\n");
return;
}
/*1. PRBS mode select set r_bist_mode(reg0x76[6:4]) */
data = pattern_type;
ctc_dkit_serdes_para.addr_offset = 0x76;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x8f) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*1. Enable r_bist_chk set r_bist_chk(reg0x77[0]) = 1 and r_bist_chk_zero(reg0x77[1]) = 1*/
data = 0x3;
ctc_dkit_serdes_para.addr_offset = 0x77;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfc) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*2. Read bist status*/
data = 0;
ctc_dkit_serdes_para.addr_offset = 0xe0;
ctc_dkit_serdes_para.data = 0;
while(--time_count)
{
sal_task_sleep(1);
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
data = (3 & (ctc_dkit_serdes_para.data));
if(0 != data)
{
break;
}
}
while (1)
{
if (g_usw_dkit_master[lchip]->monitor_task[CTC_DKIT_MONITOR_TASK_PRBS].task_end)
{
goto End;
}
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
data = (3 & (ctc_dkit_serdes_para.data));
if (p_serdes_para->str[0])
{
p_file = sal_fopen(p_serdes_para->str, "a");
}
/*get systime*/
sal_time(&tv);
p_time_str = sal_ctime(&tv);
if ((0 == time_count) || (3 != data)) //timeout, or error occur
{
CTC_DKITS_PRINT_FILE(p_file, "Serdes %d prbs check error, sync = %d, %s", p_serdes_para->serdes_id, !time_count, p_time_str);
goto End;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "Serdes %d prbs check success, %s", p_serdes_para->serdes_id, p_time_str);
}
if (p_file)
{
sal_fclose(p_file);
p_file = NULL;
}
sal_task_sleep(p_serdes_para->para[2]*1000);
}
}
End:
if (p_file)
{
sal_fclose(p_file);
p_file = NULL;
}
return;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_prbs(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
int ret = CLI_SUCCESS;
char* pattern[PATTERN_NUM] = {"PRBS7+","PRBS7-","PRBS15+","PRBS15-","PRBS23+","PRBS23-","PRBS31+","PRBS31-", "PRBS9", "Squareware", "PRBS11", "PRBS1T"};
char* enable = NULL;
bool pass = FALSE;
sal_file_t p_file = NULL;
uint8 task_id = CTC_DKIT_MONITOR_TASK_PRBS;
uint8 lchip = 0;
uint32 cmd = 0;
uint32 field_val = 0;
char buffer[SAL_TASK_MAX_NAME_LEN] = {0};
lchip = p_serdes_para->lchip;
if (p_serdes_para->para[1] > (PATTERN_NUM-1))
{
CTC_DKIT_PRINT("Pattern not supported!\n");
return CLI_ERROR;
}
cmd = DRV_IOR(OobFcReserved_t, OobFcReserved_reserved_f);
DRV_IOCTL(lchip, 0, cmd, &field_val);
if (1 == field_val)
{
CTC_DKIT_PRINT("do prbs check, must close link monitor thread\n");
return CLI_ERROR;
}
if (CTC_DKIT_SERDIS_CTL_MONITOR == p_serdes_para->para[0])
{
if (NULL == g_usw_dkit_master[lchip]->monitor_task[task_id].monitor_task)
{
if (NULL == g_usw_dkit_master[lchip]->monitor_task[task_id].para)
{
g_usw_dkit_master[lchip]->monitor_task[task_id].para
= (ctc_dkit_monitor_para_t*)mem_malloc(MEM_CLI_MODULE, sizeof(ctc_dkit_monitor_para_t));
if (NULL == g_usw_dkit_master[lchip]->monitor_task[task_id].para)
{
return CLI_ERROR;
}
}
g_usw_dkit_master[lchip]->monitor_task[task_id].task_end = 0;
sal_memcpy(g_usw_dkit_master[lchip]->monitor_task[task_id].para, p_serdes_para , sizeof(ctc_dkit_monitor_para_t));
sal_sprintf(buffer, "SerdesPrbs-%d", lchip);
ret = sal_task_create(&g_usw_dkit_master[lchip]->monitor_task[task_id].monitor_task,
buffer,
SAL_DEF_TASK_STACK_SIZE,
SAL_TASK_PRIO_DEF,
_ctc_tm_dkit_misc_serdes_monitor_handler,
g_usw_dkit_master[lchip]->monitor_task[task_id].para);
}
return CLI_SUCCESS;
}
else if (CTC_DKIT_SERDIS_CTL_DISABLE == p_serdes_para->para[0])
{
if (g_usw_dkit_master[p_serdes_para->lchip]->monitor_task[task_id].monitor_task)
{
g_usw_dkit_master[lchip]->monitor_task[task_id].task_end = 1;
sal_task_destroy(g_usw_dkit_master[lchip]->monitor_task[task_id].monitor_task);
g_usw_dkit_master[lchip]->monitor_task[task_id].monitor_task = NULL;
if (g_usw_dkit_master[lchip]->monitor_task[task_id].para)
{
mem_free(g_usw_dkit_master[lchip]->monitor_task[task_id].para);
}
return CLI_SUCCESS;
}
}
ret = _ctc_tm_dkit_misc_do_serdes_prbs(p_serdes_para, &pass);
if(CLI_EOL == ret)
{
CTC_DKIT_PRINT("prbs is enable, need disable first(default prbs is enable with 6, so must disable prbs 6)\n");
return CLI_ERROR;
}
else if (CLI_ERROR == ret)
{
return CLI_ERROR;
}
if (0 != p_serdes_para->str[0])
{
p_file = sal_fopen(p_serdes_para->str, "wt");
if (!p_file)
{
CTC_DKIT_PRINT("Open file %s fail!!!\n", p_serdes_para->str);
return CLI_ERROR;
}
}
if ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0])
||(CTC_DKIT_SERDIS_CTL_DISABLE == p_serdes_para->para[0]))
{
enable = (CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0])? "Yes":"No";
CTC_DKITS_PRINT_FILE(p_file, "\n%-12s%-6s%-10s%-9s%-9s\n", "Serdes_ID", "Dir", "Pattern", "Enable", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-12d%-6s%-10s%-9s%-9s\n", p_serdes_para->serdes_id, "TX", pattern[p_serdes_para->para[1]], enable, " -");
}
else if (CTC_DKIT_SERDIS_CTL_CEHCK == p_serdes_para->para[0])
{
if (CLI_ERROR == ret)
{
enable = "Not Sync";
}
else
{
enable = pass? "Pass" : "Fail";
}
CTC_DKITS_PRINT_FILE(p_file, "\n%-12s%-6s%-10s%-9s%-9s%-9s\n", "Serdes_ID", "Dir", "Pattern", "Enable", "Result", "Err_cnt");
CTC_DKITS_PRINT_FILE(p_file, "-----------------------------------------------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-12d%-6s%-10s%-9s%-9s%-9u\n", p_serdes_para->serdes_id, "RX", pattern[p_serdes_para->para[1]], " -", enable, p_serdes_para->para[4]);
}
if (p_file)
{
sal_fclose(p_file);
}
return CLI_SUCCESS;
}
int32
_ctc_tm_dkit_misc_loopback_12g_clear(uint8 lchip, uint32 serdes_id)
{
uint32 addr[4] = {0x06, 0x0e, 0x13, 0x91};
uint16 mask[4] = {0xe7, 0xcf, 0xfb, 0xfe};
uint16 data[4] = {0 , 0 , 0x04, 0 };
uint8 cnt;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL; //(lane+3) * 0x100
ctc_dkit_serdes_para.serdes_id = serdes_id;
ctc_dkit_serdes_para.lchip = lchip;
/*reg0x06[4] cfg_rx2tx_lp_en reg0x06[3] cfg_tx2rx_lp_en 0*/
/*reg0x0e[5] cfg_txlb_en reg0x0e[4] cfg_rxlb_en 0*/
/*reg0x13[2] cfg_cdrck_en 1*/
/*reg0x91[0] r_lbslv_in_pmad 0*/
for(cnt = 0; cnt < 4; cnt++)
{
ctc_dkit_serdes_para.addr_offset = addr[cnt];
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask[cnt]) | data[cnt]);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_loopback(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
uint16 data = 0;
uint8 recfg_poly = FALSE;
uint8 lchip = p_serdes_para->lchip;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
/*p_serdes_para->para[0]: CTC_DKIT_SERDIS_CTL_ENABLE/CTC_DKIT_SERDIS_CTL_DISABLE*/
/*p_serdes_para->para[1]: CTC_DKIT_SERDIS_LOOPBACK_INTERNAL/CTC_DKIT_SERDIS_LOOPBACK_EXTERNAL*/
/*p_serdes_para->para[2]: CTC_DKIT_SERDIS_LOOPBACK_EXTERNAL_MODE0/1/2 LS1/LS2/LS3*/
if(p_serdes_para->serdes_id > (DRV_IS_DUET2(lchip)?39:31))
{
CTC_DKIT_PRINT("Parameter Error, invalid serdes ID!\n");
return CLI_ERROR;
}
if(CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id))
{
/*28G INTERNAL LOOP not support*/
if(CTC_DKIT_SERDIS_LOOPBACK_INTERNAL == p_serdes_para->para[1])
{
CTC_DKIT_PRINT("Feature not supported!\n");
return CLI_SUCCESS;
}
/*28G EXTERNAL LOOP*/
else
{
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x8000 : 0);
/*Register 9803h: LOOPBACK FIFO Bit15 - LOOPBACK_EN*/
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_COMMON_PLL; //0x8400
ctc_dkit_serdes_para.serdes_id = p_serdes_para->serdes_id;
ctc_dkit_serdes_para.addr_offset = 0x1403; //(0x9803-0x8400)
ctc_dkit_serdes_para.lchip = p_serdes_para->lchip;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0x7fff) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
}
else
{
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL; //(lane+3) * 0x100
ctc_dkit_serdes_para.serdes_id = p_serdes_para->serdes_id;
ctc_dkit_serdes_para.lchip = p_serdes_para->lchip;
/*12G INTERNAL LOOP LM1*/
if(CTC_DKIT_SERDIS_LOOPBACK_INTERNAL == p_serdes_para->para[1])
{
_ctc_tm_dkit_misc_loopback_12g_clear(p_serdes_para->lchip, p_serdes_para->serdes_id);
/*reg0x06[3] cfg_tx2rx_lp_en*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x08 : 0);
ctc_dkit_serdes_para.addr_offset = 0x06;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xf7) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*reg0x0e[5] cfg_txlb_en*/
/*reg0x0e[4] cfg_txlb_en*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x30 : 0);
ctc_dkit_serdes_para.addr_offset = 0x0e;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xcf) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*When LM1 enable and polarity is inverted (read from reg), save poly status and set as normal;*/
/*when LM1 disable and polarity is inverted (read from global variable), set reg as inverded.*/
ctc_dkit_serdes_para.addr_offset = 0x83;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
recfg_poly = FALSE;
if(CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0])
{
/*TX: r_tx_pol_inv(reg0x83[1]): 1'b0, Normal(default) 1'b1, Inverted*/
g_tm_serdes_poly_tx[ctc_dkit_serdes_para.serdes_id] = (uint8)((ctc_dkit_serdes_para.data >> 1) & 0x1);
/*RX: r_rx_pol_inv(reg0x83[3]): 1'b0, Normal(default) 1'b1, Inverted*/
g_tm_serdes_poly_rx[ctc_dkit_serdes_para.serdes_id] = (uint8)((ctc_dkit_serdes_para.data >> 3) & 0x1);
if(1 == g_tm_serdes_poly_tx[ctc_dkit_serdes_para.serdes_id])
{
ctc_dkit_serdes_para.data &= 0xfffd;
recfg_poly = TRUE;
}
if(1 == g_tm_serdes_poly_rx[ctc_dkit_serdes_para.serdes_id])
{
ctc_dkit_serdes_para.data &= 0xfff7;
recfg_poly = TRUE;
}
}
else
{
if(1 == g_tm_serdes_poly_tx[ctc_dkit_serdes_para.serdes_id])
{
ctc_dkit_serdes_para.data |= 0x2;
recfg_poly = TRUE;
}
if(1 == g_tm_serdes_poly_rx[ctc_dkit_serdes_para.serdes_id])
{
ctc_dkit_serdes_para.data |= 0x8;
recfg_poly = TRUE;
}
}
if(recfg_poly)
{
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
}
/*12G EXTERNAL LOOP 3 modes*/
else
{
switch(p_serdes_para->para[2])
{
case CTC_DKIT_SERDIS_LOOPBACK_EXTERNAL_MODE0: //LS1
_ctc_tm_dkit_misc_loopback_12g_clear(p_serdes_para->lchip, p_serdes_para->serdes_id);
/*reg0x06[4] cfg_rx2tx_lp_en*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x10 : 0);
ctc_dkit_serdes_para.addr_offset = 0x06;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xef) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*reg0x0e[4] cfg_rxlb_en*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x10 : 0);
ctc_dkit_serdes_para.addr_offset = 0x0e;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xef) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*reg0x13[2] cfg_cdrck_en*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0 : 0x04);
ctc_dkit_serdes_para.addr_offset = 0x13;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfb) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
break;
case CTC_DKIT_SERDIS_LOOPBACK_EXTERNAL_MODE1: //LS2
_ctc_tm_dkit_misc_loopback_12g_clear(p_serdes_para->lchip, p_serdes_para->serdes_id);
/*reg0x06[4] cfg_rx2tx_lp_en*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x10 : 0);
ctc_dkit_serdes_para.addr_offset = 0x06;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xef) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*reg0x0e[4] cfg_rxlb_en*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x10 : 0);
ctc_dkit_serdes_para.addr_offset = 0x0e;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xef) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*reg0x13[2] cfg_cdrck_en*/
data = 0x04;
ctc_dkit_serdes_para.addr_offset = 0x13;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfb) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
break;
case CTC_DKIT_SERDIS_LOOPBACK_EXTERNAL_MODE2: //LS3
_ctc_tm_dkit_misc_loopback_12g_clear(p_serdes_para->lchip, p_serdes_para->serdes_id);
/*reg0x91[0] r_lbslv_in_pmad*/
data = ((CTC_DKIT_SERDIS_CTL_ENABLE == p_serdes_para->para[0]) ? 0x01 : 0);
ctc_dkit_serdes_para.addr_offset = 0x91;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & 0xfe) | data);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
break;
default:
CTC_DKIT_PRINT("Feature not supported!\n");
return CLI_SUCCESS;
}
}
}
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_status(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
char* pll_select = NULL;
char* sigdet = NULL;
uint8 lane_id = 0;
uint8 hss_id = 0;
uint8 is_hss15g = 0;
uint32 value = 0;
uint32 lol_value = 0;
uint32 cmd = 0;
uint32 tbl_id = 0;
uint32 fld_id = 0;
char* pll_ready = "-";
uint8 lchip = 0;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_wr;
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
DKITS_SERDES_ID_CHECK(p_serdes_para->serdes_id);
lchip = p_serdes_para->lchip;
CTC_DKIT_LCHIP_CHECK(lchip);
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id);
if (is_hss15g)
{
hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(p_serdes_para->serdes_id);
lane_id = CTC_DKIT_MAP_SERDES_TO_LANE_ID(p_serdes_para->serdes_id);
}
else
{
hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(p_serdes_para->serdes_id);
lane_id = CTC_DKIT_MAP_SERDES_TO_LANE_ID(p_serdes_para->serdes_id);
}
ctc_dkit_serdes_wr.lchip = p_serdes_para->lchip;
ctc_dkit_serdes_wr.serdes_id = p_serdes_para->serdes_id;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
CTC_DKIT_PRINT("\n------Serdes%d Hss%d Lane%d Status-----\n", p_serdes_para->serdes_id, hss_id, lane_id);
if(CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id))
{
pll_select = "PLLA";
ctc_dkit_serdes_wr.addr_offset = 0x002e; //0x8z2e
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
pll_ready = DKITS_IS_BIT_SET(ctc_dkit_serdes_wr.data, 2) ? "YES" : "NO";
sigdet = DKITS_IS_BIT_SET(ctc_dkit_serdes_wr.data, 3) ? "YES" : "NO";
}
else
{
tbl_id = Hss12GLaneMiscCfg0_t + hss_id * (Hss12GLaneMiscCfg1_t - Hss12GLaneMiscCfg0_t);
fld_id = Hss12GLaneMiscCfg0_cfgHssL0AuxTxCkSel_f +
lane_id * (Hss12GLaneMiscCfg0_cfgHssL1AuxTxCkSel_f - Hss12GLaneMiscCfg0_cfgHssL0AuxTxCkSel_f);
cmd = DRV_IOR(tbl_id, fld_id);
DRV_IOCTL(lchip, 0, cmd, &value);
if(4 > lane_id)
{
if(0 == value)
{
pll_select = "PLLA";
}
else if(1 == value)
{
pll_select = "PLLB";
}
else
{
CTC_DKIT_PRINT("Get serdes %u pll select error!\n", p_serdes_para->serdes_id);
return CLI_ERROR;
}
}
else
{
if(0 == value)
{
pll_select = "PLLB";
}
else if(1 == value)
{
pll_select = "PLLC";
}
else
{
CTC_DKIT_PRINT("Get serdes %u pll select error!\n", p_serdes_para->serdes_id);
return CLI_ERROR;
}
}
tbl_id = Hss12GLaneMon0_t + hss_id * (Hss12GLaneMon1_t - Hss12GLaneMon0_t);
fld_id = Hss12GLaneMon0_monHssL0PmaRstDone_f +
lane_id * (Hss12GLaneMon0_monHssL1PmaRstDone_f - Hss12GLaneMon0_monHssL0PmaRstDone_f);
cmd = DRV_IOR(tbl_id, fld_id);
DRV_IOCTL(lchip, 0, cmd, &value);
fld_id = Hss12GLaneMon0_monHssL0LolUdl_f +
lane_id * (Hss12GLaneMon0_monHssL1LolUdl_f - Hss12GLaneMon0_monHssL0LolUdl_f);
cmd = DRV_IOR(tbl_id, fld_id);
DRV_IOCTL(lchip, 0, cmd, &lol_value);
pll_ready = (((1 == value) && (0 == lol_value)) ? "YES" : "NO");
fld_id = Hss12GLaneMon0_monHssL0RxEiFiltered_f +
lane_id * (Hss12GLaneMon0_monHssL1RxEiFiltered_f - Hss12GLaneMon0_monHssL0RxEiFiltered_f);
cmd = DRV_IOR(tbl_id, fld_id);
DRV_IOCTL(lchip, 0, cmd, &value);
sigdet = ((1 == value) ? "YES" : "NO");
}
CTC_DKIT_PRINT("%-20s:%s\n", "PLL Select", pll_select);
CTC_DKIT_PRINT("%-20s:%s\n", "PLL Ready", pll_ready);
CTC_DKIT_PRINT("%-20s:%s\n", "Sigdet", sigdet);
CTC_DKIT_PRINT("------------------------------------\n");
return CLI_SUCCESS;
}
int32
_ctc_tm_dkit_misc_serdes_polr_check(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
int ret = CLI_SUCCESS;
bool pass = 0;
ctc_dkit_serdes_ctl_para_t serdes_para;
sal_memset(&serdes_para, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para.serdes_id = p_serdes_para->serdes_id;
serdes_para.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para.para[1] = 6; /* PRBS pattern 6 */
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para, &pass);
serdes_para.serdes_id = p_serdes_para->para[0];
serdes_para.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para.para[1] = 6; /* PRBS pattern 6 */
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para, &pass);
if (CLI_ERROR == ret)
{
CTC_DKIT_PRINT("%% SerDes %d TX and SerDes %d RX PRBS not match!\n", p_serdes_para->serdes_id, p_serdes_para->para[0]);
}
else
{
if (pass)
{
CTC_DKIT_PRINT("SerDes %d TX and SerDes %d RX PRBS match successfully!\n", p_serdes_para->serdes_id, p_serdes_para->para[0]);
}
else
{
CTC_DKIT_PRINT("%% SerDes %d TX and SerDes %d RX PRBS check fail!\n", p_serdes_para->serdes_id, p_serdes_para->para[0]);
}
}
serdes_para.serdes_id = p_serdes_para->serdes_id;
serdes_para.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para.para[1] = 6; /* PRBS pattern 6 */
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para, &pass);
return CLI_SUCCESS;
}
int32
_ctc_tm_dkit_misc_serdes_dfe_set_en(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
uint8 lchip = p_serdes_para->lchip;
uint8 mask_reg = 0;
uint8 lane = 0;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
uint8 serdes_id = p_serdes_para->serdes_id;
uint8 opr = p_serdes_para->para[0];
uint32 value = 0;
uint32 tbl_id = 0;
uint32 fld_id = 0;
uint32 cmd = 0;
uint8 step = 0;
uint8 hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
Hss12GLaneRxEqCfg0_m rx_eq_cfg;
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_para.serdes_id = serdes_id;
ctc_dkit_serdes_para.lchip = p_serdes_para->lchip;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id) ? CTC_DKIT_SERDES_COMMON_PLL : CTC_DKIT_SERDES_ALL;
lane = CTC_DKIT_MAP_SERDES_TO_LANE_ID(serdes_id);
if(CTC_DKIT_SERDES_IS_HSS28G(serdes_id))
{
CTC_DKIT_PRINT("Cannot change HSS28G DFE status (always enable)! Serdes ID=%u\n", serdes_id);
return CLI_SUCCESS;
}
if(CTC_DKIT_SERDIS_CTL_DFE_OFF == opr)
{
/*0x23[0] cfg_dfe_pd 0-enable 1-disable set 0 if loopback enabled*/
mask_reg = 0xfe;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x01);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x23[2] cfg_dfeck_en 1-enable 0-disable */
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x23[3] cfg_erramp_pd 0-enable 1-disable */
mask_reg = 0xf7;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x08);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x22[4:0] cfg_dfetap_en 5'h1f-enable 5'h0-disable */
mask_reg = 0xe0;
ctc_dkit_serdes_para.addr_offset = 0x22;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x1a[2] cfg_pi_dfe_en 1-enable 0-disable */
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x1a;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x30[0] cfg_summer_en 1 */
/*Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaHoldDfe 0*/
value = 0;
tbl_id = Hss12GLaneRxEqCfg0_t + hss_id * (Hss12GLaneRxEqCfg1_t - Hss12GLaneRxEqCfg0_t);
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
step = Hss12GLaneRxEqCfg0_cfgHssL1Pcs2PmaHoldDfe_f - Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f;
fld_id = Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f + step * lane;
DRV_IOW_FIELD(lchip, tbl_id, fld_id, &value, &rx_eq_cfg);
/*Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaEnDfeDig 1-enable 0-disable*/
fld_id = Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaEnDfeDig_f + step * lane;
DRV_IOW_FIELD(lchip, tbl_id, fld_id, &value, &rx_eq_cfg);
cmd = DRV_IOW(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
/*0x31[2] cfg_rstn_dfedig_gen1 1-enable 0-disable */
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x31;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
else if(CTC_DKIT_SERDIS_CTL_DFE_ON == opr)
{
/*0x23[0] cfg_dfe_pd 0-enable 1-disable set 0 if loopback enabled*/
mask_reg = 0xfe;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x23[2] cfg_dfeck_en 1-enable 0-disable */
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x04);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x23[3] cfg_erramp_pd 0-enable 1-disable */
mask_reg = 0xf7;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x22[4:0] cfg_dfetap_en 5'h1f-enable 5'h0-disable */
mask_reg = 0xe0;
ctc_dkit_serdes_para.addr_offset = 0x22;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x1f);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x1a[2] cfg_pi_dfe_en 1-enable 0-disable */
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x1a;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x04);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
/*0x30[0] cfg_summer_en 1 */
/*Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaHoldDfe 0*/
value = 0;
tbl_id = Hss12GLaneRxEqCfg0_t + hss_id * (Hss12GLaneRxEqCfg1_t - Hss12GLaneRxEqCfg0_t);
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
step = Hss12GLaneRxEqCfg0_cfgHssL1Pcs2PmaHoldDfe_f - Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f;
fld_id = Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f + step * lane;
DRV_IOW_FIELD(lchip, tbl_id, fld_id, &value, &rx_eq_cfg);
/*Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaEnDfeDig 1-enable 0-disable*/
value = 1;
fld_id = Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaEnDfeDig_f + step * lane;
DRV_IOW_FIELD(lchip, tbl_id, fld_id, &value, &rx_eq_cfg);
cmd = DRV_IOW(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
/*0x31[2] cfg_rstn_dfedig_gen1 1-enable 0-disable */
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x31;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
ctc_dkit_serdes_para.data = ((ctc_dkit_serdes_para.data & mask_reg) | 0x04);
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_para);
}
return CLI_SUCCESS;
}
int32
_ctc_tm_dkit_misc_serdes_dfe_get_val(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
uint8 lchip = p_serdes_para->lchip;
uint8 mask_reg = 0;
uint8 lane = 0;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
uint8 serdes_id = p_serdes_para->serdes_id;
uint32 value = 0;
uint32 tbl_id = 0;
uint32 fld_id = 0;
uint32 cmd = 0;
uint8 step = 0;
uint8 hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(serdes_id);
uint8 en_flag = TRUE;
Hss12GLaneRxEqCfg0_m rx_eq_cfg;
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
ctc_dkit_serdes_para.serdes_id = serdes_id;
ctc_dkit_serdes_para.lchip = p_serdes_para->lchip;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL;
lane = CTC_DKIT_MAP_SERDES_TO_LANE_ID(serdes_id);
if(CTC_DKIT_SERDES_IS_HSS28G(serdes_id))
{
p_serdes_para->para[0] = CTC_DKIT_SERDIS_CTL_DFE_ON;
/*tap 1*/
ctc_dkit_serdes_para.addr_offset = 0x002b;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x007f & ctc_dkit_serdes_para.data;
p_serdes_para->para[1] = value;
/*tap 2*/
ctc_dkit_serdes_para.addr_offset = 0x002c;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x007f & (ctc_dkit_serdes_para.data>>8);
p_serdes_para->para[1] |= (value<<8);
/*tap 3*/
ctc_dkit_serdes_para.addr_offset = 0x002c;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x007f & ctc_dkit_serdes_para.data;
p_serdes_para->para[1] |= (value<<16);
}
else
{
/*0x23[0] cfg_dfe_pd 0-enable 1-disable set 0 if loopback enabled*/
if(en_flag)
{
mask_reg = 0xfe;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if(0 != (ctc_dkit_serdes_para.data & (~mask_reg)))
{
en_flag = FALSE;
}
}
/*0x23[2] cfg_dfeck_en 1-enable 0-disable */
if(en_flag)
{
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if(0 == (ctc_dkit_serdes_para.data & (~mask_reg)))
{
en_flag = FALSE;
}
}
/*0x23[3] cfg_erramp_pd 0-enable 1-disable */
if(en_flag)
{
mask_reg = 0xf7;
ctc_dkit_serdes_para.addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if(0 != (ctc_dkit_serdes_para.data & (~mask_reg)))
{
en_flag = FALSE;
}
}
/*0x22[4:0] cfg_dfetap_en 5'h1f-enable 5'h0-disable */
if(en_flag)
{
mask_reg = 0xe0;
ctc_dkit_serdes_para.addr_offset = 0x22;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if(0 == (ctc_dkit_serdes_para.data & (~mask_reg)))
{
en_flag = FALSE;
}
}
/*0x1a[2] cfg_pi_dfe_en 1-enable 0-disable */
if(en_flag)
{
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x1a;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if(0 == (ctc_dkit_serdes_para.data & (~mask_reg)))
{
en_flag = FALSE;
}
}
/*Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaEnDfeDig 1-enable 0-disable*/
value = 0;
tbl_id = Hss12GLaneRxEqCfg0_t + hss_id * (Hss12GLaneRxEqCfg1_t - Hss12GLaneRxEqCfg0_t);
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
step = Hss12GLaneRxEqCfg0_cfgHssL1Pcs2PmaHoldDfe_f - Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f;
fld_id = Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaEnDfeDig_f + step * lane;
DRV_IOR_FIELD(lchip, tbl_id, fld_id, &value, &rx_eq_cfg);
if(en_flag)
{
if(0 == value)
{
en_flag = FALSE;
}
}
/*0x31[2] cfg_rstn_dfedig_gen1 1-enable 0-disable */
if(en_flag)
{
mask_reg = 0xfb;
ctc_dkit_serdes_para.addr_offset = 0x31;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
if(0 == (ctc_dkit_serdes_para.data & (~mask_reg)))
{
en_flag = FALSE;
}
}
p_serdes_para->para[0] = en_flag ? CTC_DKIT_SERDIS_CTL_DFE_ON : CTC_DKIT_SERDIS_CTL_DFE_OFF;
/*tap 1*/
ctc_dkit_serdes_para.addr_offset = 0xc5;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x3f & ctc_dkit_serdes_para.data;
p_serdes_para->para[1] = value;
/*tap 2*/
ctc_dkit_serdes_para.addr_offset = 0xc6;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x1f & ctc_dkit_serdes_para.data;
p_serdes_para->para[1] |= (value<<8);
/*tap 3*/
ctc_dkit_serdes_para.addr_offset = 0xc7;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x0f & ctc_dkit_serdes_para.data;
p_serdes_para->para[1] |= (value<<16);
/*tap 4*/
ctc_dkit_serdes_para.addr_offset = 0xc8;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x0f & ctc_dkit_serdes_para.data;
p_serdes_para->para[1] |= (value<<24);
/*tap 5*/
ctc_dkit_serdes_para.addr_offset = 0xc9;
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_para);
value = 0x0f & ctc_dkit_serdes_para.data;
p_serdes_para->para[2] = value;
}
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_12g_eye(ctc_dkit_serdes_wr_t* p_ctc_dkit_serdes_para, ctc_dkit_serdes_ctl_para_t* p_serdes_para,
uint8 height_flag, uint8 center_flag, uint32 times, uint32* p_rslt_sum)
{
uint32 val_0x23 = 0; //save 0x23 value
uint16 mask_0x23 = 0x0d; //bit 0, 2, 3
uint32 val_0x1a = 0; //save 0x1a value
uint16 mask_0x1a = 0x4; //bit 2
uint16 mask_reg = 0;
uint32 val_isc = 0;
uint8 lchip = 0;
uint16 data = 0;
uint32 proc_wait = 1000;
uint32 cmd = 0;
uint8 step = 0;
uint32 tbl_id = 0;
uint32 fld_id = 0;
uint8 hss_id = CTC_DKIT_MAP_SERDES_TO_HSSID(p_serdes_para->serdes_id);
uint8 lane = CTC_DKIT_MAP_SERDES_TO_LANE_ID(p_serdes_para->serdes_id);
uint32 val_don = 0;
uint32 val_ret[3]= {0};
int32 ret = 0;
uint32 lock_id = DRV_MCU_LOCK_EYE_SCAN_0 + lane;
Hss12GIscanMon0_m isc_mon;
Hss12GLaneRxEqCfg0_m rx_eq_cfg;
ret = drv_usw_mcu_lock(lchip, lock_id, hss_id);
if(0 != ret)
{
CTC_DKIT_PRINT("Get lock error (eye scan)! hss_id=%u, lane=%u\n", hss_id, lane);
return CLI_ERROR;
}
/*
1. 0x94[4] r_iscan_reg write 1
2. 0x2b[4] hwt_fom_sel write 0
2a. 0x49[4] cfg_figmerit_sel 0~central phase 1~all phase
2b. 0x2b[6] cfg_man_volt_en
2c. 0x2c[4] cfg_os_man_en
*/
/*1. 0x94[4] r_iscan_reg write 1*/
mask_reg = 0xef;
p_ctc_dkit_serdes_para->addr_offset = 0x94;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x10);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*2. 0x2b[4] hwt_fom_sel write 0*/
mask_reg = 0xef;
p_ctc_dkit_serdes_para->addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*2a. 0x49[4] cfg_figmerit_sel 0~central phase 1~all phase*/
mask_reg = 0xef;
p_ctc_dkit_serdes_para->addr_offset = 0x49;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
if(center_flag)
{
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x00);
}
else
{
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x10);
}
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
if(TRUE == height_flag)
{
/*2b. 0x2b[6] cfg_man_volt_en*/
mask_reg = 0xbf;
p_ctc_dkit_serdes_para->addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*2c. 0x2c[4] cfg_os_man_en*/
mask_reg = 0xef;
p_ctc_dkit_serdes_para->addr_offset = 0x2c;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
}
else
{
/*2b. 0x2b[6] cfg_man_volt_en*/
mask_reg = 0xbf;
p_ctc_dkit_serdes_para->addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x40);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*2c. 0x2c[4] cfg_os_man_en*/
mask_reg = 0xef;
p_ctc_dkit_serdes_para->addr_offset = 0x2c;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x10);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
}
/*
read procedure
0. write Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaHoldDfe value 1
1. 0x2b[1] cfg_iscan_sel write 1
2. DFE related reg 0x23 0x1a save
2a. wait > 100ns
3. 0x2b[0] cfg_iscan_en write 1
4. wait Hss12GIscanMon[0~2].monHssL[0~7]IscanDone jumps to 1
5. read Hss12GIscanMon[0~2].monHssL[0~7]IscanResults to get value
5. write Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaHoldDfe value 0
*/
/*0. write Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaHoldDfe value 1*/
val_isc = 1;
tbl_id = Hss12GLaneRxEqCfg0_t + hss_id * (Hss12GLaneRxEqCfg1_t - Hss12GLaneRxEqCfg0_t);
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
step = Hss12GLaneRxEqCfg0_cfgHssL1Pcs2PmaHoldDfe_f - Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f;
fld_id = Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f + step * lane;
DRV_IOW_FIELD(lchip, tbl_id, fld_id, &val_isc, &rx_eq_cfg);
cmd = DRV_IOW(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
/*1. 0x2b[1] cfg_iscan_sel write 1*/
mask_reg = 0xfd;
p_ctc_dkit_serdes_para->addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x02);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*2. DFE related reg*/
p_ctc_dkit_serdes_para->addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
val_0x23 = (mask_0x23 & p_ctc_dkit_serdes_para->data);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & (~mask_0x23)) | 0x4);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->addr_offset = 0x1a;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
val_0x1a = (mask_0x1a & p_ctc_dkit_serdes_para->data);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & (~mask_0x1a)) | 0x4);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
sal_task_sleep(1);
/*3. 0x2b[0] cfg_iscan_en write 1*/
mask_reg = 0xfe;
p_ctc_dkit_serdes_para->addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x01);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*4. wait Hss12GIscanMon[0~2].monHssL[0~7]IscanDone jumps to 1*/
tbl_id = Hss12GIscanMon0_t + hss_id * (Hss12GIscanMon1_t - Hss12GIscanMon0_t);
step = Hss12GIscanMon0_monHssL1IscanDone_f - Hss12GIscanMon0_monHssL0IscanDone_f;
fld_id = Hss12GIscanMon0_monHssL0IscanDone_f + step * lane;
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
while(--proc_wait)
{
DRV_IOCTL(lchip, 0, cmd, &isc_mon);
DRV_IOR_FIELD(lchip, tbl_id, fld_id, &val_don, &isc_mon);
if(val_don)
{
break;
}
sal_task_sleep(5);
}
if(0 == proc_wait)
{
CTC_DKIT_PRINT("Get eye diagram result timeout!\n");
}
/*5. read Hss12GIscanMon[0~2].monHssL[0~7]IscanResults to get value*/
fld_id = Hss12GIscanMon0_monHssL0IscanResults_f + step * lane;
DRV_IOR_FIELD(lchip, tbl_id, fld_id, val_ret, &isc_mon);
if(val_ret[2])
{
CTC_DKIT_PRINT("Error %u\n", val_ret[2]);
}
/*
disable iscan
1. 0x2b[1] cfg_iscan_sel write 0
2. recover DFE related reg value
3. 0x2b[0] cfg_iscan_en write 0
4. write Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaHoldDfe value 0
*/
/*1. 0x2b[1] cfg_iscan_sel write 0*/
mask_reg = 0xfd;
p_ctc_dkit_serdes_para->addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*2. recover DFE related reg value*/
p_ctc_dkit_serdes_para->addr_offset = 0x23;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & (~mask_0x23)) | val_0x23);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->addr_offset = 0x1a;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & (~mask_0x1a)) | val_0x1a);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*3. 0x2b[0] cfg_iscan_en write 0*/
mask_reg = 0xfe;
p_ctc_dkit_serdes_para->addr_offset = 0x2b;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
p_ctc_dkit_serdes_para->data = ((p_ctc_dkit_serdes_para->data & mask_reg) | 0x00);
ctc_tm_dkit_misc_write_serdes(p_ctc_dkit_serdes_para);
/*4. write Hss12GLaneRxEqCfg[0~2].cfgHssL[0~7]Pcs2PmaHoldDfe value 0*/
val_isc = 0;
tbl_id = Hss12GLaneRxEqCfg0_t + hss_id * (Hss12GLaneRxEqCfg1_t - Hss12GLaneRxEqCfg0_t);
cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
step = Hss12GLaneRxEqCfg0_cfgHssL1Pcs2PmaHoldDfe_f - Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f;
fld_id = Hss12GLaneRxEqCfg0_cfgHssL0Pcs2PmaHoldDfe_f + step * lane;
DRV_IOW_FIELD(lchip, tbl_id, fld_id, &val_isc, &rx_eq_cfg);
cmd = DRV_IOW(tbl_id, DRV_ENTRY_FLAG);
DRV_IOCTL(lchip, 0, cmd, &rx_eq_cfg);
ret = drv_usw_mcu_unlock(lchip, lock_id, hss_id);
if (DRV_E_NONE != ret)
{
CTC_DKIT_PRINT("Get unlock error (eye scan)! hss_id=%u, lane=%u\n", hss_id, lane);
return CLI_ERROR;
}
if(TRUE == height_flag)
{
data = (uint16)(0x000000ff & val_ret[0]);
CTC_DKIT_PRINT(" %-10d%-10s%-10s%-10s%10d\n", times + 1, "-", "-", "-", data);
}
else
{
data = (uint16)(0x0000003f & val_ret[0]);
CTC_DKIT_PRINT(" %-10d%-10d%-10s%-10s%-10s%-10s\n", times + 1, data, "-", "-", "-", "-");
}
(*p_rslt_sum) += data;
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_28g_eye(ctc_dkit_serdes_wr_t* p_ctc_dkit_serdes_para, ctc_dkit_serdes_ctl_para_t* p_serdes_para,
uint32 times, uint32* p_rslt_sum)
{
uint32 data = 0;
int16 signed_data = 0;
int32 signed_data32 = 0;
uint32 mlt_factor = 1000;
uint8 dac = 0;
/*0x802a + 0x100*lane*/
p_ctc_dkit_serdes_para->addr_offset = 0x002a;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
signed_data = (p_ctc_dkit_serdes_para->data) & 0x7fff;
signed_data <<= 1;
signed_data >>= 1;
/*0x804c + 0x100*lane*/
p_ctc_dkit_serdes_para->addr_offset = 0x004c;
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
if((p_ctc_dkit_serdes_para->data) & (1<<7))
{
/* overwrite enabled 0x804f + 0x100*lane*/
p_ctc_dkit_serdes_para->addr_offset = 0x004f;
}
else
{
/* overwrite disabled 0x807f + 0x100*lane*/
p_ctc_dkit_serdes_para->addr_offset = 0x007f;
}
ctc_tm_dkit_misc_read_serdes(p_ctc_dkit_serdes_para);
dac = (uint8)(((p_ctc_dkit_serdes_para->data) >> 12) & 0xf);
signed_data32 = signed_data * mlt_factor;
data = (uint32)(signed_data32 / 2048 * (dac*50 + 200));
data /= mlt_factor;
CTC_DKIT_PRINT(" %-10d%-10s%-10s%-10s%10d\n", times + 1, "-", "-", "-", data);
(*p_rslt_sum) += data;
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_eye(ctc_dkit_serdes_ctl_para_t* p_serdes_para)
{
uint32 times = 0;
uint32 i = 0;
uint8 lchip = 0;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_para;
uint32 rslt_sum = 0;
DKITS_PTR_VALID_CHECK(p_serdes_para);
lchip = p_serdes_para->lchip;
CTC_DKIT_LCHIP_CHECK(lchip);
sal_memset(&ctc_dkit_serdes_para, 0, sizeof(ctc_dkit_serdes_wr_t));
times = p_serdes_para->para[1];
if (0 == times)
{
times = 10;
}
ctc_dkit_serdes_para.lchip = lchip;
ctc_dkit_serdes_para.serdes_id = p_serdes_para->serdes_id;
ctc_dkit_serdes_para.type = CTC_DKIT_SERDES_ALL;
if ((CTC_DKIT_SERDIS_EYE_HEIGHT == p_serdes_para->para[0])
|| (CTC_DKIT_SERDIS_EYE_ALL == p_serdes_para->para[0]))
{
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
CTC_DKIT_PRINT(" %-10s%-10s%-10s%-10s%s\n", "No.", "An", "Ap", "Amin", "EyeOpen");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
if(CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id))
{
for (i = 0; i < times; i++)
{
_ctc_tm_dkit_misc_serdes_28g_eye(&ctc_dkit_serdes_para, p_serdes_para, i, &rslt_sum);
}
}
else
{
for (i = 0; i < times; i++)
{
_ctc_tm_dkit_misc_serdes_12g_eye(&ctc_dkit_serdes_para, p_serdes_para, TRUE,
((CTC_DKIT_EYE_METRIC_PRECISION_TYPE_E6 == p_serdes_para->precision) ? TRUE : FALSE),
i, &rslt_sum);
}
}
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
CTC_DKIT_PRINT(" %-10s%-10s%-10s%-10s%10d\n","Avg", "-", "-", "-", (rslt_sum/times));
}
if ((CTC_DKIT_SERDIS_EYE_WIDTH == p_serdes_para->para[0])
|| (CTC_DKIT_SERDIS_EYE_ALL == p_serdes_para->para[0]))
{
rslt_sum = 0;
CTC_DKIT_PRINT("\n Eye width measure\n");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
CTC_DKIT_PRINT(" %-10s%-10s%-10s%-10s%-10s%s\n", "No.", "Width", "Az", "Oes", "Ols", "DeducedWidth");
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
if(CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id))
{
CTC_DKIT_PRINT(" Feature not support!\n");
}
else
{
for (i = 0; i < times; i++)
{
_ctc_tm_dkit_misc_serdes_12g_eye(&ctc_dkit_serdes_para, p_serdes_para, FALSE,
((CTC_DKIT_EYE_METRIC_PRECISION_TYPE_E6 == p_serdes_para->precision) ? TRUE : FALSE),
i, &rslt_sum);
}
CTC_DKIT_PRINT(" ---------------------------------------------------------------\n");
CTC_DKIT_PRINT(" %-10s%-10d%-10s%-10s%-10s%-10s\n\n", "Avg", (rslt_sum/times), "-", "-", "-", "-");
}
}
else if(CTC_DKIT_SERDIS_EYE_HEIGHT != p_serdes_para->para[0])
{
CTC_DKIT_PRINT(" Feature not support!\n");
}
return CLI_SUCCESS;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(uint16* tap_count, uint8 tap_id)
{
uint8 tap_best = 0;
uint8 i = 0;
uint16 tap_count_equal[TAP_MAX_VALUE] = {0};
uint16 tap_count_num = 0;
uint8 min = 0,max = 0;
uint8 count_valid = 0;
if (0 == tap_id)
{
min = 0;
max = 10;
}
else if (1 == tap_id)
{
min = 40;
max = TAP_MAX_VALUE - 1;
}
else if (2 == tap_id)
{
min = 0;
max = 20;
}
for (i = min; i <= max; i++)
{
if (tap_count[i] != 0)
{
tap_best = (tap_count[i] >= tap_count[tap_best])? i : tap_best;
count_valid = 1;
}
}
if (0 == count_valid)
{
return 0xFF;
}
for (i = 0; i < TAP_MAX_VALUE; i++)
{
if (tap_count[tap_best] == tap_count[i])
{
tap_count_equal[tap_count_num++] = i;
}
}
tap_best = tap_count_equal[tap_count_num / 2];
return tap_best;
}
STATIC int32
_ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(uint16* tap_count, uint8 tap_id)
{
uint8 tap_best = 0;
uint8 i = 0;
uint16 tap_count_equal[TAP_MAX_VALUE] = {0};
uint16 tap_count_num = 0;
uint8 min = 0,max = 0;
uint8 count_valid = 0;
if (0 == tap_id)
{
min = 0;
max = 5;
}
else if (1 == tap_id)
{
min = 0;
max = 15;
}
else if (2 == tap_id)
{
min = 30;
max = TAP_MAX_VALUE - 1;
}
else if (3 == tap_id)
{
min = 0;
max = 10;
}
for (i = min; i <= max; i++)
{
if (tap_count[i] != 0)
{
tap_best = (tap_count[i] >= tap_count[tap_best])? i : tap_best;
count_valid = 1;
}
}
if (0 == count_valid)
{
return 0xFF;
}
for (i = 0; i < TAP_MAX_VALUE; i++)
{
if (tap_count[tap_best] == tap_count[i])
{
tap_count_equal[tap_count_num++] = i;
}
}
tap_best = tap_count_equal[tap_count_num / 2];
return tap_best;
}
/*
28G:
Coeff Register Name Address
C0 TX_FIR_POST_3 8za4h[13:8]
C1 TX_FIR_POST_2 8za5h[13:8]
C2 TX_FIR_POST_1 8za6h[13:8]
C3 TX_FIR_MAIN 8za7h[13:8]
C4 TX_FIR_PRECURSOR 8za8h[13:8]
12G:
Coeff Register Name Address
C0 cfg_itx_ipdriver_base[2:0] 33h[2:0]
C1 cfg_ibias_tune_reserve[5:0] 52h[5:0]
C2 pcs_tap_adv[4:0] 03h[4:0]
C3 pcs_tap_dly[4:0] 04h[4:0]
*/
STATIC int32
_ctc_tm_dkit_misc_serdes_ffe_scan(void* p_para)
{
uint8 lchip = 0;
uint16 tap0 = 0;
uint16 tap1 = 0;
uint16 tap2 = 0;
uint16 tap3 = 0;
uint16 tap4 = 0;
uint16 tap0_best = 0;
uint16 tap1_best = 0;
uint16 tap2_best = 0;
uint16 tap3_best = 0;
uint16 tap4_best = 0;
uint16 tap0_count[TAP_MAX_VALUE] = {0};
uint16 tap1_count[TAP_MAX_VALUE] = {0};
uint16 tap2_count[TAP_MAX_VALUE] = {0};
uint16 tap3_count[TAP_MAX_VALUE] = {0};
uint16 tap4_count[TAP_MAX_VALUE] = {0};
uint32 tap_sum_thrd = 0;
uint8 is_hss15g = 0;
uint8 pattern = 0;
uint32 delay = 0;
bool pass = FALSE;
sal_file_t p_file = NULL;
sal_time_t tv;
char* p_time_str = NULL;
uint8 i = 0;
int32 ret = CLI_SUCCESS;
char* pattern_desc[PATTERN_NUM] = {"PRBS7+","PRBS7-","PRBS15+","PRBS15-","PRBS23+","PRBS23-","PRBS31+","PRBS31-", "PRBS9", "PRBS11"};
ctc_dkit_serdes_ctl_para_t serdes_para_prbs;
ctc_dkit_serdes_wr_t ctc_dkit_serdes_wr;
ctc_dkit_serdes_ctl_para_t* p_serdes_para = (ctc_dkit_serdes_ctl_para_t*)p_para;
is_hss15g = !CTC_DKIT_SERDES_IS_HSS28G(p_serdes_para->serdes_id);
lchip = p_serdes_para->lchip;
sal_memset(&ctc_dkit_serdes_wr, 0, sizeof(ctc_dkit_serdes_wr_t));
pattern = (uint8)p_serdes_para->para[1];
if(pattern > 8)
{
pattern++;
}
tap_sum_thrd = p_serdes_para->para[2];
delay = p_serdes_para->para[3];
if (p_serdes_para->serdes_id == p_serdes_para->para[0])
{
CTC_DKIT_PRINT("Source serdes should not equal to dest serdes!!!\n");
return CLI_ERROR;
}
if ((p_serdes_para->ffe.coefficient0_min > p_serdes_para->ffe.coefficient0_max)
|| (p_serdes_para->ffe.coefficient1_min > p_serdes_para->ffe.coefficient1_max)
|| (p_serdes_para->ffe.coefficient2_min > p_serdes_para->ffe.coefficient2_max)
|| (p_serdes_para->ffe.coefficient3_min > p_serdes_para->ffe.coefficient3_max)
|| (p_serdes_para->ffe.coefficient4_min > p_serdes_para->ffe.coefficient4_max))
{
CTC_DKIT_PRINT("Invalid ffe para!!!\n");
return CLI_ERROR;
}
if(is_hss15g)
{
if ((p_serdes_para->ffe.coefficient0_max > 7)
|| (p_serdes_para->ffe.coefficient1_max >= TAP_MAX_VALUE)
|| (p_serdes_para->ffe.coefficient2_max > 31)
|| (p_serdes_para->ffe.coefficient3_max > 31))
{
CTC_DKIT_PRINT("Invalid ffe para!!!\n");
return CLI_ERROR;
}
}
else
{
if ((p_serdes_para->ffe.coefficient0_max >= TAP_MAX_VALUE)
|| (p_serdes_para->ffe.coefficient1_max >= TAP_MAX_VALUE)
|| (p_serdes_para->ffe.coefficient2_max >= TAP_MAX_VALUE)
|| (p_serdes_para->ffe.coefficient3_max >= TAP_MAX_VALUE)
|| (p_serdes_para->ffe.coefficient4_max >= TAP_MAX_VALUE))
{
CTC_DKIT_PRINT("Invalid ffe para!!!\n");
return CLI_ERROR;
}
}
if (pattern > (PATTERN_NUM-1))
{
CTC_DKIT_PRINT("PRBS pattern is invalid!!!\n");
return CLI_ERROR;
}
if (0 != p_serdes_para->str[0])
{
p_file = sal_fopen(p_serdes_para->str, "wt");
if (!p_file)
{
CTC_DKIT_PRINT("Open file %s fail!!!\n", p_serdes_para->str);
return CLI_ERROR;
}
}
/*get systime*/
sal_time(&tv);
p_time_str = sal_ctime(&tv);
CTC_DKITS_PRINT_FILE(p_file, "Serdes %d %s FFE scan record, destination serdes %d, %s\n",
p_serdes_para->serdes_id, pattern_desc[p_serdes_para->para[1]], p_serdes_para->para[0], p_time_str);
if (is_hss15g)/************************************ hss15g *******************************************/
{
ctc_dkit_serdes_wr.lchip = p_serdes_para->lchip;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
ctc_dkit_serdes_wr.serdes_id = p_serdes_para->serdes_id;
CTC_DKITS_PRINT_FILE(p_file, "--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
/*for tap0*/
for (tap0 = p_serdes_para->ffe.coefficient0_min; tap0 <= p_serdes_para->ffe.coefficient0_max; tap0++)
{
for (tap1 = p_serdes_para->ffe.coefficient1_min; tap1 <= p_serdes_para->ffe.coefficient1_max; tap1++)
{
for (tap2 = p_serdes_para->ffe.coefficient2_min; tap2 <= p_serdes_para->ffe.coefficient2_max; tap2++)
{
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
if (tap0 + tap1 + tap2 + tap3 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0x33; /* C0 cfg_itx_ipdriver_base[2:0] 33h[2:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xf8) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x52; /* C1 cfg_ibias_tune_reserve[5:0] 52h[5:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x03; /* C2 pcs_tap_adv[4:0] 03h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x04; /* C3 pcs_tap_dly[4:0] 04h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Pass");
tap0_count[tap0]++;
tap1_count[tap1]++;
tap2_count[tap2]++;
tap3_count[tap3]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap0-------\n");
tap0_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap0_count, 0);
tap1_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap1_count, 1);
tap2_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap2_count, 2);
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap3_count, 3);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "----------------Count-----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n","No.", "C0", "C1", "C2", "C3");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < 8; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d\n", i, tap0_count[i], tap1_count[i], tap2_count[i], tap3_count[i]);
}
for (; i < 32; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10s%-10d%-10d%-10d\n", i, "-", tap1_count[i], tap2_count[i], tap3_count[i]);
}
for (; i < 64; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10s%-10d%-10s%-10s\n", i, "-", tap1_count[i], "-", "-");
}
/*for tap1*/
CTC_DKITS_PRINT_FILE(p_file, "\n--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
sal_memset(tap1_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap2_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap3_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
tap0 = tap0_best;
for (tap1 = p_serdes_para->ffe.coefficient1_min; tap1 <= p_serdes_para->ffe.coefficient1_max; tap1++)
{
for (tap2 = p_serdes_para->ffe.coefficient2_min; tap2 <= p_serdes_para->ffe.coefficient2_max; tap2++)
{
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
if (tap0 + tap1 + tap2 + tap3 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0x33; /* C0 cfg_itx_ipdriver_base[2:0] 33h[2:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xf8) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x52; /* C1 cfg_ibias_tune_reserve[5:0] 52h[5:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x03; /* C2 pcs_tap_adv[4:0] 03h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x04; /* C3 pcs_tap_dly[4:0] 04h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Pass");
tap1_count[tap1]++;
tap2_count[tap2]++;
tap3_count[tap3]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap1-------\n");
tap1_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap1_count, 1);
tap2_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap2_count, 2);
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap3_count, 3);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "----------------Count-----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n","No.", "C0", "C1", "C2", "C3");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < 32; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10s%-10d%-10d%-10d\n", i, "-", tap1_count[i], tap2_count[i], tap3_count[i]);
}
for (; i < 64; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10s%-10d%-10s%-10s\n", i, "-", tap1_count[i], "-", "-");
}
/*for tap2*/
CTC_DKITS_PRINT_FILE(p_file, "\n--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
sal_memset(tap2_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap3_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
tap0 = tap0_best;
tap1 = tap1_best;
for (tap2 = p_serdes_para->ffe.coefficient2_min; tap2 <= p_serdes_para->ffe.coefficient2_max; tap2++)
{
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
if (tap0 + tap1 + tap2 + tap3 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0x33; /* C0 cfg_itx_ipdriver_base[2:0] 33h[2:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xf8) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x52; /* C1 cfg_ibias_tune_reserve[5:0] 52h[5:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x03; /* C2 pcs_tap_adv[4:0] 03h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x04; /* C3 pcs_tap_dly[4:0] 04h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Pass");
tap2_count[tap2]++;
tap3_count[tap3]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap2-------\n");
tap2_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap2_count, 2);
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap3_count, 3);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "\n--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < 32; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10s%-10s%-10d%-10d\n", i, "-", "-", tap2_count[i], tap3_count[i]);
}
/*for tap3*/
CTC_DKITS_PRINT_FILE(p_file, "\n--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
sal_memset(tap3_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
tap0 = tap0_best;
tap1 = tap1_best;
tap2 = tap2_best;
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
if (tap0 + tap1 + tap2 + tap3 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0x33; /* C0 cfg_itx_ipdriver_base[2:0] 33h[2:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xf8) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x52; /* C1 cfg_ibias_tune_reserve[5:0] 52h[5:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x03; /* C2 pcs_tap_adv[4:0] 03h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0x04; /* C3 pcs_tap_dly[4:0] 04h[4:0] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xe0) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Pass");
tap3_count[tap3]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap3-------\n");
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_12g_best_tap(tap3_count, 3);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "\n--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < 32; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10s%-10s%-10s%-10d\n", i, "-", "-", "-", tap3_count[i]);
}
CTC_DKITS_PRINT_FILE(p_file, "\n--------------Scan result-------------\n");
CTC_DKIT_PRINT( "C0: %5d\n", tap0_best);
CTC_DKIT_PRINT( "C1: %5d\n", tap1_best);
CTC_DKIT_PRINT( "C2: %5d\n", tap2_best);
CTC_DKIT_PRINT( "C3: %5d\n", tap3_best);
}
else /************************************ hss28g *******************************************/
{
ctc_dkit_serdes_wr.lchip = p_serdes_para->lchip;
ctc_dkit_serdes_wr.type = CTC_DKIT_SERDES_ALL;
ctc_dkit_serdes_wr.serdes_id = p_serdes_para->serdes_id;
CTC_DKITS_PRINT_FILE(p_file, "--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "C4", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
/*for tap0*/
for (tap0 = p_serdes_para->ffe.coefficient0_min; tap0 <= p_serdes_para->ffe.coefficient0_max; tap0++)
{
for (tap1 = p_serdes_para->ffe.coefficient1_min; tap1 <= p_serdes_para->ffe.coefficient1_max; tap1++)
{
for (tap2 = p_serdes_para->ffe.coefficient2_min; tap2 <= p_serdes_para->ffe.coefficient2_max; tap2++)
{
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
for (tap4 = p_serdes_para->ffe.coefficient4_min; tap4 <= p_serdes_para->ffe.coefficient4_max; tap4++)
{
if (tap0 + tap1 + tap2 + tap3 + tap4 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0xa7; /* C0 TX_FIR_MAIN 8za7h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa8; /* C1 TX_FIR_PRECURSOR 8za8h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa6; /* C2 TX_FIR_POST_1 8za6h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa5; /* C3 TX_FIR_POST_2 8za5h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa4; /* C4 TX_FIR_POST_3 8za4h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap4;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Pass");
tap0_count[tap0]++;
tap1_count[tap1]++;
tap2_count[tap2]++;
tap3_count[tap3]++;
tap4_count[tap4]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
}
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap0-------\n");
tap0_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap0_count, 0);
tap1_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap1_count, 1);
tap2_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap2_count, 2);
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap3_count, 3);
tap4_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap4_count, 4);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "C4: %5d, count: %d\n", tap4_best, tap4_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "----------------Count-----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n","No.", "C0", "C1", "C2", "C3", "C4");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < TAP_MAX_VALUE; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10d\n", i, tap0_count[i], tap1_count[i], tap2_count[i], tap3_count[i], tap4_count[i]);
}
/*for tap1*/
CTC_DKITS_PRINT_FILE(p_file, "--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "C4", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
sal_memset(tap1_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap2_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap3_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap4_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
tap0 = tap0_best;
for (tap1 = p_serdes_para->ffe.coefficient1_min; tap1 <= p_serdes_para->ffe.coefficient1_max; tap1++)
{
for (tap2 = p_serdes_para->ffe.coefficient2_min; tap2 <= p_serdes_para->ffe.coefficient2_max; tap2++)
{
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
for (tap4 = p_serdes_para->ffe.coefficient4_min; tap4 <= p_serdes_para->ffe.coefficient4_max; tap4++)
{
if (tap0 + tap1 + tap2 + tap3 + tap4 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0xa7; /* C0 TX_FIR_MAIN 8za7h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa8; /* C1 TX_FIR_PRECURSOR 8za8h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa6; /* C2 TX_FIR_POST_1 8za6h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa5; /* C3 TX_FIR_POST_2 8za5h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa4; /* C4 TX_FIR_POST_3 8za4h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap4;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Pass");
tap1_count[tap1]++;
tap2_count[tap2]++;
tap3_count[tap3]++;
tap4_count[tap4]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap1-------\n");
tap1_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap1_count, 1);
tap2_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap2_count, 2);
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap3_count, 3);
tap4_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap4_count, 4);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "C4: %5d, count: %d\n", tap4_best, tap4_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "----------------Count-----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n","No.", "C0", "C1", "C2", "C3", "C4");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < TAP_MAX_VALUE; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10d\n", i, tap0_count[i], tap1_count[i], tap2_count[i], tap3_count[i], tap4_count[i]);
}
/*for tap2*/
CTC_DKITS_PRINT_FILE(p_file, "--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "C4", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
sal_memset(tap2_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap3_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap4_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
tap0 = tap0_best;
tap1 = tap1_best;
for (tap2 = p_serdes_para->ffe.coefficient2_min; tap2 <= p_serdes_para->ffe.coefficient2_max; tap2++)
{
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
for (tap4 = p_serdes_para->ffe.coefficient4_min; tap4 <= p_serdes_para->ffe.coefficient4_max; tap4++)
{
if (tap0 + tap1 + tap2 + tap3 + tap4 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0xa7; /* C0 TX_FIR_MAIN 8za7h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa8; /* C1 TX_FIR_PRECURSOR 8za8h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa6; /* C2 TX_FIR_POST_1 8za6h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa5; /* C3 TX_FIR_POST_2 8za5h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa4; /* C4 TX_FIR_POST_3 8za4h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap4;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Pass");
tap1_count[tap1]++;
tap2_count[tap2]++;
tap3_count[tap3]++;
tap4_count[tap4]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap2-------\n");
tap2_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap2_count, 2);
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap3_count, 3);
tap4_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap4_count, 4);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "C4: %5d, count: %d\n", tap4_best, tap4_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "----------------Count-----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n","No.", "C0", "C1", "C2", "C3", "C4");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < TAP_MAX_VALUE; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10d\n", i, tap0_count[i], tap1_count[i], tap2_count[i], tap3_count[i], tap4_count[i]);
}
/*for tap3*/
CTC_DKITS_PRINT_FILE(p_file, "--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "C4", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
sal_memset(tap3_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
sal_memset(tap4_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
tap0 = tap0_best;
tap1 = tap1_best;
tap2 = tap2_best;
for (tap3 = p_serdes_para->ffe.coefficient3_min; tap3 <= p_serdes_para->ffe.coefficient3_max; tap3++)
{
for (tap4 = p_serdes_para->ffe.coefficient4_min; tap4 <= p_serdes_para->ffe.coefficient4_max; tap4++)
{
if (tap0 + tap1 + tap2 + tap3 + tap4 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0xa7; /* C0 TX_FIR_MAIN 8za7h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa8; /* C1 TX_FIR_PRECURSOR 8za8h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa6; /* C2 TX_FIR_POST_1 8za6h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa5; /* C3 TX_FIR_POST_2 8za5h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa4; /* C4 TX_FIR_POST_3 8za4h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap4;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Pass");
tap1_count[tap1]++;
tap2_count[tap2]++;
tap3_count[tap3]++;
tap4_count[tap4]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap3-------\n");
tap3_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap3_count, 3);
tap4_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap4_count, 4);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "C4: %5d, count: %d\n", tap4_best, tap4_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "----------------Count-----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n","No.", "C0", "C1", "C2", "C3", "C4");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < TAP_MAX_VALUE; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10d\n", i, tap0_count[i], tap1_count[i], tap2_count[i], tap3_count[i], tap4_count[i]);
}
/*for tap4*/
CTC_DKITS_PRINT_FILE(p_file, "--------------FFE scan----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n", "C0", "C1", "C2", "C3", "C4", "Result");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
sal_memset(tap4_count, 0, sizeof(uint16)*TAP_MAX_VALUE);
tap0 = tap0_best;
tap1 = tap1_best;
tap2 = tap2_best;
tap3 = tap3_best;
for (tap4 = p_serdes_para->ffe.coefficient4_min; tap4 <= p_serdes_para->ffe.coefficient4_max; tap4++)
{
if (tap0 + tap1 + tap2 + tap3 + tap4 <= tap_sum_thrd)
{
/*set ffe*/
ctc_dkit_serdes_wr.addr_offset = 0xa7; /* C0 TX_FIR_MAIN 8za7h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap0;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa8; /* C1 TX_FIR_PRECURSOR 8za8h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap1;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa6; /* C2 TX_FIR_POST_1 8za6h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap2;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa5; /* C3 TX_FIR_POST_2 8za5h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap3;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.addr_offset = 0xa4; /* C4 TX_FIR_POST_3 8za4h[13:8] */
ctc_tm_dkit_misc_read_serdes(&ctc_dkit_serdes_wr);
ctc_dkit_serdes_wr.data = (ctc_dkit_serdes_wr.data & 0xc0ff) | tap4;
ctc_tm_dkit_misc_write_serdes(&ctc_dkit_serdes_wr);
/*enable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_ENABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
/*check rx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->para[0];
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_CEHCK;
serdes_para_prbs.para[1] = pattern;
serdes_para_prbs.para[3] = delay;
ret = _ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
if (CLI_ERROR == ret)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Not Sync");
}
else if (pass)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Pass");
tap1_count[tap1]++;
tap2_count[tap2]++;
tap3_count[tap3]++;
tap4_count[tap4]++;
}
else
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10s\n", tap0, tap1, tap2, tap3, tap4, "Fail");
}
/*disable tx*/
sal_memset(&serdes_para_prbs, 0, sizeof(ctc_dkit_serdes_ctl_para_t));
serdes_para_prbs.serdes_id = p_serdes_para->serdes_id;
serdes_para_prbs.para[0] = CTC_DKIT_SERDIS_CTL_DISABLE;
serdes_para_prbs.para[1] = pattern;
_ctc_tm_dkit_misc_do_serdes_prbs(&serdes_para_prbs, &pass);
}
}
CTC_DKITS_PRINT_FILE(p_file, "-------Check best value of tap4-------\n");
tap4_best = _ctc_tm_dkit_misc_serdes_ffe_get_28g_best_tap(tap4_count, 4);
CTC_DKITS_PRINT_FILE(p_file, "C0: %5d, count: %d\n", tap0_best, tap0_count[tap0_best]);
CTC_DKITS_PRINT_FILE(p_file, "C1: %5d, count: %d\n", tap1_best, tap1_count[tap1_best]);
CTC_DKITS_PRINT_FILE(p_file, "C2: %5d, count: %d\n", tap2_best, tap2_count[tap2_best]);
CTC_DKITS_PRINT_FILE(p_file, "C3: %5d, count: %d\n", tap3_best, tap3_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "C4: %5d, count: %d\n", tap4_best, tap4_count[tap3_best]);
CTC_DKITS_PRINT_FILE(p_file, "----------------Count-----------------\n");
CTC_DKITS_PRINT_FILE(p_file, "%-10s%-10s%-10s%-10s%-10s%-10s\n","No.", "C0", "C1", "C2", "C3", "C4");
CTC_DKITS_PRINT_FILE(p_file, "--------------------------------------\n");
for (i = 0; i < TAP_MAX_VALUE; i++)
{
CTC_DKITS_PRINT_FILE(p_file, "%-10d%-10d%-10d%-10d%-10d%-10d\n", i, tap0_count[i], tap1_count[i], tap2_count[i], tap3_count[i], tap4_count[i]);
}
CTC_DKITS_PRINT_FILE(p_file, "\n--------------Scan result-------------\n");
CTC_DKIT_PRINT( "C0: %5d\n", tap0_best);
CTC_DKIT_PRINT( "C1: %5d\n", tap1_best);
CTC_DKIT_PRINT( "C2: %5d\n", tap2_best);
CTC_DKIT_PRINT( "C3: %5d\n", tap3_best);
CTC_DKIT_PRINT( "C4: %5d\n", tap4_best);
}
return ret;
}
int32
ctc_tm_dkit_misc_serdes_ctl(void* p_para)
{
ctc_dkit_serdes_ctl_para_t* p_serdes_para = (ctc_dkit_serdes_ctl_para_t*)p_para;
DKITS_PTR_VALID_CHECK(p_serdes_para);
CTC_DKIT_LCHIP_CHECK(p_serdes_para->lchip);
DRV_INIT_CHECK(p_serdes_para->lchip);
switch (p_serdes_para->type)
{
case CTC_DKIT_SERDIS_CTL_LOOPBACK:
_ctc_tm_dkit_misc_serdes_loopback(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_PRBS:
_ctc_tm_dkit_misc_serdes_prbs(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_EYE:
_ctc_tm_dkit_misc_serdes_eye(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_FFE:
_ctc_tm_dkit_misc_serdes_ffe_scan(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_STATUS:
_ctc_tm_dkit_misc_serdes_status(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_POLR_CHECK:
_ctc_tm_dkit_misc_serdes_polr_check(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_DFE:
_ctc_tm_dkit_misc_serdes_dfe_set_en(p_serdes_para);
break;
case CTC_DKIT_SERDIS_CTL_GET_DFE:
_ctc_tm_dkit_misc_serdes_dfe_get_val(p_serdes_para);
break;
default:
break;
}
return CLI_SUCCESS;
}
| [
"zhwwan@gmail.com"
] | zhwwan@gmail.com |
8b4f08c1721e209f3c2867b546af1a65a348a04e | 576cb82b7d2a0d2bd0ec6fcf0ed3253024d81c96 | /rf/zb/hdr/zb_aps.h | 0e536d680e541200a6eba727b38efbee4cc553c5 | [
"MIT"
] | permissive | Youngho-Oh/Airmail | 3886905ef39f8950142466de8d4452406715affe | 643c949e72db33bcb25f188ea35051422c88cc0c | refs/heads/master | 2021-06-07T01:33:28.000778 | 2021-03-01T11:58:15 | 2021-03-01T11:58:15 | 145,212,320 | 2 | 1 | null | null | null | null | UTF-8 | C | false | false | 25,876 | h | /***************************************************************************
* ZBOSS ZigBee Pro 2007 stack *
* *
* Copyright (c) 2012 DSR Corporation Denver CO, USA. *
* http://www.dsr-wireless.com *
* *
* All rights reserved. *
* Copyright (c) 2011 ClarIDy Solutions, Inc., Taipei, Taiwan. *
* http://www.claridy.com/ *
* *
* Copyright (c) 2011 Uniband Electronic Corporation (UBEC), *
* Hsinchu, Taiwan. *
* http://www.ubec.com.tw/ *
* *
* Copyright (c) 2011 DSR Corporation Denver CO, USA. *
* http://www.dsr-wireless.com *
* *
* All rights reserved. *
* *
* *
* ZigBee Pro 2007 stack, also known as ZBOSS (R) ZB stack is available *
* under either the terms of the Commercial License or the GNU General *
* Public License version 2.0. As a recipient of ZigBee Pro 2007 stack, you*
* may choose which license to receive this code under (except as noted in *
* per-module LICENSE files). *
* *
* ZBOSS is a registered trademark of DSR Corporation AKA Data Storage *
* Research LLC. *
* *
* GNU General Public License Usage *
* This file may be used under the terms of the GNU General Public License *
* version 2.0 as published by the Free Software Foundation and appearing *
* in the file LICENSE.GPL included in the packaging of this file. Please *
* review the following information to ensure the GNU General Public *
* License version 2.0 requirements will be met: *
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. *
* *
* Commercial Usage *
* Licensees holding valid ClarIDy/UBEC/DSR Commercial licenses may use *
* this file in accordance with the ClarIDy/UBEC/DSR Commercial License *
* Agreement provided with the Software or, alternatively, in accordance *
* with the terms contained in a written agreement between you and *
* ClarIDy/UBEC/DSR. *
* *
****************************************************************************
PURPOSE: APS layer API
*/
#ifndef ZB_APS_H
#define ZB_APS_H 1
/*! \addtogroup aps_api */
/*! @{ */
#include "rf/zb/hdr/zb_types.h"
/**
APS addressing mode constants
*/
enum zb_aps_addr_mode_e
{
ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT = 0, /*!< 0x00 = DstAddress and
* DstEndpoint not present */
ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT = 1, /*!< 0x01 = 16-bit group
* address for DstAddress;
* DstEndpoint not present */
ZB_APS_ADDR_MODE_16_ENDP_PRESENT = 2, /*!< 0x02 = 16-bit address for DstAddress and
DstEndpoint present */
ZB_APS_ADDR_MODE_64_ENDP_PRESENT = 3 /*!< 0x03 = 64-bit extended address for
DstAddress and DstEndpoint present */
};
#define ZB_MIN_ENDPOINT_NUMBER 1
#define ZB_MAX_ENDPOINT_NUMBER 240
typedef enum zb_aps_status_e
{
ZB_APS_STATUS_SUCCESS = 0x00, /*!< A request has been executed
* successfully. */
ZB_APS_STATUS_INVALID_BINDING = 0xa4, /*!< An APSME-UNBIND.request failed due to
the requested binding link not existing in the
binding table. */
ZB_APS_STATUS_INVALID_GROUP = 0xa5, /*!< An APSME-REMOVE-GROUP.request has
been issued with a group identifier that does
not appear in the group table. */
ZB_APS_STATUS_INVALID_PARAMETER = 0xa6, /*!< A parameter value was invalid or out of
range.
ZB_APS_STATUS_NO_ACK 0xa7 An APSDE-DATA.request requesting
acknowledged transmission failed due to no
acknowledgement being received. */
ZB_APS_STATUS_NO_BOUND_DEVICE = 0xa8, /*!< An APSDE-DATA.request with a destination
addressing mode set to 0x00 failed due to
there being no devices bound to
this device. */
ZB_APS_STATUS_NO_SHORT_ADDRESS = 0xa9, /*!< An APSDE-DATA.request with a destination
addressing mode set to 0x03 failed due to no
corresponding short address found in the
address map table. */
ZB_APS_STATUS_NOT_SUPPORTED = 0xaa, /*!< An APSDE-DATA.request with a destination
addressing mode set to 0x00 failed due to a
binding table not being supported on the
device. */
ZB_APS_STATUS_SECURED_LINK_KEY = 0xab, /*!< An ASDU was received that was secured
using a link key. */
ZB_APS_STATUS_SECURED_NWK_KEY = 0xac, /*!< An ASDU was received that was secured
using a network key. */
ZB_APS_STATUS_SECURITY_FAIL = 0xad, /*!< An APSDE-DATA.request requesting
security has resulted in an error during the
corresponding security
processing. */
ZB_APS_STATUS_TABLE_FULL = 0xae, /*!< An APSME-BIND.request or APSME.ADD-
GROUP.request issued when the binding or
group tables, respectively, were
full. */
ZB_APS_STATUS_UNSECURED = 0xaf, /*!< An ASDU was received without
* any security */
ZB_APS_STATUS_UNSUPPORTED_ATTRIBUTE = 0xb0 /*!< An APSME-GET.request or APSME-
SET.request has been issued with an
unknown attribute identifier. */
} zb_aps_status_t;
/**
APSDE data request structure.
This data structure passed to zb_apsde_data_request() in the packet buffer
(at its tail).
*/
typedef struct zb_apsde_data_req_s
{
union zb_addr_u dst_addr; /*!< Destination address */
zb_uint16_t profileid; /*!< The identifier of the profile for which this
frame is intended. */
zb_uint16_t clusterid; /*!< The identifier of the object for which this
frame is intended. */
zb_uint8_t dst_endpoint; /*!< either the number of the individual endpoint
of the entity to which the ASDU is being
transferred or the broadcast endpoint (0xff). */
zb_uint8_t src_endpoint; /*!< The individual endpoint of the entity from
which the ASDU is being transferred. */
zb_uint8_t radius; /*!< The distance, in hops, that a frame will be
* allowed to travel through the network. */
zb_uint8_t addr_mode; /*!< The type of destination address supplied by
the DstAddr parameter - @see zb_aps_addr_mode_e */
zb_uint8_t tx_options; /*!< The transmission options for the ASDU to be
transferred. These are a bitwise OR of one or
more of the following:
0x01 = Security enabled transmission
0x02 = Use NWK key
0x04 = Acknowledged transmission
0x08 = Fragmentation permitted.
\see zb_apsde_tx_opt_e
*/
} zb_apsde_data_req_t;
/**
APSME binding structure.
This data structure passed to zb_apsme_bind_request()
*/
typedef struct zb_apsme_binding_req_s
{
zb_ieee_addr_t src_addr; /*!< The source IEEE address for the binding entry. */
zb_uint8_t src_endpoint; /*!< The source endpoint for the binding entry. */
zb_uint16_t clusterid; /*!< The identifier of the cluster on the source
device that is to be bound to the destination device.*/
zb_uint8_t addr_mode; /*!< The type of destination address supplied by
the DstAddr parameter - @see zb_aps_addr_mode_e */
union zb_addr_u dst_addr; /*!< The destination address for the binding entry. */
zb_uint8_t dst_endpoint; /*!< This parameter will be present only if
the DstAddrMode parameter has a value of
0x03 and, if present, will be the
destination endpoint for the binding entry.*/
} zb_apsme_binding_req_t;
/**
Parsed APS header
This data structure passed to zb_aps_hdr_parse()
*/
typedef struct zb_aps_hdr_s
{
zb_uint8_t fc;
zb_uint16_t src_addr;
zb_uint16_t dst_addr;
zb_uint16_t group_addr;
zb_uint8_t dst_endpoint;
zb_uint8_t src_endpoint;
zb_uint16_t clusterid;
zb_uint16_t profileid;
zb_uint8_t aps_counter;
} ZB_PACKED_STRUCT zb_aps_hdr_t;
/**
Parameters of the APSDE-DATA.indication primitive.
*/
typedef zb_aps_hdr_t zb_apsde_data_indication_t;
/**
The transmission options for the ASDU to be
transferred. These are a bitwise OR of one or
more.
*/
enum zb_apsde_tx_opt_e
{
ZB_APSDE_TX_OPT_SECURITY_ENABLED = 1, /*!< 0x01 = Security enabled transmission */
ZB_APSDE_TX_OPT_USE_NWK_KEY = 2, /*!< 0x02 = Use NWK key */
ZB_APSDE_TX_OPT_ACK_TX = 4, /*!< 0x04 = Acknowledged transmission */
ZB_APSDE_TX_OPT_FRAG_PERMITTED = 8 /*!< 0x08 = Fragmentation permitted */
};
/**
NLDE-DATA.request primitive
This function can be called via scheduler, returns immediatly.
Later zb_nlde_data_confirm will be called to pass NLDE-DATA.request result up.
@param apsdu - packet to send (@see zb_buf_t) and parameters at buffer tail
\see zb_nlde_data_req_t
@b Example:
@code
{
zb_apsde_data_req_t *req;
zb_ushort_t i;
buf = ZB_BUF_FROM_REF(param);
ZB_BUF_INITIAL_ALLOC(buf, 10, ptr);
for (i = 0 ; i < 10 ; ++i)
{
ptr[i] = i % 32 + '0';
}
req = ZB_GET_BUF_TAIL(buf, sizeof(zb_apsde_data_req_t));
req->dst_addr.addr_short = 0; // ZC
req->addr_mode = ZB_APS_ADDR_MODE_16_ENDP_PRESENT;
req->tx_options = ZB_APSDE_TX_OPT_ACK_TX;
req->radius = 5;
req->profileid = 2;
req->src_endpoint = 10;
req->dst_endpoint = 10;
buf->u.hdr.handle = 0x11;
TRACE_MSG(TRACE_APS3, "Sending apsde_data.request", (FMT__0));
ZB_SCHEDULE_CALLBACK(zb_apsde_data_request, ZB_REF_FROM_BUF(buf));
}
@endcode
*/
void zb_apsde_data_request(zb_uint8_t param) ZB_CALLBACK;
/**
Remove APS header from the packet
@param packet - APS packet
@param ptr - (out) pointer to the APS data begin
@b Example:
@code
void data_indication(zb_uint8_t param)
{
zb_ushort_t i;
zb_uint8_t *ptr;
zb_buf_t *asdu = (zb_buf_t *)ZB_BUF_FROM_REF(param);
ptr = ZB_APS_HDR_CUT_P(asdu);
TRACE_MSG(TRACE_APS3, "data_indication: packet %p len %d handle 0x%x", (FMT__P_D_D,
asdu, (int)ZB_BUF_LEN(asdu), asdu->u.hdr.status));
for (i = 0 ; i < ZB_BUF_LEN(asdu) ; ++i)
{
TRACE_MSG(TRACE_APS3, "%x %c", (FMT__D_C, (int)ptr[i], ptr[i]));
}
zb_free_buf(asdu);
}
@endcode
*/
#define ZB_APS_HDR_CUT_P(packet, ptr) \
ZB_BUF_CUT_LEFT(packet, zb_aps_full_hdr_size(ZB_BUF_BEGIN(packet)), ptr)
/**
Remove APS header from the packet
@param packet - APS packet
@param ptr - (out) pointer to the APS data begin
@b Example:
@code
void data_indication(zb_uint8_t param)
{
zb_ushort_t i;
zb_buf_t *asdu = (zb_buf_t *)ZB_BUF_FROM_REF(param);
ZB_APS_HDR_CUT(asdu);
TRACE_MSG(TRACE_APS3, "data_indication: packet %p len %d handle 0x%x", (FMT__P_D_D,
asdu, (int)ZB_BUF_LEN(asdu), asdu->u.hdr.status));
zb_free_buf(asdu);
}
@endcode
*/
#define ZB_APS_HDR_CUT(packet) \
zb_buf_cut_left(packet, zb_aps_full_hdr_size(ZB_BUF_BEGIN(packet)))
/**
APSME-ADD-GROUP.request primitive parameters
*/
typedef struct zb_apsme_add_group_req_s
{
zb_uint16_t group_address; /*!< The 16-bit address of the group being added. */
zb_uint8_t endpoint; /*!< The endpoint to which the given group is being added. */
} zb_apsme_add_group_req_t;
/**
APSME-ADD-GROUP.confirm primitive parameters
*/
typedef struct zb_apsme_add_group_conf_s
{
zb_uint16_t group_address; /*!< The 16-bit address of the group being added. */
zb_uint8_t endpoint; /*!< The endpoint to which the given group is being added. */
zb_uint8_t status;
} zb_apsme_add_group_conf_t;
/*! @} */
/*! \addtogroup aps_ib */
/*! @{ */
/**
APS Information Base constants
*/
typedef enum zb_aps_aib_attr_id_e
{
ZB_APS_AIB_BINDING = 0xc1, /*!< The current set of binding table entries in the device
(see subclause 2.2.8.2.1). */
ZB_APS_AIB_DESIGNATED_COORD = 0xc2, /*!< TRUE if the device should become the ZigBee Coordinator on
startup, FALSE if otherwise. */
ZB_APS_AIB_CHANNEL_MASK = 0xc3, /*!< The mask of allowable channels for this device
to use for network operations. */
ZB_APS_AIB_USE_EXT_PANID = 0xc4, /*!< The 64-bit address of a network to form or to join. */
ZB_APS_AIB_GROUP_TABLE = 0xc5, /*!< The current set of group table entries (see Table 2.25). */
ZB_APS_AIB_NONMEMBER_RADIUS = 0xc6, /*!< The value to be used for the NonmemberRadius
parameter when using NWK layer multicast. */
ZB_APS_AIB_PERMISSION_CONFIG = 0xc7, /*!< The current set of permission configuration items. */
ZB_APS_AIB_USE_INSECURE_JOIN = 0xc8, /*!< A flag controlling the use of insecure join at startup. */
ZB_APS_AIB_INTERFRAME_DELAY = 0xc9, /*!< Fragmentation parameter - the standard delay, in
milliseconds, between sending two blocks of a
fragmented transmission (see subclause 2.2.8.4.5). */
ZB_APS_AIB_LAST_CHANNEL_ENERGY = 0xca, /*!< The energy measurement for the channel energy
scan performed on the previous channel just
before a channel change (in accordance with [B1]). */
ZB_APS_AIB_LAST_CHANNEL_FAILURE_RATE = 0xcb, /*!< The latest percentage of transmission network
transmission failures for the previous channel just before
a channel change (in percentage of failed transmissions
to the total number of transmissions attempted) */
ZB_APS_AIB_CHANNEL_TIMER = 0xcc /*!< A countdown timer (in hours) indicating the time to the next
permitted frequency agility channel change. A value of NULL
indicates the channel has not been changed previously. */
} zb_aps_aib_attr_id_t;
/**
APSME GET request structure
*/
typedef struct zb_apsme_get_request_s
{
zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute to read. */
} zb_apsme_get_request_t;
/**
APSME GET confirm structure
*/
typedef struct zb_apsme_get_confirm_s
{
zb_aps_status_t status; /*!< The results of the request to read an AIB attribute value. */
zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute that was read.*/
zb_uint8_t aib_length; /*!< The length, in octets, of the attribute value being returned.*/
/* Various */ /*!< The value of the AIB attribute that was read.*/
} ZB_PACKED_STRUCT zb_apsme_get_confirm_t;
/**
APSME SET request structure
*/
typedef struct zb_apsme_set_request_s
{
zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute to be written. */
zb_uint8_t aib_length; /*!< The length, in octets, of the attribute value being set. */
/* Various */ /*!< The value of the AIB attribute that should be written. */
} ZB_PACKED_STRUCT zb_apsme_set_request_t;
/**
APSME SET confirm structure
*/
typedef struct zb_apsme_set_confirm_s
{
zb_aps_status_t status; /*!< The result of the request to write the AIB Attribute. */
zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute that was written. */
} ZB_PACKED_STRUCT zb_apsme_set_confirm_t;
/**
APSME GET request primitive
*/
void zb_apsme_get_request(zb_uint8_t param) ZB_CALLBACK;
/**
APSME GET confirm primitive
*/
void zb_apsme_get_confirm(zb_uint8_t param) ZB_CALLBACK;
/**
APSME SET request primitive
*/
void zb_apsme_set_request(zb_uint8_t param) ZB_CALLBACK;
/**
APSME SET confirm primitive
*/
void zb_apsme_set_confirm(zb_uint8_t param) ZB_CALLBACK;
/*! @} */
/*! \cond internals_doc */
/*! \addtogroup ZB_APS */
/*! @{ */
/**
Initialize APS subsystem
*/
void zb_aps_init();
/**
APSDE-DATA.confirm primitive
The primitive reports the results of a request to transfer a data PDU (ASDU) from
Note that zb_apsde_data_confirm must be defined in the APS layer!
APS layer just calls this function.
@param nsdu - sent packet - @see zb_buf_t. APS must free or reuse it. Following packet fields
are used:
* status - The status of the corresponding request.
INVALID_REQUEST,
MAX_FRM_COUNTER,
NO_KEY,
BAD_CCM_OUTPUT,
ROUTE_ERROR,
BT_TABLE_FULL,
FRAME_NOT_BUFFERED
or any status values returned
from security suite or the
MCPS-DATA.confirm
primitive.
* handle - The handle associated with the NSDU being confirmed.
*/
void zb_apsde_data_confirm(zb_uint8_t param) ZB_CALLBACK;
/**
APS command codes constants
*/
enum zb_aps_commands_e
{
APS_CMD_SKKE_1 = 1,
APS_CMD_SKKE_2,
APS_CMD_SKKE_3,
APS_CMD_SKKE_4,
APS_CMD_TRANSPORT_KEY,
APS_CMD_UPDATE_DEVICE,
APS_CMD_REMOVE_DEVICE,
APS_CMD_REQUEST_KEY,
APS_CMD_SWITCH_KEY,
APS_CMD_EA_INIT_CHLNG,
APS_CMD_EA_RSP_CHLNG,
APS_CMD_EA_INIT_MAC_DATA,
APS_CMD_EA_RSP_MAC_DATA,
APS_CMD_TUNNEL
};
/**
NLDE-DATA.indication primitive
This function called via scheduler by the NWK layer to pass
incoming data packet to the APS layer.
Note that zb_nlde_data_indication() must be defined in the APS layer!
NWK layer just calls this function.
@param nsdu - The set of octets comprising the NSDU to be
transferred (with length)
Other fields got from MAC nsdu by macros
*/
void zb_apsde_data_indication(zb_uint8_t param) ZB_CALLBACK;
zb_uint8_t aps_find_src_ref(zb_address_ieee_ref_t src_addr_ref, zb_uint8_t src_end, zb_uint16_t cluster_id);
/**
APSME-BIND.request primitive.
*/
void zb_apsme_bind_request(zb_uint8_t param) ZB_CALLBACK;
/**
APSME-BIND.confirm primitive
*/
void zb_apsme_bind_confirm(zb_uint8_t param) ZB_CALLBACK;
/**
APSME-UNBIND.request primitive.
*/
void zb_apsme_unbind_request(zb_uint8_t param) ZB_CALLBACK;
/**
APSME-UNBIND.confirm primitive
*/
void zb_apsme_unbind_confirm(zb_uint8_t param) ZB_CALLBACK;
/**
Signals user that data is sent and acknowledged
*/
void zb_apsde_data_acknowledged(zb_uint8_t param) ZB_CALLBACK;
/**
APSME-UPDATE-DEVICE.indication primitive
*/
void zb_apsme_update_device_indication(zb_uint8_t param) ZB_CALLBACK;
/**
Send APS command.
Internal routine to be used to send APS command frame.
See 2.2.5.2.2 APS Command Frame Format
@param param - buffer with command body
@param dest_addr - address of device to send to
@param command - command id
@param secure - if true, secure transfer at nwk level
*/
void zb_aps_send_command(zb_uint8_t param, zb_uint16_t dest_addr, zb_uint8_t command, zb_bool_t secure);
/**
\par Macros for APS FC parse-compose
*/
#define ZB_APS_FC_GET_FRAME_TYPE(fc) ((fc) & 3)
#define ZB_APS_FC_SET_FRAME_TYPE(fc, t) ((fc) |= (t))
#define ZB_APS_FC_GET_DELIVERY_MODE(fc) (((fc)>>2) & 3)
#define ZB_APS_FC_SET_DELIVERY_MODE(fc, m) ((fc) |= (m) << 2)
#define ZB_APS_FC_GET_ACK_FORMAT(fc) (((fc)>>4) & 1)
#define ZB_APS_FC_SET_ACK_FORMAT(fc, f) ((fc) |= ((f) << 4))
#define ZB_APS_FC_GET_SECURITY(fc) (((fc)>>5) & 1)
#define ZB_APS_FC_SET_SECURITY(fc, f) ((fc) |= ((f) << 5))
#define ZB_APS_FC_GET_ACK_REQUEST(fc) (((fc)>>6) & 1)
#define ZB_APS_FC_SET_ACK_REQUEST(fc, f) ((fc) |= ((f) << 6))
#define ZB_APS_FC_GET_EXT_HDR_PRESEBT(fc) (((fc)>>7) & 1)
#define ZB_APS_FC_SET_EXT_HDR_PRESENT(fc, f) ((fc) |= ((f) << 7))
/**
Setup FC for APS command: frame type, ack request, ack format
*/
#define ZB_APS_FC_SET_COMMAND(fc, need_ack) \
(fc) |= (/*frame type*/ZB_APS_FRAME_COMMAND | /*ack req*/(((need_ack)) << 6) | /*ack format*/(1 << 4))
enum zb_aps_frame_type_e
{
ZB_APS_FRAME_DATA = 0,
ZB_APS_FRAME_COMMAND = 1,
ZB_APS_FRAME_ACK = 2
};
enum zb_aps_frame_delivery_mode_e
{
ZB_APS_DELIVERY_UNICAST = 0,
ZB_APS_DELIVERY_INDIRECT = 1,
ZB_APS_DELIVERY_BROADCAST = 2,
ZB_APS_DELIVERY_GROUP = 3
};
/**
Ger APS header size (not include AUX security hdr)
*/
#define ZB_APS_HDR_SIZE(fc) \
(2 + /* fc + aps counter */ \
((ZB_APS_FC_GET_FRAME_TYPE(fc) == ZB_APS_FRAME_COMMAND) ? 0 : ( \
/* Packet either has dest endpoint (1) or group address (2) */ \
1 + \
(ZB_APS_FC_GET_DELIVERY_MODE(fc) == ZB_APS_DELIVERY_GROUP) + \
/* cluster id, profile id */ \
2 + 2 + \
/* src endpoint */ \
1 + \
/* TODO: handle fragmentation and Extended header. Now suppose no Extended header */ \
0 \
)))
/**
Return APS header + APS aux hdr size
*/
zb_ushort_t zb_aps_full_hdr_size(zb_uint8_t *pkt);
#define APS_CONFIRM_STATUS(buf, s, func) \
do \
{ \
(buf)->u.hdr.status = (s); \
ZB_SCHEDULE_CALLBACK((func), ZB_REF_FROM_BUF((buf))); \
} \
while(0)
/**
APSME-ADD-GROUP.request primitive
Note that this routine DOES NOT call APSME-ADD-GROUP.confirm primitive.
Instead, from the application layer use zb_zdo_add_group_req which has
additional parameter - user's callback to be called as
APSME-ADD-GROUP.confirm.
@param param - buffer with parameter. \see zb_apsme_add_group_req_t
*/
void zb_apsme_add_group_request(zb_uint8_t param) ZB_CALLBACK;
#define ZDO_MGMT_APS_LEAVE_RESP_CLID 0x8034 /* it is from zdo for leave callback*/
void zb_aps_hdr_parse(zb_buf_t *packet, zb_aps_hdr_t *aps_hdr, zb_bool_t cut_nwk_hdr) ZB_SDCC_REENTRANT;
/*! @} */
/*! \endcond */
#endif /* ZB_APS_H */
| [
"eclipse@LAPTOP-SKE9HMRR"
] | eclipse@LAPTOP-SKE9HMRR |
4222280a8645db91edd357c5d11689238fc8cea3 | e054280532480396830fd7a1293f8fe98684d9ae | /Example/Pods/Headers/Public/MarsSDK/mars/openssl/ecdh_crypt.h | fd22f3a4074f9ef0432a9249917a55a390c9c06e | [
"MIT"
] | permissive | 7General/Mars-IM | 9d03e08219ef1c0cd0f07dc224c0432a6590b0f3 | c3a27191068ff4ea79a8689ec012b9efb6901f81 | refs/heads/master | 2021-09-15T03:19:31.943428 | 2018-05-25T02:32:58 | 2018-05-25T02:32:58 | 125,340,185 | 1 | 0 | null | null | null | null | UTF-8 | C | false | false | 83 | h | ../../../../../../../MarsSDK/Frameworks/mars.framework/Headers/openssl/ecdh_crypt.h | [
"wanghuizhou@guazi.com"
] | wanghuizhou@guazi.com |
9a3809e69e227e74bd5aba1d3f6d1d4a897b6036 | 1ed1f659cd8b56d930b74f5ec932b095daf7fbf2 | /libft/ft_putnbr_fd.c | 44c90eb17704918cd51533dcbbfd6abe78c07d0f | [] | no_license | Hallocoos/push_swap | 4e7f788e2aef29acf6973cd51b47f4364b0bc5d3 | 50bf43e296470a867c32742cb49e123dfd407aa5 | refs/heads/master | 2021-07-05T14:10:54.220690 | 2020-10-28T07:08:13 | 2020-10-28T07:08:13 | 198,821,441 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 1,168 | c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hde-vos <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/06 12:47:51 by hde-vos #+# #+# */
/* Updated: 2019/06/10 15:53:45 by hde-vos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
if (n == -2147483648)
ft_putstr_fd("-2147483648", fd);
else
{
if (n < 0)
{
ft_putchar_fd('-', fd);
n *= -1;
}
if (n >= 10)
{
ft_putnbr_fd(n / 10, fd);
}
ft_putchar_fd((n % 10) + '0', fd);
}
}
| [
"hde-vos@c3r2s4.wethinkcode.co.za"
] | hde-vos@c3r2s4.wethinkcode.co.za |
450c02cfd9eb653bb788a37f1ca68adb7a8899f0 | 9a38c5010b5c2e43662078e7554dcfd3aeea8e14 | /lab05/lab05.c | b9cdbd48a54ccde84eb7731454adc7454f98f379 | [] | no_license | kinderferraz/mc202 | 2531a44ad29242544c7b3bc0a021886d985bcb26 | 1d959ce0574b93f1ded8c91b2fcc5536b2a9232e | refs/heads/master | 2022-11-04T23:27:15.767634 | 2020-06-26T14:59:12 | 2020-06-26T14:59:12 | 275,178,979 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 2,102 | c | /* Tarefa de laborátorio 05 -- MC202 G
Alkindar Ferraz Rodrigues -- 154532 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 30
typedef struct pes {
char nome[30];
int telefone;
} pessoa;
pessoa cria_pessoa (char nome[], int telefone);
void adiciona_pessoa (pessoa *lista, pessoa pessoa, int c);
pessoa *dobra_lista (pessoa *lista, int n);
pessoa *ordena_lista (pessoa *lista, int fim);
void imprime_ganhador (pessoa *lista, int ganhador);
int checa_fim (char nome[], char const fim[]);
int main () {
int n, c;
char nome[MAX];
int telefone;
int ganhador;
pessoa pessoa;
struct pes *lista;
n = 4;
c = 0;
lista = malloc(n * sizeof(pessoa));
while (1) {
scanf(" %s", nome);
if (checa_fim(nome, "fim")) {
break;
}
scanf(" %d", &telefone);
pessoa = cria_pessoa(nome, telefone);
adiciona_pessoa(lista, pessoa, c);
c++;
if (c == n){
n *= 2;
lista = dobra_lista(lista, n);
}
}
lista = ordena_lista(lista, c);
scanf(" %d", &ganhador);
imprime_ganhador(lista, ganhador);
free(lista);
return 0;
}
pessoa cria_pessoa (char nome[], int telefone) {
pessoa nova;
strcpy(nova.nome, nome);
nova.telefone = telefone;
return nova;
}
void adiciona_pessoa(pessoa *lista, pessoa pessoa, int i) {
lista[i] = pessoa;
}
pessoa *dobra_lista(pessoa *lista, int n){
pessoa *lst;
int i;
lst = malloc(n * sizeof(pessoa));
for (i = 0; i < n; i ++){
lst[i] = lista[i];
}
free(lista);
return lst;
}
pessoa *ordena_lista(pessoa *lista, int c) {
/*bubblesort*/
int k, j;
pessoa aux;
for (k = 1; k < c; k++) {
for (j = 0; j < c - 1; j++) {
if (lista[j].telefone > lista[j + 1].telefone) {
aux = lista[j];
lista[j] = lista[j + 1];
lista[j + 1] = aux;
}
}
}
return lista;
}
void imprime_ganhador(pessoa *lista, int fim) {
printf("%s %d\n", lista[fim-1].nome, lista[fim-1].telefone);
}
int checa_fim(char nome[], char const fim[]) {
int i;
i = 0;
while (nome[i] != '\0') {
i++;
}
if (i > 4) {
return 0;
}
for (i = 0; i < 3; i++){
if (nome[i] != fim[i]){
return 0;
}
}
return 1;
}
| [
"ferraz.alkindar@gmail.com"
] | ferraz.alkindar@gmail.com |
1556b9269c38f430f48db24b4d6006513e014adb | 8020382e0fef4c88461dcc707b9780f6c4027838 | /Projects/STM32F746ZG-Nucleo/Examples/TIM/TIM_OnePulse/Inc/main.h | a42c55f403fa2ae63b061a44a18e4322576d4aef | [
"BSD-2-Clause"
] | permissive | ghsecuritylab/STM32_Cube_F7 | 4de70ea1be9a08e043632d14cf7d35b9128a418c | 2147c24a0cbccfae331ca18a519f8ff6b91e860f | refs/heads/master | 2021-03-01T17:56:24.377267 | 2017-12-05T14:27:52 | 2017-12-05T14:27:52 | 245,803,945 | 0 | 0 | null | 2020-03-08T11:43:37 | 2020-03-08T11:43:36 | null | UTF-8 | C | false | false | 3,360 | h | /**
******************************************************************************
* @file TIM/TIM_OnePulse/Inc/main.h
* @author MCD Application Team
* @version V1.0.2
* @date 30-December-2016
* @brief Header for main.c module
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of STMicroelectronics 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 HOLDER 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f7xx_hal.h"
#include "stm32f7xx_nucleo_144.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Definition for TIMx clock resources */
#define TIMx TIM3
#define TIMx_CLK_ENABLE __HAL_RCC_TIM3_CLK_ENABLE
/* Definition for TIMx Pins */
#define TIMx_CHANNEL_GPIO_PORT __HAL_RCC_GPIOB_CLK_ENABLE
#define TIMx_GPIO_PORT GPIOB
#define GPIO_PIN_CHANNEL1 GPIO_PIN_4
#define GPIO_PIN_CHANNEL2 GPIO_PIN_5
#define GPIO_PUPD_CHANNEL1 GPIO_PULLUP
#define GPIO_PUPD_CHANNEL2 GPIO_PULLUP
#define GPIO_AF_TIMx GPIO_AF2_TIM3
/* Exported functions ------------------------------------------------------- */
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
| [
"trent.gill@gmail.com"
] | trent.gill@gmail.com |
048b8f71ad1e2c743959746a58ea97270b3cfe9c | a6db43f659041bd3fa66e4474ac85f89979b5a57 | /systemTest/library/movement/moveArray.h | e9e4ff323c24ae2e86472ad5dda1f00ba16a81b4 | [] | no_license | elpistars/backup | 4f699d3330c6a45ce341e6114a3c632a772e2275 | c74c6277f27898731538220b64a9f3ddebe637ee | refs/heads/master | 2020-05-01T02:08:55.024544 | 2019-04-11T10:55:19 | 2019-04-11T10:55:19 | 177,211,992 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 84,729 | h | #ifndef MOVEARRAY_H
#define MOVEARRAY_H
int id[18]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
int idh[2]={19,20};
int searchingX[9]={700,650,600,550,500,450,400,350,300};
int searchingY[2]={420,324};
//----------------------------------------------------------------TES------------------------------------------------------------------
int dudukGK [5][18]=
//11, 12
{
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,517 ,325 ,699 ,206 ,818 ,666 ,358 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,517 ,345 ,679 ,156 ,868 ,716 ,308 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,517 ,345 ,689 ,86 ,938 ,786 ,238 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,517 ,345 ,689 ,26 ,1018 ,776 ,228 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,345 ,689 ,26 ,1018 ,796 ,208 ,507 ,516}};
int speed_dudukGK[5]=
{
30,30,30,30,30
};
int delay_dudukGK[5]=
{
1000000,1000000,1000000,1000000,1000000};
int Array_SiapJalantoStandbyGK [9][18]=
//11, 12
{{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,341 ,682 ,240 ,783 ,647 ,376 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,300 ,724 ,280 ,743 ,607 ,416 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,260 ,764 ,320 ,703 ,567 ,456 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,340 ,684 ,360 ,663 ,567 ,456 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,420 ,604 ,400 ,623 ,567 ,456 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,420 ,604 ,440 ,583 ,537 ,486 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,460 ,564 ,460 ,563 ,537 ,486 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,485 ,538 ,485 ,538 ,537 ,486 ,507 ,516},
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,500 ,524 ,532 ,502 ,512 ,512 ,507 ,516}};
int Speed_SiapJalantoStandbyGK[9]=
{
150,150,150,150,150,150,150,100,80
};
int Delay_SiapJalantoStandbyGK[13]=
{
1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000};
int tendangArdhi[8][18]={
{238,786,275,749,461,563,359,665,510,514,397,647,286,738,633,391,510,514},
{238,786,275,750,461,562,352,664,508,516,372,669,320,704,600,426,510,511},
{235,786,274,671,461,562,350,664,505,513,370,666,314,705,601,426,541,510},
{235,784,273,673,462,561,350,663,507,514,368,667,333,715,599,426,600,505},
{162,784,272,673,462,559,350,667,419,509,368,667,332,682,599,424,598,510},
{230,781,269,673,461,557,345,673,416,490,303,709,417,743,516,422,432,461},
{228,782,418,673,462,559,348,668,445,505,296,739,209,808,653,402,469,510},
{227,783,348,600,461,559,340,652,496,505,265,754,277,767,577,431,493,488}};
int jalanjomblo[5][18]=
{
/*0*/{235,788,279,744,462,561,358,666,507,517,305,719,206,818,666,358,508,516},
/*1*/{415,628,278,748,459,561,356,665,502,508,362,667,290,726,630,416,502,511},
/*2*/{285,776,275,754,457,560,351,663,500,500,441,568,428,565,567,489,502,520},
/*3*/{295,752,273,754,457,561,357,678,517,525,512,511,521,502,532,514,509,519},
/*4*/{226,829,547,511,515,516,351,673,507,525,480,543,521,503,517,524,502,520} };
int Speed_jalanjomblo[5]={ 120,120,120,120,120};
int Delay_jalanjomblo[5]={ 20000,20000,20000,20000,20000};
/*int Array_JalanAndre[5][18]= { // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{161,736,281,751,462,561,358,666,494,540,358,632,299,714,612,400,494,536}, {161,736,281,751,462,561,358,666,490,551,341,673,257,734,674,400,507,465}, {235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,508 ,516 ,391 ,633 ,307 ,734 ,624 ,400 ,507 ,516 },
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,508 ,516 ,335 ,633 ,307 ,734 ,604 ,400 ,414 ,476 },
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,508 ,516 ,335 ,633 ,307 ,734 ,604 ,400 ,494 ,508 },
{216 ,807 ,279 ,744 ,462 ,561 ,358 ,666 ,508 ,516 ,379 ,712 ,307 ,742 ,604 ,400 ,544 ,607 },
{248 ,773 ,279 ,746 ,442 ,561 ,358 ,666 ,508 ,516 ,379 ,654 ,307 ,738 ,604 ,400 ,535 ,516 }
};*/
/*int Array_Jalanjo[1][18]=
{
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,301 ,722 ,170 ,853 ,687 ,336 ,507 ,516 };
int Speed_JalanAndre[8]={ 120,120,150,120,1500,120,120,120};
int Delay_JalanAndre[8]=
{
{ 2000000,200000,250000,500000,500000,500000,500000,500000};
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,301 ,722 ,170 ,853 ,687 ,336 ,507 ,516 },
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,301 ,722 ,170 ,853 ,687 ,336 ,507 ,449 },
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,255 ,722 ,170 ,853 ,625 ,336 ,507 ,449 },
{195 ,819 ,279 ,744 ,442 ,561 ,358 ,666 ,507 ,516 ,255 ,771 ,170 ,853 ,625 ,336 ,513 ,498 },
{346 ,819 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,269 ,771 ,201 ,853 ,625 ,336 ,547 ,463 },
{346 ,819 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,233 ,857 ,201 ,853 ,625 ,416 ,547 ,523 },
{346 ,819 ,279 ,744 ,442 ,561 ,358 ,666 ,507 ,516 ,239 ,835 ,251 ,758 ,625 ,464 ,518 ,531 }
};
*/
int Array_JalanAndre2[8][18]=
{
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,517 ,305 ,719 ,206 ,818 ,666 ,358 ,508 ,516},
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,517 ,305 ,719 ,206 ,818 ,666 ,358 ,556 ,516},
{182 ,758 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,517 ,305 ,719 ,206 ,818 ,666 ,358 ,508 ,469},
{70 ,728 ,318 ,743 ,462 ,561 ,358 ,666 ,507 ,517 ,285 ,699 ,226 ,838 ,646 ,338 ,508 ,545},
{173 ,791 ,318 ,743 ,462 ,561 ,358 ,666 ,507 ,517 ,285 ,699 ,226 ,838 ,646 ,338 ,554 ,545},
{296 ,876 ,318 ,743 ,462 ,561 ,358 ,666 ,507 ,517 ,325 ,739 ,186 ,798 ,686 ,400 ,510 ,545},
{296 ,876 ,318 ,743 ,462 ,561 ,358 ,666 ,507 ,517 ,325 ,739 ,186 ,798 ,686 ,378 ,485 ,457},
{70 ,728 ,318 ,743 ,462 ,561 ,358 ,666 ,507 ,517 ,285 ,699 ,226 ,838 ,646 ,338 ,521 ,545 }
}; //378
int Speed_JalanAndre[8]={ 120,120,150,120,1500,120,120,120};
int Delay_JalanAndre[8]={ 2000000,200000,250000,500000,500000,500000,500000,500000};
int Array_Berdiri [18] = {212,812,312,712,312,712,362,662,482,542,512,512,512,512,512,512,482,542};
int Array_RobotDance[21][18]= {
{12,512,312,712,112,912,162,462,482,542,512,512,512,512,512,512,482,542},//gerak kanan
{83, 583, 312, 712, 112, 912, 219, 519, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{155, 655, 312, 712, 112, 912, 276, 576, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{226, 726, 312, 712, 112, 912, 333, 633, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{298, 798, 312, 712, 112, 912, 390, 691, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{369, 869, 312, 712, 112, 912, 447, 748, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{441, 941, 312, 712, 112, 912, 504, 805, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{512,1012,312,712,112,912,562,862,482,542,512,512,512,512,512,512,482,542},//gerak kiri
{441, 941, 312, 712, 112, 912, 504, 805, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{369, 869, 312, 712, 112, 912, 447, 748, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{298, 798, 312, 712, 112, 912, 390, 691, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{226, 726, 312, 712, 112, 912, 333, 633, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{155, 655, 312, 712, 112, 912, 276, 576, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{83, 583, 312, 712, 112, 912, 219, 519, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{12,512,312,712,112,912,162,462,482,542,512,512,512,512,512,512,482,542},//gerak kanan
{83, 583, 312, 712, 112, 912, 219, 519, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{155, 655, 312, 712, 112, 912, 276, 576, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{226, 726, 312, 712, 112, 912, 333, 633, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{298, 798, 312, 712, 112, 912, 390, 691, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{369, 869, 312, 712, 112, 912, 447, 748, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542},
{441, 941, 312, 712, 112, 912, 504, 805, 482, 542, 512, 512, 512, 512, 512, 512, 482, 542}
};
int Delay_RobotDance[21]= {1000000,225000,225000,225000,225000,225000,225000,1000000,225000,225000,225000,225000,225000,225000,1000000,225000,225000,225000,225000,225000,225000};
int Speed_RobotDance[21]= {200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200};
int Array_TendangMaret2015[18][18]=
{
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,512 ,400 ,624 ,309 ,715 ,624 ,400 ,507 ,512},//1
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,516 ,396 ,644 ,309 ,715 ,624 ,400 ,529 ,554},//2
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,396 ,663 ,309 ,785 ,624 ,382 ,583 ,524},//3
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,371 ,640 ,309 ,785 ,624 ,382 ,583 ,524},//4
{256 ,768 ,305 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,353 ,624 ,309 ,785 ,624 ,382 ,583 ,524},//5
{256 ,768 ,324 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,338 ,587 ,309 ,785 ,624 ,382 ,587 ,524},//6
{256 ,768 ,340 ,707 ,462 ,562 ,358 ,685 ,508 ,586 ,332 ,565 ,309 ,785 ,624 ,382 ,587 ,524},//7
{256 ,768 ,340 ,707 ,462 ,562 ,358 ,685 ,508 ,586 ,314 ,534 ,309 ,785 ,624 ,382 ,587 ,524},//8
{256 ,768 ,340 ,707 ,462 ,562 ,358 ,685 ,508 ,586 ,314 ,497 ,309 ,785 ,624 ,382 ,587 ,524},//9
{256 ,768 ,340 ,707 ,462 ,562 ,358 ,685 ,508 ,586 ,314 ,534 ,309 ,785 ,624 ,382 ,587 ,524},//10
{256 ,768 ,340 ,707 ,462 ,562 ,358 ,685 ,508 ,586 ,332 ,565 ,309 ,785 ,624 ,382 ,587 ,524},//11
{256 ,768 ,324 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,338 ,587 ,309 ,785 ,624 ,400 ,587 ,524},//12
{256 ,768 ,305 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,353 ,624 ,309 ,785 ,624 ,400 ,583 ,524},//13
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,371 ,640 ,309 ,785 ,624 ,400 ,583 ,524},//14
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,396 ,663 ,309 ,785 ,624 ,382 ,507 ,524},//15
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,403 ,716 ,309 ,785 ,624 ,422 ,507 ,524},//16
{256 ,768 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,586 ,396 ,663 ,309 ,785 ,624 ,382 ,507 ,524},//17
{112 ,912 ,279 ,745 ,462 ,562 ,358 ,685 ,508 ,516 ,385 ,639 ,309 ,715 ,624 ,400 ,507 ,517} //18
};
//int Speed_TendangMaret2015[18]={ 200, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512};
int Speed_TendangMaret2015[18]={ 200,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,510};
//asli int Delay_TendangMaret2015[18]={ 1000000,1000000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 500000, 5000, 1000000};
int Delay_TendangMaret2015[18]={ 100000,100000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,1000,500000};
int UP_F [11][18]=
{ {235,788,251,773,512,512,512,512,507,516,512,512,512,512,482,542,507,517},
{235,788,512,512,532,492,512,512,507,516,512,512,512,512,482,542,507,517},
{768,256,512,512,462,561,512,512,507,516,512,512,512,512,482,542,507,517},
{768,256,205,819,462,561,358,666,507,516,512,512,512,512,482,542,507,517},
{444,580,205,819,200,824,358,666,507,516,512,512,512,512,482,542,507,517},
{444,580,205,819,200,824,358,666,507,516,205,819,190,834,482,542,507,517},
{444,580,205,819,512,512,358,666,507,516,205,819,190,834,768,256,507,517},
{495,529,205,819,512,512,358,666,507,516,100,951,190,834,727,337,507,517},
{484,524,205,819,512,512,358,666,507,516,100,951,254,769,666,358,507,517},
{484,524,205,819,512,512,358,666,507,516,101,951,395,769,487,436,507,517},
{484,524,205,819,512,512,358,666,507,516,101,951,395,629,487,587,507,517},
/* {484,524,205,819,512,512,358,666,507,516,101,923,395,629,457,567,507,517},
{484,524,205,819,512,512,358,666,507,516,101,923,395,629,457,567,507,517},
{484,524,205,819,512,512,358,666,507,516,101,923,395,629,457,567,507,517},
{484,524,205,819,512,512,358,666,507,516,101,923,395,629,457,567,507,517},
{484,524,205,819,512,512,358,666,507,516,101,923,395,629,457,567,507,517},
*/
// {235,788,279,744,291,733,358,666,507,516,341,682,240,783,647,376,507,516}
};
// {254,759,308,715,462,561,357,665,507,515,316,708,202,810,668,358,511,519} };
// {254,749,308,714,462,561,358,668,506,516,353,671,270,748,638,393,511,519},
// {253,768,308,716,462,561,359,671,508,513,404,601,292,715,636,397,516,518},
// {235,789,279,745,462,562,358,685,512,512,400,624,309,715,624,400,507,517} };
// /*12*/ {61,972,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516,} };
int speed_UP_F [11]= { 150, 150, 150, 150, 150,
150, 150, 150, 150, 150,
100, /*35*/};
int delay_UP_F [11]= { 1000000,1000000,1500000,
1000000,1000000,1000000,
1000000,700000,700000,
700000,1000000/*,4000000*/};
int UP_F_LAST_STEP [1][18]={132,892,255,769,256,768,358,666,507,516,340,650,220,803,687,336,507,516};
int delay_UP_F_LAST_STEP [1]={1000000};
//paha //lutut //ankle bawah
int UP_B [26][18]={// 1RA 2LA 3RT 4LT 5RB 6LB 7Rph 8Lph 9R 10L 11R 12L 13R 14L 15R 16L 17R 18L //Tunning bangun belakang langsung
/*0*/ {512 ,512 ,512 ,512 ,462 ,561 ,512 ,512 ,512 ,512 ,507 ,516 ,502 ,522 ,502 ,522 ,512 ,512},
/*1*/ {1023 ,0 ,512 ,512 ,512 ,512 ,512 ,512 ,512 ,512 ,507 ,516 ,502 ,522 ,502 ,522 ,512 ,512},
/*2*/ {1023 ,0 ,205 ,819 ,512 ,512 ,512 ,512 ,512 ,512 ,507 ,516 ,502 ,522 ,502 ,522 ,512 ,512},
/*3*/ {780 ,244 ,204 ,820 ,204 ,820 ,512 ,512 ,512 ,512 ,507 ,516 ,502 ,522 ,502 ,522 ,512 ,512},
/*4*/ {780 ,244 ,204 ,820 ,204 ,820 ,512 ,512 ,512 ,512 ,814 ,210 ,150 ,874 ,502 ,522 ,512 ,512},//kaki
/*5*/ {880 ,144 ,204 ,820 ,512 ,512 ,512 ,512 ,512 ,512 ,814 ,210 ,150 ,874 ,200 ,824 ,512 ,512},
/*6*/ {735 ,317 ,218 ,813 ,534 ,534 ,512 ,512 ,510 ,510 ,834 ,204 ,89 ,942 ,212 ,802 ,514 ,514},
/*7*/ {70 ,1023 ,248 ,785 ,511 ,504 ,512 ,512 ,475 ,532 ,211 ,819 ,170 ,860 ,445 ,596 ,547 ,492},
/*8*/ {70 ,1021 ,246 ,710 ,512 ,507 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
/*9*/ {394 ,1021 ,448 ,710 ,585 ,512 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
/*10*/ {382 ,1021 ,161 ,710 ,433 ,512 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
/*11*/ {379 ,896 ,159 ,769 ,433 ,512 ,539 ,660 ,491 ,491 ,143 ,954 ,201 ,857 ,424 ,603 ,467 ,451},
/*12*/ {446 ,896 ,197 ,749 ,433 ,512 ,538 ,637 ,494 ,490 ,168 ,966 ,187 ,897 ,464 ,563 ,412 ,472},
/*13*/ {430 ,936 ,197 ,747 ,432 ,519 ,512 ,632 ,470 ,519 ,352 ,983 ,323 ,874 ,459 ,571 ,369 ,400},
/*14*/ {426 ,828 ,197 ,733 ,432 ,517 ,512 ,627 ,443 ,516 ,320 ,971 ,323 ,870 ,462 ,567 ,340 ,440},
/*15*/ {411 ,853 ,197 ,640 ,432 ,528 ,510 ,629 ,513 ,517 ,426 ,983 ,311 ,803 ,597 ,571 ,351 ,405},
/*16*/ {411 ,861 ,196 ,636 ,431 ,581 ,528 ,612 ,583 ,525 ,359 ,953 ,138 ,802 ,678 ,584 ,446 ,404},
/*17*/ {410 ,737 ,193 ,673 ,430 ,707 ,513 ,671 ,668 ,512 ,348 ,968 ,270 ,629 ,669 ,604 ,429 ,432},
/*18*/ {409 ,627 ,192 ,704 ,429 ,667 ,513 ,657 ,662 ,512 ,355 ,970 ,266 ,629 ,727 ,604 ,429 ,489},
/*19*/ {411 ,625 ,190 ,702 ,427 ,665 ,339 ,635 ,533 ,516 ,258 ,980 ,283 ,629 ,751 ,604 ,466 ,511},
/*20*/ {509 ,545 ,297 ,727 ,397 ,668 ,337 ,629 ,522 ,515 ,69 ,980 ,258 ,597 ,632 ,596 ,502 ,518},
/*21*/ {509 ,545 ,255 ,812 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,190 ,834 ,707 ,317 ,507 ,517},
/*22*/ {495 ,529 ,255 ,812 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,190 ,834 ,707 ,317 ,507 ,517},
{484,524,255,819,512,512,358,666,507,516,100,951,254,769,666,358,507,517},
{484,524,255,819,512,512,358,666,507,516,101,951,395,769,487,436,507,517},
{484,524,255,819,512,512,358,666,507,516,101,951,395,629,487,587,507,517}};
/* //tunning asli
[26][18]={// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*0/ {235 ,788 ,512 ,512 ,462 ,561 ,512 ,512 ,507 ,516 ,512 ,512 ,512 ,512 ,512 ,512 ,507 ,516},
/*1/ {542 ,482 ,824 ,200 ,512 ,512 ,512 ,512 ,496 ,528 ,0 ,1023 ,541 ,483 ,422 ,602 ,512 ,512},
/*2/ {632 ,392 ,824 ,200 ,512 ,512 ,512 ,512 ,496 ,528 ,129 ,895 ,541 ,483 ,422 ,602 ,512 ,512},
/*3/ {632 ,392 ,824 ,200 ,512 ,512 ,512 ,512 ,496 ,528 ,129 ,895 ,541 ,483 ,422 ,602 ,512 ,512},
/*4/ {632 ,392 ,824 ,200 ,512 ,512 ,512 ,512 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
/*5/ {70 ,954 ,239 ,785 ,512 ,512 ,512 ,512 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
/*6/ {70 ,954 ,246 ,785 ,512 ,512 ,512 ,512 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
/*7/ {70 ,1023 ,248 ,785 ,511 ,504 ,512 ,512 ,475 ,532 ,211 ,819 ,170 ,860 ,445 ,596 ,547 ,492},
/*8/ {70 ,1021 ,246 ,710 ,512 ,507 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
/*9/ {394 ,1021 ,448 ,710 ,585 ,512 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
/*10/ {382 ,1021 ,161 ,710 ,433 ,512 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
/*11/ {379 ,896 ,159 ,769 ,433 ,512 ,539 ,660 ,491 ,491 ,143 ,954 ,201 ,857 ,424 ,603 ,467 ,451},
/*12/ {446 ,896 ,197 ,749 ,433 ,512 ,538 ,637 ,494 ,490 ,168 ,966 ,187 ,897 ,464 ,563 ,412 ,472},
/*13/ {430 ,936 ,197 ,747 ,432 ,519 ,512 ,632 ,470 ,519 ,352 ,983 ,323 ,874 ,459 ,571 ,369 ,400},
/*14/ {426 ,828 ,197 ,733 ,432 ,517 ,512 ,627 ,443 ,516 ,320 ,971 ,323 ,870 ,462 ,567 ,340 ,440},
/*15/ {411 ,853 ,197 ,640 ,432 ,528 ,510 ,629 ,513 ,517 ,426 ,983 ,311 ,803 ,597 ,571 ,351 ,405},
/*16/ {411 ,861 ,196 ,636 ,431 ,581 ,528 ,612 ,583 ,525 ,359 ,953 ,138 ,802 ,678 ,584 ,446 ,404},
/*17/ {410 ,737 ,193 ,673 ,430 ,707 ,513 ,671 ,668 ,512 ,348 ,968 ,270 ,629 ,669 ,604 ,429 ,432},
/*18/ {409 ,627 ,192 ,704 ,429 ,667 ,513 ,657 ,662 ,512 ,355 ,970 ,266 ,629 ,727 ,604 ,429 ,489},
/*19/ {411 ,625 ,190 ,702 ,427 ,665 ,339 ,635 ,533 ,516 ,258 ,980 ,283 ,629 ,751 ,604 ,466 ,511},
/*20/ {509 ,545 ,297 ,727 ,397 ,668 ,337 ,629 ,522 ,515 ,69 ,980 ,258 ,597 ,632 ,596 ,502 ,518},
/*21/ {509 ,545 ,255 ,812 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,190 ,834 ,707 ,317 ,507 ,517},
/*22/ {495 ,529 ,255 ,812 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,190 ,834 ,707 ,317 ,507 ,517},
{484,524,255,819,512,512,358,666,507,516,100,951,254,769,666,358,507,517},
{484,524,255,819,512,512,358,666,507,516,101,951,395,769,487,436,507,517},
{484,524,255,819,512,512,358,666,507,516,101,951,395,629,487,587,507,517}};
*/
int speed_UP_B[26]={ 100, 150, 500, 100, 100,
100, 100, 100, 100, 100,
100, 100, 100, 100, 100,
100, 100, 100, 100, 100,
100, 100, 150, 150, 150,
100};
int delay_UP_B[26]={ 2000000, 3000000, 1000000,
1000000, 2000000, 2000000,
2000000, 1500000, 700000,
700000, 700000, 700000,
700000, 700000, 700000,
1000000, 1000000, 1000000,
1000000, 1000000, 1000000,
900000, 800000, 1000000,
1000000, 1000000};
int UP_B_LAST_STEP [1][18]={480,520,270,750,250,750,512,512,506,517,732,297,230,808,374,669,517,517};
//int UP_B_LAST_STEP [1][18]={32,992,255,769,256,768,358,666,507,516,372,662,220,803,687,336,507,516};
int delay_UP_B_LAST_STEP [1]={1000000};
int razishoot[18][18]=
{
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{235,789,279,745,462,562,358,685,512,512,400,624,309,715,624,400,507,517},//1
{191,826,279,745,462,562,358,685,508,516,396,644,309,715,624,400,529,584},//2
{235,789,279,745,462,562,358,685,508,586,396,663,309,785,624,382,553,524},//3
{273,822,279,745,462,562,358,685,508,586,371,640,309,785,624,382,553,524},//4
{296,854,305,745,462,562,358,685,508,586,353,624,309,785,624,382,553,524},//5
{308,867,324,745,462,562,358,685,508,586,338,587,309,785,624,382,557,524},//6
{324,871,340,707,462,562,358,685,508,586,332,565,309,785,624,382,557,524},//7
{324,871,340,707,462,562,358,685,508,586,314,534,309,785,624,382,557,524},//8
{324,871,340,707,462,562,358,685,508,586,314,497,309,785,624,382,557,524},//9
{324,871,340,707,462,562,358,685,508,586,314,534,309,785,624,382,557,524},//10
{324,871,340,707,462,562,358,685,508,586,332,565,309,785,624,382,557,524},//11
{308,867,324,745,462,562,358,685,508,586,338,587,309,785,624,400,557,524},//12
{296,854,305,745,462,562,358,685,508,586,353,624,309,785,624,400,553,524},//13
{273,822,279,745,462,562,358,685,508,586,371,640,309,785,624,400,553,524},//14
{235,789,279,745,462,562,358,685,508,586,396,663,309,785,624,382,553,524},//15
{235,789,279,745,462,562,358,685,508,586,403,716,309,785,624,422,553,524},//16
{235,789,279,745,462,562,358,685,508,586,396,663,309,785,624,382,553,524},//17
{235,789,279,745,462,562,358,685,508,516,418,614,309,715,624,400,507,517}//18
};
int razishoot_speed[18]={ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512};
int razishoot_delay[18]={ 1000000,1000000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 500000, 1000, 10000000};
int razishoot2[22][18]=
{
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,512 ,400 ,630 ,309 ,715 ,624 ,400 ,507 ,517},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,528 ,400 ,651 ,309 ,759 ,624 ,385 ,513 ,531},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,544 ,400 ,672 ,309 ,803 ,624 ,370 ,519 ,545},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,400 ,694 ,309 ,848 ,624 ,356 ,525 ,559},
{289 ,789 ,293 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,392 ,659 ,309 ,821 ,624 ,360 ,531 ,563},
{344 ,789 ,307 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,385 ,624 ,309 ,794 ,624 ,363 ,537 ,566},
{400 ,789 ,322 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,377 ,590 ,309 ,768 ,624 ,366 ,543 ,569},
{456 ,789 ,336 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,370 ,555 ,309 ,741 ,624 ,369 ,549 ,572},
{512 ,789 ,351 ,745 ,462 ,562 ,358 ,685 ,486 ,560 ,363 ,521 ,309 ,715 ,624 ,372 ,556 ,575},
{456 ,789 ,336 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,370 ,555 ,309 ,741 ,624 ,369 ,549 ,572},
{400 ,789 ,322 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,377 ,590 ,309 ,768 ,624 ,366 ,543 ,569},
{344 ,789 ,307 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,385 ,624 ,309 ,794 ,624 ,363 ,537 ,566},
{289 ,789 ,293 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,392 ,659 ,309 ,821 ,624 ,360 ,531 ,563},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,400 ,694 ,309 ,848 ,624 ,356 ,525 ,559},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,385 ,768 ,309 ,848 ,624 ,395 ,525 ,559},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,400 ,694 ,309 ,848 ,624 ,356 ,525 ,559},
{289 ,789 ,293 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,392 ,659 ,309 ,821 ,624 ,360 ,531 ,563},
{344 ,789 ,307 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,385 ,624 ,309 ,794 ,624 ,363 ,537 ,566},
{400 ,789 ,322 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,377 ,590 ,309 ,768 ,624 ,366 ,543 ,569},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,400 ,694 ,309 ,848 ,624 ,356 ,525 ,559},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,560 ,400 ,630 ,309 ,715 ,624 ,400 ,507 ,543},
{235 ,789 ,279 ,745 ,462 ,562 ,358 ,685 ,512 ,512 ,400 ,630 ,309 ,715 ,624 ,400 ,507 ,517} };
int razishoot2_speed[22][18]={{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512},
{ 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512}};
int razishoot2_delay[22]={5000,5000,5000,5000,5000,5000,5000,5000,2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000};
int F_getup[5][18]={{234,789,509,514,462,561,353,670,508,515,346,677,282,741,617,406,508,515},
{461,562,496,527,501,522,353,670,508,515,346,677,282,741,617,406,508,515},
{611,412,580,443,155,868,353,670,498,525,55,968,121,902,835,188,504,519},
{394,629,264,759,454,569,354,669,512,511,80,943,38,985,705,318,512,511},
{235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516}};
int B_getup[4][18]={{424,599,630,393,511,512,353,670,508,515,599,424,191,832,539,484,508,515},
// {545,478,770,253,521,502,353,670,508,515,600,423,111,912,796,227,508,515},
{215,808,520,503,521,502,353,670,508,515,600,423,181,842,796,237,508,515},
{235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516}};
int walkReady[18]= {235,788,279,744,291,733,358,666,507,516,320,690,240,783,647,376,507,516};
/*1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
//int walkReady[18]= {235,788,279,744,291,733,358,666,507,516,341,682,240,783,647,376,507,516};
int walkReady2[18]= {235,788,279,744,291,733,358,666,507,516,341,682,240,783,647,376,507,516};
int SIT_1[18] ={182,841,294,729,490,533,353,670,508,515,268,755,71,952,753,270,508,515};
int SIT_2[18] ={180,844,294,730,250,774,351,673,507,517,274,750,41,983,751,273,505,519};
//int STANDUP_1[18] ={182,841,294,729,250,774,353,670,508,515,268,755,71,952,753,270,508,515};
int STANDUP_2[18] ={235,788,215,809,250,774,358,666,507,516,301,722,170,853,687,336,507,516};
//1 2 3 4 5 6 7 8 9 10 11 12 13 14
int FSL[7][18]= {/*0*/ {235,788,279,744,291,733,358,666,513,522,342,644,320,781,647,379,513,522},
/*1*/ {235,788,279,744,291,733,358,666,519,528,344,649,344,776,645,388,519,528},
/*2*/ {235,788,279,744,291,733,358,666,524,533,346,650,359,770,643,389,524,533},
/*3*/ {235,788,279,744,291,733,358,666,528,537,352,652,352,763,640,389,528,537},
/*4*/ {235,788,279,744,291,733,358,666,521,544,354,659,354,778,637,379,531,541},
/*5*/ {235,788,279,744,291,733,358,666,503,555,354,656,354,811,635,362,533,544},
/*6*/ {235,788,279,744,291,733,358,666,494,560,355,656,355,826,634,355,534,546} };
int FSL2[7][18]={/*0*/ {233,786,279,744,291,733,358,666,503,555,353,625,345,807,645,386,533,544},
/*1*/ {248,801,279,744,291,733,358,666,521,544,357,618,330,765,649,427,531,541},
/*2*/ {263,816,279,744,291,733,358,666,528,537,355,613,349,744,657,433,528,537},
/*3*/ {276,829,279,744,291,733,358,666,524,533,352,618,352,751,656,434,524,533},
/*4*/ {287,840,279,744,291,733,358,666,519,528,353,620,354,760,667,423,519,528},
/*5*/ {295,848,279,744,291,733,358,666,513,522,357,619,355,769,668,418,513,522},
/*6*/ {301,854,279,744,291,733,358,666,507,516,364,616,360,775,679,419,507,516} };
int FSR[7][18] ={/*0*/ {235,788,279,744,291,733,358,666,501,510,342,681,242,782,646,377,501,510},
/*1*/ {235,788,279,744,291,733,358,666,495,504,345,679,247,778,643,379,495,504},
/*2*/ {235,788,279,744,291,733,358,666,490,499,348,677,253,773,640,381,490,499},
/*3*/ {235,788,279,744,291,733,358,666,486,495,351,674,260,767,637,384,486,495},
/*4*/ {235,788,279,744,291,733,358,666,479,502,344,671,245,761,644,387,482,492},
/*5*/ {235,788,279,744,291,733,358,666,468,520,327,669,212,757,661,389,479,490},
/*6*/ {235,788,279,744,291,733,358,666,463,529,320,668,197,755,668,390,477,489} };
int FSR2[7][18]={/*0*/ {236,789,279,744,291,733,358,666,468,520,298,670,216,756,637,382,479,490},
/*1*/ {221,774,279,744,291,733,358,666,479,502,305,666,258,759,602,375,482,492},
/*2*/ {206,759,279,744,291,733,358,666,486,495,310,668,279,764,586,371,486,495},
/*3*/ {193,746,279,744,291,733,358,666,490,499,305,671,272,771,589,368,490,499},
/*4*/ {182,735,279,744,291,733,358,666,495,504,303,670,263,775,596,363,495,504},
/*5*/ {174,727,279,744,291,733,358,666,501,510,304,666,254,777,605,357,501,510},
/*6*/ {168,721,279,744,291,733,358,666,507,516,307,659,248,775,614,352,507,516} };
int FML[7][18]= {/*0*/ {169,722,279,744,291,733,358,666,513,522,302,660,246,769,621,348,513,522},
/*1*/ {166,719,279,744,291,733,358,666,518,527,308,651,248,761,625,348,518,527},
/*2*/ {167,720,279,744,291,733,358,666,519,533,314,650,252,761,628,346,523,532},
/*3*/ {171,724,279,744,291,733,358,666,513,541,321,662,257,778,629,341,527,537},
/*4*/ {179,732,279,744,291,733,358,666,504,550,327,682,262,801,630,338,530,541},
/*5*/ {189,742,279,744,291,733,358,666,496,556,332,704,266,820,631,342,532,543},
/*6*/ {201,754,279,744,291,733,358,666,493,558,335,724,267,827,633,354,533,544} };
int FML2[7][18]={/*0*/ {215,768,279,744,291,733,358,666,496,556,337,736,266,820,636,374,532,543},
/*1*/ {230,783,279,744,291,733,358,666,504,550,338,740,262,801,641,396,530,541},
/*2*/ {246,799,279,744,291,733,358,666,513,541,339,737,257,778,647,416,527,537},
/*3*/ {260,813,279,744,291,733,358,666,519,533,340,732,252,761,654,428,523,532},
/*4*/ {274,827,279,744,291,733,358,666,518,527,343,730,248,761,660,427,518,527},
/*5*/ {285,838,279,744,291,733,358,666,513,522,347,730,246,769,666,418,513,522},
/*6*/ {294,847,279,744,291,733,358,666,507,516,354,726,248,775,671,409,507,516} };
int FMR[7][18]= {/*0*/ {300,853,279,744,291,733,358,666,501,510,363,721,254,777,675,402,501,510},
/*1*/ {303,856,279,744,291,733,358,666,496,505,372,715,262,775,675,398,496,505},
/*2*/ {302,855,279,744,291,733,358,666,490,504,373,709,262,771,677,395,491,500},
/*3*/ {298,851,279,744,291,733,358,666,482,510,361,702,245,766,682,394,486,496},
/*4*/ {290,843,279,744,291,733,358,666,473,519,341,696,222,761,685,393,482,493},
/*5*/ {280,833,279,744,291,733,358,666,467,527,319,691,203,757,681,392,480,491},
/*6*/ {268,821,279,744,291,733,358,666,465,530,299,688,196,756,669,390,479,490} };
int FMR2[7][18]={/*0*/ {254,807,279,744,291,733,358,666,467,527,287,686,203,757,649,387,480,491},
/*1*/ {239,792,279,744,291,733,358,666,473,519,283,685,222,761,627,382,482,493},
/*2*/ {223,776,279,744,291,733,358,666,482,510,286,684,245,766,607,376,486,496},
/*3*/ {209,762,279,744,291,733,358,666,490,504,291,683,262,771,595,369,491,500},
/*4*/ {195,748,279,744,291,733,358,666,496,505,293,680,262,775,596,363,496,505},
/*5*/ {184,737,279,744,291,733,358,666,501,510,293,676,254,777,605,357,501,510},
/*6*/ {175,728,279,744,291,733,358,666,507,516,297,669,248,775,614,352,507,516} };
int FEL[7][18]={/*0*/ {166,719,279,744,291,733,358,666,513,522,312,650,246,769,621,349,513,522},
/*1*/ {168,721,279,744,291,733,358,666,519,528,318,641,248,760,625,348,519,528},
/*2*/ {172,725,279,744,291,733,358,666,524,533,323,634,252,751,626,350,524,533},
/*3*/ {180,733,279,744,291,733,358,666,528,537,326,631,259,744,623,355,528,537},
/*4*/ {191,744,279,744,291,733,358,666,521,544,330,647,264,765,621,350,531,541},
/*5*/ {204,757,279,744,291,733,358,666,503,555,337,682,267,807,625,343,533,544},
/*6*/ {218,771,279,744,291,733,358,666,494,560,345,713,268,826,633,355,534,546}, };
int FEL2[7][18]={/*0*/ {235,788,279,744,291,733,358,666,503,555,354,696,266,811,634,362,533,544},
/*1*/ {235,788,279,744,291,733,358,666,521,544,352,679,262,778,636,379,531,541},
/*2*/ {235,788,279,744,291,733,358,666,528,537,349,672,256,763,639,386,528,537},
/*3*/ {235,788,279,744,291,733,358,666,524,533,346,675,250,770,642,383,524,533},
/*4*/ {235,788,279,744,291,733,358,666,519,528,344,678,245,776,644,380,519,528},
/*5*/ {235,788,279,744,291,733,358,666,513,522,342,681,241,781,646,377,513,522},
/*6*/ {235,788,279,744,291,733,358,666,507,516,341,682,240,783,647,376,507,516}, };
int FER[7][18]= {/*0*/ {303,856,279,744,291,733,358,666,501,510,373,711,254,777,674,402,501,510},
/*1*/ {301,854,279,744,291,733,358,666,495,504,382,705,263,775,675,398,495,504},
/*2*/ {297,850,279,744,291,733,358,666,490,499,389,700,272,771,673,397,490,499},
/*3*/ {289,842,279,744,291,733,358,666,486,495,392,697,279,764,668,400,486,495},
/*4*/ {278,831,279,744,291,733,358,666,479,502,376,693,258,759,673,402,482,492},
/*5*/ {265,818,279,744,291,733,358,666,468,520,341,686,216,756,680,398,479,490},
/*6*/ {251,804,279,744,291,733,358,666,463,529,310,678,197,755,668,390,477,489} };
int FER2[7][18]={/*0*/ {235,788,279,744,291,733,358,666,468,520,327,669,212,757,661,389,479,490},
/*1*/ {235,788,279,744,291,733,358,666,479,502,344,671,245,761,644,387,482,492},
/*2*/ {235,788,279,744,291,733,358,666,486,495,351,674,260,767,637,384,486,495},
/*3*/ {235,788,279,744,291,733,358,666,490,499,348,677,253,773,640,381,490,499},
/*4*/ {235,788,279,744,291,733,358,666,495,504,345,679,247,778,643,379,495,504},
/*5*/ {235,788,279,744,291,733,358,666,521,490,342,681,242,782,646,377,501,510},
/*6*/ {235,788,279,744,291,733,358,666,527,496,341,682,240,783,647,376,507,516} };
int RML[7][18]={/*0*/ {235,789,279,745,291,733,358,666,480,560,348,671,252,760,642,389,480,560},
/*1*/ {235,789,279,745,291,733,358,666,488,567,347,665,251,748,643,395,488,567},
/*2*/ {235,789,279,745,291,733,358,666,492,574,348,663,252,744,642,397,496,573},
/*3*/ {235,789,279,745,291,733,358,666,490,582,349,669,255,757,641,391,504,577},
/*4*/ {235,789,279,745,291,733,358,666,486,588,351,679,259,777,639,381,512,579},
/*5*/ {235,789,279,745,291,733,358,666,483,591,353,689,263,796,637,371,520,578},
/*6*/ {235,789,279,745,291,733,358,666,486,588,354,694,265,807,636,366,526,574} };
int RML2[7][18]={/*0*/ {235,789,279,745,291,733,358,666,494,580,355,694,266,807,635,366,530,567},
/*1*/ {235,789,279,745,291,733,358,666,507,568,353,690,263,799,637,370,533,558},
/*2*/ {235,789,279,745,291,733,358,666,519,554,351,684,259,786,639,376,533,549},
/*3*/ {235,789,279,745,291,733,358,666,524,532,345,679,246,776,645,381,524,532},
/*4*/ {235,789,279,745,291,733,358,666,526,541,348,679,252,776,642,381,530,540},
/*5*/ {235,789,279,745,291,733,358,666,516,525,343,681,242,781,647,379,516,525},
/*6*/ {235,789,279,745,291,733,358,666,508,517,342,683,241,784,648,377,508,517} };
int RMR[7][18]= {/*0*/ {235,789,279,745,291,733,358,666,500,509,344,682,244,783,646,378,500,509},
/*1*/ {235,789,279,745,291,733,358,666,493,501,346,680,249,779,644,380,493,501},
/*2*/ {235,789,279,745,291,733,358,666,484,499,346,677,249,773,644,383,485,495},
/*3*/ {235,789,279,745,291,733,358,666,471,506,341,674,239,766,649,386,476,492},
/*4*/ {235,789,279,745,291,733,358,666,457,518,335,672,226,762,655,388,467,492},
/*5*/ {235,789,279,745,291,733,358,666,445,531,331,670,218,759,659,390,458,495},
/*6*/ {235,789,279,745,291,733,358,666,437,539,331,671,218,760,659,389,451,499} };
int RMR2[7][18]={/*0*/ {235,789,279,745,291,733,358,666,434,542,336,672,229,762,654,388,447,505},
/*1*/ {235,789,279,745,291,733,358,666,437,539,346,674,248,766,644,386,446,513},
/*2*/ {235,789,279,745,291,733,358,666,443,535,356,676,268,770,634,384,448,521},
/*3*/ {235,789,279,745,291,733,358,666,451,533,362,677,281,773,628,383,452,529},
/*4*/ {235,789,279,745,291,733,358,666,458,537,360,678,277,774,630,382,458,537},
/*5*/ {235,789,279,745,291,733,358,666,465,545,354,677,265,773,636,383,465,545},
/*6*/ {235,789,279,745,291,733,358,666,473,552,350,675,257,768,640,385,473,552} };
int LML[7][18]= {/*0*/ {235,788,279,744,291,733,358,666,515,524,342,680,241,780,646,378,515,524},
/*1*/ {235,788,279,744,291,733,358,666,523,531,344,678,245,775,644,380,523,531},
/*2*/ {235,788,279,744,291,733,358,666,525,540,347,678,251,775,641,380,529,539},
/*3*/ {235,788,279,744,291,733,358,666,518,553,350,683,258,785,638,375,532,548},
/*4*/ {235,788,279,744,291,733,358,666,506,567,352,689,262,798,636,369,532,557},
/*5*/ {235,788,279,744,291,733,358,666,493,579,354,693,265,806,634,365,529,566},
/*6*/ {235,788,279,744,291,733,358,666,485,587,353,693,264,806,635,365,525,573} };
int LML2[7][18]={/*0*/ {235,788,279,744,291,733,358,666,482,590,352,688,262,795,636,370,519,577},
/*1*/ {235,788,279,744,291,733,358,666,485,587,350,678,258,776,638,380,511,578},
/*2*/ {235,788,279,744,291,733,358,666,489,581,348,668,254,756,640,390,503,576},
/*3*/ {235,788,279,744,291,733,358,666,491,573,347,662,251,743,641,396,495,572},
/*4*/ {235,788,279,744,291,733,358,666,487,566,346,664,250,747,642,394,487,566},
/*5*/ {235,788,279,744,291,733,358,666,479,559,347,670,251,759,641,388,479,559},
/*6*/ {235,788,279,744,291,733,358,666,472,551,349,674,256,767,639,384,472,551} };
int LMR[7][18]={/*0*/ {235,788,279,744,291,733,358,666,464,544,353,676,264,772,635,382,464,544},
/*1*/ {235,788,279,744,291,733,358,666,457,536,359,677,276,773,629,381,457,536},
/*2*/ {235,788,279,744,291,733,358,666,450,532,361,676,280,772,627,382,451,528},
/*3*/ {235,788,279,744,291,733,358,666,442,534,355,675,267,769,633,383,447,520},
/*4*/ {235,788,279,744,291,733,358,666,436,538,345,673,247,765,643,385,445,512},
/*5*/ {235,788,279,744,291,733,358,666,433,541,335,671,228,761,653,387,446,504},
/*6*/ {235,788,279,744,291,733,358,666,436,538,330,670,217,759,658,388,450,498} };
int LMR2[7][18]={/*0*/ {235,788,279,744,291,733,358,666,444,530,330,669,217,758,658,389,457,494},
/*1*/ {235,788,279,744,291,733,358,666,456,517,334,671,225,761,654,387,466,491},
/*2*/ {235,788,279,744,291,733,358,666,470,505,340,673,238,765,648,385,475,491},
/*3*/ {235,788,279,744,291,733,358,666,483,498,345,676,248,772,643,382,484,494},
/*4*/ {235,788,279,744,291,733,358,666,492,500,345,679,248,778,643,379,492,500},
/*5*/ {235,788,279,744,291,733,358,666,499,508,343,681,243,782,645,377,499,508},
/*6*/ {235,788,279,744,291,733,358,666,507,516,341,682,240,783,647,376,507,516} };
int LTML[7][18]={/*0*/ {312,712,279,745,291,733,358,666,514,522,342,681,241,781,646,377,514,522},
/*1*/ {312,712,279,745,291,733,358,666,520,528,345,678,245,776,644,380,520,528},
/*2*/ {312,712,279,745,291,733,359,664,527,529,344,679,250,777,642,379,525,534},
/*3*/ {312,712,279,745,291,733,363,660,536,524,350,686,257,790,639,373,529,539},
/*4*/ {312,712,279,745,291,733,370,653,544,507,354,696,263,807,637,366,533,543},
/*5*/ {312,712,279,745,291,733,379,644,551,515,357,704,267,821,636,361,535,546},
/*6*/ {312,712,279,745,291,733,388,635,553,512,359,709,269,826,636,361,535,547} };
int LTML2[7][18]={/*0*/ {312,712,279,745,291,733,398,625,498,558,360,708,267,821,638,365,534,546},
/*1*/ {312,712,279,745,291,733,406,617,506,551,358,702,263,807,641,372,532,542},
/*2*/ {312,712,279,745,291,733,413,610,515,543,355,693,257,790,643,380,529,538},
/*3*/ {312,712,279,745,291,733,417,606,521,534,350,686,250,777,646,386,524,533},
/*4*/ {312,712,279,745,291,733,419,604,519,527,346,683,245,776,647,385,519,527},
/*5*/ {312,712,279,745,291,733,419,604,513,522,343,684,241,781,647,381,513,522},
/*6*/ {312,712,279,745,291,733,419,604,507,516,340,683,240,783,645,378,507,516} };
int LTMR[7][18]={/*0*/ {312,712,279,745,291,733,419,604,501,510,339,680,242,782,642,376,501,510},
/*1*/ {312,712,279,745,291,733,419,604,496,504,340,677,247,778,638,376,496,504},
/*2*/ {312,712,279,745,291,733,417,606,489,502,337,673,246,773,637,377,490,499},
/*3*/ {312,712,279,745,291,733,413,610,480,508,330,668,233,766,643,380,485,494},
/*4*/ {312,712,279,745,291,733,406,617,472,517,321,665,216,760,651,382,481,491},
/*5*/ {312,712,279,745,291,733,398,625,465,525,315,663,202,756,658,385,477,489},
/*6*/ {312,712,279,745,291,733,388,635,462,528,314,664,197,754,662,387,476,488} };
int LTMR2[7][18]={/*0*/ {312,712,279,745,291,733,379,644,464,525,319,666,202,756,662,387,477,488},
/*1*/ {312,712,279,745,291,733,370,653,471,517,327,669,216,760,657,386,480,490},
/*2*/ {312,712,279,745,291,733,363,660,479,507,337,673,233,766,650,384,484,494},
/*3*/ {312,712,279,745,291,733,359,664,488,502,344,676,246,773,644,381,489,498},
/*4*/ {312,712,279,745,291,733,358,666,495,503,345,679,247,778,643,379,495,503},
/*5*/ {312,712,279,745,291,733,358,666,501,509,342,681,242,782,646,377,501,509},
/*6*/ {312,712,279,745,291,733,358,666,507,516,341,682,240,783,647,376,507,516} };
int RTML[7][18]={/*0*/ {312,712,279,745,291,733,419,604,513,522,343,684,241,781,647,381,513,522},
/*1*/ {312,712,279,745,291,733,419,604,519,527,346,683,245,776,647,385,519,527},
/*2*/ {312,712,279,745,291,733,417,606,521,534,350,686,250,777,646,386,524,533},
/*3*/ {312,712,279,745,291,733,413,610,515,543,355,693,257,790,643,380,529,538},
/*4*/ {312,712,279,745,291,733,406,617,506,551,358,702,263,807,641,372,532,542},
/*5*/ {312,712,279,745,291,733,398,625,498,558,360,708,267,821,638,365,534,546},
/*6*/ {312,712,279,745,291,733,388,635,495,561,359,709,269,826,636,361,535,547} };
int RTML2[7][18]={/*0*/ {312,712,279,745,291,733,379,644,498,559,357,704,267,821,636,361,535,546},
/*1*/ {312,712,279,745,291,733,370,653,506,552,354,696,263,807,637,366,533,543},
/*2*/ {312,712,279,745,291,733,363,660,516,544,350,686,257,790,639,373,529,539},
/*3*/ {312,712,279,745,291,733,359,664,521,535,347,679,250,777,642,379,525,534},
/*4*/ {312,712,279,745,291,733,358,666,520,528,344,678,245,776,644,380,520,528},
/*5*/ {312,712,279,745,291,733,358,666,514,522,342,681,241,781,646,377,514,522},
/*6*/ {312,712,279,745,291,733,358,666,507,516,341,682,240,783,647,376,507,516} };
int RTMR[7][18]={/*0*/ {312,712,279,745,291,733,358,666,501,509,342,681,242,782,646,377,501,509},
/*1*/ {312,712,279,745,291,733,358,666,495,503,345,679,247,778,643,379,495,503},
/*2*/ {312,712,279,745,291,733,359,664,488,502,344,676,246,773,644,381,489,498},
/*3*/ {312,712,279,745,291,733,363,660,479,507,337,673,233,766,650,384,484,494},
/*4*/ {312,712,279,745,291,733,370,653,471,517,327,669,216,760,657,386,480,490},
/*5*/ {312,712,279,745,291,733,379,644,464,525,319,666,202,756,662,387,477,488},
/*6*/ {312,712,279,745,291,733,388,635,462,528,314,664,197,754,662,387,476,488} };
int RTMR2[7][18]={/*0*/ {312,712,279,745,291,733,398,625,465,525,315,663,202,756,658,385,477,489},
/*1*/ {312,712,279,745,291,733,406,617,472,517,321,665,216,760,651,382,481,491},
/*2*/ {312,712,279,745,291,733,413,610,480,508,330,668,233,766,643,380,485,494},
/*3*/ {312,712,279,745,291,733,417,606,489,502,337,673,246,773,637,377,490,499},
/*4*/ {312,712,279,745,291,733,419,604,496,504,340,677,247,778,638,376,496,504},
/*5*/ {312,712,279,745,291,733,419,604,501,510,339,680,242,782,642,376,501,510},
/*6*/ {312,712,279,745,291,733,419,604,507,516,340,683,240,783,645,378,507,516} };
int LKICK[6][18]={/*0*/ {235,788,279,744,291,733,354,665,541,582,350,665,287,722,624,403,571,581},
/*1*/ {235,788,279,744,291,733,354,669,522,602,350,773,287,936,624,299,572,583},
/*2*/ {235,788,279,744,291,733,354,669,522,602,400,803,287,516,624,601,572,583},
/*3*/ {235,788,279,744,291,733,354,669,522,602,350,773,287,936,624,299,572,583},
/*4*/ {235,788,279,744,291,733,354,665,541,582,350,665,287,722,624,403,571,581},
/*5*/ {235,788,279,744,291,733,358,666,507,516,341,682,240,783,647,376,507,516} };
int RKICK[6][18]={/*0*/ {235,788,279,744,291,733,358,669,441,482,358,673,301,736,620,399,442,447},
/*1*/ {235,788,279,744,291,733,354,669,421,511,250,673,87,736,724,399,440,446},
/*2*/ {235,788,279,744,291,733,354,669,421,511,220,623,507,736,422,399,440,446},
/*3*/ {235,788,279,744,291,733,354,669,421,511,250,673,87,736,724,399,440,446},
/*4*/ {235,788,279,744,291,733,358,669,441,492,358,673,301,736,620,399,442,447},
/*5*/ {235,788,279,744,291,733,358,666,507,516,341,682,240,783,647,376,507,516} };
int SIT_DOWN[18]= {182,841,294,729,490,533,353,670,508,515,268,755,71,952,753,270,508,515 };
int delay_tendang[5]={ 2000000,3000000, 2000000, 2000000, 2000000};
int tendang_kanan[5][18]={
/*position 1*/ {154,888,279,744,462,561,358,666,507,517,305,719,293,747,619,414,508,516},
/*position 2*/ {235,788,279,744,462,561,358,660,507,566,451,547,398,620,580,441,507,516},
/*position 3*/ {235,788,318,656,462,561,358,669,518,563,436,639,444,701,559,413,446,475},
/*position 4*/ {235,810,305,644,462,561,358,651,486,584,572,581,185,614,578,433,446,484},
/*position 5*/ {235,788,419,713,462,561,358,669,503,562,217,606,365,682,594,432,475,473}};
int speed_tendang_kanan[5][18]={
/*speed 1*/ {150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150},
/*speed 2*/ {150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150},
/*speed 3*/ {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100},
/*speed 4*/ {300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300},
/*speed 5*/ {100,100,100,100,100,100,512,100,512,100,512,100,512,100,512,100,512,100}};
int tendang_kiri[12][18]={
{235 ,788 ,279 ,744 ,462 ,561 ,358 ,666 ,508 ,516 ,391 ,633 ,307 ,734 ,624 ,400 ,507 ,516},
{233 ,787 ,280 ,745 ,461 ,559 ,357 ,663 ,507 ,516 ,346 ,678 ,206 ,839 ,674 ,346 ,509 ,508} ,
{233 ,787 ,280 ,745 ,461 ,559 ,356 ,660 ,505 ,514 ,283 ,737 ,112 ,918 ,721 ,306 ,512 ,507} ,
{233 ,787 ,279 ,745 ,462 ,559 ,344 ,658 ,502 ,512 ,276 ,743 ,45 ,980 ,765 ,262 ,508 ,506 } ,
{230 ,787 ,279 ,745 ,462 ,559 ,340 ,659 ,499 ,511 ,288 ,734 ,25 ,997 ,796 ,234 ,504 ,506 } ,
{233 ,787 ,487 ,745 ,512 ,559 ,343 ,656 ,500 ,510 ,274 ,745 ,28 ,995 ,768 ,260 ,508 ,502 } ,
{234 ,787 ,484 ,746 ,461 ,559 ,344 ,658 ,459 ,488 ,277 ,724 ,28 ,957 ,779 ,261 ,529 ,502} ,
{234 ,787 ,481 ,746 ,461 ,558 ,345 ,657 ,438 ,469 ,292 ,700 ,23 ,940 ,788 ,262 ,537 ,501} ,
{237 ,786 ,493 ,791 ,460 ,557 ,340 ,687 ,386 ,432 ,287 ,683 ,24 ,867 ,781 ,263 ,550 ,500} ,
{238 ,784 ,498 ,792 ,460 ,557 ,341 ,660 ,385 ,457 ,285 ,684 ,24 ,928 ,776 ,290 ,554 ,498} ,
{238 ,784 ,500 ,792 ,459 ,557 ,342 ,660 ,386 ,453 ,285 ,749 ,24 ,877 ,773 ,373 ,555 ,498} ,
{238 ,784 ,502 ,792 ,458 ,557 ,342 ,662 ,386 ,450 ,285 ,741 ,25 ,696 ,771 ,518 ,558 ,498}
};
int speed_tendang[12]={ 350 , 350 , 350 , 100 , 50 , 350,50,50,50,200,512,512 };
int delaytendang[12]={ 2000000, 2000000, 2000000, 2000000, 2000000, 2000000,100000,100000,100000,2000000,100000,100000};
int RTest [18]= {235,788,279,744,462,561,358,666,507,516,316,690,351,650,570,457,507,516};
int INIT[18]= { /*0*/ 235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516 };
int BALANCE[1][18]= { /*0*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int F_R_S[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,291,732,160,863,687,336,457,486},
/*1*/ {235,787,279,744,462,561,358,666,487,526,271,722,60 ,843,737,326,477,496},
/*2*/ {235,788,279,744,462,561,358,666,507,516,271,712,160,863,672,306,507,516} };
int F_L_S[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,301,722,160,863,687,336,537,566},
/*1*/ {236,788,279,744,462,561,357,665,497,536,301,752,160,963,687,286,527,546},
/*2*/ {235,788,279,744,462,561,358,666,507,516,311,752,160,863,717,351,507,516} };
int ff_r_l[3][18]= { /*0*/ {135,688,279,744,462,561,357,665,507,516,261,682,160,863,647,296,527,536},
/*1*/ {235,788,279,744,462,561,357,665,497,536,301,802,160,983,687,296,527,536},
/*2*/ {285,838,279,744,462,561,358,666,507,516,331,752,160,863,717,366,507,516} };
int ff_l_r[3][18]= { /*0*/ {335,888,279,744,462,561,358,666,507,516,341,762,160,863,727,376,487,496},
/*1*/ {235,788,279,744,462,561,358,666,487,526,241,722,80 ,863,707,336,487,496},
/*2*/ {185,738,279,744,462,561,358,666,507,516,271,692,160,863,657,306,507,516} };
int F_R_E[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,271,692,160,863,657,306,547,566},
/*1*/ {236,788,279,744,462,561,357,665,497,536,301,732,160,963,707,286,527,546},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,160,863,687,336,507,516} };
int F_L_E[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,331,752,160,863,717,366,447,476},
/*1*/ {235,787,279,744,462,561,358,666,487,526,271,722,60 ,863,737,326,477,496},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,160,863,687,336,507,516} };
int FRT_R_M[6][18]= { /*0*/ {285,837,279,744,462,561,358,666,507,516,301,762,160,863,707,346,447,486},
/*1*/ {235,787,279,744,462,561,358,666,487,526,251,742,60 ,843,737,326,477,496},
/*2*/ {205,758,279,744,462,561,458,666,507,516,281,702,160,863,677,316,507,516},
/*3*/ {175,727,279,744,462,561,358,566,507,516,261,702,160,863,667,306,537,566},
/*4*/ {236,788,279,744,462,561,357,665,497,536,281,772,160,963,687,286,527,546},
/*5*/ {265,818,279,744,462,561,358,666,507,516,311,752,160,863,707,346,507,516} };
int FLT_L_M[6][18]= { /*0*/ {175,727,279,744,462,561,358,666,507,516,271,712,160,863,677,316,537,566},
/*1*/ {236,788,279,744,462,561,357,665,497,536,281,772,160,963,697,286,527,546},
/*2*/ {265,818,279,744,462,561,358,566,507,516,311,732,160,863,707,346,507,516},
/*3*/ {285,837,279,744,462,561,458,666,507,516,331,752,160,863,727,346,447,486},
/*4*/ {235,787,279,744,462,561,358,666,487,526,251,742,60 ,863,737,336,477,496},
/*5*/ {205,758,279,744,462,561,358,666,507,516,281,702,160,863,677,316,507,516} };
int B_R_S[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,311,712,160,863,687,336,457,486},
/*1*/ {235,787,279,744,462,561,358,666,487,526,281,712,60 ,863,737,336,477,496},
/*2*/ {235,788,279,744,462,561,358,666,508,515,341,722,160,863,697,366,507,516} };
int B_L_S[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,331,692,160,863,687,336,537,566},
/*1*/ {236,788,279,744,462,561,357,665,497,536,311,742,160,963,687,286,527,546},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,682,160,863,667,316,507,516} };
int B_R_M[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,341,742,170,863,707,376,547,566},
/*1*/ {236,788,279,744,462,561,357,665,497,536,301,742,160,993,687,266,527,546},
/*2*/ {235,788,279,744,462,561,358,666,507,516,281,672,160,863,657,306,507,516} };
int B_L_M[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,281,682,160,853,657,306,477,486},
/*1*/ {235,787,279,744,462,561,358,666,487,526,271,722,60 ,863,737,336,477,496},
/*2*/ {235,788,279,744,462,561,358,666,507,516,341,742,160,863,717,366,507,516} };
int B_R_E[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,341,722,160,863,707,356,537,566},
/*1*/ {236,788,279,744,462,561,357,665,497,536,301,782,160,963,687,286,527,546},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,160,863,687,336,507,516} };
int B_L_E[3][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,291,692,160,863,667,316,447,486},
/*1*/ {235,787,279,744,462,561,358,666,487,526,241,722,60 ,863,737,336,477,496},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,160,863,687,336,507,516} };
int RFT[3][18]= { /*0*/ {235,788,279,744,462,561,338,686,457,566,271,722,110,853,717,336,507,516},
/*1*/ {235,788,279,744,462,561,338,686,477,546,301,722,170,853,687,336,487,516},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int LFT[3][18]= { /*0*/ {235,788,279,744,462,561,337,685,457,566,301,752,170,913,687,306,507,516},
/*1*/ {235,788,279,744,462,561,337,685,477,546,301,722,170,853,687,336,507,536},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int RBT[3][18]= { /*0*/ {235,788,279,744,462,561,398,626,457,566,271,722,110,853,717,336,507,516},
/*1*/ {235,788,279,744,462,561,398,626,477,546,301,722,160,863,687,336,487,516},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int LBT[3][18]= { /*0*/ {235,788,279,744,462,561,397,625,457,566,301,752,170,913,687,306,507,516},
/*1*/ {235,788,279,744,462,561,397,625,477,546,301,722,160,863,687,336,507,536},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int R[3][18]= { /*0*/ {235,788,279,744,462,561,358,666,457,566,271,722,120,853,717,336,507,516},
/*1*/ {235,788,279,744,462,561,358,666,477,546,301,722,170,853,687,336,487,516},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int L[3][18]= { /*0*/ {235,788,279,744,462,561,357,665,457,566,301,752,170,903,687,306,507,516},
/*1*/ {235,788,279,744,462,561,357,665,477,546,301,722,170,853,687,336,507,536},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int Fst_R[3][18]= { /*0*/ {235,788,279,744,462,561,358,666,447,596,271,722,110,853,717,336,507,516},
/*1*/ {235,788,279,744,462,561,358,666,447,576,301,722,170,853,687,336,487,516},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int Fst_L[3][18]= { /*0*/ {235,788,279,744,462,561,357,665,427,576,301,742,170,893,687,316,507,516},
/*1*/ {235,788,279,744,462,561,357,665,447,576,301,722,170,853,687,336,507,536},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int RT[3][18]= { /*0*/ {235,788,279,744,462,561,438,566,507,516,271,722,110,853,717,336,507,516},
/*1*/ {235,788,279,744,462,561,408,616,507,516,301,722,170,853,687,336,507,516},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int LT[3][18]= { /*0*/ {235,788,279,744,462,561,457,585,507,516,301,752,170,913,687,306,507,516},
/*1*/ {235,788,279,744,462,561,407,615,507,516,301,722,170,853,687,336,507,516},
/*2*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int B[5][18]= { /*0*/ {234,789,509,514,462,561,353,670,508,515,346,677,282,741,617,406,508,515},
/*1*/ {461,562,496,527,501,522,353,670,508,515,346,677,282,741,617,406,508,515},
/*2*/ {611,412,580,443,155,868,353,670,498,525,55 ,968,121,902,835,188,504,519},
/*3*/ {394,629,264,759,454,569,354,669,512,511,80 ,943,38 ,985,705,318,512,511},
/*4*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int F_PShoot_R[5][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,301,722,170,853,687,336,537,566},
/*1*/ {236,788,279,744,462,561,357,665,497,536,301,782,170,953,687,286,527,546},
/*2*/ {235,788,279,744,462,561,358,666,507,516,331,792,170,853,737,386,507,516},
/*3*/ {235,787,279,744,462,561,358,666,507,516,321,802,170,853,757,386,447,470},
/*4*/ {235,787,279,744,462,561,358,666,487,526,351,752,40 ,853,737,336,477,466} };
int F_PShoot_R2[5][18]= { /*0*/ {235,787,279,744,462,561,358,666,487,526,201,712,430,853,457,336,477,466},
/*1*/ {235,787,279,744,462,561,358,666,487,526,201,712,280,853,537,336,477,466},
/*2*/ {235,787,279,744,462,561,358,666,487,526,271,722,10 ,853,737,336,477,466},
/*3*/ {235,787,279,744,462,561,358,666,507,516,321,722,210,853,667,336,477,476},
/*4*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int F_PShoot_L[5][18]= { /*0*/ {236,788,279,744,462,561,357,665,507,516,301,722,170,853,687,336,457,486},
/*1*/ {235,787,279,744,462,561,358,666,487,526,271,722,70 ,853,737,336,477,496},
/*2*/ {235,788,279,744,462,561,357,665,507,516,231,692,170,853,637,286,507,516},
/*3*/ {236,788,279,744,462,561,357,665,507,516,221,702,170,853,637,266,553,576},
/*4*/ {236,788,279,744,462,561,357,665,497,536,271,672,170,983,687,286,557,546} };
int F_PShoot_L2[5][18]= { /*0*/ {236,788,279,744,462,561,357,665,497,536,311,822,170,593 ,677,566,557,546},
/*1*/ {236,788,279,744,462,561,357,665,497,536,311,852,170,963 ,687,416,557,546},
/*2*/ {236,788,279,744,462,561,357,665,497,536,301,802,170,1023,687,266,557,546},
/*3*/ {236,788,279,744,462,561,357,665,507,516,301,702,170,813 ,687,356,547,546},
/*4*/ {235,788,279,744,462,561,357,665,507,516,301,722,170,853 ,687,336,507,516} };
int F_Shoot_R[7][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,321,722,210,853,667,336,477,476},
/*1*/ {235,787,279,744,462,561,358,666,487,526,271,722,10 ,853,737,336,477,456},
/*2*/ {235,787,279,744,462,561,358,666,487,526,221,722,512,853,467,356,477,455}, //440
/*3*/ {235,787,279,744,462,561,358,666,487,526,221,722,290,853,467,356,477,456},
/*4*/ {235,787,279,744,462,561,358,666,487,526,271,722,10 ,853,737,336,477,456},
/*5*/ {235,787,279,744,462,561,358,666,507,516,321,722,210,853,667,336,477,476},
/*6*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int delayF_Shoot_R[7]= /*0*/ {1000000, 1000000, 1000000,1000000,
1000000, 1000000, 1000000};
int speedF_Shoot_R[7]= /*0*/ {100, 1000, 1000, 1000,
100, 100, 100};
// 1000,1000}; //--->2 terakhir delay kepala
int F_Shoot_L[7][18]= { /*0*/ {236,788,279,744,462,561,357,665,507,516,301,702,170,813 ,687,356,547,546},
/*1*/ {236,788,279,744,462,561,357,665,497,536,301,752,170,1013,687,286,557,546},
/*2*/ {236,788,279,744,462,561,357,665,497,536,301,802,170,583 ,677,556,563,546},
/*3*/ {236,788,279,744,462,561,357,665,497,536,301,802,170,733, 677,556,557,546},
/*4*/ {236,788,279,744,462,561,357,665,497,536,301,752,170,1013,687,286,557,546},
/*5*/ {236,788,279,744,462,561,357,665,507,516,301,702,170,813 ,687,356,547,546},
/*6*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853 ,687,336,507,516} };
int delayF_Shoot_L[7]= /*0*/ {1000000, 100000, 100000, 100000,
1000000, 1000000, 1000000};
int speedF_Shoot_L
[7]= /*0*/ {100, 1000, 1000, 1000,
100, 100, 100};
// 1000,1000}; //--->2 terakhir delay kepala
int R_Shoot[7][18]= { /*0*/ {235,787,279,744,462,561,358,666,507,516,321,722,210,853,667,336,477,466},
/*1*/ {235,787,279,744,462,561,358,666,487,526,271,722,10 ,853,737,336,477,456},
/*2*/ {235,787,279,744,462,561,358,666,387,556,321,722,210,853,657,336,327,455},
/*3*/ {235,787,279,744,462,561,358,666,507,516,321,722,210,853,667,336,477,466},
/*4*/ {235,788,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516} };
int walkreadytendang[1][18]= {{ /*0*/ 235, 788, 279, 744, 462, 561, 358, 666, 507, 516, 328, 695, 240, 783, 647, 376, 507, 516 }};
//kcepatan walkready tendang
int vwalkreadytendang[1][18]= {{/*0*/ 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 170, 170, 220, 220, 120, 120, 72, 72 }};
int tendang[6][18]= { /*0*/ {235, 788, 279, 744, 462, 561, 358, 666, 507, 516, 328, 695, 240, 783, 647, 376, 507, 516 }, //delay250
/*1*/ {235, 788, 279, 744, 462, 561, 358, 669, 441, 484, 374, 657, 298, 736, 636, 404, 442, 452 }, //delay1300
/*2*/ {235, 788, 279, 744, 462, 561, 354, 669, 421, 511, 394, 721, 119, 746, 644, 391, 440, 447 }, //delay500
/*3*/ {235, 788, 279, 744, 462, 561, 354, 669, 421, 511, 220, 642, 507, 215, 502, 402, 424, 449 }, //delay2000
/*4*/ {235, 788, 279, 744, 462, 561, 354, 669, 425, 511, 304, 628, 301, 738, 706, 388, 432, 449 }, //delay800
/*5*/ {235, 788, 279, 744, 462, 561, 354, 669, 425, 511, 341, 682, 240, 647, 507, 388, 432, 449 } //delay800
};
int delayTendang[1][6]={{250000,1300000,500000,2000000,800000,800000}};
//kecepatan tendang
int vtendang[6][18]= {
/*0*/ {50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50 },
/*1*/ {37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 69, 37, 37, 37, 21 },
/*2*/ { 0, 0, 0, 0, 0, 0, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767 },
/*3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1023, 1023, 1023, 170, 1023, 1023, 1023 },
/*4*/ { 0, 0, 0, 0, 0, 0, 0, 0, 69, 0, 117, 255, 117, 255, 117, 255, 133, 0 },
/*5*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 32, 32, 32, 32, 0, 0, 0 }};
int DVC_SHOOT [5][18]={ {154,888,279,744,462,561,358,666,507,517,305,719,293,747,619,414,508,516},
//speed=150
{235,788,279,744,462,561,358,661,507,516,464,569,421,628,579,439,507,516},
//speed=150
{235,788,302,689,462,561,358,669,518,563,436,641,444,701,511,413,446,475},
//speed=150
{235,788,286,725,462,561,358,669,503,542,572,602,218,625,578,433,446,467},
//speed=150
{235,788,292,655,462,561,358,669,503,562,217,606,365,682,594,432,475,473}};
//speed=100; speed 7,9,11,13,15,17=512
/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20*/
int speed_DVC_SHOOT [5][20] = { {150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,1000,1000},
{150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,1000,1000},
{150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,1000,1000},
{150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,1000,1000},
{100,100,100,100,100,100,512,100,512,100,512,100,512,100,512,100,512,100,1000,1000}};
int delay_DVC_SHOOT [5] = {2000000, 500000, 800000, 700000, 1000000};
int GSR_L[7][18]={
/*0*/ {235,788,279,733,291,733,358,666,512,512,317,707,241,783,648,376,512,512}, //tegak
/*1*/ {235,788,279,744,291,733,358,666,512,512,317,707,241,783,648,376,539,529}, //miring
/*2*/ {235,788,279,744,291,733,358,666,512,600,317,707,241,773,648,376,539,529}, //dorong
/*3*/ {235,788,279,744,291,733,358,666,512,512,317,707,241,783,648,376,487,487}, //miring
/*4*/ {235,788,279,744,291,733,358,666,512,512,307,707,231,783,648,376,429,487}, //tarik
/*6*/ {235,788,279,733,291,733,358,666,512,512,317,707,241,783,648,376,512,512}, //tegak
/*7*/ {235,788,279,744,291,733,358,666,512,512,342,682,241,783,648,376,487,496}};
int GSR_L_SPD[8]={100,80,80,90,100,100,100,100};
int GSR_L_DLY[8]={1000000,550000,1000000,650000,1000000,1000000,700000,1000000};
int GSR_R[7][18]={
/*0*/ {235,788,279,733,291,733,358,666,512,512,317,707,241,783,648,376,512,512}, //tegak
/*1*/ {235,788,279,744,291,733,358,666,512,512,317,707,241,783,648,376,485,485}, //miring
/*2*/ {235,788,279,744,291,733,358,666,374,512,317,707,241,783,658,376,485,485}, //dorong
/*3*/ {235,788,279,744,291,733,358,666,512,512,317,707,241,783,648,376,537,537}, //miring
/*4*/ {235,788,279,744,291,733,358,666,512,512,317,717,241,783,648,376,537,595}, //tarik
/*6*/ {235,788,279,733,291,733,358,666,512,512,317,707,241,783,648,376,512,512}, //tegak
/*3*/ {235,788,279,744,291,733,358,666,512,512,342,682,241,783,648,376,487,496}};
int GSR_R_SPD[28]={ 100, 80, 80, 90, 100,
100, 100, 110, 100, 100,
100, 100, 100, 100, 100,
100, 100, 100, 100, 100,
100, 100, 100, 100, 100,
100, 100, 100};
int GSR_R_DLY[28]={ 1000000, 550000, 1000000,
650000, 1000000, 1000000,
650000, 1000000, 700000,
700000, 700000, 700000,
700000, 700000, 700000,
1000000, 1000000, 1000000,
1000000, 1000000, 1000000,
1000000, 1000000, 1000000,
1000000, 1000000, 4000000,
2000000};
int standGK[18]= {226,829,547,511,515,516,351,673,507,525,480,543,521,503,517,524,502,520};
//int SIT_1[18] ={182,841,294,729,490,533,353,670,508,515,268,755,71,952,753,270,508,515};
//int SIT_2[18] ={362,667,270,744,516,532,358,665,497,517,283,743,23,1010,798,229,496,513};
//int diri [1][18] = {512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512};
//int TEGAK
int STANDUP_1[7][18] ={
/*0*/ {444,580,205,819,512,512,358,666,507,516,205,819,190,835},
/*1*/ {495,529,205,819,512,512,358,666,507,516,120,904,190,835},
/*2*/ {484,524,205,819,512,512,358,666,507,516,120,904,254,765},
/*3*/ {484,524,205,819,512,512,358,666,507,516,101,923,395,765},
/*4*/ {484,524,205,819,512,512,358,666,507,516,101,923,395,625},
/*5*/ {337,687,279,744,462,561,358,666,507,516,342,682,170,855},
/*6*/ {61,972,279,744,462,561,358,666,507,516,301,722,170,853}};
//int STANDUP_1[7][18] ={
// /*0*/ {444,580,205,819,512,512,358,666,507,516,205,819,190,834,768,256,507,517},
// /*1*/ {495,529,205,819,512,512,358,666,507,516,120,904,190,834,707,317,507,517},
// /*2*/ {484,524,205,819,512,512,358,666,507,516,120,904,254,769,666,358,507,517},
// /*3*/ {484,524,205,819,512,512,358,666,507,516,101,923,395,769,457,416,507,517},
// /*4*/ {484,524,205,819,512,512,358,666,507,516,101,923,395,629,457,567,507,517},
// /*5*/ {337,687,279,744,462,561,358,666,507,516,342,682,170,853,687,336,507,516},
// /*6*/ {61,972,279,744,462,561,358,666,507,516,301,722,170,853,687,336,507,516,} };
int delay_STANDUP_1 [7]= {0,0,0,0,0,0,0};
int speed_STANDUP_1 [7]= {150, 150, 150, 150,
150, 100, 200/*150*/};
//int STANDUP_2[18] ={235,788,279,744,462,561,358,666,507,517,305,719,206,818,666,358,508,516};
//int UP_F [13][18]={/*0*/{235,788,251,773,462,561,358,666,507,516,512,512,512,512,482,542,507,517},
// /*1*/ {235,788,512,512,462,561,358,666,507,516,512,512,512,512,482,542,507,517},
// /*2*/ {768,256,512,512,462,561,358,666,507,516,512,512,512,512,482,542,507,517},
// /*3*/ {768,256,205,819,462,561,358,666,507,516,512,512,512,512,482,542,507,517},
// /*4*/ {444,580,205,819,200,824,358,666,507,516,512,512,512,512,482,542,507,517},
// /*5*/ {444,580,205,819,200,824,358,666,507,516,205,819,190,834,482,542,507,517},
// /*6*/ {444,580,205,819,512,512,358,666,507,516,205,819,190,834,768,256,507,517},
// /*7*/ {495,529,205,819,512,512,358,666,507,516,120,904,190,834,707,317,507,517},
// /*8*/ {484,524,205,819,512,512,358,666,507,516,120,904,254,769,666,358,507,517},
// /*9*/ {484,524,205,819,512,512,358,666,507,516,101,923,395,769,457,416,507,517},
// /*10*/ {484,524,205,819,512,512,358,666,507,516,101,923,395,629,457,567,507,517},
// /*11*/ {337,687,279,744,462,561,358,666,507,516,342,682,170,853,687,336,507,516},
// /*12*/ {235,788,215,809,250,774,358,666,507,516,301,722,170,853,687,336,507,516} };
//int speed_UP_F [13]= { 150, 200, 200, 150, 150,
// 150, 150, 150, 150, 150,
// 150, 150, 250/*150*/};
//int delay_UP_F [13]= { 1000000,1000000,1500000,
// 1000000,1000000,1000000,
// 1000000,700000,700000,
// 700000,1000000,1000000,1000000};
//int UP_B [27][18]={/*0*/{235 ,788 ,512 ,512 ,462 ,561 ,358 ,666 ,507 ,516 ,512 ,512 ,512 ,512 ,512 ,512 ,507 ,516},
// /*1*/ {542 ,482 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,0 ,1023 ,541 ,483 ,422 ,602 ,512 ,512},
// /*2*/ {632 ,392 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,129 ,895 ,541 ,483 ,422 ,602 ,512 ,512},
// /*3*/ {632 ,392 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,129 ,895 ,541 ,483 ,422 ,602 ,512 ,512},
// /*4*/ {632 ,392 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
// /*5*/ {70 ,954 ,239 ,785 ,512 ,512 ,357 ,667 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
// /*6*/ {70 ,954 ,246 ,785 ,512 ,512 ,526 ,667 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
// /*7*/ {70 ,1023 ,248 ,785 ,511 ,504 ,524 ,649 ,475 ,532 ,211 ,819 ,170 ,860 ,445 ,596 ,547 ,492},
// /*8*/ {70 ,1021 ,246 ,710 ,512 ,507 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
// /*9*/ {394 ,1021 ,448 ,710 ,585 ,507 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
// /*10*/ {382 ,1021 ,161 ,710 ,601 ,507 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
// /*11*/ {379 ,896 ,159 ,769 ,601 ,524 ,539 ,660 ,491 ,491 ,143 ,954 ,201 ,857 ,424 ,603 ,467 ,451},
// /*12*/ {446 ,848 ,197 ,749 ,433 ,525 ,538 ,637 ,494 ,490 ,168 ,966 ,187 ,897 ,464 ,563 ,412 ,472},
// /*13*/ {430 ,936 ,197 ,747 ,432 ,519 ,512 ,632 ,470 ,519 ,352 ,983 ,323 ,874 ,459 ,571 ,369 ,400},
// /*14*/ {426 ,828 ,197 ,733 ,432 ,517 ,512 ,627 ,443 ,516 ,320 ,971 ,323 ,870 ,462 ,567 ,340 ,440},
// /*15*/ {411 ,853 ,197 ,640 ,432 ,528 ,510 ,629 ,513 ,517 ,426 ,983 ,311 ,803 ,597 ,571 ,351 ,405},
// /*16*/ {411 ,861 ,196 ,636 ,431 ,581 ,528 ,612 ,583 ,525 ,359 ,953 ,138 ,802 ,678 ,584 ,446 ,404},
// /*17*/ {410 ,737 ,193 ,673 ,430 ,707 ,513 ,671 ,668 ,512 ,348 ,968 ,270 ,629 ,669 ,604 ,429 ,432},
// /*18*/ {409 ,627 ,192 ,704 ,429 ,667 ,513 ,657 ,662 ,512 ,355 ,970 ,266 ,629 ,727 ,604 ,429 ,489},
// /*19*/ {411 ,625 ,190 ,702 ,427 ,665 ,339 ,635 ,533 ,516 ,258 ,980 ,283 ,629 ,751 ,604 ,466 ,511},
// /*20*/ {509 ,545 ,197 ,700 ,397 ,668 ,337 ,629 ,522 ,515 ,69 ,980 ,258 ,597 ,632 ,596 ,502 ,518},
// /*21*/ {509 ,545 ,197 ,700 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,190 ,834 ,707 ,317 ,507 ,517},
// /*22*/ {495 ,529 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,190 ,834 ,707 ,317 ,507 ,517},
// /*23*/ {484 ,524 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,254 ,769 ,666 ,358 ,507 ,517},
// /*24*/ {484 ,524 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,101 ,923 ,395 ,769 ,457 ,416 ,507 ,517},
// /*25*/ {484 ,524 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,101 ,923 ,395 ,629 ,457 ,567 ,507 ,517},
// /*26*/ {337 ,687 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,342 ,682 ,170 ,853 ,687 ,336 ,507 ,516} };
//int speed_UP_B[27]={ 100, 100, 700, 100, 100,
// 100, 100, 100, 100, 100,
// 100, 100, 100, 100, 100,
// 100, 100, 100, 100, 100,
// 100, 100, 100, 100, 100,
// 100, 50};
/*int delay_UP_B[27]={ 2000000, 3000000, 1000000,
1000000, 2000000, 2000000,
1500000, 1000000, 700000,
700000, 700000, 700000,
700000, 700000, 700000,
1000000, 1000000, 1000000,
1000000, 1000000, 1000000,
1000000, 1000000, 1000000,
1000000, 1000000, 1000000};
*/
int UP_B_GK [27][18]={
{235 ,788 ,512 ,512 ,462 ,561 ,358 ,666 ,507 ,516 ,512 ,512 ,512 ,512 ,512 ,512 ,507 ,516},
{542 ,482 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,0 ,1023 ,541 ,483 ,422 ,602 ,512 ,512},
{632 ,392 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,129 ,895 ,541 ,483 ,422 ,602 ,512 ,512},
{632 ,392 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,129 ,895 ,541 ,483 ,422 ,602 ,512 ,512},
{632 ,392 ,824 ,200 ,512 ,512 ,357 ,667 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
{70 ,954 ,239 ,785 ,512 ,512 ,357 ,667 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
{70 ,954 ,246 ,785 ,512 ,512 ,526 ,667 ,496 ,528 ,127 ,915 ,140 ,898 ,431 ,586 ,512 ,512},
{70 ,1023 ,248 ,785 ,511 ,504 ,524 ,649 ,475 ,532 ,211 ,819 ,170 ,860 ,445 ,596 ,547 ,492},
{70 ,1021 ,246 ,710 ,512 ,507 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
{394 ,1021 ,448 ,710 ,585 ,507 ,526 ,667 ,496 ,528 ,298 ,897 ,213 ,896 ,460 ,587 ,480 ,424},
{380 ,1023,170,713,378,503,526,666,496,528,296,895,215,895,462,586,478,422},
{379 ,896 ,159 ,769 ,601 ,524 ,539 ,660 ,491 ,491 ,143 ,954 ,201 ,857 ,424 ,603 ,467 ,451},
{446 ,848 ,197 ,749 ,433 ,525 ,538 ,637 ,494 ,490 ,168 ,966 ,187 ,897 ,464 ,563 ,412 ,472},
{430 ,936 ,197 ,747 ,432 ,519 ,512 ,632 ,470 ,519 ,352 ,983 ,323 ,874 ,459 ,571 ,369 ,400},
{426 ,828 ,197 ,733 ,432 ,517 ,512 ,627 ,443 ,516 ,320 ,971 ,323 ,870 ,462 ,567 ,340 ,440},
{411 ,853 ,197 ,640 ,432 ,528 ,510 ,629 ,513 ,517 ,426 ,983 ,311 ,803 ,597 ,571 ,351 ,405},
{411 ,861 ,196 ,636 ,431 ,581 ,528 ,612 ,583 ,525 ,359 ,953 ,138 ,802 ,678 ,584 ,446 ,404},
{410 ,737 ,193 ,673 ,430 ,707 ,513 ,671 ,668 ,512 ,348 ,968 ,270 ,629 ,669 ,604 ,429 ,432},
{409 ,627 ,192 ,704 ,429 ,667 ,513 ,657 ,662 ,512 ,355 ,970 ,266 ,629 ,727 ,604 ,429 ,489},
{411 ,625 ,190 ,702 ,427 ,665 ,339 ,635 ,533 ,516 ,258 ,980 ,283 ,629 ,751 ,604 ,466 ,511},
{495,529,254,819,512,512,358,666,507,516,120,904,190,834,707,317,507,517},
{495 ,529 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,190 ,834 ,707 ,317 ,507 ,517},
{484 ,524 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,120 ,904 ,254 ,769 ,666 ,358 ,507 ,517},
{484 ,524 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,101 ,923 ,395 ,769 ,457 ,416 ,507 ,517},
{484 ,524 ,205 ,819 ,512 ,512 ,358 ,666 ,507 ,516 ,101 ,923 ,395 ,629 ,457 ,567 ,507 ,517},
{337 ,687 ,279 ,744 ,462 ,561 ,358 ,666 ,507 ,516 ,342 ,682 ,170 ,853 ,687 ,336 ,507 ,516},
{235,788,279,744,462,561,358,666,507,517,305,719,206,818,666,358,508,516} };
int speed_UP_B_GK[27] = {100,100,300,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100};
int delay_UP_B_GK[27] = {2000000,3000000,1000000,1000000,2000000,2000000,2000000,1000000,700000,700000,
700000,700000,700000,700000,700000,1000000,1000000,1000000,1000000,1000000,
1000000,1000000,1000000,1000000,1000000,1000000,1000000};
int UP_F_GK[9][18]= {
/*0*/{511,504,533,526,217,842,360,674,497,502,517,515,488,548,842,183,476,511},
/*1*/{511,504,221,800,217,842,360,674,497,502,517,515,488,548,842,183,476,511},
/*2*/{473,565,216,788,509,508,361,665,504,501,53,973,140,893,674,371,493,522},
/*3*/{472,564,266,760,509,507,361,650,507,512,53,984,256,796,552,474,474,525},
/*4*/{472,564,266,760,509,507,361,650,507,512,53,984,256,796,552,474,474,525},
/*5*/{379,642,274,747,507,507,372,648,498,506,138,905,263,797,574,443,472,522},
/*6*/{463,568,274,746,506,507,362,652,495,514,145,890,152,886,620,409,473,520},
/*7*/{113,920,285,734,502,508,362,667,496,514,244,769,98,928,729,288,476,518},
/*8*/{235,788,279,744,462,561,358,666,507,517,305,719,206,818,666,358,508,516} };
int delay_UP_F_GK [9]={2500000,250000,2500000,2000000,2000000,2000000,2000000,2000000,500000 };
int speed_UP_F_GK [9]={100,200,200,50,50,0,200,500,500 };
int jatoh_kiri2_GK[2][18]={
/*0*/{235,792,278,202,462,561,357,665,504,517,302,719,200,824,669,358,505,517},
/*1*/{236,794,278,202,462,562,359,685,491,493,306,643,178,922,671,222,508,513} };
int delay_jatoh_kiri2_GK[2]={50000,2000000/*delay terbaring ditanah*/};
int speed_jatoh_kiri2_GK[2]={500,500};
int pukul_kiri[3][18]={
/*0*/{236,610,264,198,460,599,357,668,508,503,339,750,244,888,641,348,432,432},
/*1*/{235,938,260,198,460,565,358,665,509,497,339,751,243,886,642,347,431,432},
/*2*/{236,610,264,198,460,599,357,668,508,503,339,750,244,888,641,348,432,432} };
int delay_pukul_kiri[3]={3000000,500000,1000000};
// int speed_pukul_kiri[3]={100,500,500};
int balikbadan_kiri[1][18]={
/*0*/{264,509,257,495,458,600,359,761,505,502,339,744,246,889,641,348,431,432} };
int delay_balikbadan_kiri[1]={1000000};
int speed_balikbadan_kiri[1]={100};
int jatoh_kanan2_GK[2][18]={
/*0*/{247,784,838,745,501,561,359,666,505,519,302,720,203,825,669,356,505,515},
/*1*/{248,786,837,745,501,561,358,666,523,520,368,718,143,825,798,355,504,513} };
int speed_jatoh_kanan2_GK[6]={500,500};
int delay_jatoh_kanan2_GK[2]={50000,2000000/*delay terbaring ditanah*/};
int pukul_kanan[3][18]={
/*0*/{402,787,839,767,461,561,358,666,561,552,340,674,168,833,713,333,561,567},
/*1*/{95,787,831,769,411,561,361,665,563,550,335,677,170,830,713,331,561,567},
/*2*/{406,787,840,769,302,561,364,664,563,550,340,673,168,833,713,333,561,567} };
int speed_pukul_kanan[3]={100,500,500};
int delay_pukul_kanan[3]={3000000,500000,1000000};
int balikbadan_kanan[1][18]={
/*0*/{471,767,616,768,304,561,357,665,589,553,344,676,167,831,713,334,563,568} };
int delay_balikbadan_kanan[1]={1000000};
int speed_balikbadan_kanan[1]={100};
int jatoh_kanan_GK[7][18]= {
/*0*/{226,829,547,511,515,516,351,673,507,525,480,543,521,503,517,524,502,520},
/*1*/{228,828,841,764,515,516,351,673,523,525,480,541,517,501,519,527,507,520},
/*2*/{227,795,839,790,514,515,350,661,587,581,508,497,473,502,562,505,582,574},
/*3*/{416,796,839,790,539,514,352,660,586,578,511,499,472,503,564,507,578,569},
/*4*/{70,796,823,791,485,514,355,660,586,575,512,500,472,504,566,508,578,566},
/*5*/{422,798,840,790,233,514,356,660,582,572,513,500,473,505,565,507,574,562},
/*6*/{463,796,593,789,225,514,354,660,583,572,516,491,470,507,563,508,574,559} };
int delay_jatoh_kanan_GK [7]={40000,500000,4000000/*delay terbaring ditanah*/,1000000,500000,1000000,1000000 };
int speed_jatoh_kanan_GK [7]={300,200,200,0,0,100,100 };
int jatoh_kiri_GK[6][18]={
/*0*/{226,830,282,201,514,517,352,672,505,524,478,543,520,502,516,525,499,520},
/*1*/{227,830,279,202,513,516,352,672,501,521,478,541,517,508,507,527,258,257},
/*2*/{211,656,272,198,513,516,350,654,459,480,458,482,495,703,517,536,257,284},
/*3*/{209,1023,273,200,513,516,350,655,517,483,480,484,505,699,517,533,515,551},
/*4*/{209,530,273,196,513,708,351,661,518,482,479,483,504,702,517,535,578,524},
/*5*/{213,527,275,403,512,709,359,658,515,503,512,499,462,757,498,554,526,537} };
int delay_jatoh_kiri_GK[6]={500000,5000000/*delay terbaring ditanah*/,3000000,500000,1000000,1000000};
int speed_jatoh_kiri_GK[6]={500,100,100,0,0,100};
int jatoh_depan1[9][18]={/*0*/{205,828,262,768,504,520,355,661,518,521,481,539,520,501,521,524,510,517},
/*1*/{372,667,258,774,502,519,357,664,518,521,441,581,280,742,836,194,508,514},
/*2*/{473,565,216,788,509,508,361,665,504,501,53,973,140,893,674,371,493,522},
/*3*/{472,564,266,760,509,507,361,650,507,512,53,984,256,796,552,474,474,525},
/*4*/{472,564,266,760,509,507,361,650,507,512,53,984,256,796,552,474,474,525},
/*5*/{379,642,274,747,507,507,372,648,498,506,138,905,263,797,574,443,472,522},
/*6*/{463,568,274,746,506,507,362,652,495,514,145,890,152,886,620,409,473,520},
/*7*/{113,920,285,734,502,508,362,667,496,514,244,769,98,928,729,288,476,518},
/*8*/{235,788,279,744,462,561,358,666,507,517,305,719,206,818,666,358,508,516} };
int delay_jatoh_depan1 [9]={3000000,300000,2500000,2000000,2000000,2000000,2000000,2000000,2000000 };
int speed_jatoh_depan1 [9]={400,200,200,50,50,0,200,500,500 };
int jatoh_depan2[2][18]={/*0*/{113,920,538,510,502,519,357,661,517,515,480,541,520,512,728,288,510,513},
/*1*/{235,788,537,511,502,519,357,664,516,515,482,539,484,546,827,197,509,512} };
int delay_jatoh_depan2 [2]={300000,300000 };
int speed_jatoh_depan2 [2]={50,200};
int walk_ready_GK[5][18]={
/*0*/{235,788,279,744,462,561,358,666,507,517,305,719,206,818,666,358,508,516},
/*1*/{415,628,278,748,459,561,356,665,502,508,362,667,290,726,630,416,502,511},
/*2*/{285,776,275,754,457,560,351,663,500,500,441,568,428,565,567,489,502,520},
/*3*/{295,752,273,754,457,561,357,678,517,525,512,511,521,502,532,514,509,519},
/*4*/{226,829,547,511,515,516,351,673,507,525,480,543,521,503,517,524,502,520}
};
int delay_walk_ready_GK[5]={1000000,1000000,1000000,1000000,1000000};
int speed_walk_ready_GK[5]={0,0,0,0,0};
int jatohpr[2][18]={ {212,760,836,755,495,560,357,679,514,525,512,512,521,505,529,513,508,519},
{236,761,836,756,494,560,357,679,512,522,457,512,186,510,770,511,518,514} };
int speed_jatohpr[2]={400,400};
int delay_jatohpr[2]={40000,5000000};
int Array_JatohKanan2016[5][18]=
{
{235,788 ,279 ,744 ,291 ,733 ,358 ,666 ,507 ,516 ,345 ,689 ,26 ,1018 ,796 ,208 ,507 ,516},
{242 ,512 ,808 ,769 ,509 ,563 ,349 ,663 ,644 ,515 ,283 ,731 ,27 ,1010 ,798 ,232 ,655 ,470},
{242 ,512 ,808 ,769 ,509 ,563 ,349 ,663 ,644 ,643 ,283 ,731 ,27 ,1010 ,798 ,232 ,655 ,470},
{242 ,512 ,808 ,769 ,509 ,815 ,349 ,663 ,644 ,611 ,283 ,731 ,27 ,532 ,798 ,232 ,655 ,470},
{242 ,814 ,808 ,210 ,509 ,483 ,364 ,667 ,501 ,523 ,509 ,548 ,501 ,532 ,798 ,232 ,513 ,504}
};
int Speed_JatohKanan2016[5]= { 50,0,100,200,100};
int Delay_JatohKanan2016[5]= { 200,3000000,300000,3000000,2000000};
int Array_JatohKiri2016[5][18]=
{
/*Duduk */ {242,829,268,769,509,563,349,663,521,515,283,731,27,1010,798,232,515,505},
/*JatohKanan*/ {519,826,163,198,508,517,344,665,484,448,266,737,57,1010,767,227,574,419},
{519,826,163,198,508,517,344,665,454,448,266,737,57,1010,767,227,574,419},
/*MiringinBadan*/ {517,828,233,212,215,564,385,758,392,445,372,731,519,1010,841,237,562,458},
/*Tengkurep*/ {241,822,808,209,508,483,363,669,501,521,507,545,502,533,800,229,513,506}
};
int Speed_JatohKiri2016[5]= { 50,0,100,200,100};
int Delay_JatohKiri2016[5]= { 200,3000000,300000,3000000,2000000};
#endif
| [
"elpistar6@gmail.com"
] | elpistar6@gmail.com |
26d7203741be8f121b6df2715f2300a3a12dc1c9 | 2ea5429655a02743c4b3baf7e5ab2005fda04166 | /libft/ft_isalnum.c | 021a963d778adff2ef337951931100645cb13f49 | [] | no_license | MilkyBay/FdF | 13176358350ce4f0ed18d02a0b9d90d309a31f13 | 67018a2fea6176af56c569c06bcf24ebfd4f722d | refs/heads/master | 2020-09-22T03:55:58.937772 | 2019-11-30T16:48:00 | 2019-11-30T16:48:00 | 225,040,554 | 0 | 2 | null | null | null | null | UTF-8 | C | false | false | 981 | c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pthuy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/08 19:35:01 by pthuy #+# #+# */
/* Updated: 2019/10/09 12:55:25 by pthuy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
return (ft_isdigit(c) || ft_isalpha(c));
}
| [
"pthuy@vo-g4.21-school.ru"
] | pthuy@vo-g4.21-school.ru |
a42e92b2f7c1563c139cf9a0575ac7dfb148e396 | 4b4ab8dcab747913d105a687d64b3dec00b0789d | /Switch_Network/Switch_NetworkConfiguration.h | d5ce937b5b34d144f48ae96ed259ffa8e29ff260 | [
"MIT"
] | permissive | woutercharle/switch | 8f90a1b5266b7aef3ee199de0767910f486c21b7 | 632f48fde60d071fdda0b4e7655db0a8354b5ef4 | refs/heads/master | 2020-04-17T11:12:03.744878 | 2019-01-19T20:02:21 | 2019-01-19T20:02:21 | 166,531,427 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 2,572 | h | /*?*************************************************************************
* Switch_NetworkConfiguration.h
* -----------------------
* copyright : (C) 2013 by Wouter Charle
* email : wouter.charle@gmail.com
*
* DISCLAIMER OF DAMAGES
* ---------------------
* Wouter Charle has made every effort possible to ensure that the software
* is free of any bugs or errors, however in no way is the software to
* be considered error or bug free. You assume all responsibility for
* any damages or lost data that may result from any errors or bugs in
* the software.
*
* IN NO EVENT WILL VISION++ BE LIABLE TO YOU FOR ANY GENERAL, SPECIAL,
* INDIRECT, CONSEQUENTIAL, INCIDENTAL OR OTHER DAMAGES ARISING OUT OF
* THIS LICENSE.
*
* In no case shall Wouter Charle's liability exceed the purchase price for
* the software or services.
*
***************************************************************************/
#ifndef _SWITCH_NETWORKCONFIGURATION
#define _SWITCH_NETWORKCONFIGURATION
/*
The channel on which the network operates
Frequency = 2400 + channel
Must be a value in [0x00, 0x7D]
*/
#define NC_NETWORK_CHANNEL 0x36
/*
*/
#define NC_PAYLOAD_SIZE 32
/*
The number of TX retries in case of failure
*/
#define NC_NR_RETRIES 15
/*
The delay between two TX retries in milliseconds
*/
#define NC_RETRY_DELAY_MS 20
/*
The power amplifier level of the rf transmissions
*/
#define NC_POWER_AMPLIER_LEVEL RF24_PA_MAX
/*
The data rate of the rf transmissions
*/
#define NC_DATA_RATE RF24_2MBPS
/*
The cyclic redundancy check length
*/
#define NC_CRC_LENGTH RF24_CRC_16
/*
Broadcast pipe address:
When the node is not part of a network, it broadcasts its information
over the broadcast pipe. This information is used by other nodes to
integrate the node in the network. When the node is part of a network
it listens to other node's broadcasts over the broadcast pipe on RX P0.
*/
#define NC_BROADCAST_PIPE 0xFF29A45D3cULL
/*
Node receive pipes:
Every node receives broadcasts on RX pipe0.
The other pipes are for directed traffic.
RX P1 => traffic from the parent node
RX P2-P5 => traffic from the child nodes
The full RX pipe address is the suffix in byte 0, followed by the device address
*/
#define NC_RX_P1_SUFFIX 0x5a
#define NC_RX_P2_SUFFIX 0x69
#define NC_RX_P3_SUFFIX 0x96
#define NC_RX_P4_SUFFIX 0xa5
#define NC_RX_P5_SUFFIX 0xc3
#endif // _SWITCH_NETWORKCONFIGURATION
| [
"wouter.charle@gmail.com"
] | wouter.charle@gmail.com |
0c943e1fe34eb012b93229df6dfebaece6c60849 | 44a6baf7e9edb276f892e78397cbf8adba2410d7 | /consigna_5/src/mi_nuevo_proyecto.c | 7ff0f386829c65c33f7586f17eacf409b77e7ecb | [] | no_license | eugenioorosco8/driver | d4250b838f0f8b658d8b2a48498d6f0858facaed | c5f706e0fe380cab4e07ce57471b0716ed726d3e | refs/heads/master | 2016-08-11T06:58:59.220166 | 2015-10-07T18:03:34 | 2015-10-07T18:03:34 | 43,071,766 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 4,772 | c | /* Copyright 2015, Eugenio Orosco
* All rights reserved.
*
* This file is not part of CIAA Firmware.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. Neither the name of the copyright holder 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 HOLDER 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.
*
*/
/** \brief Blinking Bare Metal example source file
**
** This is a mini example of the CIAA Firmware.
**
**/
/** \addtogroup CIAA_Firmware CIAA Firmware
** @{ */
/** \addtogroup Examples CIAA Firmware Examples
** @{ */
/** \addtogroup Baremetal Bare Metal example source file
** @{ */
/*
* Initials Name
* ---------------------------
*
*/
/*
* modification history (new versions first)
* -----------------------------------------------------------
* yyyymmdd v0.0.1 initials initial version
*/
/*==================[inclusions]=============================================*/
#include "mi_nuevo_proyecto.h" /* <= own header */
#include "ledDriver.h"
#include "TeclasDriver.h"
#include "chip.h"
#include "TimerDriver.h"
#include "AdcDriver.h"
/*==================[macros and definitions]=================================*/
#define MAXDELAY 700000
/*==================[internal data declaration]==============================*/
/*==================[internal functions declaration]=========================*/
void MyRITimerISR(void);
void MyEocAdcISR(void);
/*==================[internal data definition]===============================*/
uint16_t adc_value;
/*==================[external data definition]===============================*/
/*==================[internal functions definition]==========================*/
/*==================[external functions definition]==========================*/
/** \brief Main function
*
* This is the main entry point of the software.
*
* \returns 0
*
* \remarks This function never returns. Return value is only to avoid compiler
* warnings or errors.
*/
int main(void)
{
uint16_t UmbralBajo = 90, UmbralAlto = 900;
/* perform the needed initialization here */
InicializarCPU();
InicializarAdc(1);
InicializarIntAdc();
InicializarLeds();
InicializarTimer(100);
while(1){
/* Consigna 5.1
adc_value=AdcPolling();
ApagaLed(LED1);
ApagaLed(LED2);
if(adc_value<50) PrenderLed(LED1);
if(adc_value>900) PrenderLed(LED2);
*/
// Consigna 5,2
if(LeerTecla(TECLA1)){
delayNoelegante(MAXDELAY);
UmbralBajo++;
if(UmbralBajo > 1024) UmbralBajo = 1024;
}
if(LeerTecla(TECLA2)){
delayNoelegante(MAXDELAY);
UmbralBajo--;
if(UmbralBajo < 0) UmbralBajo = 0;
}
if(LeerTecla(TECLA3)){
delayNoelegante(MAXDELAY);
UmbralAlto++;
if(UmbralAlto < 1024) UmbralAlto = 1024;
}
if(LeerTecla(TECLA4)){
delayNoelegante(MAXDELAY);
UmbralAlto--;
if(UmbralAlto < 0) UmbralAlto = 0;
}
;
if(adc_value<UmbralBajo) PrenderLed(LED1);
if(adc_value>UmbralAlto) PrenderLed(LED2);
}
return 0;
}
// funcion de atenci+on de interrupcion
void MyRITimerISR(void){
Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW,ADC_TRIGGERMODE_RISING);
Chip_RIT_ClearInt(LPC_RITIMER);
}
// funcion de atenci+on de interrupcion
void MyEocAdcISR(void){
Chip_ADC_ReadValue(LPC_ADC0, 1, &adc_value);
}
/** @} doxygen end group definition */
/** @} doxygen end group definition */
/** @} doxygen end group definition */
/*==================[end of file]============================================*/
| [
"eugenioorosco8@gmail.com"
] | eugenioorosco8@gmail.com |
fbf47f21f7cdfb7efd89261408f62ed67bc089ef | da7c499625123f5d1a28e3d75b037523df11ccb5 | /devel/coda/src/bosio/main/one-way-pipe.c | a25e6b8c47e7c8b5aea45f3242c15773a057a932 | [] | no_license | emuikernel/BDXDaq | 84d947b0a4c0c1799a855dbe6c59e9560a8fc4e2 | cf678d3b71bdfb95996e8b7e97ad3657ef98262f | refs/heads/master | 2021-01-18T07:26:38.855967 | 2015-06-08T15:45:58 | 2015-06-08T15:45:58 | 48,211,085 | 3 | 2 | null | 2015-12-18T02:56:53 | 2015-12-18T02:56:52 | null | UTF-8 | C | false | false | 2,598 | c | /*
* one-way-pipe.c - example of using a pipe to communicate data between a
* process and its child process. The parent reads input
* from the user, and sends it to the child via a pipe.
* The child prints the received data to the screen.
*/
#include <stdio.h> /* standard I/O routines. */
#include <unistd.h> /* defines pipe(), amongst other things. */
/* this routine handles the work of the child process. */
void
do_child(int data_pipe[])
{
char c[2]; /* data received from the parent. */
int rc; /* return status of read(). */
/* first, close the un-needed write-part of the pipe. */
close(data_pipe[1]);
/* now enter a loop of reading data from the pipe, and printing it */
while ((rc = read(data_pipe[0], c, 1)) > 0)
{
/*printf("do_child: got '%c' (%d), nbytes=%d\n",c[0],c[0],rc);*/
putchar(c[0]);
}
/* probably pipe was broken, or got EOF via the pipe. */
exit(0);
}
/* this routine handles the work of the parent process. */
void
do_parent(int data_pipe[])
{
char c[2]; /* data received from the user. */
int rc; /* return status of getchar(). */
/* first, close the un-needed read-part of the pipe. */
close(data_pipe[0]);
/* now enter a loop of read user input, and writing it to the pipe. */
while ((c[0] = getchar()) > 0)
{
/*printf("do_partner: got '%c'\n",c[0]);*/
/* write the character to the pipe. */
rc = write(data_pipe[1], c, 1);
if(rc == -1)
{ /* write failed - notify the user and exit */
perror("Parent: write");
close(data_pipe[1]);
exit(1);
}
}
/* probably got EOF from the user. */
close(data_pipe[1]); /* close the pipe, to let the child know we're done. */
exit(0);
}
/* and the main function. */
int
main(int argc, char* argv[])
{
int data_pipe[2]; /* an array to store the file descriptors of the pipe. */
int pid; /* pid of child process, or 0, as returned via fork. */
int rc; /* stores return values of various routines. */
/* first, create a pipe. */
rc = pipe(data_pipe);
if(rc == -1)
{
perror("pipe");
exit(1);
}
/* now fork off a child process, and set their handling routines. */
pid = fork();
switch(pid)
{
case -1: /* fork failed. */
perror("fork");
exit(1);
case 0: /* inside child process. */
do_child(data_pipe);
/* NOT REACHED */
default: /* inside parent process. */
do_parent(data_pipe);
/* NOT REACHED */
}
return 0; /* NOT REACHED */
}
| [
"andrea.celentano@ge.infn.it"
] | andrea.celentano@ge.infn.it |
30502826a12cca7ff87214b1b56e0fa426784ee4 | 6720496e9b03e59e1c37df2ea9a7f2645592c76e | /stringCompress.c | cbeb5634efbbe15c4506b5766504a13c2468fc53 | [] | no_license | Rounak-Das-02/2nd-semester-codes | ae41eccb1e5fdc668a07858d97b47c102c4d4557 | 93e04fd333c5e2fd9b4f6f8dc5213340eca3393d | refs/heads/master | 2023-06-21T10:46:10.245315 | 2021-07-03T18:12:49 | 2021-07-03T18:12:49 | 345,369,612 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 621 | c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char ch;
#define FOR(x , y) for(int i = x; i <=y ; i++)
#define length(s) strlen(s)
typedef int i;
int main()
{
ch s[1000];
scanf("%s" , s);
i count = 0 ;
FOR(1 , length(s)-1)
{
if(s[i] != s[i-1])
{
printf("%c" , s[i-1]);
if(count == 0)
continue;
printf("%d" , count+1);
count = 0;
}
else
{
count++;
}
}
printf("%c" , s[length(s) - 1]);
if(count !=0)
printf("%d" , count+1);
return 0;
} | [
"dasrounak2002@gmail.com"
] | dasrounak2002@gmail.com |
9851a502c28267ed769c3e9e1b02ed4d9e1da1aa | ab34b8903b9991154c5d99839321238ce9fce13b | /tests/kms_force_connector.c | 7485ca84c32c6004fbcf7f258d6bd0795c4b611d | [
"MIT"
] | permissive | chenxianqin/intel-gpu-tools | c9e24740e12e42c2db2ffe3809129cdba23768ff | a2c67866fb447a5d00abb3061b0d735df30fd40c | refs/heads/master | 2021-01-10T13:37:07.310820 | 2015-10-20T20:46:26 | 2015-10-23T17:01:05 | 44,858,997 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 4,269 | c | /*
* Copyright © 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#include "igt.h"
IGT_TEST_DESCRIPTION("Check the debugfs force connector/edid features work"
" correctly.");
#define CHECK_MODE(m, h, w, r) igt_assert(m.hdisplay == h && m.vdisplay == w \
&& m.vrefresh == r)
igt_main
{
/* force the VGA output and test that it worked */
int drm_fd = 0;
drmModeRes *res;
drmModeConnector *vga_connector = NULL, *temp;
igt_display_t display;
int start_n_modes;
igt_fixture {
drm_fd = drm_open_driver_master(DRIVER_INTEL);
res = drmModeGetResources(drm_fd);
/* find the vga connector */
for (int i = 0; i < res->count_connectors; i++) {
vga_connector = drmModeGetConnector(drm_fd, res->connectors[i]);
if (vga_connector->connector_type == DRM_MODE_CONNECTOR_VGA)
break;
drmModeFreeConnector(vga_connector);
vga_connector = NULL;
}
igt_require(vga_connector);
}
igt_subtest("force-connector-state") {
/* force the connector on and check the reported values */
kmstest_force_connector(drm_fd, vga_connector, FORCE_CONNECTOR_ON);
temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
igt_assert(temp->connection == DRM_MODE_CONNECTED);
igt_assert(temp->count_modes > 0);
drmModeFreeConnector(temp);
/* attempt to use the display */
kmstest_set_vt_graphics_mode();
igt_display_init(&display, drm_fd);
igt_display_commit(&display);
/* force the connector off */
kmstest_force_connector(drm_fd, vga_connector,
FORCE_CONNECTOR_OFF);
temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
igt_assert(temp->connection == DRM_MODE_DISCONNECTED);
igt_assert(temp->count_modes == 0);
drmModeFreeConnector(temp);
/* check that the previous state is restored */
kmstest_force_connector(drm_fd, vga_connector,
FORCE_CONNECTOR_UNSPECIFIED);
temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
igt_assert(temp->connection == vga_connector->connection);
drmModeFreeConnector(temp);
}
igt_subtest("force-edid") {
kmstest_force_connector(drm_fd, vga_connector,
FORCE_CONNECTOR_ON);
temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
start_n_modes = temp->count_modes;
drmModeFreeConnector(temp);
/* test edid forcing */
kmstest_force_edid(drm_fd, vga_connector,
igt_kms_get_base_edid(), EDID_LENGTH);
temp = drmModeGetConnector(drm_fd,
vga_connector->connector_id);
CHECK_MODE(temp->modes[0], 1920, 1080, 60);
CHECK_MODE(temp->modes[1], 1280, 720, 60);
CHECK_MODE(temp->modes[2], 1024, 768, 60);
CHECK_MODE(temp->modes[3], 800, 600, 60);
CHECK_MODE(temp->modes[4], 640, 480, 60);
drmModeFreeConnector(temp);
/* remove edid */
kmstest_force_edid(drm_fd, vga_connector, NULL, 0);
temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
/* the connector should now have the same number of modes that
* it started with */
igt_assert(temp->count_modes == start_n_modes);
drmModeFreeConnector(temp);
kmstest_force_connector(drm_fd, vga_connector,
FORCE_CONNECTOR_UNSPECIFIED);
}
igt_fixture {
drmModeFreeConnector(vga_connector);
}
igt_exit();
}
| [
"thomas.wood@intel.com"
] | thomas.wood@intel.com |
65ed10595ab68e8a5c146856f87b22f629848b4a | e3498c9689e537c0f5e210b228b952735ac439b4 | /qcom-caf/audio/qahw_api/inc/qahw_effect_trumpet.h | 3257f7b6513d4d9595c16348247467125a0a6c61 | [
"LicenseRef-scancode-unicode",
"Apache-2.0"
] | permissive | meizucustoms/android_device_meizu_m1721 | db9aae05d0417bd1c662f29be90f2befa4e12b8f | 403342a572cf23c13034620b7b6af0e0df717585 | refs/heads/lineage-19.1 | 2023-02-04T07:42:20.434573 | 2022-08-05T12:22:51 | 2022-08-05T12:22:51 | 254,040,806 | 14 | 15 | null | 2022-07-31T16:58:53 | 2020-04-08T09:19:02 | C++ | UTF-8 | C | false | false | 4,528 | h | /* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* 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 The Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* 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 QAHW_EFFECT_TRUMPET_H_
#define QAHW_EFFECT_TRUMPET_H_
#include <qahw_effect_api.h>
#ifdef __cplusplus
extern "C" {
#endif
#define QAHW_EFFECT_TRUMPET_LIBRARY "libtrumpet.so"
static const qahw_effect_uuid_t SL_IID_TRUMPET_ = {0x5e46f50b, 0xcc86, 0x4d6e, 0x9610, {0x54, 0x72, 0x76, 0x1d, 0xd0, 0xe2}};
static const qahw_effect_uuid_t * const SL_IID_TRUMPET = &SL_IID_TRUMPET_;
static const qahw_effect_uuid_t SL_IID_TRUMPET_UUID_ = {0xa52a402b, 0xe254, 0x4fb9, 0xab7a, {0x7c, 0xf5, 0x83, 0x44, 0xe3, 0xf3}};
static const qahw_effect_uuid_t * const SL_IID_TRUMPET_UUID = &SL_IID_TRUMPET_UUID_;
/* enumerated parameter settings for trumpet effect used by both set and get*/
typedef enum {
TRUMPET_PARAM_ENABLE,
TRUMPET_PARAM_PREGAIN,
TRUMPET_PARAM_POSTGAIN,
TRUMPET_PARAM_SYSTEMGAIN,
TRUMPET_PARAM_MI_DV_LEVELER_STEERING,
TRUMPET_PARAM_MI_DIALOG_ENHANCER,
TRUMPET_PARAM_MI_SURROUND_COMPRESSOR,
TRUMPET_PARAM_MI_IEQ_STEERING,
TRUMPET_PARAM_DIALOG_AMOUNT,
TRUMPET_PARAM_DIALOG_DUCKING,
TRUMPET_PARAM_DIALOG_ENABLE,
TRUMPET_PARAM_VOLUME_LEVELER_AMOUNT,
TRUMPET_PARAM_VOLUME_LEVELER_IN_TARGET,
TRUMPET_PARAM_VOLUME_LEVELER_OUT_TARGET,
TRUMPET_PARAM_VOLUME_LEVELER_ENABLE,
TRUMPET_PARAM_VOLUME_MODELER_CALIBRATION,
TRUMPET_PARAM_VOLUME_MODELER_ENABLE,
TRUMPET_PARAM_VOLMAX_BOOST,
TRUMPET_PARAM_BASS_BOOST,
TRUMPET_PARAM_BASS_CUTOFF_FREQ,
TRUMPET_PARAM_BASS_WIDTH,
TRUMPET_PARAM_BASS_ENABLE,
TRUMPET_PARAM_BASS_EXTRACT_CUTOFF_FREQ,
TRUMPET_PARAM_BASS_EXTRACT_ENABLE,
TRUMPET_PARAM_REGULATOR_SET,
TRUMPET_PARAM_REGULATOR_OVERDRIVE,
TRUMPET_PARAM_REGULATOR_TIMBRE_PRESERVE,
TRUMPET_PARAM_REGULATOR_RELAXATION_AMT,
TRUMPET_PARAM_REGULATOR_SPKR_DIST_ENABLE,
TRUMPET_PARAM_REGULATOR_ENABLE,
TRUMPET_PARAM_VIRTUAL_BASS_MODE,
TRUMPET_PARAM_VIRTUAL_BASS_SRC_FREQ,
TRUMPET_PARAM_VIRTUAL_BASS_MIX_FREQ,
TRUMPET_PARAM_VIRTUAL_BASS_OVERALL_GAIN,
TRUMPET_PARAM_VIRTUAL_BASS_SUBGAINS,
TRUMPET_PARAM_VIRTUAL_BASS_SLOPE_GAIN,
TRUMPET_PARAM_FRONT_SPK_ANG,
TRUMPET_PARAM_SURROUND_SPK_ANG,
TRUMPET_PARAM_HEIGHT_SPK_ANG,
TRUMPET_PARAM_HEIGHT_FILTER_MODE,
TRUMPET_PARAM_SURROUND_BOOST,
TRUMPET_PARAM_SURROUND_DECODER_ENABLE,
TRUMPET_PARAM_CALIBRATION,
TRUMPET_PARAM_GRAPHICS_ENABLE,
TRUMPET_PARAM_GRAPHICS_SET,
TRUMPET_PARAM_AUDIO_OPTIMIZER_ENABLE,
TRUMPET_PARAM_AUDIO_OPTIMIZER_SET,
TRUMPET_PARAM_PROCESS_OPTIMIZER_ENABLE,
TRUMPET_PARAM_PROCESS_OPTIMIZER_SET,
TRUMPET_PARAM_IEQ_ENABLE,
TRUMPET_PARAM_IEQ_AMOUNT,
TRUMPET_PARAM_IEQ_SET,
TRUMPET_PARAM_OP_MODE,
TRUMPET_PARAM_DYNAMIC_PARAMETER,
TRUMPET_PARAM_INIT_INFO,
TRUMPET_PARAM_CENTER_SPREADING,
TRUMPET_PARAM_METADATA_PARAM,
TRUMPET_PARAM_CIDK_VALIDATE = 100,
} qahw_trumpet_params_t;
#ifdef __cplusplus
} // extern "C"
#endif
#endif /*QAHW_EFFECT_TRUMPET_H_*/
| [
"teledurak@gmail.com"
] | teledurak@gmail.com |
8efc57489d84f8b352884f53091dedb0c643c20c | 6d4a2bb09b943b8d85fc7f24ba58861ed9a7cd4f | /test_void_pointer.c | 4ac81f18fbff483ff3026c06a3b4663efdb2ab3e | [] | no_license | yilianshaqi/c_test | 59fcf87a26fcca4f5558f781bc76ebad056d6a96 | 56bb76df8f3843ef321967e7b0f70887f5aa6ca7 | refs/heads/master | 2021-01-11T10:56:29.866069 | 2016-11-04T12:47:37 | 2016-11-04T12:47:37 | 72,846,374 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 968 | c | /*************************************************************************
> File Name: test_void_pointer.c
> Author: huangyang
> Mail:
> Created Time: Wed 19 Oct 2016 04:22:08 AM PDT
************************************************************************/
#include<stdio.h>
void main()
{
int *p;
int num=9;
p=#
printf("*p=%d\n",*p);
char *str;
void *pv;
char hi='d';
str=pv; //void 指向char没有问题
str=&hi;
printf("*hi=%c\t &hi=%p\n",*str,&hi);
pv=p; //int 指向void 也没有问题
pv=str; //编译也ok
long ss=100;
// printf("*pv=%c\n",*pv); // warning: dereferencing ‘void *’ pointer [enabled by default] test_void_pointer.c:24:2: error: invalid use of void expression char型指针指向void型,void本身类型没有变化
pv=&ss;
p=pv;
printf("*p=%d\t p=%p\n",*p,p);
int count=9;
int *pcount;
void *ps=&count;
// ps=pcount;
pcount=ps;
printf("*pcount=%d\n",*pcount);
}
| [
"huangyangwork@sina.com"
] | huangyangwork@sina.com |
0fab598bfc0a4c79245154cbd8627918c2bf0d19 | fb90beb5dbf18f8e14b594e90ca5c17320e8bb02 | /OperatorAndRepetitive/operatorPractice2.c | 9f2fa7dd617e513295b0ec671f281787efc64efc | [] | no_license | LSHFreeRoad/C_LANGUAGE_STUDY | 976ea26740548bc861d95a8f6cb92ecbc076c8f8 | c956ee9eda7edca9e0422a33e29cd3406fbd3abc | refs/heads/master | 2020-03-29T01:56:45.405494 | 2018-09-19T09:10:03 | 2018-09-19T09:10:03 | 149,407,248 | 0 | 0 | null | null | null | null | UHC | C | false | false | 2,483 | c | #define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
/*
논리 연산자는 조건식이나 값을 논리적으로 판단함
if 조건문에서 조건식을 판단할 때 주로 사용함
&& : AND(논리곱), 양쪽 모두 참일 때 참임
|| : OR(논리합), 양쪽 중 한 쪽만 참이라도 참임
! : NOT(논리 부정), 참과 거짓을 뒤집음
거짓은 0을 사용하고 참은 보통 1을 사용함
*/
//c 언어에서는 0이 아닌 모든 값이 참임
printf("%d\n", 1 && 1); //둘 다 참이어야 함
//논리 연산에서 중요한 부분이 단락
//평가인데 단락평가는 첫 번째 값의 결과가 확실할 때
//두 번째 값은 확인(평가)하지 않는 방법이다
printf("%d\n", 1 && 0); //첫 번째 값이 거짓이면
//두 번째 값에 상관없이 전체 논리값은 거짓(0)이 됨
printf("%d\n", 0 && 1);
printf("%d\n", 0 && 0);
printf("%d\n", 2 && 3);
printf("===================\n");
printf("%d\n", 1 || 1); //하나만 참이면 참이 됨
printf("%d\n", 1 || 0);
printf("%d\n", 0 || 1);
printf("%d\n", 0 || 0);
printf("%d\n", 2 || 3);
printf("===================\n");
printf("%d\n", !1);
printf("%d\n", !0);
printf("%d\n", !3);
printf("===================\n");
int num1 = 20, num2 = 10, num3 = 30, num4 = 15;
printf("%d\n", num1 > num2 && num3 > num4);
//양쪽 모두 참이어서 참
printf("%d\n", num1 > num2 && num3 < num4);
//앞만 참이므로 거짓
printf("%d\n", num1 > num2 || num3 < num4);
//앞에 것이 참이므로 참
printf("%d\n", num1 < num2 || num3 < num4);
//양쪽 모두 거짓이므로 거짓
printf("%d\n", !(num1 > num2));
//참의 not 연산은 거짓
printf("===================\n");
int num5 = 1, num6 = 0;
if (num5 && num6) //num6가 거짓이므로 거짓
printf("참\n");
else
printf("거짓\n");
if (num5 || num6) //num5가 참이므로 참
printf("참\n");
else
printf("거짓\n");
if (!num5) //
printf("참\n");
else
printf("거짓\n");
printf("=====================\n");
int num7 = 1, num8 = 0;
printf("%s\n", num7 && num8 ? "참" : "거짓");
printf("%s\n", num7 || num8 ? "참" : "거짓");
int num9, num10;
scanf("%d %d", &num9, &num10);
printf("%s\n", num9 && num10 ? "참" : "거짓");
printf("%s\n", num9 || num10 ? "참" : "거짓");
printf("%s\n", !num9 ? "참" : "거짓");
return 0;
} | [
"noreply@github.com"
] | LSHFreeRoad.noreply@github.com |
a53d5609931f4b93b75764afd53903cdb62f1e92 | 32cc9f43690023ec03e611cf0e11590fda22bb4c | /fillit-files/ft_fillit_magic_withstruct.c | f3710dfd313d84440b78597b5e421f2bfc6bebff | [] | no_license | Bumbieris31/fillit | 5d319cbbae48cbb81e482d621b12888bcd5b2e49 | e19e45b8570548a0aa02ee8228357ea1cd8b276b | refs/heads/master | 2020-04-30T10:19:14.465474 | 2019-04-01T18:26:19 | 2019-04-01T18:26:19 | 176,774,034 | 0 | 0 | null | 2019-03-20T16:26:53 | 2019-03-20T16:26:52 | null | UTF-8 | C | false | false | 2,197 | c | #include <string.h>
#include "libft.h"
#include "fillit.h"
char **make_board(int tcount);
char **incr_board(char **board);
void ft_print_board(char **board);
int *ft_locate_tetri_space(int tetri[][6], t_tbox *tbox);
void ft_put_tetri(int tetri[][6], t_tbox *tbox);
int *ft_check_for_space(int tetri[][6], t_tbox *tbox);
int ft_check_incr(t_tbox *tbox);
t_tbox *ft_make_tbox(int tetri_count)
{
t_tbox *tbox;
tbox = (t_tbox*)malloc(sizeof(t_tbox));
tbox->tcount = tetri_count;
tbox->tindex = 0;
tbox->board = make_board(tetri_count);
tbox->xy[0] = 0;
tbox->xy[1] = 0;
return(tbox);
}
void ft_fillit_magic()
{
int tetri[7][6] = {{0, 1, 0, 2, 1, 2}, {1, 0, 2, 0, 3, 0}, {1, 0, 2, 0, 2, 1}, \
{1, 0, 2, 0, 2, 1}, {0, 1, 1, 1, 1, 0}, {1, -1, 1, 0, 1, 1}, {2, -1, 2, 0, 1, 0}}; // ¬ , | , L, L, [], ^, _|
int *x_y_val;
t_tbox *tbox;
tbox = ft_make_tbox(7);
if (tbox->board == NULL)
ft_putstr("Make fail! \n");
else
{
while (ft_check_incr(tbox))
tbox->board = incr_board(tbox->board);
while (tbox->tindex < tbox->tcount)
{
x_y_val = NULL;
while (x_y_val == NULL)
{
x_y_val = ft_check_for_space(tetri, tbox);
if (x_y_val == NULL)
{
tbox->board = incr_board(tbox->board);
ft_putstr("\nIncr happened \n");
}
if (tbox->board == NULL)
{
ft_putstr("Epic increment fail! \n");
break;
}
}
ft_put_tetri(tetri, tbox);
ft_putstr("\nTetri planted -_-\n");
ft_print_board(tbox->board);
tbox->tindex++;
}
}
}
/*
char **ft_fillit_solve(int tetri[][6], t_tbox *tbox)
{
int *a;
char **ret;
a = ft_check_for_space(tetri, tbox);
if (a != NULL)
{
ft_put_tetri(tetri, tbox);
tbox->tindex++;
if (tbox->tindex == tbox->tcount)
return (tbox->board);
ret = ft_fillit_solve(tetri, tbox);
}
else if (a == NULL && ft_check_incr(tbox) == 0)
{
}
// vienu tetri atpakal, tad pakustini to tetri uz prieksu, tad megini atkal.
}
*/
int main(void)
{
/*
int tetri[5][6] = {{0, 1, 0, 2, 1, 2}, {1, 0, 2, 0, 3, 0}, {1, 0, 2, 0, 2, 1}, \
{1, 0, 2, 0, 2, 1}, {0, 1, 1, 1, 1, 0}}; // ¬ , I , L, L, []
t_tbox *tbox;
tbox = ft_make_tbox(5);
ft_fillit_solve(tetri, tbox);
*/
ft_fillit_magic();
} | [
"abumbier@f1r4s1.codam.nl"
] | abumbier@f1r4s1.codam.nl |
4b8020cd85369455fd68c2cc9d50624ab3f856eb | c9cde2ab28bc223ce7eebadc791973ee7e50f0ee | /src/TC_CRC.c | 650c09325ecaf315a56379cf7ebf629be39568b0 | [] | no_license | DamianPala/C_Utils | 07bc30404a59e55635bbaf4c5b3d72785829773c | 2d1c2b2e2c070511936a7b4be87823cbef98d3e8 | refs/heads/master | 2020-04-03T14:05:19.654529 | 2018-09-18T06:30:12 | 2018-09-18T06:30:12 | 81,711,341 | 0 | 0 | null | null | null | null | UTF-8 | C | false | false | 10,008 | c | /*=======================================================================================*
* @file TC_CRC.c
* @author Damian Pala
* @date 19-03-2017
* @brief This file contains unit tests for CRC module.
*======================================================================================*/
/**
* @addtogroup TC_CRC CRC calculations tests
* @{
* @brief Unit tests implementation.
*/
/*======================================================================================*/
/* ####### PREPROCESSOR DIRECTIVES ####### */
/*======================================================================================*/
/*---------------------- INCLUDE DIRECTIVES FOR STANDARD HEADERS -----------------------*/
/*----------------------- INCLUDE DIRECTIVES FOR OTHER HEADERS -------------------------*/
#include "unity.h"
#include "unity_fixture.h"
#include "CRC.c"
/*----------------------------- LOCAL OBJECT-LIKE MACROS -------------------------------*/
/*---------------------------- LOCAL FUNCTION-LIKE MACROS ------------------------------*/
/*======================================================================================*/
/* ####### LOCAL TYPE DECLARATIONS ####### */
/*======================================================================================*/
/*-------------------------------- OTHER TYPEDEFS --------------------------------------*/
/*------------------------------------- ENUMS ------------------------------------------*/
/*------------------------------- STRUCT AND UNIONS ------------------------------------*/
/*======================================================================================*/
/* ####### OBJECT DEFINITIONS ####### */
/*======================================================================================*/
/*--------------------------------- EXPORTED OBJECTS -----------------------------------*/
/*---------------------------------- LOCAL OBJECTS -------------------------------------*/
/**
* @brief CRC Test Group.
*/
TEST_GROUP(CRC);
/*======================================================================================*/
/* ####### LOCAL FUNCTIONS PROTOTYPES ####### */
/*======================================================================================*/
static uint32_t CalcIterateCrc(uint8_t *data, size_t dataSize, CRC_CalcSize_T crcSize);
/*======================================================================================*/
/* ####### LOCAL FUNCTIONS DEFINITIONS ####### */
/*======================================================================================*/
/*======================================================================================*/
/* ####### TESTS DEFINITIONS ####### */
/*======================================================================================*/
/**
* @brief Setup Test Environment.
*/
TEST_SETUP(CRC)
{
}
/**
* @brief Tear Down Test Environment.
*/
TEST_TEAR_DOWN(CRC)
{
}
#define TEST_DATA_LEN 12
typedef struct CRC_TestData_Tag
{
uint8_t data[TEST_DATA_LEN];
uint32_t crc8_polynom;
uint32_t crc16_polynom;
uint32_t crc32_polynom;
uint32_t crc8_initVal;
uint32_t crc16_initVal;
uint32_t crc32_initVal;
uint32_t crc8_xorVal;
uint32_t crc16_xorVal;
uint32_t crc32_xorVal;
uint32_t crc8;
uint32_t crc16;
uint32_t crc32;
} CRC_TestData_T;
CRC_TestData_T CRC_TestData[4] =
{
{
.data = {0xab, 0xbc, 0xcd, 0xde, 0xa1, 0xb2, 0xc3, 0xd4, 0xa5, 0xb6, 0xc7, 0xd7},
.crc8_polynom = 0xE0,
.crc16_polynom = 0x8408,
.crc32_polynom = 0xEDB88320,
.crc8_initVal = 0xF1,
.crc16_initVal = 0xF1F1,
.crc32_initVal = 0xF1F1F1F1,
.crc8_xorVal = 0xAB,
.crc16_xorVal = 0xABAB,
.crc32_xorVal = 0xABABABAB,
.crc8 = 0x8B,
.crc16 = 0x0C1B,
.crc32 = 0xADB383EB,
},
{
.data = {0x12, 0x34, 0x56, 0x78, 0x12, 0x32, 0x52, 0x72, 0x11, 0x31, 0x51, 0x71},
.crc8_polynom = 0xE0,
.crc16_polynom = 0x8408,
.crc32_polynom = 0xEDB88320,
.crc8_initVal = 0xF1,
.crc16_initVal = 0xF1F1,
.crc32_initVal = 0xF1F1F1F1,
.crc8_xorVal = 0xAB,
.crc16_xorVal = 0xABAB,
.crc32_xorVal = 0xABABABAB,
.crc8 = 0xCB,
.crc16 = 0x9F23,
.crc32 = 0x88C9AF4B,
},
{
.data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
.crc8_polynom = 0xE0,
.crc16_polynom = 0x8408,
.crc32_polynom = 0xEDB88320,
.crc8_initVal = 0xF1,
.crc16_initVal = 0xF1F1,
.crc32_initVal = 0xF1F1F1F1,
.crc8_xorVal = 0xAB,
.crc16_xorVal = 0xABAB,
.crc32_xorVal = 0xABABABAB,
.crc8 = 0x4B,
.crc16 = 0x9333,
.crc32 = 0x6EE5610B,
},
{
.data = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
.crc8_polynom = 0xE0,
.crc16_polynom = 0x8408,
.crc32_polynom = 0xEDB88320,
.crc8_initVal = 0xF1,
.crc16_initVal = 0xF1F1,
.crc32_initVal = 0xF1F1F1F1,
.crc8_xorVal = 0xAB,
.crc16_xorVal = 0xABAB,
.crc32_xorVal = 0xABABABAB,
.crc8 = 0x4B,
.crc16 = 0xA3F3,
.crc32 = 0x0DF7CBAB,
}
};
static uint32_t CalcIterateCrc(uint8_t *data, size_t dataSize, CRC_CalcSize_T crcSize)
{
uint32_t crc;
CRC_CalcIterateStart(crcSize);
for (size_t byteCnt = 0; byteCnt < dataSize; byteCnt++)
{
crc = CRC_CalcIterate(data[byteCnt], crcSize);
}
return crc;
}
TEST(CRC, CRC8_should_BeCalculatedProperly)
{
uint32_t crc;
uint8_t testIterator = 0;
crc = CRC_CalcCRC8(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_8);
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
testIterator++;
crc = CRC_CalcCRC8(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_8);
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
testIterator++;
crc = CRC_CalcCRC8(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_8);
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
testIterator++;
crc = CRC_CalcCRC8(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_8);
TEST_ASSERT_EQUAL_HEX8(CRC_TestData[testIterator].crc8, crc);
}
TEST(CRC, CRC16_should_BeCalculatedProperly)
{
uint32_t crc;
uint8_t testIterator = 0;
crc = CRC_CalcCRC16(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_16);
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
testIterator++;
crc = CRC_CalcCRC16(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_16);
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
testIterator++;
crc = CRC_CalcCRC16(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_16);
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
testIterator++;
crc = CRC_CalcCRC16(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_16);
TEST_ASSERT_EQUAL_HEX16(CRC_TestData[testIterator].crc16, crc);
}
TEST(CRC, CRC32_should_BeCalculatedProperly)
{
uint32_t crc;
uint8_t testIterator = 0;
crc = CRC_CalcCRC32(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX32(CRC_TestData[testIterator].crc32, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_16);
TEST_ASSERT_EQUAL_HEX32(CRC_TestData[testIterator].crc32, crc);
testIterator++;
crc = CRC_CalcCRC32(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX32(CRC_TestData[testIterator].crc32, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_16);
TEST_ASSERT_EQUAL_HEX32(CRC_TestData[testIterator].crc32, crc);
testIterator++;
crc = CRC_CalcCRC32(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX32(CRC_TestData[testIterator].crc32, crc);
CalcIterateCrc(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data), CRC_CALC_SIZE_16);
TEST_ASSERT_EQUAL_HEX32(CRC_TestData[testIterator].crc32, crc);
testIterator++;
crc = CRC_CalcCRC32(CRC_TestData[testIterator].data, sizeof(CRC_TestData[testIterator].data));
TEST_ASSERT_EQUAL_HEX32(CRC_TestData[testIterator].crc32, crc);
}
/**
* @} end of group TC_S-FIFO Static FIFO Queue unit tests
*/
| [
"mail@damianpala.com"
] | mail@damianpala.com |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.