예제 #1
0
buffp buff_realloc(buffp b, unsigned size)
{
  void *p;

  if (!b || !(b->buffer))
    return buff_alloc(size);

  if (!size)
    {
      buff_free(b);
      return NULL;
    }

  p = get_mem(size);
  if (!p)
    {
      buff_free(b);
      return NULL;
    }

  if (size > b->alloc)
    memcpy(p, b->buffer, b->alloc);
  else
    memcpy(p, b->buffer, size);
  free_mem(b->buffer);
  b->buffer = p;
  b->alloc = size;
  return b;
}
예제 #2
0
파일: http.c 프로젝트: whtc123/mysource
static void httpserver_session_free(HttpSession *session)
{	
	queue_remove(&session->node);
	event_fd_del(session->ev);
	close(session->fd);
	close(session->file_fd);
	if(session->request.buff)
		buff_free( session->request.buff);
	if(session->response)
		buff_free( session->response);
}
예제 #3
0
static SList *preprocess(newspost_data *data, SList *file_list) {
	Buff *tmpstring = NULL;
	SList *parfiles = NULL;

	/* make the from line */
	if (data->name != NULL) {
		tmpstring = buff_create(tmpstring, "%s", data->from->data);
		data->from = buff_create(data->from, "%s <%s>",
					 data->name->data, tmpstring->data);
		buff_free(tmpstring);
	}

	if (data->text == FALSE) {
		/* calculate CRCs if needed; generate any sfv files */
		if ((data->yenc == TRUE) || (data->sfv != NULL)) {
			calculate_crcs(file_list);
			
			if (data->sfv != NULL)
				newsfv(file_list, data);
		}
		
		/* generate any par files */
		if (data->par != NULL) {
			parfiles = par_newspost_interface(data, file_list);
			if (data->yenc == TRUE)
				calculate_crcs(parfiles);
		}
	}

	return parfiles;
}
예제 #4
0
/* returns number of bytes read */
static Buff *read_text_file(Buff *text_buffer, const char *filename) {
	FILE *file;
	Buff *line = NULL;

	buff_free(text_buffer);
	file = fopen(filename, "r");
	if (file != NULL) {
		while (!feof(file)) {
			line = get_line(line, file);
			if(line == NULL){
				text_buffer = buff_add(text_buffer, "\r\n");
				continue;
			}

			/* translate for posting */
			if (line->data[0] == '.')
				text_buffer = buff_add(text_buffer, ".");

			text_buffer = buff_add(text_buffer, "%s", line->data);

			if(text_buffer->data[(text_buffer->length - 1)] == '\r')
				text_buffer = buff_add(text_buffer, "\n");
			else
				text_buffer = buff_add(text_buffer, "\r\n");
		}
		fclose(file);
	}
	return text_buffer;
}
예제 #5
0
파일: txdb.c 프로젝트: haraldh/bitc
static int
txdb_save_tx(struct txdb   *txdb,
             const uint256 *blkHash,
             const uint256 *txHash,
             mtime_t        timestamp,
             const uint8   *buf,
             size_t         len)
{
    struct tx_ser_data txdata;
    struct buff *bufd;
    struct buff *bufk;
    char hashStr[80];
    char *err;

    err = NULL;
    memset(&txdata, 0, sizeof txdata);

    if (blkHash) {
        memcpy(&txdata.blkHash, blkHash, sizeof *blkHash);
    }

    txdata.buf       = (uint8 *)buf;
    txdata.len       = len;
    txdata.timestamp = timestamp;

    uint256_snprintf_reverse(hashStr, sizeof hashStr, txHash);
    bufk = txdb_serialize_tx_key(txdb->tx_seq, hashStr);
    bufd = txdb_serialize_tx_data(&txdata);

    leveldb_put(txdb->db, txdb->wr_opts,
                buff_base(bufk), buff_curlen(bufk),
                buff_base(bufd), buff_curlen(bufd),
                &err);

    buff_free(bufk);
    buff_free(bufd);

    if (err) {
        Warning(LGPFX" failed to save tx %s: %s\n", hashStr, err);
        free(err);
    }

    return err != NULL;
}
예제 #6
0
파일: script.c 프로젝트: jma127/bitc-rpc
static void script_tx_sighash(struct wallet *wallet, uint256 *hash,
                              const struct buff *scriptPubKey,
                              const struct btc_msg_tx *tx, uint32 idx,
                              enum script_hash_type hashType) {
  struct btc_msg_tx *tx2;
  struct buff *buf;
  int i;

  ASSERT(idx < tx->in_count);

  memset(hash, 0, sizeof *hash);
  tx2 = btc_msg_tx_dup(tx);

  Log(LGPFX " Computing sighash for txi-%u/%llu\n", idx, tx2->in_count);

  /*
   * Zero-out all the inputs' signatures.
   */
  for (i = 0; i < tx2->in_count; i++) {
    tx2->tx_in[i].scriptLength = 0;
  }

  size_t len = buff_maxlen(scriptPubKey);
  ASSERT(len > 0);

  ASSERT(tx2->tx_in[idx].scriptSig == NULL);
  ASSERT(tx2->tx_in[idx].scriptLength == 0);

  tx2->tx_in[idx].scriptLength = len;
  tx2->tx_in[idx].scriptSig = safe_malloc(len);

  memcpy(tx2->tx_in[idx].scriptSig, buff_base(scriptPubKey), len);

  ASSERT((hashType & 0x1f) == SIGHASH_ALL);

  /*
   * Final step:
   *
   * Serialize tx + hashType (as a uint32) and compute hash.
   */

  buf = buff_alloc();
  serialize_tx(buf, tx2);
  serialize_uint32(buf, hashType);
  hash256_calc(buff_base(buf), buff_curlen(buf), hash);
  buff_free(buf);

  btc_msg_tx_free(tx2);
  free(tx2);
}
예제 #7
0
buffp set_menu_last(buffp b)
{
    MENU_NODE *pNode;
    if (!b)
        return b;
    pNode = (MENU_NODE *)b->buffer;
    if (!pNode)
    {
        buff_free(b);
        return NULL;
    }
    while (pNode->next)
        pNode = pNode->next;
    pNode->data.menuflag |= MF_END;
    return b;
}
예제 #8
0
파일: buff.c 프로젝트: whtc123/mysource
int buff_free(Buff *buff)
{
	if(--buff->ref_cnt  > 0 )
		return buff->ref_cnt;
	if( buff->reference != NULL )
	{
		buff_free(buff->reference);
		buff->reference=NULL;
	}
	else
	{
		free(buff->ptr);
		buff->ptr=NULL;
		buff->start=NULL;
		
	}
	free(buff);
	return 0;
}
예제 #9
0
resp make_bitmap_resource(buffp b)
{
    WORD	rgb_count;
    DWORD	image_size;
    BITMAPINFOHEADER   *bmp_info_header;
    BITMAP_NODE  *bmp_image;
    resp r;
    RGBQUAD	*rgb_quad;
    char	*bmp_bits;

    r = res_new();
    r->type = (strp)RT_BITMAP;
    r->flags = FLAG_DEFAULT;

    if (*(char *)b->buffer != 'B' ||
            *(((char *)b->buffer) + 1) != 'M')
        FATAL(("Invalid bitmap resource"));

    ALLOC(bmp_info_header, BITMAPINFOHEADER);
    get_bmp_info_header(bmp_info_header, (BYTE *)b->buffer + BMP_FILE_HEADER);

    rgb_count = bit_to_rgb(bmp_info_header->biBitCount);
    CALLOC(rgb_quad, rgb_count, RGBQUAD);
    memcpy(rgb_quad, (BYTE *)b->buffer + BMP_FILE_HEADER + bmp_info_header->biSize,
           rgb_count * sizeof(RGBQUAD));

    image_size = bmp_info_header->biSizeImage;
    NALLOC(bmp_bits, image_size, char *);
    memcpy(bmp_bits, (BYTE *)b->buffer + BMP_FILE_HEADER +
           bmp_info_header->biSize + rgb_count * sizeof(RGBQUAD),
           image_size);

    BUFF_STRUCT(r->b, bmp_image, BITMAP_NODE);

    bmp_image->data.bmp_hdr = bmp_info_header;
    bmp_image->data.rgb_quad = rgb_quad;
    bmp_image->data.bitmap_bits = (BYTE*)bmp_bits;

    buff_free(b);

    return r;
}
예제 #10
0
파일: tool.c 프로젝트: adamsch1/csearch
void crawl_parse_free( crawl_parse_t *c ) {
	buff_free( &c->buff );
}
예제 #11
0
파일: tool.c 프로젝트: adamsch1/csearch
void crawl_fetch_free( crawl_fetch_t *f ) {
	free( f->url );
	buff_free( &f->buff );
}
예제 #12
0
파일: txdb.c 프로젝트: haraldh/bitc
int
txdb_craft_tx(struct txdb              *txdb,
              const struct btc_tx_desc *tx_desc,
              btc_msg_tx               *tx)
{
    struct buff *buf;
    char hashStr[80];
    uint256 txHash;
    uint64 change;
    uint32 numCoins;
    bool relevant;
    mtime_t ts;
    int res;

    res = 0;
    relevant = 0;
    tx->version = 1;
    txdb_prepare_txout(tx_desc, tx);

    /*
     * In order to properly size 'tx->txIn', we need to determine how many coins
     * we're going to use. Right now, let's just vastly overestimate.
     */
    numCoins = hashtable_getnumentries(txdb->hash_txo);
    tx->tx_in = safe_calloc(numCoins, sizeof *tx->tx_in);

    txdb_print_coins(txdb, 1);
    txdb_select_coins(txdb, tx_desc, tx, &change);

    /*
     * Change! XXX: fix me.
     */
    if (change > 0) {
        const char *btc_change;

        btc_change = wallet_get_change_addr(btc->wallet);
        tx->out_count++;
        txdb_set_txo(tx, tx->out_count - 1, btc_change, change);
        Warning(LGPFX" change: %llu -- %.8f BTC\n", change, change / ONE_BTC);
    }

    txdb_sign_tx_inputs(txdb, tx);

    /*
     * Now that the tx is ready, serialize it and check that it's not too big.
     */
    btcmsg_print_tx(tx);

    buf = buff_alloc();
    serialize_tx(buf, tx);
    if (buff_curlen(buf) > BTC_TX_MAX_SIZE) {
        Warning(LGPFX" tx too large: %zu\n", buff_curlen(buf));
        res = 1;
        goto exit;
    }

    hash256_calc(buff_base(buf), buff_curlen(buf), &txHash);

    uint256_snprintf_reverse(hashStr, sizeof hashStr, &txHash);
    Warning(LGPFX" %s (%zu bytes)\n", hashStr, buff_curlen(buf));
    Log_Bytes(LGPFX" TX: ", buff_base(buf), buff_curlen(buf));

    if (bitc_testing) {
        Warning("TESTING! Not saving/relaying tx.\n");
        goto exit;
    }

    ts = time(NULL);

    res = txdb_remember_tx(txdb, 0 /* save to disk */, ts,
                           buff_base(buf), buff_curlen(buf),
                           &txHash, NULL, &relevant);

    txdb_save_tx_label(tx_desc, hashStr);
    txdb_export_tx_info(txdb);

    res = peergroup_new_tx_broadcast(btc->peerGroup, buf,
                                     ts + 2 * 60 * 60, &txHash);
    if (res) {
        Warning(LGPFX" failed to transmit tx: %d\n", res);
        bitcui_set_status("got errors while broadcasting tx");
    }
exit:
    buff_free(buf);
    /*
     * XXX: We should mark the coins used by this tx as "reserved", so that we
     * do not attempt to use conflicting coins in subsequent TXs.
     */
    return res;
}
예제 #13
0
resp make_icon_resource(buffp b)
{
    BYTE *temp;
    WORD	i, type, count, rgb_count;
    ICONDIR_NODE *cur_entry, *icon_entry_table;
    ICON_NODE *cur_image;
    DWORD	image_offset, image_size;
    BYTE	*temp_offset;
    BITMAPINFOHEADER  *bmp_info_header;
    RGBQUAD	*rgb_quad;
    char	*XOR_bits, *AND_bits;
    WORD	mask_bytes;
    static unsigned IdOrdinal = 1;
    resp r, rIcon;

    type = get_word((BYTE *)b->buffer + TYPE_OFFSET);
    count = get_word((BYTE *)b->buffer + TYPE_OFFSET + 2);
    if (type != 1)
        FATAL(("Invalid icon resource, type=%d", type));

    r = res_new();
    r->type = (char *)RT_GROUP_ICON;
    r->flags = FLAG_DEFAULT;

    r->b = buff_alloc(count * sizeof(ICONDIR_NODE));
    r->b->len = r->b->alloc;
    icon_entry_table = (ICONDIR_NODE *)r->b->buffer;

    cur_entry = icon_entry_table;
    cur_entry->next = (ICONDIR_NODE *)NULL;
    i = 0;
    while (1)
    {
        temp = (BYTE *)b->buffer + ICON_DIR_OFFSET + i * DIR_ENTRY_SIZE;
        cur_entry->data.bWidth = temp[0];
        cur_entry->data.bHeight = temp[1];
        cur_entry->data.wOrdinalNumber = IdOrdinal;
        cur_entry->data.bColorCount = temp[2];
        cur_entry->data.wPlanes = get_word(&temp[4]);
        cur_entry->data.wBitsPerPel = 0; /* Unused by library */
        cur_entry->data.dwBytesInRes = 0; /* Unused by library */
        image_size = get_dword(&temp[8]);
        image_offset = get_dword(&temp[12]);

        temp_offset = (BYTE *)b->buffer + image_offset;

        ALLOC(bmp_info_header, BITMAPINFOHEADER);
        get_bmp_info_header(bmp_info_header, temp_offset);
        temp_offset += bmp_info_header->biSize;

        rgb_count = bit_to_rgb(bmp_info_header->biBitCount);
        CALLOC(rgb_quad, rgb_count, RGBQUAD);
        memcpy((char *)rgb_quad, (char *)temp_offset,sizeof(RGBQUAD)*rgb_count);
        temp_offset += sizeof(RGBQUAD) * rgb_count;

        mask_bytes =  (int)(bmp_info_header->biWidth *
                            bmp_info_header->biHeight * bmp_info_header->biBitCount) / 16;

        NALLOC(XOR_bits, mask_bytes, char *);
        memcpy(XOR_bits, (char *)temp_offset, mask_bytes);
        temp_offset += mask_bytes;

        mask_bytes /=  bmp_info_header->biBitCount;
        /* AND mask is always MonoChrome */

        NALLOC(AND_bits, mask_bytes, char *);
        memcpy(AND_bits, (char *)temp_offset, mask_bytes);

        rIcon = res_new();
        BUFF_STRUCT(rIcon->b, cur_image, ICON_NODE);
        cur_image->data.icon_bmp_hdr = bmp_info_header;
        cur_image->data.icon_rgb_quad = rgb_quad;
        cur_image->data.icon_xor_mask = (BYTE*)XOR_bits;
        cur_image->data.icon_and_mask = (BYTE*)AND_bits;

        rIcon->type = RT_ICON;
        rIcon->name = (const char *)(IdOrdinal);
        /* Flags? */
        add_common_resource(rIcon);

        IdOrdinal++;
        if (count == ++i)
            break;
        else {
            ALLOC(cur_entry->next, ICONDIR_NODE);
            cur_entry = cur_entry->next;
            cur_entry->next = (ICONDIR_NODE *)NULL;
        }
    }

    buff_free(b);

    return r;
}
예제 #14
0
파일: txdb.c 프로젝트: haraldh/bitc
void
txdb_confirm_one_tx(struct txdb   *txdb,
                    const uint256 *blkHash,
                    const uint256 *txHash)
{
    leveldb_iterator_t *iter;
    struct tx_entry *txe;
    char bkHashStr[80];
    char txHashStr[80];

    ASSERT(!uint256_iszero(blkHash));
    ASSERT(!uint256_iszero(txHash));

    txe = txdb_get_tx_entry(txdb, txHash);
    if (txe == NULL) {
        return;
    }

    if (txe->relevant == 0) {
        txdb_remove_from_hashtable(txdb, txHash);
        NOT_TESTED();
        return;
    }

    if (!uint256_iszero(&txe->blkHash)) {
        /*
         * It's possible for the ASSERT below to fire if a tx is confirmed in
         * a block that is later orphaned. The tx should then be relayed again
         * until it finds its way in a new block.
         */
        ASSERT(uint256_issame(&txe->blkHash, blkHash));
        return;
    }

    peergroup_stop_broadcast_tx(btc->peerGroup, txHash);
    memcpy(&txe->blkHash, blkHash, sizeof *blkHash);

    uint256_snprintf_reverse(bkHashStr, sizeof bkHashStr, blkHash);
    uint256_snprintf_reverse(txHashStr, sizeof txHashStr, txHash);
    Warning(LGPFX" %s confirmed in %s\n", txHashStr, bkHashStr);

    NOT_TESTED();

    iter = leveldb_create_iterator(txdb->db, txdb->rd_opts);
    leveldb_iter_seek_to_first(iter);

    while (leveldb_iter_valid(iter)) {
        struct tx_ser_key *txkey;
        struct tx_ser_data *txdata;
        struct buff *buf;
        const char *key;
        const char *val;
        size_t klen;
        size_t vlen;
        char *err = NULL;

        key = leveldb_iter_key(iter, &klen);
        txkey = txdb_deserialize_tx_key(key, klen);

        if (txkey == NULL || uint256_issame(txHash, &txkey->txHash) == 0) {
            free(txkey);
            leveldb_iter_next(iter);
            continue;
        }

        NOT_TESTED();

        val = leveldb_iter_value(iter, &vlen);
        txdata = txdb_deserialize_tx_data(val, vlen);
        ASSERT(uint256_iszero(&txdata->blkHash));
        ASSERT(txdata->timestamp != 0);
        memcpy(&txdata->blkHash, blkHash, sizeof *blkHash);

        buf = txdb_serialize_tx_data(txdata);

        leveldb_put(txdb->db, txdb->wr_opts, key, klen,
                    buff_base(buf), buff_curlen(buf), &err);
        buff_free(buf);
        if (err) {
            Warning(LGPFX" failed to write tx entry: %s\n", err);
        }

        txdb_export_tx_info(txdb);

        free(txkey);
        free(txdata->buf);
        free(txdata);
        break;
    }
    leveldb_iter_destroy(iter);
}
예제 #15
0
static ex_t display_words(bfpath *bfp, int argc, char **argv, bool show_probability)
{
    byte buf[BUFSIZE];
    buff_t *buff = buff_new(buf, 0, BUFSIZE);
    const byte *word;

    const char *path = bfp->filepath;

    const char *head_format = !show_probability ? "%-30s %6s %6s\n"   : "%-30s %6s  %6s  %6s\n";
    const char *data_format = !show_probability ? "%-30s %6lu %6lu\n" : "%-30s %6lu  %6lu  %f\n";

    void *dsh = NULL; /* initialize to silence bogus gcc warning */
    void *dbe;

    int rv = 0;
    ex_t ec = EX_OK;

    dsv_t msgcnts;

    /* protect against broken stat(2) that succeeds for empty names */
    if (path == NULL || *path == '\0') {
        fprintf(stderr, "Expecting non-empty directory or file name.\n");
        return EX_ERROR;
    }

    dbe = ds_init(bfp);
    dsh = ds_open(dbe, bfp, DS_READ);;
    if (dsh == NULL)
	/* print error, cleanup, and exit */
	ds_open_failure(bfp, dbe);

    if (DST_OK != ds_txn_begin(dsh)) {
	ds_close(dsh);
	ds_cleanup(dbe);
	fprintf(stderr, "Cannot begin transaction.\n");
	return EX_ERROR;
    }

    if (show_probability)
    {
	ds_get_msgcounts(dsh, &msgcnts);
	robs = ROBS;
	robx = ROBX;
    }

    fprintf(fpo, head_format, "", "spam", "good", "  Fisher");
    while (argc >= 0)
    {
	dsv_t val;
	word_t *token;
	int rc;

	unsigned long spam_count;
	unsigned long good_count;
	double rob_prob = 0.0;
	
	if (argc == 0)
	{
	    if (get_token(buff, stdin) != 0)
		break;
	    token = &buff->t;
	} else {
	    word = (const byte *) *argv++;
	    if (--argc == 0)
		argc = -1;
	    token = word_news((const char *)word);
	}

	rc = ds_read(dsh, token, &val);
	switch (rc) {
	    case 0:
		spam_count = val.spamcount;
		good_count = val.goodcount;

		if (!show_probability)
		    fprintf(fpo, data_format, token->u.text, spam_count, good_count);
		else
		{
		    rob_prob = calc_prob(good_count, spam_count, msgcnts.goodcount, msgcnts.spamcount);
		    fprintf(fpo, data_format, token->u.text, spam_count, good_count, rob_prob);
		}
		break;
	    case 1:
		break;
	    default:
		fprintf(stderr, "Cannot read from database.\n");
		ec = EX_ERROR;
		goto finish;
	}

	if (token != &buff->t)
	    word_free(token);
    }

finish:
    if (DST_OK != rv ? ds_txn_abort(dsh) : ds_txn_commit(dsh)) {
	fprintf(stderr, "Cannot %s transaction.\n", rv ? "abort" : "commit");
	ec = EX_ERROR;
    }
    ds_close(dsh);
    ds_cleanup(dbe);

    buff_free(buff);

    return ec;
}
예제 #16
0
void res_free(resp r)
{
  buff_free(r->b);
  free_mem(r);
}
예제 #17
0
resp make_cursor_resource(buffp b)
{
    WORD i, type, count, HotX, HotY;
    CURSORDIR_NODE *cur_entry, *cursor_entry_table;
    CURSOR_NODE *cur_image;
    DWORD	image_offset, image_size;
    BYTE *temp_offset;
    BITMAPINFOHEADER  *bmp_info_header;
    RGBQUAD *rgb_quad;
    char *XOR_bits, *AND_bits;
    WORD mask_bytes;
    static unsigned IdOrdinal = 1;
    resp r, rCursor;

    type = get_word((BYTE *)b->buffer + TYPE_OFFSET);
    count = get_word((BYTE *)b->buffer + TYPE_OFFSET + 2);
    if (type != 2)
        FATAL(("Invalid cursor resource, type=%d", type));

    r = res_new();
    r->type = (char *)RT_GROUP_CURSOR;
    r->flags = FLAG_DEFAULT;

    BUFF_STRUCT(r->b, cursor_entry_table, CURSORDIR_NODE);
    cur_entry = cursor_entry_table;
    cur_entry->next = NULL;
    i = 0;

    while (1) {
        temp_offset = (BYTE *)b->buffer + CURSOR_DIR_OFFSET + i * DIR_ENTRY_SIZE;
        cur_entry->data.wWidth = temp_offset[0];
        cur_entry->data.wHeight = temp_offset[1];
        cur_entry->data.wOrdinalNumber = IdOrdinal;
        cur_entry->data.wPlanes = 0;
        cur_entry->data.wBitsPerPel = 0;
        cur_entry->data.dwBytesInRes = 0;
        HotX = get_word((BYTE *)&temp_offset[4]);
        HotY = get_word((BYTE *)&temp_offset[6]);
        image_size = get_dword((BYTE *)&temp_offset[8]);
        image_offset = get_dword((BYTE *)&temp_offset[12]);

        temp_offset = (BYTE *)b->buffer + image_offset;

        ALLOC(bmp_info_header, BITMAPINFOHEADER);
        get_bmp_info_header(bmp_info_header, temp_offset);

        temp_offset += bmp_info_header->biSize;

        NALLOC(rgb_quad, sizeof(RGBQUAD) * 2, RGBQUAD *);
        memcpy((char *)rgb_quad, (char *)temp_offset, sizeof(RGBQUAD) * 2);

        temp_offset += sizeof(RGBQUAD) * 2;

        mask_bytes =  (bmp_info_header->biWidth + 31)/32;
        mask_bytes = mask_bytes << 2;
        mask_bytes = (int)(mask_bytes * bmp_info_header->biHeight)/2;

        NALLOC(AND_bits, mask_bytes, char *);
        NALLOC(XOR_bits, mask_bytes, char *);

        memcpy(XOR_bits, (char *)temp_offset, mask_bytes);
        memcpy(AND_bits, (char *)temp_offset + mask_bytes, mask_bytes);

        rCursor = res_new();
        BUFF_STRUCT(rCursor->b, cur_image, CURSOR_NODE);
        cur_image->data.wHotSpotX = HotX;
        cur_image->data.wHotSpotY = HotY;
        cur_image->data.bmp_hdr = bmp_info_header;
        cur_image->data.rgb_quad = rgb_quad;
        cur_image->data.xor_mask = (BYTE*)XOR_bits;
        cur_image->data.and_mask = (BYTE*)AND_bits;

        rCursor->type = RT_CURSOR;
        rCursor->name = (const char *)(IdOrdinal);
        /* Flags? */
        add_common_resource(rCursor);

        IdOrdinal++;
        if (count == ++i)
            break;
        else {
            ALLOC(cur_entry->next, CURSORDIR_NODE);
            cur_entry = cur_entry->next;
            cur_entry->next = (CURSORDIR_NODE *)NULL;
        }
    }

    buff_free(b);

    return r;
}
예제 #18
0
static int post_file(newspost_data *data, file_entry *file_data, 
	  int filenumber, int number_of_files,
	  const char *filestring, char *data_buffer) {
	long number_of_bytes;
	int j, retval;
	int number_of_tries = 0;
	int parts_posted = 0;
	int number_of_parts = 
		get_number_of_encoded_parts(data, file_data);
	static int total_failures = 0;
	boolean posting_started = FALSE;
	Buff * subject = NULL;

	if(file_data->parts != NULL){
		if(file_data->parts[0] == TRUE) return NORMAL;
	}

	for (j = 1; j <= number_of_parts; j++) {

		if ((file_data->parts != NULL) &&
		    (file_data->parts[j] == FALSE))
			continue;

		subject = make_subject(subject, data, filenumber, number_of_files,
			     file_data->filename->data, j, number_of_parts,
			     filestring);
		
		number_of_bytes = get_encoded_part(data, file_data, j,
						   data_buffer);
		if (posting_started == FALSE) {
			ui_posting_file_start(data, file_data, 
				      number_of_parts, number_of_bytes);
			posting_started = TRUE;
		}
	
		ui_posting_part_start(file_data, j, number_of_parts,
				      number_of_bytes);

		retval = nntp_post(subject->data, data, data_buffer,
				   number_of_bytes, FALSE);

		if (retval == NORMAL) {
			ui_posting_part_done(file_data, j, number_of_parts,
					     number_of_bytes);
			parts_posted++;
		}
		else if (retval == POSTING_NOT_ALLOWED)
			return retval;
		else {
			if (number_of_tries < 5) {
				ui_nntp_posting_retry();
				sleep(5);
				number_of_tries++;
				continue;
			}
			else {
				total_failures++;
				if (total_failures == 5) {
					nntp_logoff();
					socket_close();
					ui_too_many_failures();
				}
			}
		}
		number_of_tries = 0;
	}
	buff_free(subject);

	ui_posting_file_done();
	return NORMAL;
}
예제 #19
0
파일: buff.c 프로젝트: MeCoRing/utillib
void buff_dec(buff_t *pb)
{
    pb->ref--;
    if(!pb->ref)
        buff_free(pb);
}
예제 #20
0
static int encode_and_post(newspost_data *data, SList *file_list,
			    SList *parfiles) {
	int number_of_parts;
	int number_of_files;
	int i;
	file_entry *file_data = NULL;
	int retval = NORMAL;
	char *data_buffer = 
		(char *) malloc(get_buffer_size_per_encoded_part(data));
	Buff *subject = NULL;
	Buff *text_buffer = NULL;

	/* create the socket */
	ui_socket_connect_start(data->address->data);
	retval = socket_create(data->address->data, data->port);
	if (retval < 0)
		return retval;

	ui_socket_connect_done();

	/* log on to the server */
	ui_nntp_logon_start(data->address->data);
	if (nntp_logon(data) == FALSE) {
		socket_close();
		return LOGON_FAILED;
	}
	ui_nntp_logon_done();

	if (data->text == TRUE) {
		file_data = file_list->data;
		/* post */
		text_buffer = read_text_file(text_buffer, file_data->filename->data);
		if(text_buffer != NULL)
			retval = nntp_post(data->subject->data, data, text_buffer->data,
					   text_buffer->length, TRUE);
	}
	else {
		/* post any sfv files... */
		if (data->sfv != NULL) {
			file_data = file_entry_alloc(file_data);
			file_data->filename = 
				buff_create(file_data->filename, "%s", data->sfv->data);
			if (stat(data->sfv->data, &file_data->fileinfo) == -1)
				ui_sfv_gen_error(data->sfv->data, errno);
			else {
				retval = post_file(data, file_data, 1, 1,
						   "SFV File", data_buffer);
				if (retval < 0)
					return retval;

				unlink(data->sfv->data);
			}
			free(file_data);
		}

		number_of_files = slist_length(file_list);

		/* if there's a prefix, post that */
		if (data->prefix != NULL) {
			ui_posting_prefix_start(data->prefix->data);

			file_data = (file_entry *) file_list->data;
			number_of_parts = 
				get_number_of_encoded_parts(data, file_data);
			subject = make_subject(subject, data, 1 , number_of_files,
				     file_data->filename->data, 0 , number_of_parts,
				     "File");

			text_buffer = read_text_file(text_buffer, data->prefix->data);
			if (text_buffer != NULL) {
				retval = nntp_post(subject->data, data, text_buffer->data, 
						   text_buffer->length, TRUE);
				if (retval == POSTING_NOT_ALLOWED)
					return retval;
				else if (retval == POSTING_FAILED) {
					/* dont bother retrying...
					   who knows what's in that file */
					ui_posting_prefix_failed();
					retval = NORMAL;
				}
				else if (retval == NORMAL)
					ui_posting_prefix_done();
			}
			else
				ui_posting_prefix_failed();

			buff_free(subject);
		}
	
		/* post the files */
		i = 1;
		while (file_list != NULL) {

			file_data = (file_entry *) file_list->data;

			retval = post_file(data, file_data, i, number_of_files,
					   "File", data_buffer);
			if (retval < 0)
				return retval;

			i++;
			file_list = slist_next(file_list);
		}

		/* post any par files */
		i = 1;
		file_list = parfiles;
		number_of_files = slist_length(parfiles);
		while (file_list != NULL) {

			file_data = (file_entry *) file_list->data;

			retval = post_file(data, file_data, i, number_of_files,
					   "PAR File", data_buffer);
			if (retval < 0)
				return retval;

			unlink(file_data->filename->data);
			buff_free(file_data->filename);
			free(file_data);
			i++;
			file_list = slist_next(file_list);
		}
		slist_free(parfiles);
	}

	nntp_logoff();
	socket_close();
	
	free(data_buffer);
	buff_free(text_buffer);

	return retval;
}