Announcement

Collapse
No announcement yet.

Need help porting a couple of C functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help porting a couple of C functions

    I've been porting two C apps into PB but now I'm stuck.
    It's a client application that talks to a server and the
    data sent is encoded.

    I've managed to port most of it but I'm a bit stuck now, so hopefully someone
    has the time and is willing to help me out.

    If you need more info or code on what it does in order to help
    me port this, just say so and I'll try to explain.

    First part:
    Code:
    path_to_hldir (const char *path, u_int16_t *hldirlen, int is_file)
    {
    	u_int8_t *hldir;
    	struct x_fhdr *fh;
    	char const *p, *p2;
    	u_int16_t pos = 2, dc = 0;
    	u_int8_t nlen;
    
    	hldir = xmalloc(2);
    	p = path;
    	while ((p2 = strchr(p, dir_char))) {
    		if (!(p2 - p)) {
    			p++;
    			continue;
    		}
    		nlen = (u_int8_t)(p2 - p);
    		pos += 3 + nlen;
    		hldir = xrealloc(hldir, pos);
    		fh = (struct x_fhdr *)(&(hldir[pos - (3 + nlen)]));
    		memset(&fh->enc, 0, 2);
    		fh->len = nlen;
    		memcpy(fh->name, p, nlen);
    		dc++;
    		p = p2 + 1;
    	}
    	if (!is_file && *p) {
    		nlen = (u_int8_t)strlen(p);
    		pos += 3 + nlen;
    		hldir = xrealloc(hldir, pos);
    		fh = (struct x_fhdr *)(&(hldir[pos - (3 + nlen)]));
    		memset(&fh->enc, 0, 2);
    		fh->len = nlen;
    		memcpy(fh->name, p, nlen);
    		dc++;
    	}
    	*((u_int16_t *)hldir) = htons(dc);
    
    	*hldirlen = pos;
    	return hldir;
    }
    And here's the second part:
    Code:
    void
    hx_tnews_list (struct htlc_conn *htlc, const char *path, int is_cat)
    {
    	u_int8_t *hldir;
    	u_int16_t hldirlen;
    	u_int32_t type;
    	void (*tfn)();
    
    	if (!htlc->fd)
    		return;
    	if (is_cat) {
    		type = HTLC_HDR_NEWS_LISTCATEGORY;
    		tfn = rcv_task_tnews_listcat;
    	} else {
    		type = HTLC_HDR_NEWS_LISTDIR;
    		tfn = rcv_task_tnews_list;
    	}
    	task_new(htlc, tfn, 0, 0, "tnews_list");
    	if (!strcmp(path, "/"))
    		hlwrite(htlc, type, 0, 0);
    	else {
    		hldir = path_to_hldir(path, &hldirlen, 0);
    		hlwrite(htlc, type, 0, 1,
    			HTLC_DATA_NEWS_DIR, hldirlen, hldir);
    		xfree(hldir);
    	}
    }
    ------------------

  • #2
    I think you'll need to look at the headers or the first part of
    the code to find out what those variable types are. They are not
    ANSI standard variable types and should be defined in code above
    the point where they are used.
    This is what I'm guessing:
    u_in8_t is an unsigned 8-bit char value.
    u_int16_t is an unsigned short. (like int, but always 16-bit)
    u_int32_t is an unsigned 32-bit long.
    struct x_fhdr is a structure defined above in the C source.
    void (*tfn)(); I believe that to be a function pointer, though
    I've never had the occasion to use them.
    Are there any specific bits that don't immediately come clear?

    ]<urt


    ------------------
    The world is strange and wonderful.*
    I reserve the right to be horrifically wrong.
    Please maintain a safe following distance.
    *wonderful sold separately.

    Comment


    • #3
      Hi, Dennis.

      If you want, send me what you've got, and I'll see if I can help
      you sort it out.


      ------------------
      Scott Martindale
      [email protected]
      Scott Martindale
      [email protected]

      Comment

      Working...
      X