12 #include <netinet/tcp.h>
26 #define aisc_assert(cond) arb_assert(cond)
30 #define AISC_MAGIC_NUMBER_FILTER 0xffffff00
38 if (aisc_core_on_error) { \
47 #define ERRBUF_SIZE 300
50 #define PRTERR(msg) if (aisc_print_error_to_stderr) fprintf(stderr, "%s: %s\n", msg, link->error);
59 memset(bl, 0,
sizeof(*bl));
98 char *
buffer = (
char *)calloc(
sizeof(
char), (
size_t)size);
106 msg->
message = strdup(buffer+
sizeof(
long));
130 if (len != 2*
sizeof(
long)) {
150 goto aisc_check_next;
154 if (len != (
long)(size*
sizeof(
long))) {
159 switch (magic_number-link->
magic) {
164 int length = strlen(errmsg);
167 strcpy(errbuf,
"SERVER_ERROR: ");
168 strcat(errbuf, errmsg);
171 fprintf(stderr,
"SERVER_ERROR: %s\n", errmsg);
172 sprintf(errbuf,
"SERVER_ERROR: overlong msg dumped to STDERR");
194 PRTERR(
"AISC_CONN_ERROR");
216 char *unix_name =
NULp;
227 shutdown(link->socket, SHUT_RDWR);
230 *error = link->error;
237 if (!main_obj.
exists() || link->error) {
238 *error = link->error;
244 aisc_client_link =
link;
256 shutdown(link->
socket, SHUT_RDWR);
274 long attribute, code;
289 while ((code=va_arg(parg,
long))) {
294 if ((o_t != (
int)o_type)) {
295 sprintf(errbuf,
"ARG NR %li DON'T FIT OBJECT", count);
303 sprintf(errbuf,
"ARG %li IS NOT AN ATTRIBUTE_TYPE", count);
310 arg_pntr[arg_cnt] = va_arg(parg,
long *);
311 arg_types[arg_cnt++] =
type;
326 (
size_t)(mes_cnt *
sizeof(
long)))) {
334 for (i=0; i<arg_cnt; i++) {
335 switch (arg_types[i]) {
349 arg_pntr[i][0] = (
long)str;
357 arg_pntr[i][0] = (
long)calloc(
sizeof(
char), (
size_t)size);
363 #if defined(DUMP_COMMUNICATION)
364 aisc_dump_hex(
"aisc_get bytestring: ", (
char *)(arg_pntr[i][0]), size);
365 #endif // DUMP_COMMUNICATION
373 link->
error =
"UNKNOWN TYPE";
390 if ((o_t != (
int)o_type)) {
391 link->
error =
"ATTRIBUTE DON'T FIT OBJECT";
392 PRTERR(
"AISC_DEBUG_ERROR");
396 attribute = attribute&0xffff;
398 link->
error =
"CLIENT DEBUG NOT CORRECT TYPE";
399 PRTERR(
"AISC_DEBUG_ERROR");
418 inline char *
part_of(
const char *
str,
size_t max_len,
size_t str_len) {
421 if (str_len <= max_len) {
426 int copy = max_len-DOTS;
428 part = (
char*)malloc(max_len+1);
429 memcpy(part, str, copy);
430 memset(part+copy,
'.', DOTS);
443 while ((code=va_arg(parg,
int))) {
449 if ((o_t != (
int)o_type)) {
450 sprintf(errbuf,
"ATTRIBUTE ARG NR %i DON'T FIT OBJECT", count);
457 sprintf(errbuf,
"ARG %i IS NOT AN ATTRIBUTE_TYPE", count);
482 const char *
str = va_arg(parg,
const char *);
485 size_t len = strlen(str)+1;
488 sprintf(errbuf,
"ARG %i: STRING \'%s\' TOO LONG", count+2, strpart);
497 size_t ilen = (len)/
sizeof(
long) + 1;
510 #if defined(DUMP_COMMUNICATION)
511 aisc_dump_hex(
"aisc_collect_sets bytestring: ", bs->
data, bs->
size);
512 #endif // DUMP_COMMUNICATION
518 link->
error =
"UNKNOWN TYPE";
594 int attribute,
int object_type,
AISC_Object&
object, ...)
601 if ((father_type&0xff00ffff)) {
602 link->
error =
"FATHER_TYPE UNKNOWN";
603 PRTERR(
"AISC_CREATE_ERROR");
607 if ((object_type&0xff00ffff)) {
608 link->
error =
"OBJECT_TYPE UNKNOWN";
609 PRTERR(
"AISC_CREATE_ERROR");
620 link->
error =
"ATTRIBUTE TYPE DON'T FIT OBJECT";
621 PRTERR(
"AISC_CREATE_ERROR");
626 if (!(mes_cnt =
aisc_collect_sets(link, mes_cnt, parg, object_type, 7)))
return 1;
631 PRTERR(
"AISC_CREATE_ERROR");
aisc_com * aisc_client_link
int aisc_close(aisc_com *link, AISC_Object &object)
#define AISC_MAX_STRING_LEN
void init(long remotePtr)
static int aisc_add_message_queue(aisc_com *link, long size)
static char errbuf[ERRBUF_SIZE]
GB_ERROR arb_open_socket(const char *name, bool do_connect, int *fd, char **filename_out)
char * part_of(const char *str, size_t max_len, size_t str_len)
long * aisc_debug_info(aisc_com *link, int o_type, const AISC_Object &object, int attribute)
int aisc_nput(aisc_com *link, int o_type, const AISC_Object &object,...)
long aisc_mes_buffer[AISC_MESSAGE_BUFFER_LEN]
#define AISC_DUMP(where, type, var)
char buffer[MESSAGE_BUFFERSIZE]
static const char * err_connection_problems
static int aisc_c_send_bytes_queue(aisc_com *link)
int aisc_put(aisc_com *link, int o_type, const AISC_Object &object,...)
aisc_bytes_list * aisc_client_bytes_first
#define AISC_MAGIC_NUMBER_FILTER
static int aisc_check_error(aisc_com *link)
static void error(const char *msg)
#define AISC_VAR_TYPE_MASK
static long aisc_init_client(aisc_com *link)
#define AISC_OBJ_TYPE_MASK
static void copy(double **i, double **j)
size_t arb_socket_read(int socket, char *ptr, size_t size)
static int aisc_collect_sets(aisc_com *link, int mes_cnt, va_list parg, int o_type, int count)
aisc_com * aisc_open(const char *path, AISC_Object &main_obj, long magic, GB_ERROR *error)
#define AISC_MESSAGE_BUFFER_LEN
static void aisc_c_add_to_bytes_queue(aisc_com *link, char *data, int size)
int aisc_get(aisc_com *link, int o_type, const AISC_Object &object,...)
ssize_t arb_socket_write(int socket, const char *ptr, size_t size)
static void aisc_free_link(aisc_com *link)
static int aisc_print_error_to_stderr
int aisc_create(aisc_com *link, int father_type, const AISC_Object &father, int attribute, int object_type, AISC_Object &object,...)
aisc_bytes_list * aisc_client_bytes_last
#define aisc_assert(cond)