Exemple #1
0
void init_seq(void *javavm, void *classfinder) {
	JavaVM *vm = (JavaVM*)javavm;
	find_class_fn = (jclass (*)(JNIEnv*, const char*))classfinder;

	JNIEnv *env;
	int res = (*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6);
	if (res == JNI_EDETACHED) {
		if ((*vm)->AttachCurrentThread(vm, &env, NULL) != JNI_OK) {
			LOG_FATAL("cannot attach to current_vm");
		}
	} else if (res != JNI_OK) {
		LOG_FATAL("bad vm env: %d", res);
	}
	memptr_id = find_field(env, "go/Seq", "memptr", "J");
	receive_refnum_id = find_field(env, "go/Seq$Receive", "refnum", "I");
	receive_handle_id = find_field(env, "go/Seq$Receive", "handle", "I");
	receive_code_id = find_field(env, "go/Seq$Receive", "code", "I");

	// Find jbyteArray class info by instantiating a jbyteArray and getting
	// its class info, because finding the jbyteArray class ("[B") using
	// find_class_fn or JNIEnv's FindClass does not work on android-L.
	jbyteArray a = (*env)->NewByteArray(env, 0);
	jclass clazz = (*env)->GetObjectClass(env, a);
	jbytearray_clazz = (*env)->NewGlobalRef(env, clazz);

	LOG_INFO("loaded go/Seq");

	if (res == JNI_EDETACHED) {
		(*vm)->DetachCurrentThread(vm);
	}
}
Exemple #2
0
int
sh_count_regexp_procs(char *procname, pcre *regexp)
{
    char            line[STRMAX], *cptr, *cp;
    int             ret = 0, fd;
    FILE           *file;
#ifndef NETSNMP_EXCACHETIME
#endif
    struct extensible ex;
    int             slow = strstr(PSCMD, "ax") != NULL;

    strcpy(ex.command, PSCMD);
    if ((fd = get_exec_output(&ex)) >= 0) {
        if ((file = fdopen(fd, "r")) == NULL) {
            setPerrorstatus("fdopen");
            close(fd);
            return (-1);
        }
        while (fgets(line, sizeof(line), file) != NULL) {
            if (slow) {
                cptr = find_field(line, 5);
                cp = strrchr(cptr, '/');
                if (cp)
                    cptr = cp + 1;
                else if (*cptr == '-')
                    cptr++;
                else if (*cptr == '[') {
                    cptr++;
                    cp = strchr(cptr, ']');
                    if (cp)
                        *cp = 0;
                }
                copy_nword(cptr, line, sizeof(line));
                cp = line + strlen(line) - 1;
                if (*cp == ':')
                    *cp = 0;
            } else {
                if ((cptr = find_field(line, NETSNMP_LASTFIELD)) == NULL)
                    continue;
                copy_nword(cptr, line, sizeof(line));
            }
            if (!strcmp(line, procname))
                ret++;
        }
        if (ftell(file) < 2) {
#ifdef USING_UCD_SNMP_ERRORMIB_MODULE
            seterrorstatus("process list unreasonable short (mem?)", 2);
#endif
            ret = -1;
        }
        fclose(file);
        wait_on_exec(&ex);
    } else {
        ret = -1;
    }
    return (ret);
}
Exemple #3
0
JNIEXPORT void JNICALL
Java_go_Seq_initSeq(JNIEnv *env, jclass clazz) {
	memptr_id = find_field(env, "go/Seq", "memptr", "J");
	receive_refnum_id = find_field(env, "go/Seq$Receive", "refnum", "I");
	receive_handle_id = find_field(env, "go/Seq$Receive", "handle", "I");
	receive_code_id = find_field(env, "go/Seq$Receive", "code", "I");

	jclass bclazz = find_class(env, "[B");
	jbytearray_clazz = (*env)->NewGlobalRef(env, bclazz);
}
static int add_static_join(char *linebuf)
{
  int status, index;
  char table_name_1[256], field_name_1[256];
  char table_name_2[256], field_name_2[256];
  FIELD *field1, *field2, *static_field = NULL; 
  char *equals_sign;
  
  equals_sign = strchr(linebuf, '=');
  if (equals_sign == NULL) {
    printf("Line not in form TBL.field = TBL2.field2 ... : %s\n", linebuf);
    return PARSE_ERROR;
  }
  *equals_sign = '\0';		/* linebuf is now 1st pair */
  if ((status = parse_table_field_pair(linebuf, table_name_1, field_name_1, 
				       &index)) 
      != OK) 
    return status;
  field1 = find_field(fields, table_name_1, field_name_1, index);
  if (!field1) {
    static_field = field1 = find_field(static_fields, table_name_1, field_name_1, index);
    if (!field1) {
      fprintf(stderr, "(6)Unable to find field %s:%s\n", 
	      table_name_1, field_name_1);
      return BAD_DATA_ERROR;
    }
  }
  linebuf = equals_sign + 1;
  equals_sign = strchr(linebuf, '=');
  if (equals_sign) *equals_sign = '\0';
  if ((status = parse_table_field_pair(linebuf, table_name_2, field_name_2,
				       &index))
      != OK) 
    return status;
  if (static_field)
    field2 = find_field(fields, table_name_2, field_name_2, index);
  else {
    static_field = field2 = find_field(static_fields, table_name_2, field_name_2, index);
  }
  if (!field2) {
    fprintf(stderr, "(7)Unable to find field %s:%s\n", 
	    table_name_2, field_name_2);
    return BAD_DATA_ERROR;
  }
  if (static_field == field1) {
    field2->static_join = field1;
    field1->join = field2;
  }
  else {
    field1->static_join = field2;
    field2->join = field1;
  }
  return OK;
}
Exemple #5
0
int find_field(struct expr *e,char *name)
  {
  if(e)
    if(e->t==',')
      if(find_field(e->l,name)) return 1;
      else return find_field(e->r,name);
    else if(e->t=='{' || e->t=='!' || e->t=='~')
      return find_field(e->r,name);
    else if(e->t=='NAME' && !strcmp(e->str,name))
      return 1;
  return 0;
  }
static int add_conditional_join(char *linebuf)
{
  /*
   * Someday, this and add_join should be remodularized...
   */
  int status, index;
  char table_name_1[256], field_name_1[256];
  char table_name_2[256], field_name_2[256];
  FIELD *field1, *field2, *field0; 
  char *equals_sign;
  
  equals_sign = strchr(linebuf, '=');
  if (equals_sign == NULL) {
    printf("Line not in form TBL.field = TBL2.field2 ... : %s\n", linebuf);
    return PARSE_ERROR;
  }
  *equals_sign = '\0';	/* linebuf is now 1st pair */
  if ((status = parse_table_field_pair(linebuf, table_name_1, field_name_1,
				       &index)) 
      != OK) 
    return status;
  field0 = field1 = find_field(fields, table_name_1, field_name_1, index);
  if (!field1) {
    fprintf(stderr, "(4)Unable to find field %s:%s\n", 
	    table_name_1, field_name_1);
    return BAD_DATA_ERROR;
  }
  if (field1->table->is_conditional[index])
      field1->table->has_conditional_join[index] = TRUE;
  do {
    linebuf = equals_sign + 1;
    equals_sign = strchr(linebuf, '=');
    if (equals_sign) *equals_sign = '\0';
    if ((status = parse_table_field_pair(linebuf, table_name_2, field_name_2, 
					 &index))
	!= OK) 
      return status;
    field2 = find_field(fields, table_name_2, field_name_2, index);
    if (!field2) {
      fprintf(stderr, "(5)Unable to find field %s:%s\n", 
	      table_name_2, field_name_2);
      return BAD_DATA_ERROR;
    }
    if (field2->table->is_conditional[index])
      field2->table->has_conditional_join[index] = TRUE;
    field1->conditional_join = field2;
    field1 = field2;
  } while (equals_sign);
  field2->conditional_join = field0;	/* close the circle */
  return OK;
}
Exemple #7
0
static SField* add_empty_field(HTable table, const char *field)
{
    SField *f, *nf;

    if ((! table) || (! field))
        return NULL;

    f = find_field(table, field);
    if (f)
        table_remove_field(table, f->name);

    nf = (SField*)calloc(1, sizeof(SField));
    if (! nf) return NULL;
    nf->name = strdup(field);

    f = table->fields;
    if (f)
    {
        while (f->next)
            f = f->next;
        f->next = nf;
    }
    else
        table->fields = nf;

    return nf;
}
int Mariadb_nodes::find_master()
{
    char str[255];
    char master_IP[256];
    int i = 0;
    int found = 0;
    int master_node = 255;
    while ((found == 0) && (i < N)) {
        if (find_field(
                    nodes[i], (char *) "show slave status;",
                    (char *) "Master_Host", &str[0]
                    ) == 0 ) {
            found = 1;
            strcpy(master_IP, str);
        }
        i++;
    }
    if (found == 1) {
        found = 0; i = 0;
        while ((found == 0) && (i < N)) {
            if (strcmp(IP[i], master_IP) == 0) {
                found = 1;
                master_node = i;
            }
            i++;
        }
    }
    return(master_node);
}
int Mariadb_nodes::check_galera()
{
    int res1 = 0;
    char str[1024];
    int cluster_size;
    MYSQL *conn;
    printf("Checking Galera\n"); fflush(stdout);
    for (int i = 0; i < N; i++) {
        conn = open_conn(port[i], IP[i], user_name, password, ssl);
        if (mysql_errno(conn) != 0) {
            printf("Error connectiong node %d\n", i);
            res1 = 1;
        } else {
            if (find_field(conn, (char *) "SHOW STATUS WHERE Variable_name='wsrep_cluster_size';", (char *) "Value", str) != 0) {
                printf("wsrep_cluster_size is not found in SHOW STATUS LIKE 'wsrep%%' results\n"); fflush(stdout);
                res1 = 1;
            } else {
                sscanf(str, "%d",  &cluster_size);
                if (cluster_size != N ) {
                    printf("wsrep_cluster_size is not %d\n", N); fflush(stdout);
                    res1 = 1;
                }
            }
        }
        mysql_close(conn);
    }
    return(res1);
}
Exemple #10
0
bool table_is_field_exists(HTable table, char *name)
{
    SField *f;

    f = find_field(table, name);
    return f? true : false;
}
Exemple #11
0
int table_remove_field(HTable table, char *field)
{
    SField *f, *pf;

    if ((! table) || (! field))
        return -1;

    f = find_field(table, field);
    if (f)
    {
        if (table->fields == f)
            table->fields = f->next;
        else
        {
            pf = table->fields;
            while (pf && (pf->next != f))
                pf = pf->next;
            if (pf)
                pf->next = f->next;
        }
        free_field(f);
    }

    return 0;
}
Exemple #12
0
 inline std::size_t content_size(response const & msg)
 {
     auto field_pos = find_field(msg.fields, "Content-Length");
     if (field_pos != msg.fields.end())
         return elib::lexical_cast<std::size_t>(field_pos->second);
     return 0;
 }
Exemple #13
0
void do_set_inode(int argc, char *argv[])
{
	const char *usage = "<inode> <field> <value>\n"
		"\t\"set_inode_field -l\" will list the names of "
		"the fields in an ext2 inode\n\twhich can be set.";
	static struct field_set_info *ss;
	
	if ((argc == 2) && !strcmp(argv[1], "-l")) {
		print_possible_fields(inode_fields);
		return;
	}

	if (common_args_process(argc, argv, 4, 4, "set_inode",
				usage, CHECK_FS_RW))
		return;

	if ((ss = find_field(inode_fields, argv[2])) == 0) {
		com_err(argv[0], 0, "invalid field specifier: %s", argv[2]);
		return;
	}

	set_ino = string_to_inode(argv[1]);
	if (!set_ino)
		return;

	if (debugfs_read_inode(set_ino, &set_inode, argv[1]))
		return;

	if (ss->func(ss, argv[3]) == 0) {
		if (debugfs_write_inode(set_ino, &set_inode, argv[1]))
			return;
	}
}
Exemple #14
0
void do_set_super(int argc, char *argv[])
{
	const char *usage = "<field> <value>\n"
		"\t\"set_super_value -l\" will list the names of "
		"superblock fields\n\twhich can be set.";
	static struct super_set_info *ss;
	
	if ((argc == 2) && !strcmp(argv[1], "-l")) {
		print_possible_fields();
		return;
	}

	if (common_args_process(argc, argv, 3, 3, "set_super_value",
				usage, CHECK_FS_RW))
		return;

	if ((ss = find_field(argv[1])) == 0) {
		com_err(argv[0], 0, "invalid field specifier: %s", argv[1]);
		return;
	}
	set_sb = *current_fs->super;
	if (ss->func(ss, argv[2]) == 0) {
		*current_fs->super = set_sb;
		ext2fs_mark_super_dirty(current_fs);
	}
}
static int add_join(char *linebuf)
{
  int status;
  char table_name_1[256], field_name_1[256];
  char table_name_2[256], field_name_2[256];
  FIELD *field1, *field2, *field0; 
  char *equals_sign;
  int  field1_index, field2_index;
  
  equals_sign = strchr(linebuf, '=');
  if (equals_sign == NULL) {
    printf("Line not in form TBL.field = TBL2.field2 ... : %s\n", linebuf);
    return PARSE_ERROR;
  }
  *equals_sign = '\0';	/* linebuf is now 1st pair */
  if ((status = parse_table_field_pair(linebuf, table_name_1, field_name_1,
				       &field1_index)) 
      != OK) 
    return status;
  field0 = field1 = find_field(fields, table_name_1, field_name_1,
			       field1_index);
  if (!field1) {
    fprintf(stderr, "(1)Unable to find field %s:%s (%d)\n", 
	    table_name_1, field_name_1, field1_index);
    return BAD_DATA_ERROR;
  }
  do {
    linebuf = equals_sign + 1;
    equals_sign = strchr(linebuf, '=');
    if (equals_sign) *equals_sign = '\0';
    if ((status = parse_table_field_pair(linebuf, table_name_2, field_name_2,
					 &field2_index))
	!= OK) 
      return status;
    field2 = find_field(fields, table_name_2, field_name_2, field2_index);
    if (!field2) {
      fprintf(stderr, "(2)Unable to find field %s:%s (%d)\n", 
	      table_name_2, field_name_2, field2_index);
      return BAD_DATA_ERROR;
    }
    field1->join = field2;
    field1 = field2;
  } while (equals_sign);

  field2->join = field0;	/* close the circle */
  return OK;
}
Exemple #16
0
 inline std::size_t content_size(request const & msg)
 {
     // if there is content, and the length to the size of the buffer
     auto field_pos = find_field(msg.fields, "Content-Length");
     if (field_pos != msg.fields.end())
         return elib::lexical_cast<std::size_t>(field_pos->second);
     return 0;
 }
Exemple #17
0
int table_get_field_type(HTable table, char *field)
{
    SField *f;

    if (! (f = find_field(table, field))) return -1;
        
    return f->type;
}
Exemple #18
0
void do_set_block_group_descriptor(int argc, char *argv[])
{
	const char *usage = "<bg number> <field> <value>\n"
		"\t\"set_block_group_descriptor -l\" will list the names of "
		"the fields in a block group descriptor\n\twhich can be set.";
	struct field_set_info	*table;
	struct field_set_info	*ss;
	char			*end;
	void			*edit, *target;
	int			size;

	/*
	 *Determine whether we are editing an ext2 or ext4 block
	 * group descriptor
	 */
	if (current_fs && current_fs->super->s_feature_incompat &
	    EXT4_FEATURE_INCOMPAT_64BIT) {
		table = ext4_bg_fields;
		edit = &set_gd4;
		size = sizeof(set_gd4);
	} else {
		table = ext2_bg_fields;
		edit = &set_gd;
		size = sizeof(set_gd);
	}

	if ((argc == 2) && !strcmp(argv[1], "-l")) {
		print_possible_fields(table);
		return;
	}

	if (common_args_process(argc, argv, 4, 4, "set_block_group_descriptor",
				usage, CHECK_FS_RW))
		return;

	set_bg = strtoul(argv[1], &end, 0);
	if (*end) {
		com_err(argv[0], 0, "invalid block group number: %s", argv[1]);
		return;
	}

	if (set_bg >= current_fs->group_desc_count) {
		com_err(argv[0], 0, "block group number too big: %d", set_bg);
		return;
	}

	if ((ss = find_field(table, argv[2])) == 0) {
		com_err(argv[0], 0, "invalid field specifier: %s", argv[2]);
		return;
	}

	target = ext2fs_group_desc(current_fs, current_fs->group_desc, set_bg);
	memcpy(edit, target, size);
	if (ss->func(ss, argv[2], argv[3]) == 0) {
		memcpy(target, edit, size);
		ext2fs_mark_super_dirty(current_fs);
	}
}
int Mariadb_nodes::check_replication(int master)
{
    int res1 = 0;
    char str[1024];
    MYSQL *conn;
    MYSQL_RES *res;
    printf("Checking Master/Slave setup\n"); fflush(stdout);
    for (int i = 0; i < N; i++) {
        conn = open_conn(port[i], IP[i], user_name, password, ssl);
        if (mysql_errno(conn) != 0) {
            printf("Error connectiong node %d\n", i); fflush(stdout);
            res1 = 1;
        } else {
            if ( i == master ) {
                // checking master
                if (conn != NULL ) {
                    if(mysql_query(conn, (char *) "SHOW SLAVE HOSTS;") != 0) {
                        printf("%s\n", mysql_error(conn));
                        res1 = 1;
                    } else {
                        res = mysql_store_result(conn);
                        if(res == NULL) {
                            printf("Error: can't get the result description\n"); fflush(stdout);
                            res1 = 1;
                        } else {
                            if (mysql_num_rows(res) != N-1) {
                                printf("Number if slaves is not equal to N-1\n"); fflush(stdout);
                                res1 = 1;
                            }
                        }
                        mysql_free_result(res);
                        do {
                            res = mysql_store_result(conn);
                            mysql_free_result(res);
                        } while ( mysql_next_result(conn) == 0 );
                    }
                }

            } else {
                // checking slave
                if (find_field(conn, (char *) "SHOW SLAVE STATUS;", (char *) "Slave_IO_Running", str) != 0) {
                    printf("Slave_IO_Running is not found in SHOW SLAVE STATUS results\n"); fflush(stdout);
                    res1 = 1;
                } else {
                    if (strcmp(str, "Yes") !=0 ) {
                        printf("Slave_IO_Running is not Yes\n"); fflush(stdout);
                        res1 = 1;
                    }
                }
            }
        }
        mysql_close(conn);
    }
    return(res1);
}
Exemple #20
0
void do_set_mmp_value(int argc, char *argv[])
{
	const char *usage = "<field> <value>\n"
		"\t\"set_mmp_value -l\" will list the names of "
		"MMP fields\n\twhich can be set.";
	static struct field_set_info *smmp;
	struct mmp_struct *mmp_s;
	errcode_t retval;

	if (argc == 2 && strcmp(argv[1], "-l") == 0) {
		print_possible_fields(mmp_fields);
		return;
	}

	if (current_fs->super->s_mmp_block == 0) {
		com_err(argv[0], 0, "no MMP block allocated\n");
		return;
	}

	if (common_args_process(argc, argv, 2, 3, "set_mmp_value",
				usage, CHECK_FS_RW))
		return;

	mmp_s = current_fs->mmp_buf;
	if (mmp_s == NULL) {
		retval = ext2fs_get_mem(current_fs->blocksize, &mmp_s);
		if (retval) {
			com_err(argv[0], retval, "allocating MMP buffer\n");
			return;
		}
		retval = ext2fs_mmp_read(current_fs,
					 current_fs->super->s_mmp_block, mmp_s);
		if (retval) {
			com_err(argv[0], retval, "reading MMP block %llu.\n",
				(long long)current_fs->super->s_mmp_block);
			ext2fs_free_mem(mmp_s);
			return;
		}
		current_fs->mmp_buf = mmp_s;
	}

	smmp = find_field(mmp_fields, argv[1]);
	if (smmp == 0) {
		com_err(argv[0], 0, "invalid field specifier: %s", argv[1]);
		return;
	}

	set_mmp = *mmp_s;
	if (smmp->func(smmp, argv[1], argv[2]) == 0) {
		ext2fs_mmp_write(current_fs, current_fs->super->s_mmp_block,
				 &set_mmp);
		*mmp_s = set_mmp;
	}
}
/**
 * Return the value of SECONDS_BEHIND_MASTER
 *
 * @param MYSQL	connection struct
 * @return value of SECONDS_BEHIND_MASTER
 */
unsigned int get_seconds_behind_master(MYSQL *conn)
{
    char SBM_str[16];
    unsigned int SBM=0;
    if (find_field(
                conn, (char *) "show slave status;",
                (char *) "Seconds_Behind_Master", &SBM_str[0]
                ) != 1) {
        sscanf(SBM_str, "%u", &SBM);
    }
    return(SBM);
}
Exemple #22
0
/* Iterate over the given php zval** and transform into protobuf compatible values.
   Write those into the given protobuf message pointer. */
int
php_message (const ProtobufCMessage* message, zval* val)
{
    HashPosition pos;
    HashTable* hash_table = Z_ARRVAL_P(val);
    zval** data;
    char* key;
    int i, j, key_len;
    long index;

    // check if all required fields are existent in the given php array.
    // NULL default values if not
    for (j=0 ; j < message->descriptor->n_fields ; ++j) {
        const ProtobufCFieldDescriptor* tmp_field = message->descriptor->fields + j;

        if (! zend_symtable_exists(hash_table, (char*)tmp_field->name,
                strlen((char*)(tmp_field->name)) + 1)) {
            if (tmp_field->label == PROTOBUF_C_LABEL_REQUIRED) {
                zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC,
                    "cannot find required field '%s'", tmp_field->name);
                return 1;
            } else {
                null_field(message, tmp_field);
            }
        }
    }

    // copy php values to proto
    zend_hash_internal_pointer_reset_ex(hash_table, &pos);
    for (;; zend_hash_move_forward_ex(hash_table, &pos)) {
        zend_hash_get_current_data_ex(hash_table, (void**)&data, &pos);

        i = zend_hash_get_current_key_ex(hash_table, &key, &key_len, &index, 0, &pos);
        
        if (i == HASH_KEY_NON_EXISTANT) {
            break;
        } else if (i == HASH_KEY_IS_STRING) {

            const ProtobufCFieldDescriptor* field = find_field(message, key);
            if (field == NULL)
                continue;

            if (write_field(message, field, data) != 0) {
                zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC,
                    "unable to pack field '%s'", field->name);
                return 1;
            }
        }
    }

    return 0;
}
int Mariadb_nodes::start_replication()
{
    char sys1[4096];
    char str[1024];
    char log_file[256];
    char log_pos[256];
    int i;
    int global_result = 0;
    global_result += stop_nodes();

    printf("Starting back Master\n");  fflush(stdout);
    sprintf(&sys1[0], "ssh -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %s@%s '%s %s'", sshkey[0], access_user, IP[0], access_sudo, start_db_command);
    printf("%s\n", sys1);  fflush(stdout);
    global_result +=  system(sys1); fflush(stdout);

    for (i = 1; i < N; i++) {
        printf("Starting node %d\n", i); fflush(stdout);
        sprintf(&sys1[0], "ssh -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %s@%s '%s %s '", sshkey[i], access_user, IP[i], access_sudo, start_db_command);
        printf("%s\n", sys1);  fflush(stdout);
        global_result += system(sys1); fflush(stdout);
    }
    sleep(5);

    global_result += connect();
    global_result += execute_query(nodes[0], create_repl_user);
    execute_query(nodes[0], (char *) "reset master;");
    execute_query(nodes[0], (char *) "stop slave;");

    find_field(nodes[0], (char *) "show master status", (char *) "File", &log_file[0]);
    find_field(nodes[0], (char *) "show master status", (char *) "Position", &log_pos[0]);
    for (i = 1; i < N; i++) {
        global_result += execute_query(nodes[i], (char *) "stop slave;");
        sprintf(str, setup_slave, IP_private[0], log_file, log_pos, port[0]);
        printf("%s", str);
        global_result += execute_query(nodes[i], str);
    }
    close_connections();
    return(global_result);
}
Exemple #24
0
// system("chat -t 1 -e '' 'AT+CGNWS' OK >> /dev/ttyACM0 < /dev/ttyACM0 2>/tmp/at_cgnws; grep +CGNWS: /tmp/at_cgnws | awk -F, '{print $4}' | grep 0x01 -q && v=`grep +CGNWS: /tmp/at_cgnws | awk -F, '{print $7}'` || v=FAIL; echo $v");
char *Gobi_ConnectISP(char *line, int size)
{
	const char *atCmd   = "+CGNWS";
	const char *tmpFile = "/tmp/at_cgnws";
	char str[64];
	char *p;

	if (Gobi_AtCommand(atCmd, tmpFile) >= 0
	    && (p = get_line_by_str(line, size, tmpFile, "+CGNWS:")) != NULL)
	{
		char *f;
		skip_space(p);
		cut_space(p);
		if ((f = find_field(p, ',', 3, str)) != NULL)
		{
			if (strcmp(str, "0x01") == 0)
			{
				if((f = find_field(p, ',', 6, str)) != NULL && strcmp(str, "NULL")) // SPN
				{
					strcpy(line,str);
					return line;
				}
				else if((f = find_field(p, ',', 7, str)) != NULL) // long name
				{
					strcpy(line,str);
					return line;
				}
				else if((f = find_field(p, ',', 8, str)) != NULL) // short name
				{
					strcpy(line,str);
					return line;
				}
				
			}
		}
	}
	return NULL;
}
int Mariadb_nodes::change_master(int NewMaster, int OldMaster)
{
    int i;
    //int OldMaster = FindMaster();
    char log_file[256];
    char log_pos[256];
    char str[1024];

    for (i = 0; i < N; i++) {
        if (i != OldMaster) {execute_query(nodes[i], (char *) "stop slave;");}
    }
    execute_query(nodes[NewMaster], create_repl_user);
    execute_query(nodes[OldMaster], (char *) "reset master;");
    find_field(nodes[NewMaster], (char *) "show master status", (char *) "File", &log_file[0]);
    find_field(nodes[NewMaster], (char *) "show master status", (char *) "Position", &log_pos[0]);
    for (i = 0; i < N; i++) {
        if (i != NewMaster) {
            sprintf(str, setup_slave, IP[NewMaster], log_file, log_pos, port[NewMaster]);
            execute_query(nodes[i], str);
        }
    }
    //for (i = 0; i < N; i++) {if (i != NewMaster) {execute_query(nodes[i], (char *) "start slave;"); }}
}
Exemple #26
0
HTable table_get_table(HTable table, char *field, HTable dflt, int *err)
{
    SField *f;

    if ((f = find_field(table, field)) && (f->type == TYPE_TABLE))
    {
        if (err) *err = 0;
        return f->value.table_value;
    }

    if (err) *err = 1;

    return dflt;
}
Exemple #27
0
int table_get_int(HTable table, char *field, int dflt, int *err)
{
    SField *f;
    int v, e;

    if ((f = find_field(table, field)) && (v = get_field_int(f, &e)) && !e)
    {
        if (err) *err = 0;
        return v;
    }

    if (err)
        *err = f? e : 1;

    return dflt;
}
Exemple #28
0
double table_get_double(HTable table, char *field, double dflt, int *err)
{
    SField *f;
    double v;
    int e;

    if ((f = find_field(table, field)) && (v = get_field_double(f, &e)) && !e)
    {
        if (err) *err = 0;
        return v;
    }

    if (err)
        *err = f? e : 1;

    return dflt;
}
Exemple #29
0
void Level::loadLevel(ifstream& file, Level& level, Player& player, Exit& exit){
    string page, line, pxyz, exyz, h, w, lvl;
    int px, py, pz, ex, ey, ez;

    vector<int>::iterator it_x;
    vector< vector<int> >::iterator it_y;

    level.x.clear();
    level.y.clear();

    int tint;

    while (getline (file, line)){
        page.append(line);
        line.erase();
    }
    level.setName(find_field(page, "Name"));
    h = find_field(page, "Height");
    level.setHeight(atoi(h.c_str()));
    w = find_field(page, "Width");
    level.setWidth(atoi(w.c_str()));
    pxyz = find_field(page, "Player");
    exyz = find_field(page, "Exit");

    lvl = find_field(page, "Map");

    stringstream ps(pxyz);
    stringstream es(exyz);
    stringstream ss(lvl);

    ps >> px >> py >> pz;
    es >> ex >> ey >> ez;

    player.set_x(px);
    player.set_y(py);
    player.set_z(pz);

    exit.set_x(ex);
    exit.set_y(ey);
    exit.set_z(ez);


    for(int j = 0; j < level.getHeight(); j++){
        for(int i = 0 ; i < level.getWidth(); i++){

                if(i != ' '){
                    ss >> tint;
                    level.x.push_back(tint);
                }
                else{
                    i++;
                }
        }
static int add_is_active_field(char *linebuf)
{
  int status, index;
  char table_name[256], field_name[256];
  FIELD *field;

  if ((status = parse_table_field_pair(linebuf, table_name, field_name, 
				       &index)) 
      != OK) 
    return status;
  if ((field = find_field(fields, table_name, field_name, index)) == NULL) {
    fprintf(stderr, "(3)Unable to find field %s:%s\n", 
	    table_name, field_name);
    return BAD_DATA_ERROR;
  }
  return append_field(&is_active_fields, table_name, field_name, 
		      NOT_SET, FALSE, tables, index);
}