NET_StreamClass * OLE_ViewStream(int format_out, void *pDataObj, URL_Struct *urls, MWContext *pContext) { NET_StreamClass *stream = nil, *viewstream; char *org_content_type; if (!(stream = XP_NEW_ZAP(NET_StreamClass))) { XP_TRACE(("OLE_ViewStream memory lossage")); return 0; } stream->name = "ole viewer"; stream->complete = ole_view_complete; stream->abort = ole_view_abort; stream->is_write_ready = ole_view_write_ready; stream->data_object = NULL; stream->window_id = pContext; stream->put_block = (MKStreamWriteFunc)ole_view_write; org_content_type = urls->content_type; urls->content_type = 0; StrAllocCopy(urls->content_type, TEXT_HTML); urls->is_binary = 1; /* secret flag for mail-to save as */ if((viewstream=NET_StreamBuilder(format_out, urls, pContext)) != 0) { char *buffer = (char*) XP_ALLOC(XP_STRLEN(fakehtml) + XP_STRLEN(urls->address) + 1); if (buffer) { XP_SPRINTF(buffer, fakehtml, urls->address); (*viewstream->put_block)(viewstream, buffer, XP_STRLEN(buffer)); (*viewstream->complete)(viewstream); XP_FREE(buffer); } } /* XXX hack alert - this has to be set back for abort to work correctly */ XP_FREE(urls->content_type); urls->content_type = org_content_type; return stream; }
static const char* xfe_netcaster_url(void) /* * returns: * On success returns a file URL pointing to tab.html * On failure returns NULL * ****************************************/ { const char * result = NULL; if (!private_xfe_netcaster_url) { private_xfe_netcaster_url = (char*)XP_ALLOC(MAXPATHLEN); if (private_xfe_netcaster_url) private_xfe_netcaster_url[0] = '\0'; else return result; } if (private_xfe_netcaster_url[0]) { result = private_xfe_netcaster_url; } else { const char * path; path = xfe_netcaster_path(); if (path) { XP_SPRINTF(private_xfe_netcaster_url,"file:%s",path); result = private_xfe_netcaster_url; } else private_xfe_netcaster_url[0] = '\0'; } return result; }
VR_INTERFACE(REGERR) VR_SetRefCount(char *component_path, int refcount) { REGERR err; RKEY rootKey; RKEY key = 0; char rcstr[MAXREGNAMELEN]; err = vr_Init(); if (err != REGERR_OK) return err; /* Use curver if path is relative */ rootKey = PATH_ROOT(component_path); /* Make sure path components (keys) exist by calling Add */ /* (special "" component must always exist, and Add fails) */ if ( component_path != NULL && *component_path == '\0' ) { err = REGERR_PARAM; } else { err = NR_RegAddKey( vreg, rootKey, component_path, &key ); } if (err != REGERR_OK) return err; *rcstr = '\0'; /* itoa(refcount, rcstr, 10); */ XP_SPRINTF(rcstr, "%d", refcount); if ( rcstr != NULL && *rcstr != '\0' ) { /* Add "RefCount" */ err = NR_RegSetEntryString( vreg, key, REFCSTR, rcstr ); } return err; } /* SetRefCount */
/* * Creates an LDAP search URL given a comma-separated list of attributes. * Returns a list of key=values separated by '\n' */ char * pref_get_ldap_attributes(char* host, char* base, char* filter, char* attrs, char** return_error) { char *value = NULL; LDAP* ld; int err, i; char *url; LDAPMessage *result; LDAPMessage *e; char *a; BerElement *ber; char **vals; ld = ldap_init(host, LDAP_PORT); if (!ld) return value; url = (char*) malloc(sizeof(char) * (strlen(host) + strlen(base) + strlen(filter) + strlen(attrs) + 20)); if (!url) return value; XP_SPRINTF(url, "ldap://%s/%s?%s?sub?%s", host, base, attrs, filter); err = ldap_url_search_s( ld, url, 0, &result ); XP_FREE(url); if (err != LDAP_SUCCESS) { *return_error = ldap_err2string(err); return value; } e = ldap_first_entry( ld, result ); if (e) { a = ldap_first_attribute( ld, e, &ber ); if (a) { int total_buf_size = 200; int remaining_buf_size = total_buf_size; value = (char*) malloc(sizeof(char*) * total_buf_size); if (!value) return NULL; value[0] = '\0'; for ( ; a != NULL; a = ldap_next_attribute( ld, e, ber )) { vals = ldap_get_values( ld, e, a ); if (vals && vals[0]) { remaining_buf_size -= (strlen(a) + strlen(vals[0]) + 2); if (remaining_buf_size < 1) { remaining_buf_size += 2 * total_buf_size; total_buf_size += 2 * total_buf_size; value = (char*) realloc(value, sizeof(char*) * total_buf_size); if (!value) return NULL; } strcat(value, "\n"); strcat(value, a); strcat(value, "="); strcat(value, vals[0]); ldap_value_free( vals ); } } ldap_memfree(a); } if (ber) ber_free(ber, 0); } ldap_msgfree(result); ldap_unbind(ld); return value; }
NET_StreamClass * IL_ViewStream(FO_Present_Types format_out, void *newshack, URL_Struct *urls, OPAQUE_CONTEXT *cx) { IL_Stream *stream = nil, *viewstream; il_container *ic = nil; char *org_content_type; char *image_url; /* multi-part reconnect hack */ ic = (il_container*)urls->fe_data; if(ic && ic->multi) { return IL_NewStream(format_out, IL_UNKNOWN, urls, cx); } /* Create stream object */ if (!(stream = XP_NEW_ZAP(NET_StreamClass))) { XP_TRACE(("il: IL_ViewStream memory lossage")); return 0; } stream->name = "image view"; stream->complete = il_view_complete; stream->abort = il_view_abort; stream->is_write_ready = il_view_write_ready; stream->data_object = NULL; stream->window_id = cx; stream->put_block = (MKStreamWriteFunc)il_view_write; ILTRACE(0,("il: new view stream, %s", urls->address)); XP_ASSERT(!unconnected_stream); unconnected_stream = stream; unconnected_urls = urls; if(!newshack) { char *buffer; org_content_type = urls->content_type; urls->content_type = 0; StrAllocCopy(urls->content_type, TEXT_HTML); urls->is_binary = 1; /* secret flag for mail-to save as */ /* Force layout to discard the old document and start a new one. We do this so that the pre-fetched image request won't be destroyed by a layout call to IL_DestroyImageGroup. */ viewstream = NET_StreamBuilder(format_out, urls, cx); if (!viewstream) { XP_FREE(stream); return NULL; } buffer = XP_STRDUP("<HTML>"); if (!buffer) { XP_FREE(stream); XP_FREE(viewstream); return NULL; } (*viewstream->put_block)(viewstream, buffer, XP_STRLEN(buffer)+1); XP_FREE(buffer); } /* !newshack */ /* Prefetch the image. We do this so that the image library can process image data even if the parser is blocked on the fake IMG tag that we send. Note that this image request will persist until the document is destroyed (when IL_DestroyImageGroup will be called.) */ image_url = (char*) XP_ALLOC(XP_STRLEN(urls->address) + 29); if (!image_url) { XP_FREE(stream); XP_FREE(viewstream); return NULL; } XP_SPRINTF(image_url, "internal-external-reconnect:%s", urls->address); if (!il_load_image(cx, image_url, urls->force_reload)) { XP_FREE(stream); XP_FREE(viewstream); return NULL; } XP_FREE(image_url); if (!newshack) { if (viewstream) { char *buffer = (char*) XP_ALLOC(XP_STRLEN(fakehtml) + XP_STRLEN(urls->address) + 1); if (buffer) { XP_SPRINTF(buffer, fakehtml, urls->address); (*viewstream->put_block)(viewstream, buffer, XP_STRLEN(buffer)); XP_FREE(buffer); } (*viewstream->complete)(viewstream); } /* this has to be set back for abort to work correctly */ XP_FREE(urls->content_type); urls->content_type = org_content_type; } /* !newshack */ return stream; }
PRIVATE int net_ColorHTMLWrite (NET_StreamClass *stream, CONST char *s, int32 l) { int32 i; int32 last_output_point; char *new_markup=0; char *tmp_markup=0; char tiny_buf[4]; CONST char *cp; int status; DataObject *obj=stream->data_object; last_output_point = 0; for(i = 0, cp = s; i < l; i++, cp++) { switch(obj->state) { case IN_CONTENT: /* do nothing until you find a '<' "<!--" or '&' */ if(*cp == '<') { /* XXX we can miss a comment spanning a block boundary */ if(i+4 <= l && !XP_STRNCMP(cp, "<!--", 4)) { StrAllocCopy(new_markup, BEGIN_COMMENT_MARKUP); StrAllocCat(new_markup, "<"); obj->state = IN_COMMENT; } else { new_markup = net_BeginColorHTMLTag(obj); } } else if(*cp == '&') { StrAllocCopy(new_markup, BEGIN_AMPERSAND_THINGY_MARKUP); StrAllocCat(new_markup, "&"); obj->state = IN_AMPERSAND_THINGY; } break; case IN_SCRIPT: /* do nothing until you find '</SCRIPT>' */ if(*cp == '<') { /* XXX we can miss a </SCRIPT> spanning a block boundary */ if(i+8 <= l && !XP_STRNCASECMP(cp, "</SCRIPT", 8)) { new_markup = net_BeginColorHTMLTag(obj); } } break; case ABOUT_TO_BEGIN_TAG: /* we have seen the first '<' * once we see a non-whitespace character * we will be in the tag identifier */ if(*cp == '>') { StrAllocCopy(new_markup, END_TAG_NAME_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(!XP_IS_SPACE(*cp)) { obj->state = IN_BEGIN_TAG; obj->tag_index = 0; obj->tag[obj->tag_index++] = *cp; if(*cp == '<') StrAllocCopy(new_markup, "<"); } break; case IN_BEGIN_TAG: /* go to the IN_TAG state when we see * the first whitespace */ if(XP_IS_SPACE(*cp)) { StrAllocCopy(new_markup, END_TAG_NAME_MARKUP); XP_SPRINTF(tiny_buf, "%c", *cp); StrAllocCat(new_markup, tiny_buf); obj->state = IN_TAG; obj->tag[obj->tag_index] = '\0'; obj->tag_type = pa_tokenize_tag(obj->tag); } else if(*cp == '>') { StrAllocCopy(new_markup, END_TAG_NAME_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(*cp == '<') { /* protect ourselves from markup */ if(!obj->in_broken_html) { obj->in_broken_html = TRUE; StrAllocCopy(new_markup, BEGIN_BROKEN_ATTRIBUTE_MARKUP); StrAllocCat(new_markup, "<"); } else { StrAllocCopy(new_markup, "<"); } } else { if (obj->tag_index < MAXTAGLEN) obj->tag[obj->tag_index++] = *cp; } break; case IN_TAG: /* do nothing until you find a opening '=' or end '>' */ if(*cp == '=') { StrAllocCopy(new_markup, "="); StrAllocCat(new_markup, BEGIN_ATTRIBUTE_VALUE_MARKUP); obj->state = BEGIN_ATTRIBUTE_VALUE; } else if(*cp == '>') { new_markup = net_EndColorHTMLTag(obj); } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; case BEGIN_ATTRIBUTE_VALUE: /* when we reach the first non-whitespace * we will enter the UNQUOTED or the QUOTED * ATTRIBUTE state */ if(!XP_IS_SPACE(*cp)) { if(*cp == '"') { obj->state = IN_QUOTED_ATTRIBUTE_VALUE; /* no need to jump to the quoted attr handler * since this char can't be a dangerous char */ } else { obj->state = IN_UNQUOTED_ATTRIBUTE_VALUE; /* need to jump to the unquoted attr handler * since this char can be a dangerous character */ goto unquoted_attribute_jump_point; } } else if(*cp == '>') { StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; case IN_UNQUOTED_ATTRIBUTE_VALUE: unquoted_attribute_jump_point: /* do nothing until you find a whitespace */ if(XP_IS_SPACE(*cp)) { StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP); XP_SPRINTF(tiny_buf, "%c", *cp); StrAllocCat(new_markup, tiny_buf); obj->state = IN_TAG; } else if(*cp == '>') { StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } else if(*cp == '&') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "&"); } break; case IN_QUOTED_ATTRIBUTE_VALUE: /* do nothing until you find a closing '"' */ if(*cp == '\"') { if(obj->in_broken_html) { StrAllocCopy(new_markup, END_BROKEN_ATTRIBUTE_MARKUP); obj->in_broken_html = FALSE; } StrAllocCat(new_markup, "\""); StrAllocCat(new_markup, END_ATTRIBUTE_VALUE_MARKUP); obj->state = IN_TAG; } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } else if(*cp == '&') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "&"); } else if(*cp == '>') { /* probably a broken attribute value */ if(!obj->in_broken_html) { obj->in_broken_html = TRUE; StrAllocCopy(new_markup, BEGIN_BROKEN_ATTRIBUTE_MARKUP); StrAllocCat(new_markup, ">"); } } break; case IN_COMMENT: /* do nothing until you find a closing '-->' */ if(!XP_STRNCMP(cp, "-->", 3)) { StrAllocCopy(new_markup, ">"); cp += 2; i += 2; StrAllocCat(new_markup, END_COMMENT_MARKUP); obj->state = IN_CONTENT; } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; case IN_AMPERSAND_THINGY: /* do nothing until you find a ';' or space */ if(*cp == ';' || XP_IS_SPACE(*cp)) { XP_SPRINTF(tiny_buf, "%c", *cp); StrAllocCopy(new_markup, tiny_buf); StrAllocCat(new_markup, END_AMPERSAND_THINGY_MARKUP); obj->state = IN_CONTENT; } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; default: XP_ASSERT(0); break; } if(new_markup) { /* push all the way up to but not including *cp */ status = (*obj->next_stream->put_block) (obj->next_stream, &s[last_output_point], i-last_output_point); last_output_point = i+1; if(status < 0) { FREE(new_markup); return(status); } /* add new markup */ status = (*obj->next_stream->put_block) (obj->next_stream, new_markup, XP_STRLEN(new_markup)); if(status < 0) { FREE(new_markup); return(status); } FREE_AND_CLEAR(new_markup); } } if(last_output_point < l) return((*obj->next_stream->put_block)(obj->next_stream, &s[last_output_point], (l-last_output_point))); else return(0); }
char * xp_TempName (XP_FileType type, const char * prefix, char* buf, char* buf2, unsigned int *count) { #define NS_BUFFER_SIZE 1024 char *value = buf; time_t now; *buf = 0; XP_ASSERT (type != xpTemporaryNewsRC); if (type == xpCache || type == xpSARCache) { /* WH_TempName() must return relative pathnames for the cache files, so that relative paths get written into the cacheFAT database, making the directory relocatable. */ *buf = 0; } else if ( (type == xpURL) && prefix ) { if ( XP_STRRCHR(prefix, '/') ) { XP_StatStruct st; XP_SPRINTF (buf, "%.500s", prefix); if (XP_Stat (buf, &st, xpURL)) XP_MakeDirectoryR (buf, xpURL); prefix = "su"; } } else { char *tmp = FE_TempDir; if (!tmp || !*tmp) tmp = "/tmp"; XP_SPRINTF (buf, "%.500s", tmp); if (!prefix || !*prefix) prefix = "tmp"; } XP_ASSERT (!XP_STRCHR (prefix, '/')); if (*buf && buf[XP_STRLEN (buf)-1] != '/') XP_STRCAT (buf, "/"); /* It's good to have the cache file names be pretty long, with a bunch of inputs; this makes the variant part be 15 chars long, consisting of the current time (in seconds) followed by a counter (to differentiate documents opened in the same second) followed by the current pid (to differentiate simultanious processes.) This organization of the bits has the effect that they are ordered the same lexicographically as by creation time. If name length was an issue we could cut the character count a lot by printing them in base 72 [A-Za-z0-9@%-_=+.,~:]. */ now = time ((time_t *) 0); sprintf (buf2, "%08X%03X%04X", (unsigned int) now, (unsigned int) *count, (unsigned int) (getpid () & 0xFFFF)); if (++(*count) > 4095) (*count) = 0; /* keep it 3 hex digits */ #ifdef CACHE_SUBDIRS if (type == xpCache || type == xpSARCache) { XP_StatStruct st; char *s; char *tmp = (type == xpCache) ? FE_CacheDir : FE_SARCacheDir; if (!tmp || !*tmp) tmp = "/tmp"; sprintf (buf, "%.500s", tmp); if (buf [XP_STRLEN(buf)-1] != '/') XP_STRCAT (buf, "/"); s = buf + XP_STRLEN (buf); value = s; /* return a relative path! */ /* The name of the subdirectory is the bottom 5 bits of the time part, in hex (giving a total of 32 directories.) */ sprintf (s, "%02X", (now & 0x1F)); if (XP_Stat (buf, &st, xpURL)) /* create the dir if necessary */ XP_MakeDirectory (buf, type); s[2] = '/'; s[3] = 0; } #endif /* !CACHE_SUBDIRS */ XP_STRNCAT (value, prefix, NS_BUFFER_SIZE - XP_STRLEN(value)); XP_STRNCAT (value, buf2, NS_BUFFER_SIZE - XP_STRLEN(value)); /* Tao */ if (type == xpAddrBook) { XP_STRNCAT (value, ".nab", NS_BUFFER_SIZE - XP_STRLEN(value)); }/* if */ value[NS_BUFFER_SIZE - 1] = '\0'; /* just in case */ DO_TRACE(("WH_TempName called: returning: %s", value)); return(value); }
void XFE_FrameListMenu::cascading() { XP_List * frame_list = getShownFrames(); XFE_Frame * frame; int i; int frame_count = XP_ListCount(frame_list); Cardinal num_children; WidgetList children; int total_slots_needed; int slots_to_add; int count; XfeChildrenGet(m_submenu,&children,&num_children); XP_ASSERT( num_children > 1 ); // Total number of slots needed total_slots_needed = m_firstslot + 1 + frame_count; // Number of slots to add slots_to_add = total_slots_needed - num_children; // Add more slots if needed if (slots_to_add > 0) { for (i = 0; i < slots_to_add; i++) { Widget item = XtVaCreateWidget(xfeCmdFrameListRaiseItem, //xmToggleButtonGadgetClass, xmPushButtonGadgetClass, m_submenu, NULL); XtAddCallback(item, XmNactivateCallback, //XmNvalueChangedCallback, &XFE_FrameListMenu::item_activate_cb, (XtPointer) this); } // Update num_slots, since we added stuff XfeChildrenGet(m_submenu,&children,&num_children); } count = 1; // Configure the items for (i = (int) m_firstslot + 1; i < (int) num_children; i++) { // Get the next frame frame = (XFE_Frame*) XP_ListNextObject(frame_list); // If the frame is valid, add its title to the slot buttons if (frame) { MWContext * context = m_parentFrame->getContext(); INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(context); XmFontList font_list; char name[1024]; XP_SPRINTF(name,"%d. %s",count++,frame->getTitle()); INTL_MidTruncateString(INTL_GetCSIWinCSID(c), name, name, MAX_ITEM_WIDTH); XmString label = fe_ConvertToXmString((unsigned char *) name, INTL_GetCSIWinCSID(c), NULL, XmFONT_IS_FONT, &font_list); if (label) { XtVaSetValues(children[i],XmNlabelString,label,NULL); XmStringFree(label); } XtManageChild(children[i]); } // If the frame is not valid, the unmanage the slot button else { XtUnmanageChild(children[i]); } } // Update the display so that the gadget buttons get drawn XmUpdateDisplay(m_submenu); if (frame_list) { XP_ListDestroy(frame_list); } }