Beispiel #1
0
APR_DECLARE_NONSTD(void) apr_terminate(void)
{
    APP_DATA *app_data;

    /* Get our instance data for shutting down. */
    if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
        return;

    /* Unregister the NLM. If it is not registered
        then just return. */
    if (unregister_NLM(app_data->gs_nlmhandle) != 0) {
        return;
    }

    /* apr_pool_terminate() is being called from the 
        library shutdown code since the memory resources
        belong to the library rather than the application */

    /* Just clean up the memory for the app that is going
        away. */
    netware_pool_proc_cleanup ();

#ifdef USE_WINSOCK
    UnregisterAppWithWinSock (app_data->gs_nlmhandle);
#endif
}
Beispiel #2
0
static int wsa_cleanup_with_handle (void *handle)
{
    APP_DATA *app_data;
    
    if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
        return APR_EGENERAL;

    return WSACleanupRTag(app_data->gs_startup_rtag);
}
Beispiel #3
0
void* getGlobalPool()
{
    APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);

    if (app_data) {
        return app_data->gPool;
    }

    return NULL;
}
Beispiel #4
0
int setGlobalPool(void *data)
{
    APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);

    NXLock(gLibLock);

    if (app_data && !app_data->gPool) {
        app_data->gPool = data;
    }

    NXUnlock(gLibLock);
    return 1;
}
Beispiel #5
0
int unregister_NLM(void *NLMHandle)
{
    APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);

    NXLock(gLibLock);
    if (app_data) {
        app_data->initialized = 0;
        NXUnlock(gLibLock);
        return 0;
    }
    NXUnlock(gLibLock);
    return 1;
}
int
on_screen_scroll(GtkAdjustment * adjustment, gpointer user_data)
{
    GtkAdjustment *adj = NULL;
    GtkWidget *w = NULL;
    AppData *app_data = get_app_data();
    ui_hide_arrows_if_exists(app_data->app_ui_data, FALSE);
    pdf_viewer_scroller_changed((PDFScroll) GPOINTER_TO_UINT(user_data));
   if ( display_mode ==1){
   	adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));
	if ( !adj) {
	/* Ignore when no document loaded */
	     if ( app_data->state == PDF_VIEWER_STATE_EMPTY ) {
		  ui_show_banner(GTK_WIDGET(app_data->app_ui_data->app_view),
						_("pdfv_ib_menu_not_available") );
            	  return TRUE;
             }
	     adj = gtk_layout_get_hadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));
         }
/* If scroll is far left/top or page fits to screen then try to move to previous page */
	 //g_print("adj->value %f",adj->value);
         if ( adj->upper <= adj->page_size || adj->value < 0.0001 ) {
              w = gtk_ui_manager_get_widget(app_data->app_ui_data->ui_manager,
					"/ToolBar/pdfv_me_menu_page_previous");
	      if ( (w != NULL) && (GTK_WIDGET_IS_SENSITIVE(w))) {	
		   pdf_viewer_navigate_page(pdf_viewer_get_current_page()-1);
                   ui_update_current_page(app_data->app_ui_data);
		   adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));	
		   gtk_adjustment_set_value(adj,adj->value + adj->upper - adj->page_size -0.0001);
	      } else {
			if ( pdf_viewer_get_current_page() == 1) {
                             ui_show_banner(GTK_WIDGET(app_data->app_ui_data->app_view),
                                           _("pdfv_ib_first_page_reached"));
                    	}
                 }
          return TRUE;
           }                   	
	 if ( adj->page_size < adj->upper &&adj->value < ( adj->upper - adj->page_size ) ) {
	      return TRUE;	       
	 } else {
		if ( pdf_viewer_get_num_pages() != pdf_viewer_get_current_page() ) {
	           pdf_viewer_navigate_page(pdf_viewer_get_current_page()+1);
                   ui_update_current_page(app_data->app_ui_data);
		   adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));	
		   gtk_adjustment_set_value(adj,adj->value + 0.0001);
		}
	   }	
         return TRUE;     
   }        
}
Beispiel #7
0
static int wsa_startup_with_handle (WORD wVersionRequested, LPWSADATA data, void *handle)
{
    APP_DATA *app_data;
    
    if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
        return APR_EGENERAL;

    app_data->gs_startup_rtag = AllocateResourceTag(handle, "WinSock Start-up", WS_LOAD_ENTRY_SIGNATURE);
    app_data->gs_socket_rtag  = AllocateResourceTag(handle, "WinSock socket()", WS_SKT_SIGNATURE);
    app_data->gs_lookup_rtag  = AllocateResourceTag(handle, "WinSock Look-up", WS_LOOKUP_SERVICE_SIGNATURE);
    app_data->gs_event_rtag   = AllocateResourceTag(handle, "WinSock Event", WS_WSAEVENT_SIGNATURE);
    app_data->gs_pcp_rtag     = AllocateResourceTag(handle, "WinSock C-Port", WS_CPORT_SIGNATURE);

    return WSAStartupRTags(wVersionRequested, data, 
                           app_data->gs_startup_rtag, 
                           app_data->gs_socket_rtag, 
                           app_data->gs_lookup_rtag, 
                           app_data->gs_event_rtag, 
                           app_data->gs_pcp_rtag);
}
Beispiel #8
0
int register_NLM(void *NLMHandle)
{
    APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);

    NXLock(gLibLock);
    if (!app_data) {
        app_data = (APP_DATA*)library_malloc(gLibHandle, sizeof(APP_DATA));

        if (app_data) {
            memset (app_data, 0, sizeof(APP_DATA));
            set_app_data(gLibId, app_data);
            app_data->gs_nlmhandle = NLMHandle;
        }
    }

    if (app_data && (!app_data->initialized)) {
        app_data->initialized = 1;
        NXUnlock(gLibLock);
        return 0;
    }

    NXUnlock(gLibLock);
    return 1;
}
Beispiel #9
0
int GetOrSetUpData(int id, libdata_t **appData,
                   libthreaddata_t **threadData )
{
  int                 err;
  libdata_t           *app_data;
  libthreaddata_t *thread_data;
  NXKey_t             key;
  NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);

  err         = 0;
  thread_data = (libthreaddata_t *) NULL;

/*
** Attempt to get our data for the application calling us. This is where we
** store whatever application-specific information we need to carry in support
** of calling applications.
*/
  app_data = (libdata_t *) get_app_data(id);

  if(!app_data) {
/*
** This application hasn't called us before; set up application AND per-thread
** data. Of course, just in case a thread from this same application is calling
** us simultaneously, we better lock our application data-creation mutex. We
** also need to recheck for data after we acquire the lock because WE might be
** that other thread that was too late to create the data and the first thread
** in will have created it.
*/
    NXLock(gLibLock);

    if(!(app_data = (libdata_t *) get_app_data(id))) {
      app_data = malloc(sizeof(libdata_t));

      if(app_data) {
        memset(app_data, 0, sizeof(libdata_t));

        app_data->tenbytes = malloc(10);
        app_data->lock     = NXMutexAlloc(0, 0, &liblock);

        if(!app_data->tenbytes || !app_data->lock) {
          if(app_data->lock)
            NXMutexFree(app_data->lock);

          free(app_data);
          app_data = (libdata_t *) NULL;
          err      = ENOMEM;
        }

        if(app_data) {
/*
** Here we burn in the application data that we were trying to get by calling
** get_app_data(). Next time we call the first function, we'll get this data
** we're just now setting. We also go on here to establish the per-thread data
** for the calling thread, something we'll have to do on each application
** thread the first time it calls us.
*/
          err = set_app_data(gLibId, app_data);

          if(err) {
            free(app_data);
            app_data = (libdata_t *) NULL;
            err      = ENOMEM;
          }
          else {
            /* create key for thread-specific data... */
            err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);

            if(err)                /* (no more keys left?) */
              key = -1;

            app_data->perthreadkey = key;
          }
        }
      }
    }

    NXUnlock(gLibLock);
  }

  if(app_data) {
    key = app_data->perthreadkey;

    if(key != -1 /* couldn't create a key? no thread data */
        && !(err = NXKeyGetValue(key, (void **) &thread_data))
        && !thread_data) {
/*
** Allocate the per-thread data for the calling thread. Regardless of whether
** there was already application data or not, this may be the first call by a
** a new thread. The fact that we allocation 20 bytes on a pointer is not very
** important, this just helps to demonstrate that we can have arbitrarily
** complex per-thread data.
*/
      thread_data = malloc(sizeof(libthreaddata_t));

      if(thread_data) {
        thread_data->_errno      = 0;
        thread_data->twentybytes = malloc(20);

        if(!thread_data->twentybytes) {
          free(thread_data);
          thread_data = (libthreaddata_t *) NULL;
          err         = ENOMEM;
        }

        if((err = NXKeySetValue(key, thread_data))) {
          free(thread_data->twentybytes);
          free(thread_data);
          thread_data = (libthreaddata_t *) NULL;
        }
      }
    }
  }

  if(appData)
    *appData = app_data;

  if(threadData)
    *threadData = thread_data;

  return err;
}
Beispiel #10
0
int dcbx_clif_cmd(UNUSED void *data,
		  UNUSED struct sockaddr_un *from,
		  UNUSED socklen_t fromlen,
		  char *ibuf, int ilen,
		  char *rbuf, int rlen)
{
	u8 status = cmd_success;
	u8 cmd;
	u8 feature;
	u8 subtype;
	u8 plen;
	char port_id[MAX_U8_BUF];
	pg_attribs pg_data;
	pfc_attribs pfc_data;
	app_attribs app_data;
	llink_attribs llink_data;
	struct dcbx_tlvs *dcbx;
	int dcb_enable;

	if (hexstr2bin(ibuf+DCB_CMD_OFF, &cmd, sizeof(cmd)) ||
		hexstr2bin(ibuf+DCB_FEATURE_OFF, &feature, sizeof(feature)))
		return cmd_invalid;

	if (feature == FEATURE_DCBX)
		return handle_dcbx_cmd(cmd, feature, ibuf, ilen, rbuf);

	if (hexstr2bin(ibuf+DCB_SUBTYPE_OFF, &subtype, sizeof(subtype)) ||
		hexstr2bin(ibuf+DCB_PORTLEN_OFF, &plen, sizeof(plen)))
		return cmd_invalid;

	if (ilen < DCB_PORT_OFF)
		return cmd_invalid;
	
	if (ibuf[DCB_VER_OFF] < (CLIF_DCBMSG_VERSION | 0x30)) {
		printf("unsupported client interface message version %x %x\n",
			ibuf[DCB_VER_OFF], CLIF_DCBMSG_VERSION | 0x30);
		return cmd_ctrl_vers_not_compatible;
	}

	if (ilen < DCB_PORT_OFF+plen) {
		printf("command too short\n");
		return cmd_invalid;
	}

	/* append standard dcb command response content */
	snprintf(rbuf , rlen, "%*.*s",
		 DCB_PORT_OFF+plen, DCB_PORT_OFF+plen, ibuf);

	memcpy(port_id, ibuf+DCB_PORT_OFF, plen);
	port_id[plen] = '\0';

	if (get_hw_state(port_id, &dcb_enable) < 0)
		return cmd_not_capable;

	dcbx = dcbx_data(port_id);
	/* OPER and PEER cmd not applicable while in IEEE-DCBX modes */
	if ((!dcbx || dcbx->active == 0) &&
	    (cmd == CMD_GET_PEER || cmd == CMD_GET_OPER))
		return cmd_not_applicable;

	switch(feature) {
	case FEATURE_DCB:
		if (cmd == CMD_SET_CONFIG)
			status = set_dcb_state(port_id, ibuf, ilen);
		else if (cmd == CMD_GET_CONFIG)
			status = get_dcb_state(port_id, rbuf+strlen(rbuf));
		else
			status = cmd_invalid;
		break;

	case FEATURE_PG:
		if (cmd == CMD_GET_PEER) {
			status = get_peer_pg(port_id, &pg_data);
		} else {
			status = get_pg(port_id, &pg_data);
		}

		if (status != cmd_success) {
			printf("error[%d] getting PG data for %s\n",
				status, port_id);
			return status;
		}

		if (cmd == CMD_SET_CONFIG) {
			if (ilen < (DCB_PORT_OFF + plen + CFG_LEN)) {
				printf("set command too short\n");
				status = cmd_invalid;
			} else {
				set_protocol_data(&pg_data.protocol, port_id,
						  ibuf, plen, NEAREST_BRIDGE);
				status = set_pg_config(&pg_data, port_id, ibuf,
					ilen);
			}
		} else {
			status = get_cmd_protocol_data(&pg_data.protocol, cmd,
					rbuf+strlen(rbuf));
			if (status == cmd_success)
				status = get_pg_data(&pg_data, cmd, port_id,
					pg_data.protocol.dcbx_st,
					rbuf+strlen(rbuf));
		}
		break;

	case FEATURE_PFC:
		if (cmd == CMD_GET_PEER) {
			status = get_peer_pfc(port_id, &pfc_data);
		} else {
			status = get_pfc(port_id, &pfc_data);
		}

		if (status != cmd_success) {
			printf("error[%d] getting PFC data for %s\n",
					status, port_id);
			return status;
		}

		if (cmd == CMD_SET_CONFIG) {
			if (ilen < (DCB_PORT_OFF + plen + CFG_LEN)) {
				printf("set command too short\n");
				status = cmd_failed;
			} else {
				set_protocol_data(&pfc_data.protocol, port_id,
						  ibuf, plen, NEAREST_BRIDGE);
				status = set_pfc_config(&pfc_data, port_id,
					ibuf, ilen);
			}
		} else {
			status = get_cmd_protocol_data(&pfc_data.protocol,
				cmd, rbuf+strlen(rbuf));
			if (status == cmd_success)
				status = get_pfc_data(&pfc_data, cmd,
					port_id, pfc_data.protocol.dcbx_st,
					rbuf+strlen(rbuf));
		}
		break;


	case FEATURE_APP:
		if (cmd == CMD_GET_PEER) {
			status = get_peer_app(port_id, (u32)subtype, &app_data);
		} else {
			status = get_app(port_id, (u32)subtype, &app_data);
		}

		if (status != cmd_success) {
			printf("error[%d] getting APP data for %s\n", status,
				port_id);
			return status;
		}

		if (cmd == CMD_SET_CONFIG) {
			if (ilen < (DCB_PORT_OFF + plen + CFG_LEN)) {
				printf("set command too short\n");
				status = cmd_failed;
			} else {
				set_app_protocol_data(port_id, ibuf, plen, ilen,
						      subtype, NEAREST_BRIDGE);
			}
		} else {
			status = get_cmd_protocol_data(&app_data.protocol, cmd,
				rbuf+strlen(rbuf));
			if (status == cmd_success)
				status = get_app_data(&app_data, cmd, port_id,
					subtype, rbuf + strlen(rbuf));
		}
		break;

	case FEATURE_LLINK:
		if (cmd == CMD_GET_PEER) {
			status = get_peer_llink(port_id, (u32)subtype,
				&llink_data);
		} else {
			status = get_llink(port_id, (u32)subtype, &llink_data);
		}

		if (status != cmd_success) {
			printf("error[%d] getting APP data for %s\n", status,
				port_id);
			return status;
		}

		if (cmd == CMD_SET_CONFIG) {
			if (ilen < (DCB_PORT_OFF + plen + CFG_LEN)) {
				printf("set command too short\n");
				status = cmd_failed;
			} else {
				set_protocol_data(&llink_data.protocol, port_id,
						  ibuf, plen, NEAREST_BRIDGE);
				status = set_llink_config(&llink_data, port_id,
					(u32)subtype, ibuf, ilen);
			}
		} else {
			status = get_cmd_protocol_data(&llink_data.protocol,
				cmd, rbuf+strlen(rbuf));
			if (status == cmd_success)
				status = get_llink_data(&llink_data, cmd,
					port_id, subtype, rbuf + strlen(rbuf));
		}
		break;

	case FEATURE_PG_DESC:
		if (cmd == CMD_GET_CONFIG) {
			status = get_bwg_desc(port_id, ibuf, ilen,
					      rbuf+strlen(rbuf));

			if (status != cmd_success) {
				printf("error[%d] getting BWG desc for %s\n",
					status, port_id);
				return status;
			}
		} else if (cmd == CMD_SET_CONFIG) {
			status = set_bwg_desc(port_id, ibuf, ilen);
		}

		break;
	default:
		break;
	}

	return status;
}
Beispiel #11
0
int8_t process_msc_setup_request(const struct setup_packet *setup)
{
	uint8_t interface = setup->wIndex;
	struct msc_application_data *msc;


#ifdef MULTI_CLASS_DEVICE
	/* Check the interface first to make sure the destination is an
	 * MSC interface. Multi-class devices will need to call
	 * msc_set_interface_list() first.
	 */
	if (!interface_is_msc(interface))
		return -1;
#endif

	/* Get application data for this interface */
	msc = get_app_data(interface);
	if (!msc)
		return -1;

	/* BOT 3.2 says the GET_MAX_LUN request is optional if there's only one
	 * LUN, but stalling this request will cause Windows 7 to hang for 18
	 * seconds when a device is first connected. */
	if (setup->bRequest == MSC_GET_MAX_LUN &&
	    setup->REQUEST.bmRequestType == 0xa1) {

		/* Stall invalid value/length */
		if (setup->wValue != 0 ||
		    setup->wLength != 1)
			return -1;

		usb_send_data_stage((void*)&msc->max_lun,
		                    1, NULL, 0);
		return 0;
	}

	if (setup->bRequest == MSC_BULK_ONLY_MASS_STORAGE_RESET &&
	    setup->REQUEST.bmRequestType == 0x21) {
		struct msc_application_data *d = get_app_data(interface);

		/* Stall invalid value/length */
		if (setup->wValue != 0 ||
		    setup->wLength != 0)
			return -1;

		if (d)
			d->state = MSC_IDLE;
		else
			return -1;

#ifdef MSC_BULK_ONLY_MASS_STORAGE_RESET_CALLBACK
		int8_t res = 0;

		res = MSC_BULK_ONLY_MASS_STORAGE_RESET_CALLBACK(interface);
		if (res < 0)
			return -1;
#endif
		/* Clear the NEEDS_RESET_RECOVERY state */
		msc->state = MSC_IDLE;

		/* Return zero-length packet. No data stage. */
		usb_send_data_stage(NULL, 0, NULL, NULL);

		return 0;
	}
	return -1;
}